Skip to content

Commit

Permalink
simpler model of onduplicates directive
Browse files Browse the repository at this point in the history
TODO add more testcases for tagging
Signed-off-by: Christoph Rueger <chrisrueger@gmail.com>
  • Loading branch information
chrisrueger committed Oct 29, 2024
1 parent a4ff903 commit ada3c3f
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 143 deletions.
66 changes: 15 additions & 51 deletions biz.aQute.bndlib.tests/test/test/IncludeResourceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ public void testIncludeResourceDuplicatesMerge() throws Exception {
a.addClasspath(new File("jar/jarA.jar"));
a.addClasspath(a.getFile("jar/jarB.jar"));
a.setIncludeResource(
"@jar/jarA.jar!/META-INF/services/*, @jar/jarB.jar!/META-INF/services/*;dup_merge:=*");
"@jar/jarA.jar!/META-INF/services/*, @jar/jarB.jar!/META-INF/services/*;onduplicates:=MERGE");
Jar jar = a.build();
assertTrue(a.check());

Expand All @@ -231,7 +231,7 @@ public void testIncludeResourceMixedMetaInfDuplicatesMerge() throws Exception {
try (Builder a = new Builder();) {
a.addClasspath(new File("jar/jarA.jar"));
a.addClasspath(a.getFile("jar/jarB.jar"));
a.setIncludeResource("@jar/jarA.jar!/META-INF/*, @jar/jarB.jar!/META-INF/*;dup_merge:=*");
a.setIncludeResource("@jar/jarA.jar!/META-INF/*, @jar/jarB.jar!/META-INF/*;onduplicates:=MERGE");
Jar jar = a.build();
assertTrue(a.check());

Expand All @@ -242,7 +242,7 @@ public void testIncludeResourceMixedMetaInfDuplicatesMerge() throws Exception {
assertEquals("a\nb", IO.collect(resourceFoo.openInputStream()));

Resource resourceManifest = jar.getResource("META-INF/bar.txt");
assertEquals("ab", IO.collect(resourceManifest.openInputStream()));
assertEquals("b", IO.collect(resourceManifest.openInputStream()));

}
}
Expand All @@ -256,42 +256,24 @@ public void testIncludeResourceDuplicatesMergeBlank() throws Exception {
// dup_merge contains a blank value. should be ignored and use
// default 'overwrite' behavior
a.setIncludeResource(
"@jar/jarA.jar!/META-INF/services/*, @jar/jarB.jar!/META-INF/services/*;dup_merge:= ");
"@jar/jarA.jar!/META-INF/services/*, @jar/jarB.jar!/META-INF/services/*;onduplicates:= ");
Jar jar = a.build();
assertFalse(a.check());
assertEquals("No value after '=' sign for attribute dup_merge:", a.getErrors()
assertEquals("No value after '=' sign for attribute onduplicates:", a.getErrors()
.get(0));

}
}

@Test
public void testIncludeResourceDuplicatesMergeMultipleGlobs() throws Exception {

try (Builder a = new Builder();) {
a.addClasspath(new File("jar/jarA.jar"));
a.addClasspath(a.getFile("jar/jarB.jar"));
a.setIncludeResource(
"@jar/jarA.jar!/META-INF/services/*, @jar/jarB.jar!/META-INF/services/*;dup_merge:=\"*foo*,*foo*\"");
Jar jar = a.build();
assertTrue(a.check());

assertTrue(jar.getDirectories()
.containsKey("META-INF/services"));

Resource resource = jar.getResource("META-INF/services/foo");
assertEquals("a\nb", IO.collect(resource.openInputStream()));

}
}

@Test
public void testIncludeResourceDuplicatesError() throws Exception {

try (Builder a = new Builder();) {
a.addClasspath(new File("jar/jarA.jar"));
a.addClasspath(a.getFile("jar/jarB.jar"));
a.setIncludeResource("@jar/jarA.jar!/META-INF/services/*, @jar/jarB.jar!/META-INF/services/*;dup_error:=*");
a.setIncludeResource(
"@jar/jarA.jar!/META-INF/services/*, @jar/jarB.jar!/META-INF/services/*;onduplicates:=ERROR");
Jar jar = a.build();
assertFalse(a.check());
assertEquals("Duplicate file: META-INF/services/foo", a.getErrors()
Expand All @@ -313,7 +295,7 @@ public void testIncludeResourceDuplicatesWarning() throws Exception {
a.addClasspath(new File("jar/jarA.jar"));
a.addClasspath(a.getFile("jar/jarB.jar"));
a.setIncludeResource(
"@jar/jarA.jar!/META-INF/services/*, @jar/jarB.jar!/META-INF/services/*;dup_warning:=*");
"@jar/jarA.jar!/META-INF/services/*, @jar/jarB.jar!/META-INF/services/*;onduplicates:=WARN");
Jar jar = a.build();
assertFalse(a.check());
assertEquals("Duplicate file: META-INF/services/foo", a.getWarnings()
Expand All @@ -335,7 +317,7 @@ public void testIncludeResourceDuplicatesOverwrite() throws Exception {
a.addClasspath(new File("jar/jarA.jar"));
a.addClasspath(a.getFile("jar/jarB.jar"));
a.setIncludeResource(
"@jar/jarA.jar!/META-INF/services/*, @jar/jarB.jar!/META-INF/services/*;dup_overwrite:=*");
"@jar/jarA.jar!/META-INF/services/*, @jar/jarB.jar!/META-INF/services/*;onduplicates:=OVERWRITE");
Jar jar = a.build();
assertTrue(a.check());

Expand All @@ -351,30 +333,11 @@ public void testIncludeResourceDuplicatesOverwrite() throws Exception {
@Test
public void testIncludeResourceDuplicatesSkip() throws Exception {

try (Builder a = new Builder();) {
a.addClasspath(new File("jar/jarA.jar"));
a.addClasspath(a.getFile("jar/jarB.jar"));
a.setIncludeResource("@jar/jarA.jar!/META-INF/services/*, @jar/jarB.jar!/META-INF/services/*;dup_skip:=*");
Jar jar = a.build();
assertTrue(a.check());

assertTrue(jar.getDirectories()
.containsKey("META-INF/services"));

Resource resource = jar.getResource("META-INF/services/foo");
assertEquals("a", IO.collect(resource.openInputStream()));

}
}

@Test
public void testIncludeResourceDuplicatesSkipPrecedence() throws Exception {

try (Builder a = new Builder();) {
a.addClasspath(new File("jar/jarA.jar"));
a.addClasspath(a.getFile("jar/jarB.jar"));
a.setIncludeResource(
"@jar/jarA.jar!/META-INF/services/*, @jar/jarB.jar!/META-INF/services/*;dup_merge:=*;dup_skip:=*");
"@jar/jarA.jar!/META-INF/services/*, @jar/jarB.jar!/META-INF/services/*;onduplicates:=SKIP");
Jar jar = a.build();
assertTrue(a.check());

Expand All @@ -387,19 +350,20 @@ public void testIncludeResourceDuplicatesSkipPrecedence() throws Exception {
}
}


@Test
public void testIncludeResourceLiteralDuplicatesMerge(@InjectTemporaryDirectory
File tmp) throws Exception {

try (Builder b = new Builder()) {
b.setIncludeResource("/a/a.txt;literal='a', /a/a.txt;literal='b';dup_merge:=*");
b.setIncludeResource("/a/a.txt;literal='a', /a/a.txt;literal='b';onduplicates:=MERGE");
b.build();
assertTrue(b.check());

b.getJar()
.writeFolder(tmp);

assertEquals("ab", IO.collect(IO.getFile(tmp, "a/a.txt")));
assertEquals("b", IO.collect(IO.getFile(tmp, "a/a.txt")));
}
}

Expand All @@ -409,7 +373,7 @@ public void testIncludeResourceLiteralMetaInfServicesDuplicatesMerge(@InjectTemp

try (Builder b = new Builder()) {
b.setIncludeResource(
"META-INF/services/a.txt;literal='a', META-INF/services/a.txt;literal='b';dup_merge:=*");
"META-INF/services/a.txt;literal='a', META-INF/services/a.txt;literal='b';onduplicates:=MERGE");
b.build();
assertTrue(b.check());

Expand All @@ -425,7 +389,7 @@ public void testIncludeResourceLiteralDuplicatesError(@InjectTemporaryDirectory
File tmp) throws Exception {

try (Builder b = new Builder()) {
b.setIncludeResource("/a/a.txt;literal='a', /a/a.txt;literal='b';dup_error:=*");
b.setIncludeResource("/a/a.txt;literal='a', /a/a.txt;literal='b';onduplicates:=ERROR");
b.build();
assertFalse(b.check());
assertEquals("Duplicate file: /a/a.txt", b.getErrors()
Expand Down
Loading

0 comments on commit ada3c3f

Please sign in to comment.