Fix packager code to generate layer index file

Update `Packager` to create the layer index file when repackaging.

Closes gh-19767
This commit is contained in:
Phillip Webb
2020-01-21 23:26:19 -08:00
parent bfd2ca7fd9
commit 7d8f8d47c8
2 changed files with 27 additions and 9 deletions

View File

@@ -159,6 +159,7 @@ public abstract class Packager {
writeLoaderClasses(writer);
writer.writeEntries(sourceJar, getEntityTransformer(), writeableLibraries);
writeableLibraries.write(writer);
writeLayerIndex(writer);
}
private void writeLoaderClasses(AbstractJarWriter writer) throws IOException {
@@ -171,6 +172,17 @@ public abstract class Packager {
}
}
private void writeLayerIndex(AbstractJarWriter writer) throws IOException {
if (this.layers != null && getLayout() instanceof LayeredLayout) {
String location = ((LayeredLayout) this.layout).getLayersIndexFileLocation();
if (StringUtils.hasLength(location)) {
List<String> layerNames = new ArrayList<>();
this.layers.forEach((layer) -> layerNames.add(layer.toString()));
writer.writeIndexFile(location, layerNames);
}
}
}
private EntryTransformer getEntityTransformer() {
if (getLayout() instanceof RepackagingLayout) {
return new RepackagingEntryTransformer((RepackagingLayout) getLayout(), this.layers);
@@ -304,8 +316,7 @@ public abstract class Packager {
}
private void addBootBootAttributesForLayeredLayout(Attributes attributes, LayeredLayout layout) {
String layersIndexFileLocation = layout.getLayersIndexFileLocation();
putIfHasLength(attributes, BOOT_LAYERS_INDEX_ATTRIBUTE, layersIndexFileLocation);
putIfHasLength(attributes, BOOT_LAYERS_INDEX_ATTRIBUTE, layout.getLayersIndexFileLocation());
putIfHasLength(attributes, BOOT_CLASSPATH_INDEX_ATTRIBUTE, layout.getClasspathIndexFileLocation());
}