Repository: karaf Updated Branches: refs/heads/master 0991d06f4 -> ca2a0a71e
Fix formatting Project: http://git-wip-us.apache.org/repos/asf/karaf/repo Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/c7996aec Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/c7996aec Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/c7996aec Branch: refs/heads/master Commit: c7996aec5f5c21f0251657e1c9ce1b6e8637fa8b Parents: 0991d06 Author: Christian Schneider <[email protected]> Authored: Tue May 9 14:44:29 2017 +0200 Committer: Christian Schneider <[email protected]> Committed: Tue May 9 14:44:29 2017 +0200 ---------------------------------------------------------------------- .../karaf/features/extension/Activator.java | 44 +++---- .../karaf/features/extension/BundleWires.java | 124 +++++++++---------- 2 files changed, 83 insertions(+), 85 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/karaf/blob/c7996aec/features/extension/src/main/java/org/apache/karaf/features/extension/Activator.java ---------------------------------------------------------------------- diff --git a/features/extension/src/main/java/org/apache/karaf/features/extension/Activator.java b/features/extension/src/main/java/org/apache/karaf/features/extension/Activator.java index 19e2769..9992d0a 100644 --- a/features/extension/src/main/java/org/apache/karaf/features/extension/Activator.java +++ b/features/extension/src/main/java/org/apache/karaf/features/extension/Activator.java @@ -28,12 +28,12 @@ import org.osgi.framework.wiring.FrameworkWiring; public class Activator implements BundleActivator, SynchronousBundleListener { private static final String WIRING_PATH = "wiring"; - private StoredWiringResolver resolver; - private BundleContext context; + private StoredWiringResolver resolver; + private BundleContext context; @Override public void start(BundleContext context) throws Exception { - this.context = context; + this.context = context; resolver = new StoredWiringResolver(context.getDataFile(WIRING_PATH).toPath()); context.addBundleListener(this); } @@ -43,23 +43,25 @@ public class Activator implements BundleActivator, SynchronousBundleListener { context.removeBundleListener(this); } - @Override - public void bundleChanged(BundleEvent event) { - if (event.getBundle().getBundleId() == 0 && event.getType() == BundleEvent.STARTED) { - resolveAll(); - } else if (event.getType() == BundleEvent.RESOLVED) { - resolver.update(event.getBundle()); - } else if (event.getType() == BundleEvent.UNRESOLVED) { - resolver.delete(event.getBundle()); - } - } + @Override + public void bundleChanged(BundleEvent event) { + if (event.getBundle().getBundleId() == 0 && event.getType() == BundleEvent.STARTED) { + resolveAll(); + } else if (event.getType() == BundleEvent.RESOLVED) { + resolver.update(event.getBundle()); + } else if (event.getType() == BundleEvent.UNRESOLVED) { + resolver.delete(event.getBundle()); + } + } - private void resolveAll() { - ServiceRegistration<ResolverHookFactory> registration = context.registerService(ResolverHookFactory.class, (triggers) -> resolver, null); - try { - context.getBundle().adapt(FrameworkWiring.class).resolveBundles(Arrays.asList(context.getBundles())); - } finally { - registration.unregister(); - } - } + private void resolveAll() { + ServiceRegistration<ResolverHookFactory> registration = context + .registerService(ResolverHookFactory.class, (triggers) -> resolver, null); + try { + context.getBundle().adapt(FrameworkWiring.class) + .resolveBundles(Arrays.asList(context.getBundles())); + } finally { + registration.unregister(); + } + } } http://git-wip-us.apache.org/repos/asf/karaf/blob/c7996aec/features/extension/src/main/java/org/apache/karaf/features/extension/BundleWires.java ---------------------------------------------------------------------- diff --git a/features/extension/src/main/java/org/apache/karaf/features/extension/BundleWires.java b/features/extension/src/main/java/org/apache/karaf/features/extension/BundleWires.java index a355b08..51ff8b1 100644 --- a/features/extension/src/main/java/org/apache/karaf/features/extension/BundleWires.java +++ b/features/extension/src/main/java/org/apache/karaf/features/extension/BundleWires.java @@ -42,82 +42,78 @@ import org.osgi.resource.Namespace; import org.osgi.resource.Requirement; class BundleWires { - long bundleId; - Map<String, String> wiring = new HashMap<>(); + long bundleId; + Map<String, String> wiring = new HashMap<>(); - BundleWires(Bundle bundle) { - this.bundleId = bundle.getBundleId(); + BundleWires(Bundle bundle) { + this.bundleId = bundle.getBundleId(); for (BundleWire wire : bundle.adapt(BundleWiring.class).getRequiredWires(null)) { this.wiring.put(getRequirementId(wire.getRequirement()), getCapabilityId(wire.getCapability())); } - } - - BundleWires(long bundleId, BufferedReader reader) throws IOException { - this.bundleId = bundleId; - while (true) { - String key = reader.readLine(); - String val = reader.readLine(); - if (key != null && val != null) { - this.wiring.put(key, val); - } else { - break; - } - } - } - - void save(Path path) { - try { - Files.createDirectories(path); - Path file = path.resolve(Long.toString(this.bundleId)); - Files.createDirectories(file.getParent()); - try (BufferedWriter fw = Files.newBufferedWriter(file, TRUNCATE_EXISTING, WRITE, CREATE)) { - for (Map.Entry<String, String> wire : wiring.entrySet()) { - fw.append(wire.getKey()).append('\n'); - fw.append(wire.getValue()).append('\n'); - } - } - } catch (IOException e) { - throw new UncheckedIOException(e); - } - } - - void delete(Path path) { - try { - Files.createDirectories(path); - Path file = path.resolve(Long.toString(this.bundleId)); - Files.deleteIfExists(file); - } catch (IOException e) { - throw new UncheckedIOException(e); - } - } - - long getFragmentHost() { - return wiring.entrySet().stream() - .filter(e -> e.getKey().startsWith(HostNamespace.HOST_NAMESPACE)) - .map(Map.Entry::getValue) - .mapToLong(s -> { - int idx = s.indexOf(';'); - if (idx > 0) { - s = s.substring(0, idx); + } + + BundleWires(long bundleId, BufferedReader reader) throws IOException { + this.bundleId = bundleId; + while (true) { + String key = reader.readLine(); + String val = reader.readLine(); + if (key != null && val != null) { + this.wiring.put(key, val); + } else { + break; + } + } + } + + void save(Path path) { + try { + Files.createDirectories(path); + Path file = path.resolve(Long.toString(this.bundleId)); + Files.createDirectories(file.getParent()); + try (BufferedWriter fw = Files.newBufferedWriter(file, TRUNCATE_EXISTING, WRITE, CREATE)) { + for (Map.Entry<String, String> wire : wiring.entrySet()) { + fw.append(wire.getKey()).append('\n'); + fw.append(wire.getValue()).append('\n'); + } } - return Long.parseLong(s.trim()); - }) - .findFirst() - .orElse(-1); - } - - void filterMatches(BundleRequirement requirement, Collection<BundleCapability> candidates) { + } catch (IOException e) { + throw new UncheckedIOException(e); + } + } + + void delete(Path path) { + try { + Files.createDirectories(path); + Path file = path.resolve(Long.toString(this.bundleId)); + Files.deleteIfExists(file); + } catch (IOException e) { + throw new UncheckedIOException(e); + } + } + + long getFragmentHost() { + return wiring.entrySet().stream().filter(e -> e.getKey().startsWith(HostNamespace.HOST_NAMESPACE)) + .map(Map.Entry::getValue).mapToLong(s -> { + int idx = s.indexOf(';'); + if (idx > 0) { + s = s.substring(0, idx); + } + return Long.parseLong(s.trim()); + }).findFirst().orElse(-1); + } + + void filterMatches(BundleRequirement requirement, Collection<BundleCapability> candidates) { String cap = wiring.get(getRequirementId(requirement)); for (Iterator<BundleCapability> candIter = candidates.iterator(); candIter.hasNext();) { BundleCapability cand = candIter.next(); if (cap != null && !cap.equals(getCapabilityId(cand)) - || cap == null && cand.getRevision().getBundle().getBundleId() != this.bundleId) { + || cap == null && cand.getRevision().getBundle().getBundleId() != this.bundleId) { candIter.remove(); } } - } - - private String getRequirementId(Requirement requirement) { + } + + private String getRequirementId(Requirement requirement) { String filter = requirement.getDirectives().get(Namespace.REQUIREMENT_FILTER_DIRECTIVE); if (filter != null) { return requirement.getNamespace() + "; " + filter;
