Merge branch '1.3.x'

This commit is contained in:
Andy Wilkinson 2016-06-15 20:22:56 +01:00
commit fc78a8de90
3 changed files with 30 additions and 4 deletions

View File

@ -163,6 +163,17 @@ public class RepackagingTests {
assertThat(isDevToolsJarIncluded(repackageFile)).isFalse(); assertThat(isDevToolsJarIncluded(repackageFile)).isFalse();
} }
@Test
public void customRepackagingTaskWithOwnMainClassNameAnNoGlobalMainClassName() {
project.newBuild().forTasks("clean", "customRepackagedJarWithOwnMainClass")
.withArguments("-PbootVersion=" + BOOT_VERSION, "-Prepackage=true",
"-PexcludeDevtools=false", "-PnoMainClass=true")
.run();
File buildLibs = new File("target/repackage/build/libs");
assertThat(new File(buildLibs, "custom.jar").exists()).isTrue();
assertThat(new File(buildLibs, "custom.jar.original").exists()).isTrue();
}
private boolean isDevToolsJarIncluded(File repackageFile) throws IOException { private boolean isDevToolsJarIncluded(File repackageFile) throws IOException {
JarFile jarFile = new JarFile(repackageFile); JarFile jarFile = new JarFile(repackageFile);
try { try {

View File

@ -23,7 +23,9 @@ dependencies {
} }
springBoot { springBoot {
if (!project.hasProperty("noMainClass")) {
mainClass = 'foo.bar.Baz' mainClass = 'foo.bar.Baz'
}
excludeDevtools = Boolean.valueOf(project.excludeDevtools) excludeDevtools = Boolean.valueOf(project.excludeDevtools)
} }
@ -50,3 +52,8 @@ task customRepackagedJar(type: BootRepackage, dependsOn: customJar) {
task customRepackagedJarWithStringReference(type: BootRepackage, dependsOn: customJar) { task customRepackagedJarWithStringReference(type: BootRepackage, dependsOn: customJar) {
withJarTask = 'customJar' withJarTask = 'customJar'
} }
task customRepackagedJarWithOwnMainClass(type: BootRepackage, dependsOn: customJar) {
withJarTask = customJar
mainClass = 'foo.bar.Baz'
}

View File

@ -254,9 +254,14 @@ public class RepackageTask extends DefaultTask {
.property("main"); .property("main");
} }
} }
if (mainClassName != null) {
getLogger().info("Setting mainClass: " + mainClassName); getLogger().info("Setting mainClass: " + mainClassName);
repackager.setMainClass(mainClassName); repackager.setMainClass(mainClassName);
} }
else {
getLogger().info("No mainClass configured");
}
}
private String getMainClassNameProperty() { private String getMainClassNameProperty() {
if (getProject().hasProperty("mainClassName")) { if (getProject().hasProperty("mainClassName")) {
@ -264,8 +269,11 @@ public class RepackageTask extends DefaultTask {
} }
ExtraPropertiesExtension extraProperties = (ExtraPropertiesExtension) getProject() ExtraPropertiesExtension extraProperties = (ExtraPropertiesExtension) getProject()
.getExtensions().getByName("ext"); .getExtensions().getByName("ext");
if (extraProperties.has("mainClassName")) {
return (String) extraProperties.get("mainClassName"); return (String) extraProperties.get("mainClassName");
} }
return null;
}
private LaunchScript getLaunchScript() throws IOException { private LaunchScript getLaunchScript() throws IOException {
if (isExecutable() || getEmbeddedLaunchScript() != null) { if (isExecutable() || getEmbeddedLaunchScript() != null) {