Browse Source

Merge branch '2.1.x'

pull/16419/head
Andy Wilkinson 7 years ago
parent
commit
ac4d6bb10f
  1. 12
      spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/BootArchiveSupport.java
  2. 3
      spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/BootJar.java
  3. 3
      spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/BootWar.java
  4. 39
      spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/bundling/AbstractBootArchiveTests.java
  5. 4
      spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/bundling/BootJarTests.java
  6. 4
      spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/bundling/BootWarTests.java

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

@ -79,10 +79,20 @@ class BootArchiveSupport { @@ -79,10 +79,20 @@ class BootArchiveSupport {
configureExclusions();
}
void configureManifest(Jar jar, String mainClassName) {
void configureManifest(Jar jar, String mainClassName, String springBootClasses,
String springBootLib) {
Attributes attributes = jar.getManifest().getAttributes();
attributes.putIfAbsent("Main-Class", this.loaderMainClass);
attributes.putIfAbsent("Start-Class", mainClassName);
attributes.computeIfAbsent("Spring-Boot-Version",
(key) -> determineSpringBootVersion());
attributes.putIfAbsent("Spring-Boot-Classes", springBootClasses);
attributes.putIfAbsent("Spring-Boot-Lib", springBootLib);
}
private String determineSpringBootVersion() {
String implementationVersion = getClass().getPackage().getImplementationVersion();
return (implementationVersion != null) ? implementationVersion : "unknown";
}
CopyAction createCopyAction(Jar jar) {

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

@ -74,7 +74,8 @@ public class BootJar extends Jar implements BootArchive { @@ -74,7 +74,8 @@ public class BootJar extends Jar implements BootArchive {
@Override
public void copy() {
this.support.configureManifest(this, getMainClassName());
this.support.configureManifest(this, getMainClassName(), "BOOT-INF/classes/",
"BOOT-INF/lib/");
super.copy();
}

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

@ -68,7 +68,8 @@ public class BootWar extends War implements BootArchive { @@ -68,7 +68,8 @@ public class BootWar extends War implements BootArchive {
@Override
public void copy() {
this.support.configureManifest(this, getMainClassName());
this.support.configureManifest(this, getMainClassName(), "WEB-INF/classes/",
"WEB-INF/lib/");
super.copy();
}

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

@ -106,6 +106,13 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> { @@ -106,6 +106,13 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
.isEqualTo(this.launcherClass);
assertThat(jarFile.getManifest().getMainAttributes().getValue("Start-Class"))
.isEqualTo("com.example.Main");
assertThat(jarFile.getManifest().getMainAttributes()
.getValue("Spring-Boot-Classes")).isEqualTo(this.classesPath);
assertThat(
jarFile.getManifest().getMainAttributes().getValue("Spring-Boot-Lib"))
.isEqualTo(this.libPath);
assertThat(jarFile.getManifest().getMainAttributes()
.getValue("Spring-Boot-Version")).isNotNull();
}
}
@ -115,8 +122,8 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> { @@ -115,8 +122,8 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
this.task.classpath(jarFile("one.jar"), jarFile("two.jar"));
executeTask();
try (JarFile jarFile = new JarFile(this.task.getArchivePath())) {
assertThat(jarFile.getEntry(this.libPath + "/one.jar")).isNotNull();
assertThat(jarFile.getEntry(this.libPath + "/two.jar")).isNotNull();
assertThat(jarFile.getEntry(this.libPath + "one.jar")).isNotNull();
assertThat(jarFile.getEntry(this.libPath + "two.jar")).isNotNull();
}
}
@ -132,7 +139,7 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> { @@ -132,7 +139,7 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
executeTask();
try (JarFile jarFile = new JarFile(this.task.getArchivePath())) {
assertThat(
jarFile.getEntry(this.classesPath + "/com/example/Application.class"))
jarFile.getEntry(this.classesPath + "com/example/Application.class"))
.isNotNull();
}
}
@ -168,8 +175,8 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> { @@ -168,8 +175,8 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
this.task.setClasspath(this.task.getProject().files(jarFile("two.jar")));
executeTask();
try (JarFile jarFile = new JarFile(this.task.getArchivePath())) {
assertThat(jarFile.getEntry(this.libPath + "/one.jar")).isNull();
assertThat(jarFile.getEntry(this.libPath + "/two.jar")).isNotNull();
assertThat(jarFile.getEntry(this.libPath + "one.jar")).isNull();
assertThat(jarFile.getEntry(this.libPath + "two.jar")).isNotNull();
}
}
@ -180,8 +187,8 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> { @@ -180,8 +187,8 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
this.task.setClasspath(jarFile("two.jar"));
executeTask();
try (JarFile jarFile = new JarFile(this.task.getArchivePath())) {
assertThat(jarFile.getEntry(this.libPath + "/one.jar")).isNull();
assertThat(jarFile.getEntry(this.libPath + "/two.jar")).isNotNull();
assertThat(jarFile.getEntry(this.libPath + "one.jar")).isNull();
assertThat(jarFile.getEntry(this.libPath + "two.jar")).isNotNull();
}
}
@ -229,9 +236,9 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> { @@ -229,9 +236,9 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
this.task.requiresUnpack("**/one.jar");
executeTask();
try (JarFile jarFile = new JarFile(this.task.getArchivePath())) {
assertThat(jarFile.getEntry(this.libPath + "/one.jar").getComment())
assertThat(jarFile.getEntry(this.libPath + "one.jar").getComment())
.startsWith("UNPACK:");
assertThat(jarFile.getEntry(this.libPath + "/two.jar").getComment()).isNull();
assertThat(jarFile.getEntry(this.libPath + "two.jar").getComment()).isNull();
}
}
@ -242,9 +249,9 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> { @@ -242,9 +249,9 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
this.task.requiresUnpack((element) -> element.getName().endsWith("two.jar"));
executeTask();
try (JarFile jarFile = new JarFile(this.task.getArchivePath())) {
assertThat(jarFile.getEntry(this.libPath + "/two.jar").getComment())
assertThat(jarFile.getEntry(this.libPath + "two.jar").getComment())
.startsWith("UNPACK:");
assertThat(jarFile.getEntry(this.libPath + "/one.jar").getComment()).isNull();
assertThat(jarFile.getEntry(this.libPath + "one.jar").getComment()).isNull();
}
}
@ -375,7 +382,7 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> { @@ -375,7 +382,7 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
executeTask();
assertThat(this.task.getArchivePath()).exists();
try (JarFile jarFile = new JarFile(this.task.getArchivePath())) {
assertThat(jarFile.getEntry(this.libPath + "/spring-boot-devtools-0.1.2.jar"))
assertThat(jarFile.getEntry(this.libPath + "spring-boot-devtools-0.1.2.jar"))
.isNull();
}
}
@ -388,7 +395,7 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> { @@ -388,7 +395,7 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
executeTask();
assertThat(this.task.getArchivePath()).exists();
try (JarFile jarFile = new JarFile(this.task.getArchivePath())) {
assertThat(jarFile.getEntry(this.libPath + "/spring-boot-devtools-0.1.2.jar"))
assertThat(jarFile.getEntry(this.libPath + "spring-boot-devtools-0.1.2.jar"))
.isNotNull();
}
}
@ -429,9 +436,9 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> { @@ -429,9 +436,9 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
executeTask();
assertThat(getEntryNames(this.task.getArchivePath())).containsSubsequence(
"org/springframework/boot/loader/",
this.classesPath + "/com/example/Application.class",
this.libPath + "/first-library.jar", this.libPath + "/second-library.jar",
this.libPath + "/third-library.jar");
this.classesPath + "com/example/Application.class",
this.libPath + "first-library.jar", this.libPath + "second-library.jar",
this.libPath + "third-library.jar");
}
protected File jarFile(String name) throws IOException {

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

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -33,7 +33,7 @@ public class BootJarTests extends AbstractBootArchiveTests<BootJar> { @@ -33,7 +33,7 @@ public class BootJarTests extends AbstractBootArchiveTests<BootJar> {
public BootJarTests() {
super(BootJar.class, "org.springframework.boot.loader.JarLauncher",
"BOOT-INF/lib", "BOOT-INF/classes");
"BOOT-INF/lib/", "BOOT-INF/classes/");
}
@Test

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

@ -32,8 +32,8 @@ import static org.assertj.core.api.Assertions.assertThat; @@ -32,8 +32,8 @@ import static org.assertj.core.api.Assertions.assertThat;
public class BootWarTests extends AbstractBootArchiveTests<BootWar> {
public BootWarTests() {
super(BootWar.class, "org.springframework.boot.loader.WarLauncher", "WEB-INF/lib",
"WEB-INF/classes");
super(BootWar.class, "org.springframework.boot.loader.WarLauncher",
"WEB-INF/lib/", "WEB-INF/classes/");
}
@Test

Loading…
Cancel
Save