Relocate launcher classes
Create alternative launcher classes under the package `org.springframework.boot.loader.launch` and use them in favor of the previous location. This update is designed to improve compatibility with future changes in the loader. Closes gh-37667
This commit is contained in:
@@ -10,7 +10,7 @@ tasks.named("bootWar") {
|
||||
// tag::properties-launcher[]
|
||||
tasks.named("bootWar") {
|
||||
manifest {
|
||||
attributes 'Main-Class': 'org.springframework.boot.loader.PropertiesLauncher'
|
||||
attributes 'Main-Class': 'org.springframework.boot.loader.launch.PropertiesLauncher'
|
||||
}
|
||||
}
|
||||
// end::properties-launcher[]
|
||||
|
||||
@@ -12,7 +12,7 @@ tasks.named<BootWar>("bootWar") {
|
||||
// tag::properties-launcher[]
|
||||
tasks.named<BootWar>("bootWar") {
|
||||
manifest {
|
||||
attributes("Main-Class" to "org.springframework.boot.loader.PropertiesLauncher")
|
||||
attributes("Main-Class" to "org.springframework.boot.loader.launch.PropertiesLauncher")
|
||||
}
|
||||
}
|
||||
// end::properties-launcher[]
|
||||
|
||||
@@ -61,9 +61,9 @@ class BootArchiveSupport {
|
||||
|
||||
static {
|
||||
Set<String> defaultLauncherClasses = new HashSet<>();
|
||||
defaultLauncherClasses.add("org.springframework.boot.loader.JarLauncher");
|
||||
defaultLauncherClasses.add("org.springframework.boot.loader.PropertiesLauncher");
|
||||
defaultLauncherClasses.add("org.springframework.boot.loader.WarLauncher");
|
||||
defaultLauncherClasses.add("org.springframework.boot.loader.launch.JarLauncher");
|
||||
defaultLauncherClasses.add("org.springframework.boot.loader.launch.PropertiesLauncher");
|
||||
defaultLauncherClasses.add("org.springframework.boot.loader.launch.WarLauncher");
|
||||
DEFAULT_LAUNCHER_CLASSES = Collections.unmodifiableSet(defaultLauncherClasses);
|
||||
}
|
||||
|
||||
|
||||
@@ -49,7 +49,7 @@ import org.gradle.work.DisableCachingByDefault;
|
||||
@DisableCachingByDefault(because = "Not worth caching")
|
||||
public abstract class BootJar extends Jar implements BootArchive {
|
||||
|
||||
private static final String LAUNCHER = "org.springframework.boot.loader.JarLauncher";
|
||||
private static final String LAUNCHER = "org.springframework.boot.loader.launch.JarLauncher";
|
||||
|
||||
private static final String CLASSES_DIRECTORY = "BOOT-INF/classes/";
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ import org.gradle.work.DisableCachingByDefault;
|
||||
@DisableCachingByDefault(because = "Not worth caching")
|
||||
public abstract class BootWar extends War implements BootArchive {
|
||||
|
||||
private static final String LAUNCHER = "org.springframework.boot.loader.WarLauncher";
|
||||
private static final String LAUNCHER = "org.springframework.boot.loader.launch.WarLauncher";
|
||||
|
||||
private static final String CLASSES_DIRECTORY = "WEB-INF/classes/";
|
||||
|
||||
|
||||
@@ -166,7 +166,7 @@ class PackagingDocumentationTests {
|
||||
assertThat(file).isFile();
|
||||
try (JarFile jar = new JarFile(file)) {
|
||||
assertThat(jar.getManifest().getMainAttributes().getValue("Main-Class"))
|
||||
.isEqualTo("org.springframework.boot.loader.PropertiesLauncher");
|
||||
.isEqualTo("org.springframework.boot.loader.launch.PropertiesLauncher");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -270,7 +270,9 @@ abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
|
||||
void loaderIsWrittenToTheRootOfTheJarWhenUsingThePropertiesLauncher() throws IOException {
|
||||
this.task.getMainClass().set("com.example.Main");
|
||||
executeTask();
|
||||
this.task.getManifest().getAttributes().put("Main-Class", "org.springframework.boot.loader.PropertiesLauncher");
|
||||
this.task.getManifest()
|
||||
.getAttributes()
|
||||
.put("Main-Class", "org.springframework.boot.loader.launch.PropertiesLauncher");
|
||||
try (JarFile jarFile = new JarFile(this.task.getArchiveFile().get().getAsFile())) {
|
||||
assertThat(jarFile.getEntry("org/springframework/boot/loader/LaunchedURLClassLoader.class")).isNotNull();
|
||||
assertThat(jarFile.getEntry("org/springframework/boot/loader/")).isNotNull();
|
||||
@@ -362,7 +364,7 @@ abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
|
||||
assertThat(jarFile.getManifest().getMainAttributes().getValue("Main-Class"))
|
||||
.isEqualTo("com.example.CustomLauncher");
|
||||
assertThat(jarFile.getManifest().getMainAttributes().getValue("Start-Class")).isEqualTo("com.example.Main");
|
||||
assertThat(jarFile.getEntry("org/springframework/boot/loader/LaunchedURLClassLoader.class")).isNull();
|
||||
assertThat(jarFile.getEntry("org/springframework/boot/loader/launch/LaunchedClassLoader.class")).isNull();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
class BootJarTests extends AbstractBootArchiveTests<BootJar> {
|
||||
|
||||
BootJarTests() {
|
||||
super(BootJar.class, "org.springframework.boot.loader.JarLauncher", "BOOT-INF/lib/", "BOOT-INF/classes/",
|
||||
super(BootJar.class, "org.springframework.boot.loader.launch.JarLauncher", "BOOT-INF/lib/", "BOOT-INF/classes/",
|
||||
"BOOT-INF/");
|
||||
}
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
class BootWarTests extends AbstractBootArchiveTests<BootWar> {
|
||||
|
||||
BootWarTests() {
|
||||
super(BootWar.class, "org.springframework.boot.loader.WarLauncher", "WEB-INF/lib/", "WEB-INF/classes/",
|
||||
super(BootWar.class, "org.springframework.boot.loader.launch.WarLauncher", "WEB-INF/lib/", "WEB-INF/classes/",
|
||||
"WEB-INF/");
|
||||
}
|
||||
|
||||
|
||||
@@ -21,5 +21,5 @@ task explode(type: Sync) {
|
||||
|
||||
task launch(type: JavaExec) {
|
||||
classpath = files(explode)
|
||||
mainClass = 'org.springframework.boot.loader.JarLauncher'
|
||||
mainClass = 'org.springframework.boot.loader.launch.JarLauncher'
|
||||
}
|
||||
Reference in New Issue
Block a user