Skip to content

Commit 409ec48

Browse files
committed
Merge branch '2.5.x' into 2.6.x
Closes gh-30790
2 parents 3f23c08 + 193ef9a commit 409ec48

File tree

4 files changed

+39
-4
lines changed
  • spring-boot-project/spring-boot-tools

4 files changed

+39
-4
lines changed

spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/BootJar.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@ private Iterable<File> classpathEntries(Spec<File> filter) {
110110
private void moveMetaInfToRoot(CopySpec spec) {
111111
spec.eachFile((file) -> {
112112
String path = file.getRelativeSourcePath().getPathString();
113-
if (path.startsWith("META-INF/") && !path.equals("META-INF/aop.xml") && !path.endsWith(".kotlin_module")) {
113+
if (path.startsWith("META-INF/") && !path.equals("META-INF/aop.xml") && !path.endsWith(".kotlin_module")
114+
&& !path.startsWith("META-INF/services/")) {
114115
this.support.moveToRoot(file);
115116
}
116117
});

spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/bundling/BootJarTests.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,27 @@ void kotlinModuleIsPackagedBeneathClassesDirectory() throws IOException {
163163
}
164164
}
165165

166+
@Test
167+
void metaInfServicesEntryIsPackagedBeneathClassesDirectory() throws IOException {
168+
getTask().getMainClass().set("com.example.Main");
169+
File classpathDirectory = new File(this.temp, "classes");
170+
File service = new File(classpathDirectory, "META-INF/services/com.example.Service");
171+
service.getParentFile().mkdirs();
172+
service.createNewFile();
173+
File applicationClass = new File(classpathDirectory, "com/example/Application.class");
174+
applicationClass.getParentFile().mkdirs();
175+
applicationClass.createNewFile();
176+
getTask().classpath(classpathDirectory);
177+
executeTask();
178+
try (JarFile jarFile = new JarFile(getTask().getArchiveFile().get().getAsFile())) {
179+
assertThat(jarFile.getEntry("BOOT-INF/classes/com/example/Application.class")).isNotNull();
180+
assertThat(jarFile.getEntry("com/example/Application.class")).isNull();
181+
assertThat(jarFile.getEntry("BOOT-INF/classes/META-INF/services/com.example.Service")).isNotNull();
182+
assertThat(jarFile.getEntry("META-INF/services/com.example.Service")).isNull();
183+
}
184+
185+
}
186+
166187
private File createPopulatedJar() throws IOException {
167188
addContent();
168189
executeTask();

spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/Packager.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2021 the original author or authors.
2+
* Copyright 2012-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -452,7 +452,8 @@ private String transformName(String name) {
452452
private boolean isTransformable(JarArchiveEntry entry) {
453453
String name = entry.getName();
454454
if (name.startsWith("META-INF/")) {
455-
return name.equals("META-INF/aop.xml") || name.endsWith(".kotlin_module");
455+
return name.equals("META-INF/aop.xml") || name.endsWith(".kotlin_module")
456+
|| name.startsWith("META-INF/services/");
456457
}
457458
return !name.startsWith("BOOT-INF/") && !name.equals("module-info.class");
458459
}

spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/test/java/org/springframework/boot/loader/tools/AbstractPackagerTests.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2021 the original author or authors.
2+
* Copyright 2012-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -484,6 +484,18 @@ void metaInfAopXmlIsMovedBeneathBootInfClassesWhenRepackaged() throws Exception
484484
assertThat(getPackagedEntry("BOOT-INF/classes/META-INF/aop.xml")).isNotNull();
485485
}
486486

487+
@Test
488+
void metaInfServicesFilesAreMovedBeneathBootInfClassesWhenRepackaged() throws Exception {
489+
this.testJarFile.addClass("A.class", ClassWithMainMethod.class);
490+
File service = new File(this.tempDir, "com.example.Service");
491+
service.createNewFile();
492+
this.testJarFile.addFile("META-INF/services/com.example.Service", service);
493+
P packager = createPackager();
494+
execute(packager, NO_LIBRARIES);
495+
assertThat(getPackagedEntry("META-INF/services/com.example.Service")).isNull();
496+
assertThat(getPackagedEntry("BOOT-INF/classes/META-INF/services/com.example.Service")).isNotNull();
497+
}
498+
487499
@Test
488500
void allEntriesUseUnixPlatformAndUtf8NameEncoding() throws IOException {
489501
this.testJarFile.addClass("A.class", ClassWithMainMethod.class);

0 commit comments

Comments
 (0)