Skip to content

Commit eacd8c0

Browse files
committed
Merge branch '2.7.x'
2 parents 85a4c94 + 56690a7 commit eacd8c0

File tree

4 files changed

+38
-3
lines changed
  • spring-boot-project/spring-boot-tools

4 files changed

+38
-3
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
@@ -113,7 +113,8 @@ private Iterable<File> classpathEntries(Spec<File> filter) {
113113
private void moveMetaInfToRoot(CopySpec spec) {
114114
spec.eachFile((file) -> {
115115
String path = file.getRelativeSourcePath().getPathString();
116-
if (path.startsWith("META-INF/") && !path.equals("META-INF/aop.xml") && !path.endsWith(".kotlin_module")) {
116+
if (path.startsWith("META-INF/") && !path.equals("META-INF/aop.xml") && !path.endsWith(".kotlin_module")
117+
&& !path.startsWith("META-INF/services/")) {
117118
this.support.moveToRoot(file);
118119
}
119120
});

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
@Override
167188
void applyLayered(Action<LayeredSpec> action) {
168189
getTask().layered(action);

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,8 @@ private String transformName(String name) {
439439
private boolean isTransformable(JarArchiveEntry entry) {
440440
String name = entry.getName();
441441
if (name.startsWith("META-INF/")) {
442-
return name.equals("META-INF/aop.xml") || name.endsWith(".kotlin_module");
442+
return name.equals("META-INF/aop.xml") || name.endsWith(".kotlin_module")
443+
|| name.startsWith("META-INF/services/");
443444
}
444445
return !name.startsWith("BOOT-INF/") && !name.equals("module-info.class");
445446
}

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)