X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fblueprint%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fblueprint%2FBlueprintBundleTracker.java;h=7ad8ddb4e3a5e4b9fd83096d99344cff4a257a06;hb=abaef4a5ae37f27542155457fe7306a4662b1eeb;hp=3f821ba731ac44e51dd380bb59fe0687b88f320d;hpb=b2a5ec266ccdfca559cfb6c2ea0cac652f5f52cd;p=controller.git diff --git a/opendaylight/blueprint/src/main/java/org/opendaylight/controller/blueprint/BlueprintBundleTracker.java b/opendaylight/blueprint/src/main/java/org/opendaylight/controller/blueprint/BlueprintBundleTracker.java index 3f821ba731..7ad8ddb4e3 100644 --- a/opendaylight/blueprint/src/main/java/org/opendaylight/controller/blueprint/BlueprintBundleTracker.java +++ b/opendaylight/blueprint/src/main/java/org/opendaylight/controller/blueprint/BlueprintBundleTracker.java @@ -7,6 +7,7 @@ */ package org.opendaylight.controller.blueprint; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -16,11 +17,12 @@ import java.util.Enumeration; import java.util.HashSet; import java.util.Hashtable; import java.util.List; -import javax.annotation.Nullable; import org.apache.aries.blueprint.NamespaceHandler; import org.apache.aries.blueprint.services.BlueprintExtenderService; import org.apache.aries.quiesce.participant.QuiesceParticipant; import org.apache.aries.util.AriesFrameworkUtil; +import org.eclipse.jdt.annotation.Nullable; +import org.gaul.modernizer_maven_annotations.SuppressModernizer; import org.opendaylight.controller.blueprint.ext.OpendaylightNamespaceHandler; import org.opendaylight.yangtools.util.xml.UntrustedXML; import org.osgi.framework.Bundle; @@ -51,7 +53,8 @@ import org.slf4j.LoggerFactory; public class BlueprintBundleTracker implements BundleActivator, BundleTrackerCustomizer, BlueprintListener, SynchronousBundleListener { private static final Logger LOG = LoggerFactory.getLogger(BlueprintBundleTracker.class); - private static final String BLUEPRINT_FILE_PATH = "org/opendaylight/blueprint/"; + private static final String ODL_CUSTOM_BLUEPRINT_FILE_PATH = "org/opendaylight/blueprint/"; + private static final String STANDARD_BLUEPRINT_FILE_PATH = "OSGI-INF/blueprint/"; private static final String BLUEPRINT_FLE_PATTERN = "*.xml"; private static final long SYSTEM_BUNDLE_ID = 0; @@ -87,7 +90,7 @@ public class BlueprintBundleTracker implements BundleActivator, BundleTrackerCus bundleTracker = new BundleTracker<>(context, Bundle.ACTIVE, this); - blueprintExtenderServiceTracker = new ServiceTracker<>(context, BlueprintExtenderService.class.getName(), + blueprintExtenderServiceTracker = new ServiceTracker<>(context, BlueprintExtenderService.class, new ServiceTrackerCustomizer() { @Override public BlueprintExtenderService addingService( @@ -107,7 +110,7 @@ public class BlueprintBundleTracker implements BundleActivator, BundleTrackerCus }); blueprintExtenderServiceTracker.open(); - quiesceParticipantTracker = new ServiceTracker<>(context, QuiesceParticipant.class.getName(), + quiesceParticipantTracker = new ServiceTracker<>(context, QuiesceParticipant.class, new ServiceTrackerCustomizer() { @Override public QuiesceParticipant addingService( @@ -128,6 +131,8 @@ public class BlueprintBundleTracker implements BundleActivator, BundleTrackerCus quiesceParticipantTracker.open(); } + @SuppressFBWarnings(value = "UPM_UNCALLED_PRIVATE_METHOD", + justification = "https://github.com/spotbugs/spotbugs/issues/811") private QuiesceParticipant onQuiesceParticipantAdded(final ServiceReference reference) { quiesceParticipant = reference.getBundle().getBundleContext().getService(reference); @@ -138,6 +143,8 @@ public class BlueprintBundleTracker implements BundleActivator, BundleTrackerCus return quiesceParticipant; } + @SuppressFBWarnings(value = "UPM_UNCALLED_PRIVATE_METHOD", + justification = "https://github.com/spotbugs/spotbugs/issues/811") private BlueprintExtenderService onBlueprintExtenderServiceAdded( final ServiceReference reference) { blueprintExtenderService = reference.getBundle().getBundleContext().getService(reference); @@ -149,21 +156,25 @@ public class BlueprintBundleTracker implements BundleActivator, BundleTrackerCus restartService.setBlueprintExtenderService(blueprintExtenderService); - blueprintContainerRestartReg = bundleContext.registerService( - BlueprintContainerRestartService.class.getName(), restartService, new Hashtable<>()); + blueprintContainerRestartReg = bundleContext.registerService(BlueprintContainerRestartService.class, + restartService, null); return blueprintExtenderService; } private void registerNamespaceHandler(final BundleContext context) { - Dictionary props = new Hashtable<>(); + Dictionary props = emptyDict(); props.put("osgi.service.blueprint.namespace", OpendaylightNamespaceHandler.NAMESPACE_1_0_0); - namespaceReg = context.registerService(NamespaceHandler.class.getName(), - new OpendaylightNamespaceHandler(), props); + namespaceReg = context.registerService(NamespaceHandler.class, new OpendaylightNamespaceHandler(), props); } private void registerBlueprintEventHandler(final BundleContext context) { - eventHandlerReg = context.registerService(BlueprintListener.class.getName(), this, new Hashtable<>()); + eventHandlerReg = context.registerService(BlueprintListener.class, this, null); + } + + @SuppressModernizer + private static Dictionary emptyDict() { + return new Hashtable<>(); } /** @@ -211,7 +222,7 @@ public class BlueprintBundleTracker implements BundleActivator, BundleTrackerCus } if (bundle.getState() == Bundle.ACTIVE) { - List paths = findBlueprintPaths(bundle); + List paths = findBlueprintPaths(bundle, ODL_CUSTOM_BLUEPRINT_FILE_PATH); if (!paths.isEmpty()) { LOG.info("Creating blueprint container for bundle {} with paths {}", bundle, paths); @@ -258,9 +269,14 @@ public class BlueprintBundleTracker implements BundleActivator, BundleTrackerCus } } - @SuppressWarnings({ "rawtypes", "unchecked" }) static List findBlueprintPaths(final Bundle bundle) { - Enumeration rntries = bundle.findEntries(BLUEPRINT_FILE_PATH, BLUEPRINT_FLE_PATTERN, false); + List paths = findBlueprintPaths(bundle, STANDARD_BLUEPRINT_FILE_PATH); + return !paths.isEmpty() ? paths : findBlueprintPaths(bundle, ODL_CUSTOM_BLUEPRINT_FILE_PATH); + } + + @SuppressWarnings({ "rawtypes", "unchecked" }) + private static List findBlueprintPaths(final Bundle bundle, final String path) { + Enumeration rntries = bundle.findEntries(path, BLUEPRINT_FLE_PATTERN, false); if (rntries == null) { return Collections.emptyList(); } else { @@ -291,7 +307,7 @@ public class BlueprintBundleTracker implements BundleActivator, BundleTrackerCus LOG.info("Shutdown of blueprint containers complete"); } - private List getBundlesToDestroy(final Collection containerBundles) { + private static List getBundlesToDestroy(final Collection containerBundles) { List bundlesToDestroy = new ArrayList<>(); // Find all container bundles that either have no registered services or whose services are no @@ -336,8 +352,7 @@ public class BlueprintBundleTracker implements BundleActivator, BundleTrackerCus return bundlesToDestroy; } - @Nullable - private Bundle findBundleWithHighestUsedServiceId(final Collection containerBundles) { + private static @Nullable Bundle findBundleWithHighestUsedServiceId(final Collection containerBundles) { ServiceReference highestServiceRef = null; for (Bundle bundle : containerBundles) { ServiceReference[] references = bundle.getRegisteredServices();