Skip to content

Commit

Permalink
improve default message
Browse files Browse the repository at this point in the history
add word 'overwritten' to the default warning.
Also use a Constant for the default strategy.

Signed-off-by: Christoph Rueger <chrisrueger@gmail.com>
  • Loading branch information
chrisrueger committed Oct 30, 2024
1 parent 5b39758 commit 1875489
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
2 changes: 1 addition & 1 deletion biz.aQute.bndlib.tests/test/test/BuilderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ public void test1017UsingPrivatePackagesVersion() throws Exception {
B.setPrivatePackage("org.osgi.service.event");
B.setIncludeResource("org/osgi/service/event/packageinfo;literal='version 2.0.0'");
B.setProperty("-fixupmessages.duplicates",
"Duplicate file:");
"Duplicate file");
B.build();
assertTrue(B.check());

Expand Down
4 changes: 2 additions & 2 deletions biz.aQute.bndlib.tests/test/test/IncludeResourceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ public void testIncludeResourceDuplicatesDefault() throws Exception {
Jar jar = a.build();
assertFalse(a.check());
assertEquals(
"Duplicate file: META-INF/services/foo (Consider using the onduplicate: directive to handle duplicates.)",
"Duplicate file overwritten: META-INF/services/foo (Consider using the onduplicate: directive to handle duplicates.)",
a.getWarnings()
.get(0));

Expand Down Expand Up @@ -463,7 +463,7 @@ public void testIncludeResourceDuplicatesTagWithoutStrategyEnum() throws Excepti
Jar jar = a.build();
assertFalse(a.check());
assertEquals(
"Duplicate file: META-INF/services/foo (Consider using the onduplicate: directive to handle duplicates.)",
"Duplicate file overwritten: META-INF/services/foo (Consider using the onduplicate: directive to handle duplicates.)",
a.getWarnings()
.get(0));

Expand Down
19 changes: 11 additions & 8 deletions biz.aQute.bndlib/src/aQute/bnd/osgi/Builder.java
Original file line number Diff line number Diff line change
Expand Up @@ -1412,11 +1412,6 @@ private boolean addAll(Jar to, Jar sub, Instruction filter, String destination,
return dupl;
}

private DupStrategy parseDupStrategy(Map<String, String> extra) {
String onduplicate = extra.get(DUP_STRATEGY);
return DupStrategy.parse(onduplicate);
}

@SuppressWarnings("deprecation")
private void copy(Jar jar, String path, File from, Instructions preprocess, Map<String, String> extra)
throws Exception {
Expand Down Expand Up @@ -2126,6 +2121,11 @@ public String system(boolean allowFail, String command, String input) throws IOE
return cachedSystemCalls.computeIfAbsent(key, asFunction(k -> super.system(allowFail, command, input)));
}

private DupStrategy parseDupStrategy(Map<String, String> extra) {
String onduplicate = extra.get(DUP_STRATEGY);
return DupStrategy.parse(onduplicate);
}

private enum DupStrategyEnum {
OVERWRITE,
MERGE,
Expand Down Expand Up @@ -2157,7 +2157,10 @@ public static DupStrategyEnum fromString(String s) {
*/
private final static class DupStrategy {

private static final String DUP_MSG_DEFAULT_OVERWRITE = "Duplicate file: %s (Consider using the %s directive to handle duplicates.)";
private static final DupStrategy DEFAULT = new DupStrategy(
DupStrategyEnum.DEFAULT_OVERWRITE, Set.of());

private static final String DUP_MSG_DEFAULT_OVERWRITE = "Duplicate file overwritten: %s (Consider using the %s directive to handle duplicates.)";
private static final String DUP_MSG = "Duplicate file: %s";
private DupStrategyEnum strategy;
private Set<String> tags;
Expand All @@ -2175,7 +2178,7 @@ public static DupStrategy parse(String directive) {
// enum ::= WARN, ERROR, MERGE,SKIP, OVERWRITE

if (directive == null || directive.isBlank()) {
return new DupStrategy(DupStrategyEnum.DEFAULT_OVERWRITE, Set.of());
return DEFAULT;
}

List<String> enumOrTags = Arrays.asList(directive.split(","));
Expand All @@ -2200,7 +2203,7 @@ public static DupStrategy parse(String directive) {

if (dupEnum == null) {
// still no enum found, make sure we warn
return new DupStrategy(DupStrategyEnum.DEFAULT_OVERWRITE, Set.of());
return DEFAULT;
}

return new DupStrategy(dupEnum, tags);
Expand Down

0 comments on commit 1875489

Please sign in to comment.