Skip to content

Commit

Permalink
Removes Require-Capability for osgi.service AnyService
Browse files Browse the repository at this point in the history
fixes #5750

Signed-off-by: Juergen Albert <[email protected]>
---
 Signed-off-by: Peter Kriens <[email protected]>
  • Loading branch information
juergen-albert authored and pkriens committed Sep 12, 2023
1 parent d185ade commit 1b4ca76
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
20 changes: 19 additions & 1 deletion biz.aQute.bndlib.tests/test/test/component/DSAnnotationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4395,7 +4395,6 @@ public void anyservice() throws Exception {
assertOk(b);
Attributes a = getAttr(jar);
checkProvides(a);
checkRequires(a, ComponentConstants.COMPONENT_SPECIFICATION_VERSION, AnyService.class.getName());

//
// Test all the defaults
Expand Down Expand Up @@ -4444,6 +4443,25 @@ public void anyservice() throws Exception {
}
}

@Test
public void anyserviceNoServiceRequirement() throws Exception {
try (Builder b = new Builder()) {
b.setProperty(Constants.DSANNOTATIONS, "test.component.DSAnnotationTest$AnyServiceUse");
b.setProperty("Private-Package", "test.component");
b.addClasspath(new File("bin_test"));

Jar jar = b.build();
assertOk(b);
Attributes a = getAttr(jar);
checkProvides(a);

jar.getManifest()
.write(System.out);

assertThat(a.getValue(Constants.REQUIRE_CAPABILITY)).doesNotContain(AnyService.class.getName());
}
}

@Component
public static class AnyServiceUseNoObject {
@Activate
Expand Down
3 changes: 3 additions & 0 deletions biz.aQute.bndlib/src/aQute/bnd/component/DSAnnotations.java
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,9 @@ private void addServiceCapability(ComponentDef definition, Set<String> provides,

private void addServiceRequirement(ReferenceDef ref, MergedRequirement requires) {
String objectClass = ref.service;
if ("org.osgi.service.component.AnyService".equals(objectClass)) {
return;
}
ReferenceCardinality cardinality = ref.cardinality;
boolean optional = cardinality == ReferenceCardinality.OPTIONAL || cardinality == ReferenceCardinality.MULTIPLE;
boolean multiple = cardinality == ReferenceCardinality.MULTIPLE
Expand Down

0 comments on commit 1b4ca76

Please sign in to comment.