Merge branch '3.4.x'

Closes gh-45449
This commit is contained in:
Moritz Halbritter 2025-05-09 11:36:28 +02:00
commit f8b75073e8
1 changed files with 18 additions and 15 deletions

View File

@ -45,10 +45,10 @@ class IndexedLayers implements Layers {
private final Map<String, List<String>> layers = new LinkedHashMap<>();
private final String classesLocation;
private final String indexFileLocation;
IndexedLayers(String indexFile, String classesLocation) {
this.classesLocation = classesLocation;
IndexedLayers(String indexFile, String indexFileLocation) {
this.indexFileLocation = indexFileLocation;
String[] lines = Arrays.stream(indexFile.split("\n"))
.map((line) -> line.replace("\r", ""))
.filter(StringUtils::hasText)
@ -72,7 +72,7 @@ class IndexedLayers implements Layers {
@Override
public String getApplicationLayerName() {
return getLayer(this.classesLocation);
return getLayer(this.indexFileLocation);
}
@Override
@ -99,18 +99,21 @@ class IndexedLayers implements Layers {
* jar.
*/
static IndexedLayers get(Context context) {
try {
try (JarFile jarFile = new JarFile(context.getArchiveFile())) {
Manifest manifest = jarFile.getManifest();
String location = manifest.getMainAttributes().getValue("Spring-Boot-Layers-Index");
ZipEntry entry = (location != null) ? jarFile.getEntry(location) : null;
if (entry != null) {
String indexFile = StreamUtils.copyToString(jarFile.getInputStream(entry), StandardCharsets.UTF_8);
String classesLocation = manifest.getMainAttributes().getValue("Spring-Boot-Classes");
return new IndexedLayers(indexFile, classesLocation);
}
try (JarFile jarFile = new JarFile(context.getArchiveFile())) {
Manifest manifest = jarFile.getManifest();
if (manifest == null) {
return null;
}
return null;
String indexFileLocation = manifest.getMainAttributes().getValue("Spring-Boot-Layers-Index");
if (indexFileLocation == null) {
return null;
}
ZipEntry entry = jarFile.getEntry(indexFileLocation);
if (entry == null) {
return null;
}
String indexFile = StreamUtils.copyToString(jarFile.getInputStream(entry), StandardCharsets.UTF_8);
return new IndexedLayers(indexFile, indexFileLocation);
}
catch (FileNotFoundException | NoSuchFileException ex) {
return null;