Add layout=NONE to packaging tools

This commit is contained in:
Dave Syer
2013-11-20 12:08:40 +00:00
parent 06c16ae452
commit c0bcb5e8e9
5 changed files with 53 additions and 9 deletions

View File

@@ -25,6 +25,7 @@ import java.util.Map;
* Common {@link Layout}s.
*
* @author Phillip Webb
* @author Dave Syer
*/
public class Layouts {
@@ -82,6 +83,17 @@ public class Layouts {
}
/**
* Executable expanded archive layout.
*/
public static class None extends Jar {
@Override
public String getLauncherClassName() {
return null;
}
}
/**
* Executable WAR layout.
*/

View File

@@ -172,12 +172,18 @@ public class Repackager {
startClass = MainClassFinder.findMainClass(source,
this.layout.getClassesLocation());
}
if (startClass == null) {
throw new IllegalStateException("Unable to find main class");
String launcherClassName = this.layout.getLauncherClassName();
if (launcherClassName != null) {
manifest.getMainAttributes()
.putValue(MAIN_CLASS_ATTRIBUTE, launcherClassName);
if (startClass == null) {
throw new IllegalStateException("Unable to find main class");
}
manifest.getMainAttributes().putValue(START_CLASS_ATTRIBUTE, startClass);
}
else if (startClass != null) {
manifest.getMainAttributes().putValue(MAIN_CLASS_ATTRIBUTE, startClass);
}
manifest.getMainAttributes().putValue(MAIN_CLASS_ATTRIBUTE,
this.layout.getLauncherClassName());
manifest.getMainAttributes().putValue(START_CLASS_ATTRIBUTE, startClass);
String bootVersion = getClass().getPackage().getImplementationVersion();
manifest.getMainAttributes().putValue(BOOT_VERSION_ATTRIBUTE, bootVersion);

View File

@@ -138,6 +138,30 @@ public class RepackagerTests {
new Repackager(this.testJarFile.getFile()).repackage(NO_LIBRARIES);
}
@Test
public void noMainClassAndLayoutIsNone() throws Exception {
this.testJarFile.addClass("a/b/C.class", ClassWithMainMethod.class);
File file = this.testJarFile.getFile();
Repackager repackager = new Repackager(file);
repackager.setLayout(new Layouts.None());
repackager.repackage(file, NO_LIBRARIES);
Manifest actualManifest = getManifest(file);
assertThat(actualManifest.getMainAttributes().getValue("Main-Class"),
equalTo("a.b.C"));
}
@Test
public void noMainClassAndLayoutIsNoneWithNoMain() throws Exception {
this.testJarFile.addClass("a/b/C.class", ClassWithoutMainMethod.class);
File file = this.testJarFile.getFile();
Repackager repackager = new Repackager(file);
repackager.setLayout(new Layouts.None());
repackager.repackage(file, NO_LIBRARIES);
Manifest actualManifest = getManifest(file);
assertThat(actualManifest.getMainAttributes().getValue("Main-Class"),
equalTo(null));
}
@Test
public void sameSourceAndDestinationWithBackup() throws Exception {
this.testJarFile.addClass("a/b/C.class", ClassWithMainMethod.class);