Add 'module' repacker layout

Add a 'module' layout for the repackager which includes all 'compile'
and 'runtime' scope dependencies and does not require a main class.

Fixes gh-1941
This commit is contained in:
Phillip Webb
2014-11-17 10:18:15 -08:00
parent 3c6c1d08e0
commit e0a0af436f
10 changed files with 187 additions and 4 deletions

View File

@@ -44,4 +44,9 @@ public interface Layout {
*/
String getClassesLocation();
/**
* Returns if loader classes should be included to make the archive executable.
*/
boolean isExecutable();
}

View File

@@ -69,6 +69,12 @@ public class Layouts {
public String getClassesLocation() {
return "";
}
@Override
public boolean isExecutable() {
return true;
}
}
/**
@@ -84,7 +90,7 @@ public class Layouts {
}
/**
* Executable expanded archive layout.
* No layout.
*/
public static class None extends Jar {
@@ -92,6 +98,12 @@ public class Layouts {
public String getLauncherClassName() {
return null;
}
@Override
public boolean isExecutable() {
return false;
}
}
/**
@@ -122,6 +134,42 @@ public class Layouts {
public String getClassesLocation() {
return "WEB-INF/classes/";
}
@Override
public boolean isExecutable() {
return true;
}
}
/**
* Module layout (designed to be used as a "plug-in")
*/
public static class Module implements Layout {
@Override
public String getLauncherClassName() {
return null;
}
@Override
public String getLibraryDestination(String libraryName, LibraryScope scope) {
if (LibraryScope.COMPILE.equals(scope) || LibraryScope.RUNTIME.equals(scope)) {
return "lib/";
}
return null;
}
@Override
public String getClassesLocation() {
return "";
}
@Override
public boolean isExecutable() {
return false;
}
}
}

View File

@@ -177,7 +177,7 @@ public class Repackager {
}
});
if (!(this.layout instanceof Layouts.None)) {
if (this.layout.isExecutable()) {
writer.writeLoaderClasses();
}
}

View File

@@ -24,6 +24,7 @@ import org.junit.rules.ExpectedException;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.nullValue;
import static org.junit.Assert.assertThat;
/**
@@ -81,4 +82,15 @@ public class LayoutsTests {
equalTo("WEB-INF/lib/"));
}
@Test
public void moduleLayout() throws Exception {
Layout layout = new Layouts.Module();
assertThat(layout.getLibraryDestination("lib.jar", LibraryScope.COMPILE),
equalTo("lib/"));
assertThat(layout.getLibraryDestination("lib.jar", LibraryScope.PROVIDED),
nullValue());
assertThat(layout.getLibraryDestination("lib.jar", LibraryScope.RUNTIME),
equalTo("lib/"));
}
}