Enable SpotBugs 94/79194/4
authorStephen Kitt <skitt@redhat.com>
Thu, 3 Jan 2019 17:00:41 +0000 (18:00 +0100)
committerRobert Varga <nite@hq.sk>
Fri, 4 Jan 2019 11:27:00 +0000 (11:27 +0000)
Change-Id: Ic8c3237c2f3cda75387af6d2220d401d1c357de6
Signed-off-by: Stephen Kitt <skitt@redhat.com>
karaf-plugin/pom.xml
karaf-plugin/src/main/java/org/opendaylight/odlparent/AetherUtil.java
karaf-plugin/src/main/java/org/opendaylight/odlparent/PopulateLocalRepoMojo.java

index 6aabcb53df986768c75189b74e95265af2104538..39d146fe61a6c9e32fd206594532054c819dfee6 100644 (file)
           </execution>
         </executions>
       </plugin>
+      <plugin>
+        <groupId>com.github.spotbugs</groupId>
+        <artifactId>spotbugs-maven-plugin</artifactId>
+        <configuration>
+          <failOnError>true</failOnError>
+          <!-- This ensure we ignore HelpMojo which fails SpotBugs -->
+          <onlyAnalyze>org.opendaylight.odlparent</onlyAnalyze>
+        </configuration>
+      </plugin>
     </plugins>
   </build>
 
index 5aae7b7d9c6d82b8609c6c7e4c18173ec46aaa8a..3d6c35486f8660d77c15c5b8712be84076e97c15 100644 (file)
@@ -97,7 +97,7 @@ public class AetherUtil {
         try {
             result = repoSystem.resolveArtifact(repoSession, request);
         } catch (ArtifactResolutionException e) {
-            LOG.warn("Unable to resolve artifact: {}", e.getMessage(), e);
+            LOG.warn("Unable to resolve artifact", e);
             return null;
         }
         LOG.trace("resolveArtifacts({}) returns {}", artifact, result.getArtifact());
index d173a7302e152af370e4633771989df2cc188ae0..025d8f15e36d99769d1c43c316afe0b3ad04be85 100644 (file)
 
 package org.opendaylight.odlparent;
 
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 import java.io.IOException;
+import java.io.InputStream;
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.net.URL;
@@ -33,7 +35,6 @@ import java.util.Set;
 import org.apache.karaf.features.internal.model.Features;
 import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.plugin.MojoFailureException;
 import org.apache.maven.plugins.annotations.Component;
 import org.apache.maven.plugins.annotations.LifecyclePhase;
 import org.apache.maven.plugins.annotations.Mojo;
@@ -101,7 +102,8 @@ public class PopulateLocalRepoMojo
     private AetherUtil aetherUtil;
 
     @Override
-    public void execute() throws MojoExecutionException, MojoFailureException {
+    @SuppressFBWarnings("REC_CATCH_EXCEPTION")
+    public void execute() throws MojoExecutionException {
 
         aetherUtil = new AetherUtil(repoSystem, repoSession, remoteRepos, localRepo);
         try {
@@ -144,8 +146,8 @@ public class PopulateLocalRepoMojo
         String karafHome = localRepo.getParent();
         File file = new File(karafHome + "/etc/org.apache.karaf.features.cfg");
         Properties prop = new Properties();
-        try {
-            prop.load(new FileInputStream(file));
+        try (InputStream is = new FileInputStream(file)) {
+            prop.load(is);
             String featuresRepositories = prop.getProperty("featuresRepositories");
             for (String mvnUrl : featuresRepositories.split(",")) {
                 String fixedUrl = mvnUrl.replace("${karaf.home}", karafHome);
@@ -171,8 +173,8 @@ public class PopulateLocalRepoMojo
         Set<Artifact> artifacts = new LinkedHashSet<>();
         File file = new File(localRepo.getParentFile().toString() + "/etc/startup.properties");
         Properties prop = new Properties();
-        try {
-            prop.load(new FileInputStream(file));
+        try (InputStream is = new FileInputStream(file)) {
+            prop.load(is);
             Enumeration<Object> mvnUrls = prop.keys();
             while (mvnUrls.hasMoreElements()) {
                 String mvnUrl = (String) mvnUrls.nextElement();