Skip to content

Commit

Permalink
auto register caps for META-INF/service
Browse files Browse the repository at this point in the history
this is an experiment based on an idea mentioned in bndtools#6304

it leverages the recent addition of PR bndtools#5912 that allowed to add annotations in comments of files in META-INF/services. But in this PR we basically pretent and add a aQute.bnd.annotation.spi.ServiceProvider annotation artificially. this causes bnd to generate Provide-Capability manifest headers for the services

make sure biz.aQute.bndlib is on the buildpath which contains the 'aQute.bnd.annotation.spi.ServiceProvider' annotation

Signed-off-by: Christoph Rueger <[email protected]>
  • Loading branch information
chrisrueger committed Oct 3, 2024
1 parent 5f76bc9 commit 99b9c73
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion biz.aQute.bndlib/src/aQute/bnd/osgi/metainf/MetaInfService.java
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,20 @@ public MetaInfService(String serviceName, String source) {
// just comment
continue;
}
implementations.put(line, new Implementation(line, annotations, comments));

// TODO: experimental: if there are no annotations present we just
// add one artificially to register the service in the manifest
// TODO should this be made configurable somehow?
if (annotations.isEmpty()) {
// this will create the capabilities for Service provider
// without any attributes e.g.
// Provide-Capability',
// "osgi.serviceloader;osgi.serviceloader=serviceName
annotations.add("aQute.bnd.annotation.spi.ServiceProvider", Attrs.EMPTY_ATTRS);
implementations.put(line, new Implementation(line, annotations, comments));
} else {
implementations.put(line, new Implementation(line, annotations, comments));
}
annotations.clear();
comments.clear();
}
Expand Down

0 comments on commit 99b9c73

Please sign in to comment.