Skip to content

Commit 342bced

Browse files
committed
Merge branch '2.1.x'
2 parents b4e890c + 2650a07 commit 342bced

File tree

5 files changed

+51
-7
lines changed

5 files changed

+51
-7
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: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2018 the original author or authors.
2+
* Copyright 2012-2019 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.
@@ -55,13 +55,15 @@ public BootJar() {
5555
getMainSpec().with(this.bootInf);
5656
this.bootInf.into("classes", classpathFiles(File::isDirectory));
5757
this.bootInf.into("lib", classpathFiles(File::isFile));
58+
this.bootInf.filesMatching("module-info.class", (details) -> {
59+
details.setRelativePath(details.getRelativeSourcePath());
60+
});
5861
}
5962

6063
private Action<CopySpec> classpathFiles(Spec<File> filter) {
6164
return (copySpec) -> copySpec
6265
.from((Callable<Iterable<File>>) () -> (this.classpath != null)
6366
? this.classpath.filter(filter) : Collections.emptyList());
64-
6567
}
6668

6769
@Override

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2018 the original author or authors.
2+
* Copyright 2012-2019 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.
@@ -54,6 +54,9 @@ public BootWar() {
5454
(copySpec) -> copySpec.from(
5555
(Callable<Iterable<File>>) () -> (this.providedClasspath != null)
5656
? this.providedClasspath : Collections.emptyList()));
57+
getRootSpec().filesMatching("module-info.class", (details) -> {
58+
details.setRelativePath(details.getRelativeSourcePath());
59+
});
5760
}
5861

5962
@Override

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

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2018 the original author or authors.
2+
* Copyright 2012-2019 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.
@@ -133,6 +133,30 @@ public void classpathFoldersArePackagedBeneathClassesPath() throws IOException {
133133
}
134134
}
135135

136+
@Test
137+
public void moduleInfoClassIsPackagedInTheRootOfTheArchive() throws IOException {
138+
this.task.setMainClassName("com.example.Main");
139+
File classpathFolder = this.temp.newFolder();
140+
File moduleInfoClass = new File(classpathFolder, "module-info.class");
141+
moduleInfoClass.getParentFile().mkdirs();
142+
moduleInfoClass.createNewFile();
143+
File applicationClass = new File(classpathFolder,
144+
"com/example/Application.class");
145+
applicationClass.getParentFile().mkdirs();
146+
applicationClass.createNewFile();
147+
this.task.classpath(classpathFolder);
148+
this.task.execute();
149+
try (JarFile jarFile = new JarFile(this.task.getArchivePath())) {
150+
assertThat(
151+
jarFile.getEntry(this.classesPath + "/com/example/Application.class"))
152+
.isNotNull();
153+
assertThat(jarFile.getEntry("com/example/Application.class")).isNull();
154+
assertThat(jarFile.getEntry("module-info.class")).isNotNull();
155+
assertThat(jarFile.getEntry(this.classesPath + "/module-info.class"))
156+
.isNull();
157+
}
158+
}
159+
136160
@Test
137161
public void classpathCanBeSetUsingAFileCollection() throws IOException {
138162
this.task.setMainClassName("com.example.Main");

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2018 the original author or authors.
2+
* Copyright 2012-2019 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.
@@ -381,7 +381,8 @@ public JarArchiveEntry transform(JarArchiveEntry entry) {
381381
}
382382
if ((entry.getName().startsWith("META-INF/")
383383
&& !entry.getName().equals("META-INF/aop.xml"))
384-
|| entry.getName().startsWith("BOOT-INF/")) {
384+
|| entry.getName().startsWith("BOOT-INF/")
385+
|| entry.getName().equals("module-info.class")) {
385386
return entry;
386387
}
387388
JarArchiveEntry renamedEntry = new JarArchiveEntry(

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2018 the original author or authors.
2+
* Copyright 2012-2019 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.
@@ -661,6 +661,20 @@ public void jarThatUsesCustomCompressionConfigurationCanBeRepackaged()
661661
repackager.repackage(dest, NO_LIBRARIES);
662662
}
663663

664+
@Test
665+
public void moduleInfoClassRemainsInRootOfJarWhenRepackaged() throws Exception {
666+
this.testJarFile.addClass("A.class", ClassWithMainMethod.class);
667+
this.testJarFile.addClass("module-info.class", ClassWithoutMainMethod.class);
668+
File source = this.testJarFile.getFile();
669+
File dest = this.temporaryFolder.newFile("dest.jar");
670+
Repackager repackager = new Repackager(source);
671+
repackager.repackage(dest, NO_LIBRARIES);
672+
try (JarFile jarFile = new JarFile(dest)) {
673+
assertThat(jarFile.getEntry("module-info.class")).isNotNull();
674+
assertThat(jarFile.getEntry("BOOT-INF/classes/module-info.class")).isNull();
675+
}
676+
}
677+
664678
private File createLibrary() throws IOException {
665679
TestJarFile library = new TestJarFile(this.temporaryFolder);
666680
library.addClass("com/example/library/Library.class",

0 commit comments

Comments
 (0)