From 3f806aa513d5cd79227c62e1c76ea99f51397f75 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Thu, 2 Apr 2020 23:55:52 -0700 Subject: [PATCH] Create a new layer for loader classes Create a dedicated layer that is used to hold the launcher support classes. The layer sits between `dependencies` and `snapshot-dependencies` so that the layer is sensible for both SNAPSHOT and RELEASE versions of Spring Boot Closes gh-20529 --- .../boot/gradle/tasks/bundling/BootJarTests.java | 2 +- .../boot/loader/tools/ImplicitLayerResolver.java | 5 +++++ .../springframework/boot/loader/tools/StandardLayers.java | 6 ++++++ .../boot/loader/tools/ImplicitLayerResolverTests.java | 4 ++-- 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/bundling/BootJarTests.java b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/bundling/BootJarTests.java index 562f849e7c..710ab6a0a4 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/bundling/BootJarTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/bundling/BootJarTests.java @@ -100,7 +100,7 @@ class BootJarTests extends AbstractBootArchiveTests { @Test void whenJarIsLayeredThenLayersIndexIsPresentAndListsLayersInOrder() throws IOException { try (JarFile jarFile = new JarFile(createLayeredJar())) { - assertThat(entryLines(jarFile, "BOOT-INF/layers.idx")).containsExactly("dependencies", + assertThat(entryLines(jarFile, "BOOT-INF/layers.idx")).containsExactly("dependencies", "spring-boot-loader", "snapshot-dependencies", "application"); } } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/ImplicitLayerResolver.java b/spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/ImplicitLayerResolver.java index f585819074..ca97b6f3bb 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/ImplicitLayerResolver.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/ImplicitLayerResolver.java @@ -24,8 +24,13 @@ package org.springframework.boot.loader.tools; */ class ImplicitLayerResolver extends StandardLayers { + private static final String SPRING_BOOT_LOADER_PREFIX = "org/springframework/boot/loader/"; + @Override public Layer getLayer(String name) { + if (name.startsWith(SPRING_BOOT_LOADER_PREFIX)) { + return SPRING_BOOT_LOADER; + } return APPLICATION; } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/StandardLayers.java b/spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/StandardLayers.java index 2a8f9ea82e..b55e777814 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/StandardLayers.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/StandardLayers.java @@ -41,6 +41,11 @@ public abstract class StandardLayers implements Layers { */ public static final Layer DEPENDENCIES = new Layer("dependencies"); + /** + * The spring boot loader layer. + */ + public static final Layer SPRING_BOOT_LOADER = new Layer("spring-boot-loader"); + /** * The snapshot dependencies layer. */ @@ -55,6 +60,7 @@ public abstract class StandardLayers implements Layers { static { List layers = new ArrayList<>(); layers.add(DEPENDENCIES); + layers.add(SPRING_BOOT_LOADER); layers.add(SNAPSHOT_DEPENDENCIES); layers.add(APPLICATION); LAYERS = Collections.unmodifiableList(layers); diff --git a/spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/test/java/org/springframework/boot/loader/tools/ImplicitLayerResolverTests.java b/spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/test/java/org/springframework/boot/loader/tools/ImplicitLayerResolverTests.java index 6fe9637ea4..49c2a48c83 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/test/java/org/springframework/boot/loader/tools/ImplicitLayerResolverTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/test/java/org/springframework/boot/loader/tools/ImplicitLayerResolverTests.java @@ -34,8 +34,8 @@ class ImplicitLayerResolverTests { @Test void iteratorReturnsLayers() { - assertThat(this.layers).containsExactly(StandardLayers.DEPENDENCIES, StandardLayers.SNAPSHOT_DEPENDENCIES, - StandardLayers.APPLICATION); + assertThat(this.layers).containsExactly(StandardLayers.DEPENDENCIES, StandardLayers.SPRING_BOOT_LOADER, + StandardLayers.SNAPSHOT_DEPENDENCIES, StandardLayers.APPLICATION); } @Test