Ensure LayoutFactory is not passed an empty file

Update `Repackager` to ensure that `getLayout` is called before we
backup the source file. This restores earlier behavior that some
custom `ModuleFactory` implementations were relying on.

Closes gh-22995
This commit is contained in:
Phillip Webb
2020-08-18 16:45:44 -07:00
parent c5b12effbf
commit f7452b9383
2 changed files with 20 additions and 0 deletions

View File

@@ -139,6 +139,15 @@ class RepackagerTests extends AbstractPackagerTests<Repackager> {
assertThat(hasLauncherClasses(this.destination)).isTrue();
}
@Test
void layoutFactoryGetsOriginalFile() throws Exception {
this.testJarFile.addClass("a/b/C.class", ClassWithMainMethod.class);
Repackager repackager = createRepackager(this.testJarFile.getFile(), false);
repackager.setLayoutFactory(new TestLayoutFactory());
repackager.repackage(this.destination, NO_LIBRARIES);
assertThat(hasLauncherClasses(this.destination)).isTrue();
}
@Test
void addLauncherScript() throws Exception {
this.testJarFile.addClass("a/b/C.class", ClassWithMainMethod.class);
@@ -266,4 +275,14 @@ class RepackagerTests extends AbstractPackagerTests<Repackager> {
}
static class TestLayoutFactory implements LayoutFactory {
@Override
public Layout getLayout(File source) {
assertThat(source.length()).isGreaterThan(0);
return new DefaultLayoutFactory().getLayout(source);
}
}
}