From 99b9c730731d4622294f4ef0c0190535be4364ed Mon Sep 17 00:00:00 2001 From: Christoph Rueger Date: Thu, 3 Oct 2024 07:42:46 +0200 Subject: [PATCH] auto register caps for META-INF/service this is an experiment based on an idea mentioned in https://github.com/bndtools/bnd/issues/6304 it leverages the recent addition of PR https://github.com/bndtools/bnd/pull/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 --- .../aQute/bnd/osgi/metainf/MetaInfService.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/biz.aQute.bndlib/src/aQute/bnd/osgi/metainf/MetaInfService.java b/biz.aQute.bndlib/src/aQute/bnd/osgi/metainf/MetaInfService.java index 358b7f7927..4705a72ffb 100644 --- a/biz.aQute.bndlib/src/aQute/bnd/osgi/metainf/MetaInfService.java +++ b/biz.aQute.bndlib/src/aQute/bnd/osgi/metainf/MetaInfService.java @@ -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(); }