Handle missing manifest files in JarTypeFilter

This commit makes sure that a jar file without a manifest is handled
properly (i.e. included in the repackaged archive).

See gh-24597
This commit is contained in:
Rob Edwards
2020-12-22 13:43:03 -07:00
committed by Stephane Nicoll
parent e8a936dfd9
commit 86eecb01b3
2 changed files with 23 additions and 2 deletions

View File

@@ -60,6 +60,11 @@ class JarTypeFilterTests {
assertThat(new JarTypeFilter().filter(createArtifact("annotation-processor"))).isTrue();
}
@Test
void whenArtifactHasNoManifestFileThenItIsIncluded() {
assertThat(new JarTypeFilter().filter(createArtifactWithNoManifest())).isFalse();
}
private Artifact createArtifact(String jarType) {
Path jarPath = this.temp.resolve("test.jar");
Manifest manifest = new Manifest();
@@ -78,4 +83,17 @@ class JarTypeFilterTests {
return artifact;
}
private Artifact createArtifactWithNoManifest() {
Path jarPath = this.temp.resolve("test.jar");
try {
new JarOutputStream(new FileOutputStream(jarPath.toFile())).close();
}
catch (IOException ex) {
throw new RuntimeException(ex);
}
Artifact artifact = mock(Artifact.class);
given(artifact.getFile()).willReturn(jarPath.toFile());
return artifact;
}
}