Source:
public void verify(Analyzer analyzer) throws Exception { Parameters provideCapabilities = new Parameters(analyzer.getJar() .getManifest() .getMainAttributes() .getValue(Constants.PROVIDE_CAPABILITY), analyzer, true); Map<String, ArrayList<String>> providerTypes = new HashMap<>(); for (Entry<String, Attrs> entry : provideCapabilities.entrySet()) { String key = Processor.removeDuplicateMarker(entry.getKey()); if ("osgi.serviceloader".equals(key)) { Attrs attrs = entry.getValue(); String serviceType = attrs.get("osgi.serviceloader"); String serviceImpl = attrs.get("register:"); if (serviceImpl == null) { analyzer.warning( "osgi.serviceloader capability found with no 'register:' directive. Descriptor cannot be managed for %s;%s", key, attrs); continue; } providerTypes.computeIfAbsent(serviceType, k -> new ArrayList<>()) .add(serviceImpl); } } for (Entry<String, ArrayList<String>> entry : providerTypes.entrySet()) { String key = "META-INF/services/" + entry.getKey(); ArrayList<String> list = entry.getValue(); Resource resource = analyzer.getJar() .getResource(key); String value = ""; if (resource != null) { value = IO.collect(resource.openInputStream()); try (BufferedReader br = new BufferedReader(new StringReader(value))) { String line; while ((line = br.readLine()) != null) { line = line.trim(); if (line.isEmpty() || (line.charAt(0) == '#')) { continue; } list.remove(line); } } } if (!list.isEmpty()) { list.add(0, "# Generated by bnd (modified: " + new Date(analyzer.lastModified()) + ")"); if (!value.isEmpty()) { value += "\n\n"; } value += Strings.join("\n", list); analyzer.getJar() .putResource(key, new EmbeddedResource(value, analyzer.lastModified())); } } }

Target:
public void verify(Analyzer analyzer) throws Exception { Parameters provideCapabilities = new Parameters(analyzer.getJar() .getManifest() .getMainAttributes() .getValue(Constants.PROVIDE_CAPABILITY), analyzer, true); Map<String, ArrayList<String>> providerTypes = new HashMap<>(); for (Entry<String, Attrs> entry : provideCapabilities.entrySet()) { String key = Processor.removeDuplicateMarker(entry.getKey()); if ("osgi.serviceloader".equals(key)) { Attrs attrs = entry.getValue(); String serviceType = attrs.get("osgi.serviceloader"); String serviceImpl = attrs.get("register:"); if (serviceImpl == null) { analyzer.warning( "osgi.serviceloader capability found with no 'register:' directive. Descriptor cannot be managed for %s;%s", key, attrs); continue; } providerTypes.computeIfAbsent(serviceType, k -> new ArrayList<>()) .add(serviceImpl); } } for (Entry<String, ArrayList<String>> entry : providerTypes.entrySet()) { String key = "META-INF/services/" + entry.getKey(); ArrayList<String> list = entry.getValue(); Resource resource = analyzer.getJar() .getResource(key); String value = ""; if (resource != null) { value = IO.collect(resource.openInputStream()); try (BufferedReader br = new BufferedReader(new StringReader(value))) { String line; while ((line = br.readLine()) != null) { line = line.trim(); if (line.isEmpty() || (line.charAt(0) == '#')) { continue; } list.remove(line); } } } if (!list.isEmpty()) { list.add(0, "# Generated by bnd"); if (!value.isEmpty()) { value += "\n\n"; } value += Strings.join("\n", list); analyzer.getJar() .putResource(key, new EmbeddedResource(value, analyzer.lastModified())); } } }