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:
@@ -44,4 +44,9 @@ public interface Layout {
|
||||
*/
|
||||
String getClassesLocation();
|
||||
|
||||
/**
|
||||
* Returns if loader classes should be included to make the archive executable.
|
||||
*/
|
||||
boolean isExecutable();
|
||||
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -177,7 +177,7 @@ public class Repackager {
|
||||
}
|
||||
});
|
||||
|
||||
if (!(this.layout instanceof Layouts.None)) {
|
||||
if (this.layout.isExecutable()) {
|
||||
writer.writeLoaderClasses();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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/"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user