Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LayoutFactory can be presented with empty source file #22995

Closed
skpandey91 opened this issue Aug 18, 2020 · 0 comments
Closed

LayoutFactory can be presented with empty source file #22995

skpandey91 opened this issue Aug 18, 2020 · 0 comments
Assignees
Labels
type: bug A general bug
Milestone

Comments

@skpandey91
Copy link

skpandey91 commented Aug 18, 2020

I am migrating from spring boot 2.2.4 to 2.3.0.
We have written our custom layout factory and we are repackaging the jar through spring boot maven plugin.
But we started failing when migrated to spring boot 2.3.0 version. Everything works fine when we lower down the version from 2.3.0.
Before returning Module we are just verifying the content of the source jar. Earlier we were able to verify the resources but now the source jar is empty.

public class ModuleLayoutFactory implements LayoutFactory {

	@Override
	public Layout getLayout(File file) {

		System.out.println("file path is " + file.getAbsolutePath() + "file Size" + file.length());
		checkJarHasModuleConfigEntryWithLabelName(file);

		return new Module();
	}

	/**
	 * verify if module has a configuration file with the label name which defines the module.
	 * @param file the jar file of the module
	 */
	private void checkJarHasModuleConfigEntryWithLabelName(File file) {

		try(InputStream in = Files.newInputStream(file.toPath());
			JarInputStream jarInputStream = new JarInputStream(in)) {
			boolean hasConfig = false;
			JarEntry jarEntry;
			while ((jarEntry = jarInputStream.getNextJarEntry()) != null) {
				if (jarEntry.getName()
					.equals("MODULE-INF/module-properties.yaml")) {
					try(InputStreamReader reader = new InputStreamReader(jarInputStream, StandardCharsets.UTF_8);
						BufferedReader buffer = new BufferedReader(reader);) {
						if (buffer.lines()
							.noneMatch(line -> line.startsWith("  name: "))) {
							throw new IllegalArgumentException("Module does not contain a name tag in MODULE-INF/module-properties.yaml");
						}
					}
					hasConfig = true;
					break;
				}
			}
			if (!hasConfig) {
				throw new IllegalArgumentException("Configuration file module-properties.yaml could not be found under MODULE-INF/");
			}
		}
		catch (IOException e) {
			throw new UncheckedIOException(String.format(
				"Cannot read jar '%s': %s", file, e), e);
		}
	}

}

Below is the sample example
https://github.com/skpandey91/sample

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Aug 18, 2020
@philwebb philwebb changed the title Spring boot maven plugin 2.3.0 is not loading the resource folder in jar LayoutFactory can be presented with 0 byte source file Aug 18, 2020
@philwebb philwebb changed the title LayoutFactory can be presented with 0 byte source file LayoutFactory can be presented with empty source file Aug 18, 2020
@philwebb philwebb added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Aug 18, 2020
@philwebb philwebb added this to the 2.3.4 milestone Aug 18, 2020
@philwebb philwebb self-assigned this Aug 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

No branches or pull requests

3 participants