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