Fix checkstyle issues to enforce it 42/63042/2
authorDavid Suarez <david.suarez.fuentes@gmail.com>
Tue, 12 Sep 2017 14:26:05 +0000 (16:26 +0200)
committerTom Pantelis <tompantelis@gmail.com>
Tue, 12 Sep 2017 16:35:48 +0000 (16:35 +0000)
Change-Id: I901673c4c8f478e914efd54d26bee56a80296868
Signed-off-by: David Suarez <david.suarez.fuentes@gmail.com>
opendaylight/config/config-persister-feature-adapter/pom.xml
opendaylight/config/config-persister-feature-adapter/src/main/java/org/opendaylight/controller/configpusherfeature/ConfigPusherFeatureActivator.java
opendaylight/config/config-persister-feature-adapter/src/main/java/org/opendaylight/controller/configpusherfeature/internal/AbstractFeatureWrapper.java
opendaylight/config/config-persister-feature-adapter/src/main/java/org/opendaylight/controller/configpusherfeature/internal/ChildAwareFeatureWrapper.java
opendaylight/config/config-persister-feature-adapter/src/main/java/org/opendaylight/controller/configpusherfeature/internal/ConfigFeaturesListener.java
opendaylight/config/config-persister-feature-adapter/src/main/java/org/opendaylight/controller/configpusherfeature/internal/ConfigPusherCustomizer.java
opendaylight/config/config-persister-feature-adapter/src/main/java/org/opendaylight/controller/configpusherfeature/internal/ConfigPushingRunnable.java
opendaylight/config/config-persister-feature-adapter/src/main/java/org/opendaylight/controller/configpusherfeature/internal/FeatureConfigPusher.java
opendaylight/config/config-persister-feature-adapter/src/main/java/org/opendaylight/controller/configpusherfeature/internal/FeatureConfigSnapshotHolder.java
opendaylight/config/config-persister-feature-adapter/src/main/java/org/opendaylight/controller/configpusherfeature/internal/FeatureServiceCustomizer.java

index d7fd2d0230a49725286d80713ff71826c526b8fc..cd6f6b1b6ff49edaff1763f355221fe21a9ea952 100644 (file)
 
     <build>
         <plugins>
 
     <build>
         <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-checkstyle-plugin</artifactId>
+                <configuration>
+                    <propertyExpansion>checkstyle.violationSeverity=error</propertyExpansion>
+                </configuration>
+            </plugin>
             <plugin>
                 <groupId>org.apache.felix</groupId>
                 <artifactId>maven-bundle-plugin</artifactId>
             <plugin>
                 <groupId>org.apache.felix</groupId>
                 <artifactId>maven-bundle-plugin</artifactId>
index c20c6f9182caa895cd50e51ee36dab887a41c4f0..99334da488b5c795ae446679947d83a1f24ac17d 100644 (file)
@@ -14,10 +14,9 @@ import org.osgi.framework.BundleContext;
 import org.osgi.util.tracker.ServiceTracker;
 
 public class ConfigPusherFeatureActivator implements BundleActivator {
 import org.osgi.util.tracker.ServiceTracker;
 
 public class ConfigPusherFeatureActivator implements BundleActivator {
-
-    BundleContext bc = null;
-    ConfigPusherCustomizer cpc = null;
-    ServiceTracker<ConfigPusher,ConfigPusher> cpst = null;
+    private BundleContext bc = null;
+    private ConfigPusherCustomizer cpc = null;
+    private ServiceTracker<ConfigPusher, ConfigPusher> cpst = null;
 
     public void start(final BundleContext context) throws Exception {
         bc = context;
 
     public void start(final BundleContext context) throws Exception {
         bc = context;
@@ -27,11 +26,11 @@ public class ConfigPusherFeatureActivator implements BundleActivator {
     }
 
     public void stop(final BundleContext context) throws Exception {
     }
 
     public void stop(final BundleContext context) throws Exception {
-        if(cpst != null) {
+        if (cpst != null) {
             cpst.close();
             cpst = null;
         }
             cpst.close();
             cpst = null;
         }
-        if(cpc != null) {
+        if (cpc != null) {
             cpc.close();
             cpc = null;
         }
             cpc.close();
             cpc = null;
         }
index bce4d3c0c51ab9c884fea5cad29399cdcac88dfb..3c8622a16880bfb425852f4b4f12538953830625 100644 (file)
@@ -10,14 +10,19 @@ package org.opendaylight.controller.configpusherfeature.internal;
 import com.google.common.base.Optional;
 import com.google.common.base.Preconditions;
 import com.google.common.io.Files;
 import com.google.common.base.Optional;
 import com.google.common.base.Preconditions;
 import com.google.common.io.Files;
+
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.File;
 import java.io.FileInputStream;
+import java.io.IOException;
 import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Set;
 import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Set;
+
 import javax.xml.bind.JAXBException;
 import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.bind.JAXBException;
 import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamException;
+
 import org.apache.karaf.features.BundleInfo;
 import org.apache.karaf.features.Capability;
 import org.apache.karaf.features.Conditional;
 import org.apache.karaf.features.BundleInfo;
 import org.apache.karaf.features.Capability;
 import org.apache.karaf.features.Conditional;
@@ -32,6 +37,7 @@ import org.opendaylight.controller.config.persist.storage.file.xml.model.ConfigS
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.w3c.dom.Element;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.w3c.dom.Element;
+import org.xml.sax.SAXException;
 
 /*
  * Wrap a Feature for the purposes of extracting the FeatureConfigSnapshotHolders from
 
 /*
  * Wrap a Feature for the purposes of extracting the FeatureConfigSnapshotHolders from
@@ -53,9 +59,9 @@ public class AbstractFeatureWrapper implements Feature {
     /*
      * @param f Feature to wrap
      */
     /*
      * @param f Feature to wrap
      */
-    public AbstractFeatureWrapper(final Feature f) {
-        Preconditions.checkNotNull(f,"FeatureWrapper requires non-null Feature in constructor");
-        this.feature = f;
+    public AbstractFeatureWrapper(final Feature feature) {
+        Preconditions.checkNotNull(feature, "FeatureWrapper requires non-null Feature in constructor");
+        this.feature = feature;
     }
 
     /*
     }
 
     /*
@@ -64,11 +70,12 @@ public class AbstractFeatureWrapper implements Feature {
      */
     public Set<FeatureConfigSnapshotHolder> getFeatureConfigSnapshotHolders() throws Exception {
         final Set<FeatureConfigSnapshotHolder> snapShotHolders = new LinkedHashSet<>();
      */
     public Set<FeatureConfigSnapshotHolder> getFeatureConfigSnapshotHolders() throws Exception {
         final Set<FeatureConfigSnapshotHolder> snapShotHolders = new LinkedHashSet<>();
-        for(final ConfigFileInfo c: getConfigurationFiles()) {
+        for (final ConfigFileInfo c : getConfigurationFiles()) {
             // Skip non config snapshot XML files
             // Skip non config snapshot XML files
-            if(isConfigSnapshot(c.getFinalname())) {
-                final Optional<FeatureConfigSnapshotHolder> featureConfigSnapshotHolder = getFeatureConfigSnapshotHolder(c);
-                if(featureConfigSnapshotHolder.isPresent()) {
+            if (isConfigSnapshot(c.getFinalname())) {
+                final Optional<FeatureConfigSnapshotHolder> featureConfigSnapshotHolder =
+                        getFeatureConfigSnapshotHolder(c);
+                if (featureConfigSnapshotHolder.isPresent()) {
                     snapShotHolders.add(featureConfigSnapshotHolder.get());
                 }
             }
                     snapShotHolders.add(featureConfigSnapshotHolder.get());
                 }
             }
@@ -76,28 +83,29 @@ public class AbstractFeatureWrapper implements Feature {
         return snapShotHolders;
     }
 
         return snapShotHolders;
     }
 
-    protected Optional<FeatureConfigSnapshotHolder> getFeatureConfigSnapshotHolder(final ConfigFileInfo c) {
+    protected Optional<FeatureConfigSnapshotHolder>
+        getFeatureConfigSnapshotHolder(final ConfigFileInfo configFileInfo) {
         try {
         try {
-            return Optional.of(new FeatureConfigSnapshotHolder(c, this));
+            return Optional.of(new FeatureConfigSnapshotHolder(configFileInfo, this));
         } catch (final JAXBException e) {
         } catch (final JAXBException e) {
-            LOG.warn("Unable to parse configuration snapshot. Config from '{}' will be IGNORED. " +
-                    "Note that subsequent config files may fail due to this problem. " +
-                    "Xml markup in this file needs to be fixed, for detailed information see enclosed exception.",
-                    c.getFinalname(), e);
+            LOG.warn("Unable to parse configuration snapshot. Config from '{}' will be IGNORED. "
+                    + "Note that subsequent config files may fail due to this problem. "
+                    "Xml markup in this file needs to be fixed, for detailed information see enclosed exception.",
+                    configFileInfo.getFinalname(), e);
         } catch (final XMLStreamException e) {
             // Files that cannot be loaded are ignored as non config subsystem files e.g. jetty.xml
             LOG.debug("Unable to read configuration file '{}'. Not a configuration snapshot",
         } catch (final XMLStreamException e) {
             // Files that cannot be loaded are ignored as non config subsystem files e.g. jetty.xml
             LOG.debug("Unable to read configuration file '{}'. Not a configuration snapshot",
-                    c.getFinalname(), e);
+                    configFileInfo.getFinalname(), e);
         }
         return Optional.absent();
     }
 
     private static boolean isConfigSnapshot(final String fileName) {
         }
         return Optional.absent();
     }
 
     private static boolean isConfigSnapshot(final String fileName) {
-        if(!Files.getFileExtension(fileName).equals(CONFIG_FILE_SUFFIX)) {
+        if (!Files.getFileExtension(fileName).equals(CONFIG_FILE_SUFFIX)) {
             return false;
         }
 
             return false;
         }
 
-        if(fileName.endsWith("jetty.xml")) {
+        if (fileName.endsWith("jetty.xml")) {
             // Special case - ignore the jetty.xml file as it contains a DTD and causes a "Connection refused"
             // error when it tries to go out to the network to retrieve it. We don't want it trying to go out
             // to the network nor do we want an error logged trying to parse it.
             // Special case - ignore the jetty.xml file as it contains a DTD and causes a "Connection refused"
             // error when it tries to go out to the network to retrieve it. We don't want it trying to go out
             // to the network nor do we want an error logged trying to parse it.
@@ -105,7 +113,7 @@ public class AbstractFeatureWrapper implements Feature {
         }
 
         File file = new File(System.getProperty("karaf.home"), fileName);
         }
 
         File file = new File(System.getProperty("karaf.home"), fileName);
-        try(FileInputStream fis = new FileInputStream(file)) {
+        try (FileInputStream fis = new FileInputStream(file)) {
             DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
             builderFactory.setNamespaceAware(true);
             builderFactory.setCoalescing(true);
             DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
             builderFactory.setNamespaceAware(true);
             builderFactory.setCoalescing(true);
@@ -114,7 +122,7 @@ public class AbstractFeatureWrapper implements Feature {
 
             Element root = builderFactory.newDocumentBuilder().parse(fis).getDocumentElement();
             return ConfigSnapshot.SNAPSHOT_ROOT_ELEMENT_NAME.equals(root.getLocalName());
 
             Element root = builderFactory.newDocumentBuilder().parse(fis).getDocumentElement();
             return ConfigSnapshot.SNAPSHOT_ROOT_ELEMENT_NAME.equals(root.getLocalName());
-        } catch (final Exception e) {
+        } catch (final ParserConfigurationException | IOException | SAXException e) {
             LOG.error("Could not parse XML file {}", file, e);
             return false;
         }
             LOG.error("Could not parse XML file {}", file, e);
             return false;
         }
index f51bf4738add6d18eb70ce064af2bc15a2c30659..91295008ab763cb2a13f55930bbb6129340cf9cb 100644 (file)
@@ -9,9 +9,11 @@ package org.opendaylight.controller.configpusherfeature.internal;
 
 import com.google.common.base.Optional;
 import com.google.common.base.Preconditions;
 
 import com.google.common.base.Optional;
 import com.google.common.base.Preconditions;
+
 import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Set;
 import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Set;
+
 import org.apache.felix.utils.version.VersionRange;
 import org.apache.felix.utils.version.VersionTable;
 import org.apache.karaf.features.Dependency;
 import org.apache.felix.utils.version.VersionRange;
 import org.apache.felix.utils.version.VersionTable;
 import org.apache.karaf.features.Dependency;
@@ -29,20 +31,21 @@ import org.slf4j.LoggerFactory;
  */
 public class ChildAwareFeatureWrapper extends AbstractFeatureWrapper implements Feature {
     private static final Logger LOG = LoggerFactory.getLogger(ChildAwareFeatureWrapper.class);
  */
 public class ChildAwareFeatureWrapper extends AbstractFeatureWrapper implements Feature {
     private static final Logger LOG = LoggerFactory.getLogger(ChildAwareFeatureWrapper.class);
-    private FeaturesService featuresService= null;
+    private FeaturesService featuresService = null;
 
 
-    protected ChildAwareFeatureWrapper(final Feature f) {
+    protected ChildAwareFeatureWrapper(final Feature feature) {
         // Don't use without a feature service
     }
 
         // Don't use without a feature service
     }
 
-    /*
-     * @param f Feature to wrap
-     * @param s FeaturesService to look up dependencies
+    /* Constructor.
+
+     * @param feature Feature to wrap
+     * @param featuresService FeaturesService to look up dependencies
      */
      */
-    ChildAwareFeatureWrapper(final Feature f, final FeaturesService s) throws Exception {
-        super(s.getFeature(f.getName(), f.getVersion()));
-        Preconditions.checkNotNull(s, "FeatureWrapper requires non-null FeatureService in constructor");
-        this.featuresService = s;
+    ChildAwareFeatureWrapper(final Feature feature, final FeaturesService featuresService) throws Exception {
+        super(featuresService.getFeature(feature.getName(), feature.getVersion()));
+        Preconditions.checkNotNull(featuresService, "FeatureWrapper requires non-null FeatureService in constructor");
+        this.featuresService = featuresService;
     }
 
     protected FeaturesService getFeaturesService() {
     }
 
     protected FeaturesService getFeaturesService() {
@@ -56,12 +59,13 @@ public class ChildAwareFeatureWrapper extends AbstractFeatureWrapper implements
     public Set<? extends ChildAwareFeatureWrapper> getChildFeatures() throws Exception {
         List<Dependency> dependencies = feature.getDependencies();
         Set<ChildAwareFeatureWrapper> childFeatures = new LinkedHashSet<>();
     public Set<? extends ChildAwareFeatureWrapper> getChildFeatures() throws Exception {
         List<Dependency> dependencies = feature.getDependencies();
         Set<ChildAwareFeatureWrapper> childFeatures = new LinkedHashSet<>();
-        if(dependencies != null) {
-            for(Dependency dependency: dependencies) {
+        if (dependencies != null) {
+            for (Dependency dependency : dependencies) {
                 Feature fi = extractFeatureFromDependency(dependency);
                 if (fi != null) {
                     if (featuresService.getFeature(fi.getName(), fi.getVersion()) == null) {
                 Feature fi = extractFeatureFromDependency(dependency);
                 if (fi != null) {
                     if (featuresService.getFeature(fi.getName(), fi.getVersion()) == null) {
-                        LOG.warn("Feature: {}, {} is missing from features service. Skipping", fi.getName(), fi.getVersion());
+                        LOG.warn("Feature: {}, {} is missing from features service. Skipping", fi.getName(), fi
+                                .getVersion());
                     } else {
                         ChildAwareFeatureWrapper wrappedFeature = new ChildAwareFeatureWrapper(fi, featuresService);
                         childFeatures.add(wrappedFeature);
                     } else {
                         ChildAwareFeatureWrapper wrappedFeature = new ChildAwareFeatureWrapper(fi, featuresService);
                         childFeatures.add(wrappedFeature);
@@ -75,10 +79,11 @@ public class ChildAwareFeatureWrapper extends AbstractFeatureWrapper implements
     @Override
     public Set<FeatureConfigSnapshotHolder> getFeatureConfigSnapshotHolders() throws Exception {
         Set<FeatureConfigSnapshotHolder> snapShotHolders = new LinkedHashSet<>();
     @Override
     public Set<FeatureConfigSnapshotHolder> getFeatureConfigSnapshotHolders() throws Exception {
         Set<FeatureConfigSnapshotHolder> snapShotHolders = new LinkedHashSet<>();
-        for(ChildAwareFeatureWrapper c: getChildFeatures()) {
-            for(FeatureConfigSnapshotHolder h: c.getFeatureConfigSnapshotHolders()) {
-                final Optional<FeatureConfigSnapshotHolder> featureConfigSnapshotHolder = getFeatureConfigSnapshotHolder(h.getFileInfo());
-                if(featureConfigSnapshotHolder.isPresent()) {
+        for (ChildAwareFeatureWrapper c : getChildFeatures()) {
+            for (FeatureConfigSnapshotHolder h : c.getFeatureConfigSnapshotHolders()) {
+                final Optional<FeatureConfigSnapshotHolder> featureConfigSnapshotHolder =
+                        getFeatureConfigSnapshotHolder(h.getFileInfo());
+                if (featureConfigSnapshotHolder.isPresent()) {
                     snapShotHolders.add(featureConfigSnapshotHolder.get());
                 }
             }
                     snapShotHolders.add(featureConfigSnapshotHolder.get());
                 }
             }
@@ -89,14 +94,14 @@ public class ChildAwareFeatureWrapper extends AbstractFeatureWrapper implements
 
     protected Feature extractFeatureFromDependency(final Dependency dependency) throws Exception {
         Feature[] features = featuresService.listFeatures();
 
     protected Feature extractFeatureFromDependency(final Dependency dependency) throws Exception {
         Feature[] features = featuresService.listFeatures();
-        VersionRange range = org.apache.karaf.features.internal.model.Feature.DEFAULT_VERSION.equals(dependency.getVersion())
-                ? VersionRange.ANY_VERSION : new VersionRange(dependency.getVersion(), true, true);
+        VersionRange range = org.apache.karaf.features.internal.model.Feature.DEFAULT_VERSION.equals(dependency
+                .getVersion()) ? VersionRange.ANY_VERSION : new VersionRange(dependency.getVersion(), true, true);
         Feature fi = null;
         Feature fi = null;
-        for(Feature f: features) {
+        for (Feature f : features) {
             if (f.getName().equals(dependency.getName())) {
             if (f.getName().equals(dependency.getName())) {
-                Version v = VersionTable.getVersion(f.getVersion());
-                if (range.contains(v) &&
-                    (fi == null || VersionTable.getVersion(fi.getVersion()).compareTo(v) < 0)) {
+                Version version = VersionTable.getVersion(f.getVersion());
+                if (range.contains(version) && (fi == null || VersionTable.getVersion(fi.getVersion())
+                        .compareTo(version) < 0)) {
                     fi = f;
                     break;
                 }
                     fi = f;
                     break;
                 }
@@ -104,5 +109,4 @@ public class ChildAwareFeatureWrapper extends AbstractFeatureWrapper implements
         }
         return fi;
     }
         }
         return fi;
     }
-
 }
 }
index 075db509f8a180910ac16bc4e4e04eaec112bfd1..d5d590aadcde6524954334c8f0818d6533ad6c10 100644 (file)
@@ -9,6 +9,7 @@ package org.opendaylight.controller.configpusherfeature.internal;
 
 import java.util.concurrent.BlockingQueue;
 import java.util.concurrent.LinkedBlockingQueue;
 
 import java.util.concurrent.BlockingQueue;
 import java.util.concurrent.LinkedBlockingQueue;
+
 import org.apache.karaf.features.FeatureEvent;
 import org.apache.karaf.features.FeaturesListener;
 import org.apache.karaf.features.FeaturesService;
 import org.apache.karaf.features.FeatureEvent;
 import org.apache.karaf.features.FeaturesListener;
 import org.apache.karaf.features.FeaturesService;
@@ -17,14 +18,15 @@ import org.opendaylight.controller.config.persist.api.ConfigPusher;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-public class ConfigFeaturesListener implements  FeaturesListener,  AutoCloseable {
+public class ConfigFeaturesListener implements FeaturesListener, AutoCloseable {
     private static final Logger LOG = LoggerFactory.getLogger(ConfigFeaturesListener.class);
     private static final int QUEUE_SIZE = 1000;
     private BlockingQueue<FeatureEvent> queue = new LinkedBlockingQueue<>(QUEUE_SIZE);
     Thread pushingThread = null;
 
     private static final Logger LOG = LoggerFactory.getLogger(ConfigFeaturesListener.class);
     private static final int QUEUE_SIZE = 1000;
     private BlockingQueue<FeatureEvent> queue = new LinkedBlockingQueue<>(QUEUE_SIZE);
     Thread pushingThread = null;
 
-    public ConfigFeaturesListener(final ConfigPusher p, final FeaturesService f) {
-        pushingThread = new Thread(new ConfigPushingRunnable(p, f, queue), "ConfigFeatureListener - ConfigPusher");
+    public ConfigFeaturesListener(final ConfigPusher configPusher, final FeaturesService featuresService) {
+        pushingThread = new Thread(new ConfigPushingRunnable(configPusher, featuresService, queue),
+                "ConfigFeatureListener - ConfigPusher");
         pushingThread.start();
     }
 
         pushingThread.start();
     }
 
@@ -40,7 +42,7 @@ public class ConfigFeaturesListener implements  FeaturesListener,  AutoCloseable
 
     @Override
     public void close() {
 
     @Override
     public void close() {
-        if(pushingThread != null) {
+        if (pushingThread != null) {
             pushingThread.interrupt();
             pushingThread = null;
         }
             pushingThread.interrupt();
             pushingThread = null;
         }
index ac10c68c8f1f26f5137dd92ceea612efb099b052..e665309c92cd2ebe30087c435f1ffb7fb0996eed 100644 (file)
@@ -20,7 +20,7 @@ public class ConfigPusherCustomizer implements ServiceTrackerCustomizer<ConfigPu
     private static final Logger LOG = LoggerFactory.getLogger(ConfigPusherCustomizer.class);
     private ConfigFeaturesListener configFeaturesListener = null;
     private FeatureServiceCustomizer featureServiceCustomizer = null;
     private static final Logger LOG = LoggerFactory.getLogger(ConfigPusherCustomizer.class);
     private ConfigFeaturesListener configFeaturesListener = null;
     private FeatureServiceCustomizer featureServiceCustomizer = null;
-    private ServiceTracker<FeaturesService,FeaturesService> fsst = null;
+    private ServiceTracker<FeaturesService, FeaturesService> fsst = null;
 
     @Override
     public ConfigPusher addingService(final ServiceReference<ConfigPusher> configPusherServiceReference) {
 
     @Override
     public ConfigPusher addingService(final ServiceReference<ConfigPusher> configPusherServiceReference) {
@@ -34,26 +34,28 @@ public class ConfigPusherCustomizer implements ServiceTrackerCustomizer<ConfigPu
     }
 
     @Override
     }
 
     @Override
-    public void modifiedService(final ServiceReference<ConfigPusher> configPusherServiceReference, final ConfigPusher configPusher) {
+    public void modifiedService(final ServiceReference<ConfigPusher> configPusherServiceReference,
+                                final ConfigPusher configPusher) {
         // we don't care if the properties change
     }
 
     @Override
         // we don't care if the properties change
     }
 
     @Override
-    public void removedService(final ServiceReference<ConfigPusher> configPusherServiceReference, final ConfigPusher configPusher) {
+    public void removedService(final ServiceReference<ConfigPusher> configPusherServiceReference,
+                               final ConfigPusher configPusher) {
         this.close();
     }
 
     @Override
     public void close() {
         this.close();
     }
 
     @Override
     public void close() {
-        if(fsst != null) {
+        if (fsst != null) {
             fsst.close();
             fsst = null;
         }
             fsst.close();
             fsst = null;
         }
-        if(configFeaturesListener != null) {
+        if (configFeaturesListener != null) {
             configFeaturesListener.close();
             configFeaturesListener = null;
         }
             configFeaturesListener.close();
             configFeaturesListener = null;
         }
-        if(featureServiceCustomizer != null) {
+        if (featureServiceCustomizer != null) {
             featureServiceCustomizer.close();
             featureServiceCustomizer = null;
         }
             featureServiceCustomizer.close();
             featureServiceCustomizer = null;
         }
index 48c494b5c7d18fa188581c20b96cde855aece821..010a27315428f3008f8a794830f9144bf6b21e7b 100644 (file)
@@ -8,10 +8,12 @@
 package org.opendaylight.controller.configpusherfeature.internal;
 
 import com.google.common.collect.LinkedHashMultimap;
 package org.opendaylight.controller.configpusherfeature.internal;
 
 import com.google.common.collect.LinkedHashMultimap;
+
 import java.util.ArrayList;
 import java.util.List;
 import java.util.concurrent.BlockingQueue;
 import java.util.concurrent.TimeUnit;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.concurrent.BlockingQueue;
 import java.util.concurrent.TimeUnit;
+
 import org.apache.karaf.features.Feature;
 import org.apache.karaf.features.FeatureEvent;
 import org.apache.karaf.features.FeatureEvent.EventType;
 import org.apache.karaf.features.Feature;
 import org.apache.karaf.features.FeatureEvent;
 import org.apache.karaf.features.FeatureEvent.EventType;
@@ -25,34 +27,37 @@ public class ConfigPushingRunnable implements Runnable {
     private static final int POLL_TIME = 1;
     private BlockingQueue<FeatureEvent> queue;
     private FeatureConfigPusher configPusher;
     private static final int POLL_TIME = 1;
     private BlockingQueue<FeatureEvent> queue;
     private FeatureConfigPusher configPusher;
-    public ConfigPushingRunnable(final ConfigPusher p, final FeaturesService f, final BlockingQueue<FeatureEvent> q) {
-        queue = q;
-        configPusher = new FeatureConfigPusher(p, f);
+
+    public ConfigPushingRunnable(final ConfigPusher configPusher, final FeaturesService featuresService,
+                                 final BlockingQueue<FeatureEvent> featureEvents) {
+        queue = featureEvents;
+        this.configPusher = new FeatureConfigPusher(configPusher, featuresService);
     }
 
     @Override
     }
 
     @Override
+    @SuppressWarnings("IllegalCatch")
     public void run() {
         List<Feature> toInstall = new ArrayList<>();
         FeatureEvent event = null;
     public void run() {
         List<Feature> toInstall = new ArrayList<>();
         FeatureEvent event = null;
-        boolean interuppted = false;
-        while(true) {
+        boolean interrupted = false;
+        while (true) {
             try {
             try {
-                if(!interuppted) {
-                    if(toInstall.isEmpty()) {
+                if (!interrupted) {
+                    if (toInstall.isEmpty()) {
                         event = queue.take();
                     } else {
                         event = queue.poll(POLL_TIME, TimeUnit.MILLISECONDS);
                     }
                         event = queue.take();
                     } else {
                         event = queue.poll(POLL_TIME, TimeUnit.MILLISECONDS);
                     }
-                    if(event != null && event.getFeature() !=null) {
-                        processFeatureEvent(event,toInstall);
+                    if (event != null && event.getFeature() != null) {
+                        processFeatureEvent(event, toInstall);
                     }
                     }
-                } else if(toInstall.isEmpty()) {
+                } else if (toInstall.isEmpty()) {
                     LOG.error("ConfigPushingRunnable - exiting");
                     return;
                 }
             } catch (final InterruptedException e) {
                     LOG.error("ConfigPushingRunnable - exiting");
                     return;
                 }
             } catch (final InterruptedException e) {
-                LOG.error("ConfigPushingRunnable - interupted");
-                interuppted = true;
+                LOG.error("ConfigPushingRunnable - interrupted");
+                interrupted = true;
             } catch (final Exception e) {
                 LOG.error("Exception while processing features {} event {}", toInstall, event, e);
             }
             } catch (final Exception e) {
                 LOG.error("Exception while processing features {} event {}", toInstall, event, e);
             }
@@ -60,18 +65,18 @@ public class ConfigPushingRunnable implements Runnable {
     }
 
     protected void processFeatureEvent(final FeatureEvent event, final List<Feature> toInstall) throws Exception {
     }
 
     protected void processFeatureEvent(final FeatureEvent event, final List<Feature> toInstall) throws Exception {
-        if(event.getType() == EventType.FeatureInstalled) {
+        if (event.getType() == EventType.FeatureInstalled) {
             toInstall.add(event.getFeature());
             toInstall.add(event.getFeature());
-            LinkedHashMultimap<Feature,FeatureConfigSnapshotHolder> result = configPusher.pushConfigs(toInstall);
+            LinkedHashMultimap<Feature, FeatureConfigSnapshotHolder> result = configPusher.pushConfigs(toInstall);
             toInstall.removeAll(result.keySet());
             toInstall.removeAll(result.keySet());
-        } else if(event.getType() == EventType.FeatureUninstalled) {
+        } else if (event.getType() == EventType.FeatureUninstalled) {
             toInstall.remove(event.getFeature());
         }
     }
 
             toInstall.remove(event.getFeature());
         }
     }
 
-    protected void logPushResult(final LinkedHashMultimap<Feature,FeatureConfigSnapshotHolder> results) {
-        for(Feature f:results.keySet()) {
-            LOG.info("Pushed configs for feature {} {}",f,results.get(f));
+    protected void logPushResult(final LinkedHashMultimap<Feature, FeatureConfigSnapshotHolder> results) {
+        for (Feature f : results.keySet()) {
+            LOG.info("Pushed configs for feature {} {}", f, results.get(f));
         }
     }
 }
         }
     }
 }
index 5d487e0b9cd8ff6aa427450679291135e320f65c..6f304452a9bd04b55b9357a3657bdaa0b065c7bd 100644 (file)
@@ -9,6 +9,7 @@ package org.opendaylight.controller.configpusherfeature.internal;
 
 import com.google.common.base.Optional;
 import com.google.common.collect.LinkedHashMultimap;
 
 import com.google.common.base.Optional;
 import com.google.common.collect.LinkedHashMultimap;
+
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
@@ -16,6 +17,7 @@ import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Set;
 import java.util.concurrent.TimeUnit;
 import java.util.List;
 import java.util.Set;
 import java.util.concurrent.TimeUnit;
+
 import org.apache.karaf.features.Feature;
 import org.apache.karaf.features.FeaturesService;
 import org.opendaylight.controller.config.persist.api.ConfigPusher;
 import org.apache.karaf.features.Feature;
 import org.apache.karaf.features.FeaturesService;
 import org.opendaylight.controller.config.persist.api.ConfigPusher;
@@ -46,15 +48,14 @@ public class FeatureConfigPusher {
      * LinkedHashMultimap to track which configs we pushed for each Feature installation
      * For future use
      */
      * LinkedHashMultimap to track which configs we pushed for each Feature installation
      * For future use
      */
-    private final LinkedHashMultimap<Feature,FeatureConfigSnapshotHolder> feature2configs = LinkedHashMultimap.create();
+    private final LinkedHashMultimap<Feature, FeatureConfigSnapshotHolder> feature2configs = LinkedHashMultimap
+            .create();
 
 
-    /*
-     * @param p - ConfigPusher to push ConfigSnapshotHolders
-     */
-    public FeatureConfigPusher(final ConfigPusher p, final FeaturesService f) {
-        pusher = p;
-        featuresService = f;
+    public FeatureConfigPusher(final ConfigPusher configPusher, final FeaturesService featuresService) {
+        pusher = configPusher;
+        this.featuresService = featuresService;
     }
     }
+
     /*
      * Push config files from Features to config subsystem
      * @param features - list of Features to extract config files from recursively and push
     /*
      * Push config files from Features to config subsystem
      * @param features - list of Features to extract config files from recursively and push
@@ -64,8 +65,8 @@ public class FeatureConfigPusher {
      * If a Feature is not in the returned LinkedHashMultimap then we couldn't push its configs
      * (Ususally because it was not yet installed)
      */
      * If a Feature is not in the returned LinkedHashMultimap then we couldn't push its configs
      * (Ususally because it was not yet installed)
      */
-    public LinkedHashMultimap<Feature, FeatureConfigSnapshotHolder> pushConfigs(final List<Feature> features)
-            throws Exception {
+    public LinkedHashMultimap<Feature, FeatureConfigSnapshotHolder> pushConfigs(
+            final List<Feature> features) throws Exception {
         LinkedHashMultimap<Feature, FeatureConfigSnapshotHolder> pushedFeatures = LinkedHashMultimap.create();
         for (Feature feature : features) {
             Set<FeatureConfigSnapshotHolder> configSnapShots = pushConfig(feature);
         LinkedHashMultimap<Feature, FeatureConfigSnapshotHolder> pushedFeatures = LinkedHashMultimap.create();
         for (Feature feature : features) {
             Set<FeatureConfigSnapshotHolder> configSnapShots = pushConfig(feature);
@@ -94,8 +95,8 @@ public class FeatureConfigPusher {
         // FIXME Workaround for BUG-2836, features service returns null for feature:
         // standard-condition-webconsole_0_0_0, 3.0.1
         if (featuresService.getFeature(feature.getName(), feature.getVersion()) == null) {
         // FIXME Workaround for BUG-2836, features service returns null for feature:
         // standard-condition-webconsole_0_0_0, 3.0.1
         if (featuresService.getFeature(feature.getName(), feature.getVersion()) == null) {
-            LOG.debug("Feature: {}, {} is missing from features service. Skipping", feature.getName(),
-                feature.getVersion());
+            LOG.debug("Feature: {}, {} is missing from features service. Skipping", feature.getName(), feature
+                    .getVersion());
             return Collections.emptySet();
         }
 
             return Collections.emptySet();
         }
 
@@ -108,47 +109,47 @@ public class FeatureConfigPusher {
         return configs;
     }
 
         return configs;
     }
 
-    private boolean isInstalled(final Feature feature) throws InterruptedException {
-        for (int retries = 0; retries < MAX_RETRIES; retries++) {
-            try {
-                List<Feature> installedFeatures = Arrays.asList(featuresService.listInstalledFeatures());
-                if (installedFeatures.contains(feature)) {
-                    return true;
-                }
-
-                LOG.info("Karaf Feature Service has not yet finished installing feature {}/{} (retry {})",
-                    feature.getName(), feature.getVersion(), retries);
-            } catch (final Exception e) {
-                LOG.warn("Karaf featuresService.listInstalledFeatures() has thrown an exception, retry {}", retries, e);
-            }
-
-            TimeUnit.MILLISECONDS.sleep(RETRY_PAUSE_MILLIS);
-        }
-        LOG.error("Giving up (after {} retries) on Karaf featuresService.listInstalledFeatures() which has not yet finished installing feature {} {}",
-            MAX_RETRIES, feature.getName(), feature.getVersion());
-        return false;
-    }
-
     private Set<FeatureConfigSnapshotHolder> pushConfig(final Set<FeatureConfigSnapshotHolder> configs,
     private Set<FeatureConfigSnapshotHolder> pushConfig(final Set<FeatureConfigSnapshotHolder> configs,
-            final Feature feature) throws InterruptedException {
+                                                        final Feature feature) throws InterruptedException {
         Set<FeatureConfigSnapshotHolder> configsToPush = new LinkedHashSet<>(configs);
         configsToPush.removeAll(pushedConfigs);
         if (!configsToPush.isEmpty()) {
 
             // Ignore features that are present in persisted current config
             final Optional<XmlFileStorageAdapter> currentCfgPusher = XmlFileStorageAdapter.getInstance();
         Set<FeatureConfigSnapshotHolder> configsToPush = new LinkedHashSet<>(configs);
         configsToPush.removeAll(pushedConfigs);
         if (!configsToPush.isEmpty()) {
 
             // Ignore features that are present in persisted current config
             final Optional<XmlFileStorageAdapter> currentCfgPusher = XmlFileStorageAdapter.getInstance();
-            if (currentCfgPusher.isPresent() &&
-                    currentCfgPusher.get().getPersistedFeatures().contains(feature.getId())) {
+            if (currentCfgPusher.isPresent() && currentCfgPusher.get().getPersistedFeatures()
+                    .contains(feature.getId())) {
                 LOG.warn("Ignoring default configuration {} for feature {}, the configuration is present in {}",
                         configsToPush, feature.getId(), currentCfgPusher.get());
             } else {
                 pusher.pushConfigs(new ArrayList<>(configsToPush));
             }
                 LOG.warn("Ignoring default configuration {} for feature {}, the configuration is present in {}",
                         configsToPush, feature.getId(), currentCfgPusher.get());
             } else {
                 pusher.pushConfigs(new ArrayList<>(configsToPush));
             }
-
             pushedConfigs.addAll(configsToPush);
         }
         Set<FeatureConfigSnapshotHolder> configsPushed = new LinkedHashSet<>(pushedConfigs);
         configsPushed.retainAll(configs);
         return configsPushed;
     }
             pushedConfigs.addAll(configsToPush);
         }
         Set<FeatureConfigSnapshotHolder> configsPushed = new LinkedHashSet<>(pushedConfigs);
         configsPushed.retainAll(configs);
         return configsPushed;
     }
+
+    @SuppressWarnings("IllegalCatch")
+    private boolean isInstalled(final Feature feature) throws InterruptedException {
+        for (int retries = 0; retries < MAX_RETRIES; retries++) {
+            try {
+                List<Feature> installedFeatures = Arrays.asList(featuresService.listInstalledFeatures());
+                if (installedFeatures.contains(feature)) {
+                    return true;
+                }
+
+                LOG.info("Karaf Feature Service has not yet finished installing feature {}/{} (retry {})", feature
+                        .getName(), feature.getVersion(), retries);
+            } catch (final Exception e) {
+                LOG.warn("Karaf featuresService.listInstalledFeatures() has thrown an exception, retry {}", retries, e);
+            }
+
+            TimeUnit.MILLISECONDS.sleep(RETRY_PAUSE_MILLIS);
+        }
+        LOG.error("Giving up (after {} retries) on Karaf featuresService.listInstalledFeatures() which has not yet "
+                + "finished installing feature {} {}", MAX_RETRIES, feature.getName(), feature.getVersion());
+        return false;
+    }
 }
 }
index 7107cc994de7dd892ae9d362661bf011678f77bc..f99e763177c37c2e8471ab3dbe8db0aa318956cb 100644 (file)
@@ -11,12 +11,14 @@ import com.google.common.base.Preconditions;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Iterables;
 import com.google.common.collect.Lists;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Iterables;
 import com.google.common.collect.Lists;
+
 import java.io.File;
 import java.nio.file.Path;
 import java.nio.file.Paths;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.SortedSet;
 import java.io.File;
 import java.nio.file.Path;
 import java.nio.file.Paths;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.SortedSet;
+
 import javax.xml.bind.JAXBContext;
 import javax.xml.bind.JAXBException;
 import javax.xml.bind.Unmarshaller;
 import javax.xml.bind.JAXBContext;
 import javax.xml.bind.JAXBException;
 import javax.xml.bind.Unmarshaller;
@@ -24,6 +26,7 @@ import javax.xml.stream.XMLInputFactory;
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamReader;
 import javax.xml.transform.stream.StreamSource;
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamReader;
 import javax.xml.transform.stream.StreamSource;
+
 import org.apache.karaf.features.ConfigFileInfo;
 import org.apache.karaf.features.Feature;
 import org.opendaylight.controller.config.persist.api.ConfigSnapshotHolder;
 import org.apache.karaf.features.ConfigFileInfo;
 import org.apache.karaf.features.Feature;
 import org.opendaylight.controller.config.persist.api.ConfigSnapshotHolder;
@@ -46,8 +49,9 @@ public class FeatureConfigSnapshotHolder implements ConfigSnapshotHolder {
      * @param holder - FeatureConfigSnapshotHolder that we
      * @param feature - new
      */
      * @param holder - FeatureConfigSnapshotHolder that we
      * @param feature - new
      */
-    public FeatureConfigSnapshotHolder(final FeatureConfigSnapshotHolder holder, final Feature feature) throws JAXBException, XMLStreamException {
-        this(holder.fileInfo,holder.getFeature());
+    public FeatureConfigSnapshotHolder(final FeatureConfigSnapshotHolder holder,
+                                       final Feature feature) throws JAXBException, XMLStreamException {
+        this(holder.fileInfo, holder.getFeature());
         this.featureChain.add(feature);
     }
 
         this.featureChain.add(feature);
     }
 
@@ -57,7 +61,8 @@ public class FeatureConfigSnapshotHolder implements ConfigSnapshotHolder {
      * @param fileInfo - ConfigFileInfo to read into the ConfigSnapshot
      * @param feature - Feature the ConfigFileInfo was attached to
      */
      * @param fileInfo - ConfigFileInfo to read into the ConfigSnapshot
      * @param feature - Feature the ConfigFileInfo was attached to
      */
-    public FeatureConfigSnapshotHolder(final ConfigFileInfo fileInfo, final Feature feature) throws JAXBException, XMLStreamException {
+    public FeatureConfigSnapshotHolder(final ConfigFileInfo fileInfo,
+                                       final Feature feature) throws JAXBException, XMLStreamException {
         Preconditions.checkNotNull(fileInfo);
         Preconditions.checkNotNull(fileInfo.getFinalname());
         Preconditions.checkNotNull(feature);
         Preconditions.checkNotNull(fileInfo);
         Preconditions.checkNotNull(fileInfo.getFinalname());
         Preconditions.checkNotNull(feature);
@@ -73,6 +78,7 @@ public class FeatureConfigSnapshotHolder implements ConfigSnapshotHolder {
         XMLStreamReader xsr = xif.createXMLStreamReader(new StreamSource(new File(fileInfo.getFinalname())));
         unmarshalled = (ConfigSnapshot) um.unmarshal(xsr);
     }
         XMLStreamReader xsr = xif.createXMLStreamReader(new StreamSource(new File(fileInfo.getFinalname())));
         unmarshalled = (ConfigSnapshot) um.unmarshal(xsr);
     }
+
     /*
      * (non-Javadoc)
      * @see java.lang.Object#hashCode()
     /*
      * (non-Javadoc)
      * @see java.lang.Object#hashCode()
@@ -83,9 +89,11 @@ public class FeatureConfigSnapshotHolder implements ConfigSnapshotHolder {
     public int hashCode() {
         final int prime = 31;
         int result = 1;
     public int hashCode() {
         final int prime = 31;
         int result = 1;
-        result = prime * result + ((unmarshalled != null && unmarshalled.getConfigSnapshot() == null) ? 0 : unmarshalled.getConfigSnapshot().hashCode());
+        result = prime * result + ((unmarshalled != null && unmarshalled.getConfigSnapshot() == null) ? 0 :
+                unmarshalled.getConfigSnapshot().hashCode());
         return result;
     }
         return result;
     }
+
     /*
      * (non-Javadoc)
      * @see java.lang.Object#equals(java.lang.Object)
     /*
      * (non-Javadoc)
      * @see java.lang.Object#equals(java.lang.Object)
@@ -103,8 +111,8 @@ public class FeatureConfigSnapshotHolder implements ConfigSnapshotHolder {
         if (getClass() != obj.getClass()) {
             return false;
         }
         if (getClass() != obj.getClass()) {
             return false;
         }
-        FeatureConfigSnapshotHolder fcsh = (FeatureConfigSnapshotHolder)obj;
-        if(this.unmarshalled.getConfigSnapshot().equals(fcsh.unmarshalled.getConfigSnapshot())) {
+        FeatureConfigSnapshotHolder fcsh = (FeatureConfigSnapshotHolder) obj;
+        if (this.unmarshalled.getConfigSnapshot().equals(fcsh.unmarshalled.getConfigSnapshot())) {
             return true;
         }
         return false;
             return true;
         }
         return false;
@@ -112,15 +120,11 @@ public class FeatureConfigSnapshotHolder implements ConfigSnapshotHolder {
 
     @Override
     public String toString() {
 
     @Override
     public String toString() {
-        StringBuilder b = new StringBuilder();
-        Path p = Paths.get(fileInfo.getFinalname());
-        b.append(p.getFileName())
-            .append("(")
-            .append(getCauseFeature())
-            .append(",")
-            .append(getFeature())
-            .append(")");
-        return b.toString();
+        StringBuilder stringBuilder = new StringBuilder();
+        Path path = Paths.get(fileInfo.getFinalname());
+        stringBuilder.append(path.getFileName()).append("(").append(getCauseFeature()).append(",").append(getFeature())
+                .append(")");
+        return stringBuilder.toString();
     }
 
     @Override
     }
 
     @Override
index 68ae3d31cbafd2776cfa17fd645f14e685ac63e4..9e9c26cbf3c81e0f69a702db81bcbbd4800dd8e2 100644 (file)
@@ -24,16 +24,18 @@ import org.osgi.util.tracker.ServiceTrackerCustomizer;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-public class FeatureServiceCustomizer implements ServiceTrackerCustomizer<FeaturesService, FeaturesService>, AutoCloseable {
+public class FeatureServiceCustomizer implements ServiceTrackerCustomizer<FeaturesService, FeaturesService>,
+        AutoCloseable {
     private static final Logger LOG = LoggerFactory.getLogger(FeatureServiceCustomizer.class);
     private ConfigPusher configPusher = null;
     private ServiceRegistration<?> registration;
 
     private static final Logger LOG = LoggerFactory.getLogger(FeatureServiceCustomizer.class);
     private ConfigPusher configPusher = null;
     private ServiceRegistration<?> registration;
 
-    FeatureServiceCustomizer(final ConfigPusher c) {
-        configPusher = c;
+    FeatureServiceCustomizer(final ConfigPusher configPusher) {
+        this.configPusher = configPusher;
     }
 
     @Override
     }
 
     @Override
+    @SuppressWarnings("IllegalCatch")
     public FeaturesService addingService(final ServiceReference<FeaturesService> reference) {
         BundleContext bc = reference.getBundle().getBundleContext();
         final FeaturesService featureService = bc.getService(reference);
     public FeaturesService addingService(final ServiceReference<FeaturesService> reference) {
         BundleContext bc = reference.getBundle().getBundleContext();
         final FeaturesService featureService = bc.getService(reference);
@@ -57,14 +59,12 @@ public class FeatureServiceCustomizer implements ServiceTrackerCustomizer<Featur
     }
 
     @Override
     }
 
     @Override
-    public void modifiedService(final ServiceReference<FeaturesService> reference,
-                                final FeaturesService service) {
+    public void modifiedService(final ServiceReference<FeaturesService> reference, final FeaturesService service) {
         // we don't care if the properties change
     }
 
     @Override
         // we don't care if the properties change
     }
 
     @Override
-    public void removedService(final ServiceReference<FeaturesService> reference,
-                               final FeaturesService service) {
+    public void removedService(final ServiceReference<FeaturesService> reference, final FeaturesService service) {
         close();
     }
 
         close();
     }