Skip to content

Commit db4623c

Browse files
committed
Merge branch '2.0.x' into 2.1.x
2 parents d2c059f + 7b5f46d commit db4623c

File tree

6 files changed

+42
-23
lines changed

6 files changed

+42
-23
lines changed

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,20 @@ class BootArchiveSupport {
7979
configureExclusions();
8080
}
8181

82-
void configureManifest(Jar jar, String mainClassName) {
82+
void configureManifest(Jar jar, String mainClassName, String springBootClasses,
83+
String springBootLib) {
8384
Attributes attributes = jar.getManifest().getAttributes();
8485
attributes.putIfAbsent("Main-Class", this.loaderMainClass);
8586
attributes.putIfAbsent("Start-Class", mainClassName);
87+
attributes.computeIfAbsent("Spring-Boot-Version",
88+
(key) -> determineSpringBootVersion());
89+
attributes.putIfAbsent("Spring-Boot-Classes", springBootClasses);
90+
attributes.putIfAbsent("Spring-Boot-Lib", springBootLib);
91+
}
92+
93+
private String determineSpringBootVersion() {
94+
String implementationVersion = getClass().getPackage().getImplementationVersion();
95+
return (implementationVersion != null) ? implementationVersion : "unknown";
8696
}
8797

8898
CopyAction createCopyAction(Jar jar) {

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
@@ -74,7 +74,8 @@ private Action<CopySpec> classpathFiles(Spec<File> filter) {
7474

7575
@Override
7676
public void copy() {
77-
this.support.configureManifest(this, getMainClassName());
77+
this.support.configureManifest(this, getMainClassName(), "BOOT-INF/classes/",
78+
"BOOT-INF/lib/");
7879
super.copy();
7980
}
8081

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ public BootWar() {
6868

6969
@Override
7070
public void copy() {
71-
this.support.configureManifest(this, getMainClassName());
71+
this.support.configureManifest(this, getMainClassName(), "WEB-INF/classes/",
72+
"WEB-INF/lib/");
7273
super.copy();
7374
}
7475

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

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,13 @@ public void basicArchiveCreation() throws IOException {
106106
.isEqualTo(this.launcherClass);
107107
assertThat(jarFile.getManifest().getMainAttributes().getValue("Start-Class"))
108108
.isEqualTo("com.example.Main");
109+
assertThat(jarFile.getManifest().getMainAttributes()
110+
.getValue("Spring-Boot-Classes")).isEqualTo(this.classesPath);
111+
assertThat(
112+
jarFile.getManifest().getMainAttributes().getValue("Spring-Boot-Lib"))
113+
.isEqualTo(this.libPath);
114+
assertThat(jarFile.getManifest().getMainAttributes()
115+
.getValue("Spring-Boot-Version")).isNotNull();
109116
}
110117
}
111118

@@ -115,8 +122,8 @@ public void classpathJarsArePackagedBeneathLibPath() throws IOException {
115122
this.task.classpath(jarFile("one.jar"), jarFile("two.jar"));
116123
this.task.execute();
117124
try (JarFile jarFile = new JarFile(this.task.getArchivePath())) {
118-
assertThat(jarFile.getEntry(this.libPath + "/one.jar")).isNotNull();
119-
assertThat(jarFile.getEntry(this.libPath + "/two.jar")).isNotNull();
125+
assertThat(jarFile.getEntry(this.libPath + "one.jar")).isNotNull();
126+
assertThat(jarFile.getEntry(this.libPath + "two.jar")).isNotNull();
120127
}
121128
}
122129

@@ -132,7 +139,7 @@ public void classpathFoldersArePackagedBeneathClassesPath() throws IOException {
132139
this.task.execute();
133140
try (JarFile jarFile = new JarFile(this.task.getArchivePath())) {
134141
assertThat(
135-
jarFile.getEntry(this.classesPath + "/com/example/Application.class"))
142+
jarFile.getEntry(this.classesPath + "com/example/Application.class"))
136143
.isNotNull();
137144
}
138145
}
@@ -168,8 +175,8 @@ public void classpathCanBeSetUsingAFileCollection() throws IOException {
168175
this.task.setClasspath(this.task.getProject().files(jarFile("two.jar")));
169176
this.task.execute();
170177
try (JarFile jarFile = new JarFile(this.task.getArchivePath())) {
171-
assertThat(jarFile.getEntry(this.libPath + "/one.jar")).isNull();
172-
assertThat(jarFile.getEntry(this.libPath + "/two.jar")).isNotNull();
178+
assertThat(jarFile.getEntry(this.libPath + "one.jar")).isNull();
179+
assertThat(jarFile.getEntry(this.libPath + "two.jar")).isNotNull();
173180
}
174181
}
175182

@@ -180,8 +187,8 @@ public void classpathCanBeSetUsingAnObject() throws IOException {
180187
this.task.setClasspath(jarFile("two.jar"));
181188
this.task.execute();
182189
try (JarFile jarFile = new JarFile(this.task.getArchivePath())) {
183-
assertThat(jarFile.getEntry(this.libPath + "/one.jar")).isNull();
184-
assertThat(jarFile.getEntry(this.libPath + "/two.jar")).isNotNull();
190+
assertThat(jarFile.getEntry(this.libPath + "one.jar")).isNull();
191+
assertThat(jarFile.getEntry(this.libPath + "two.jar")).isNotNull();
185192
}
186193
}
187194

@@ -229,9 +236,9 @@ public void unpackCommentIsAddedToEntryIdentifiedByAPattern() throws IOException
229236
this.task.requiresUnpack("**/one.jar");
230237
this.task.execute();
231238
try (JarFile jarFile = new JarFile(this.task.getArchivePath())) {
232-
assertThat(jarFile.getEntry(this.libPath + "/one.jar").getComment())
239+
assertThat(jarFile.getEntry(this.libPath + "one.jar").getComment())
233240
.startsWith("UNPACK:");
234-
assertThat(jarFile.getEntry(this.libPath + "/two.jar").getComment()).isNull();
241+
assertThat(jarFile.getEntry(this.libPath + "two.jar").getComment()).isNull();
235242
}
236243
}
237244

@@ -242,9 +249,9 @@ public void unpackCommentIsAddedToEntryIdentifiedByASpec() throws IOException {
242249
this.task.requiresUnpack((element) -> element.getName().endsWith("two.jar"));
243250
this.task.execute();
244251
try (JarFile jarFile = new JarFile(this.task.getArchivePath())) {
245-
assertThat(jarFile.getEntry(this.libPath + "/two.jar").getComment())
252+
assertThat(jarFile.getEntry(this.libPath + "two.jar").getComment())
246253
.startsWith("UNPACK:");
247-
assertThat(jarFile.getEntry(this.libPath + "/one.jar").getComment()).isNull();
254+
assertThat(jarFile.getEntry(this.libPath + "one.jar").getComment()).isNull();
248255
}
249256
}
250257

@@ -375,7 +382,7 @@ public void devtoolsJarIsExcludedByDefault() throws IOException {
375382
this.task.execute();
376383
assertThat(this.task.getArchivePath()).exists();
377384
try (JarFile jarFile = new JarFile(this.task.getArchivePath())) {
378-
assertThat(jarFile.getEntry(this.libPath + "/spring-boot-devtools-0.1.2.jar"))
385+
assertThat(jarFile.getEntry(this.libPath + "spring-boot-devtools-0.1.2.jar"))
379386
.isNull();
380387
}
381388
}
@@ -388,7 +395,7 @@ public void devtoolsJarCanBeIncluded() throws IOException {
388395
this.task.execute();
389396
assertThat(this.task.getArchivePath()).exists();
390397
try (JarFile jarFile = new JarFile(this.task.getArchivePath())) {
391-
assertThat(jarFile.getEntry(this.libPath + "/spring-boot-devtools-0.1.2.jar"))
398+
assertThat(jarFile.getEntry(this.libPath + "spring-boot-devtools-0.1.2.jar"))
392399
.isNotNull();
393400
}
394401
}
@@ -429,9 +436,9 @@ public void loaderIsWrittenFirstThenApplicationClassesThenLibraries()
429436
this.task.execute();
430437
assertThat(getEntryNames(this.task.getArchivePath())).containsSubsequence(
431438
"org/springframework/boot/loader/",
432-
this.classesPath + "/com/example/Application.class",
433-
this.libPath + "/first-library.jar", this.libPath + "/second-library.jar",
434-
this.libPath + "/third-library.jar");
439+
this.classesPath + "com/example/Application.class",
440+
this.libPath + "first-library.jar", this.libPath + "second-library.jar",
441+
this.libPath + "third-library.jar");
435442
}
436443

437444
protected File jarFile(String name) throws IOException {

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

Lines changed: 2 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.
@@ -33,7 +33,7 @@ public class BootJarTests extends AbstractBootArchiveTests<BootJar> {
3333

3434
public BootJarTests() {
3535
super(BootJar.class, "org.springframework.boot.loader.JarLauncher",
36-
"BOOT-INF/lib", "BOOT-INF/classes");
36+
"BOOT-INF/lib/", "BOOT-INF/classes/");
3737
}
3838

3939
@Test

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@
3232
public class BootWarTests extends AbstractBootArchiveTests<BootWar> {
3333

3434
public BootWarTests() {
35-
super(BootWar.class, "org.springframework.boot.loader.WarLauncher", "WEB-INF/lib",
36-
"WEB-INF/classes");
35+
super(BootWar.class, "org.springframework.boot.loader.WarLauncher",
36+
"WEB-INF/lib/", "WEB-INF/classes/");
3737
}
3838

3939
@Test

0 commit comments

Comments
 (0)