Skip to content

Commit

Permalink
Allow duplicate pids in designates if one is for regular the other for
Browse files Browse the repository at this point in the history
factory pid

This closes bndtools#6042

Signed-off-by: Konrad Windszus <kwin@apache.org>
  • Loading branch information
kwin committed Mar 15, 2024
1 parent c951830 commit 1a3880f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@ public interface DupPid4 {

}

// this is allowed (no duplicate)
@ObjectClassDefinition(pid = {
"3"
}, factoryPid = {
Expand All @@ -330,13 +331,15 @@ public interface DupPid5 {

}

// this is allowed (no duplicate)
@ObjectClassDefinition(pid = {
"4"
})
public interface DupPid6 {

}

// this is allowed (no duplicate)
@ObjectClassDefinition(factoryPid = {
"4"
})
Expand All @@ -354,7 +357,7 @@ public void testPidCollision() throws Exception {
b.setProperty(Constants.METATYPE_ANNOTATIONS, name.substring(0, name.length() - "1".length()) + "*");
b.build();
System.err.println(b.getErrors());
assertEquals(4, b.getErrors()
assertEquals(2, b.getErrors()
.size());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ public boolean analyzeJar(Analyzer analyzer) throws Exception {

Set<String> ocdIds = new HashSet<>();
Set<String> pids = new HashSet<>();
Set<String> factoryPids = new HashSet<>();

Instructions instructions = new Instructions(header);

Expand Down Expand Up @@ -142,8 +143,10 @@ public boolean analyzeJar(Analyzer analyzer) throws Exception {
analyzer.error("Duplicate OCD id %s from class %s; known ids %s", definition.id, c.getFQN(), ocdIds);
}
for (DesignateDef dDef : definition.designates) {
if (dDef.pid != null && !pids.add(dDef.pid)) {
analyzer.error("Duplicate pid %s from class %s", dDef.pid, c.getFQN());
Set<String> relevantPids = dDef.factory ? factoryPids : pids;
if (dDef.pid != null && !relevantPids.add(dDef.pid)) {
analyzer.error("Duplicate %s from class %s", dDef.factory ? "factoryPid" : "pid", dDef.pid,
c.getFQN());
}
}
String name = "OSGI-INF/metatype/" + analyzer.validResourcePath(definition.id, "Invalid resource name")
Expand Down

0 comments on commit 1a3880f

Please sign in to comment.