Enforce Checkstyle in karaf-plugin 80/79180/2
authorStephen Kitt <skitt@redhat.com>
Thu, 3 Jan 2019 14:14:33 +0000 (15:14 +0100)
committerRobert Varga <nite@hq.sk>
Thu, 3 Jan 2019 15:26:32 +0000 (15:26 +0000)
... and fix the flagged problems.

Change-Id: Ic9620bc2e000f36f54aaa411d97feb5a428f561a
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 4a1fe3bf8df92c87ef7823a8b9fe95fe3922d647..32f647fdca8c0e31d8a75d45139fcd282c57c24a 100644 (file)
@@ -9,8 +9,8 @@
 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
   <modelVersion>4.0.0</modelVersion>
   <parent>
-    <artifactId>odlparent</artifactId>
     <groupId>org.opendaylight.odlparent</groupId>
+    <artifactId>odlparent</artifactId>
     <version>4.0.8-SNAPSHOT</version>
     <relativePath>../odlparent/</relativePath>
   </parent>
         <executions>
           <execution>
             <id>check-license</id>
-            <goals>
-              <goal>check</goal>
-            </goals>
-            <phase>process-sources</phase>
             <configuration>
-              <configLocation>check-license.xml</configLocation>
-              <includeResources>false</includeResources>
-              <includeTestResources>false</includeTestResources>
-              <sourceDirectories>
-                <directory>${project.build.sourceDirectory}</directory>
-              </sourceDirectories>
               <excludes>
                 <!-- Skip Apache Licensed files -->
                 org/opendaylight/odlparent/PopulateLocalRepoMojo.java
               </excludes>
-              <failsOnError>false</failsOnError>
-              <consoleOutput>true</consoleOutput>
             </configuration>
           </execution>
         </executions>
+        <configuration>
+          <propertyExpansion>checkstyle.violationSeverity=error</propertyExpansion>
+        </configuration>
       </plugin>
       <plugin>
         <artifactId>maven-plugin-plugin</artifactId>
index 293f7588a2ab687223fb350081f40beaec392af7..5aae7b7d9c6d82b8609c6c7e4c18173ec46aaa8a 100644 (file)
@@ -21,8 +21,8 @@ import org.eclipse.aether.artifact.DefaultArtifact;
 import org.eclipse.aether.collection.CollectRequest;
 import org.eclipse.aether.graph.Dependency;
 import org.eclipse.aether.graph.DependencyFilter;
-import org.eclipse.aether.installation.InstallationException;
 import org.eclipse.aether.installation.InstallRequest;
+import org.eclipse.aether.installation.InstallationException;
 import org.eclipse.aether.repository.LocalRepository;
 import org.eclipse.aether.repository.LocalRepositoryManager;
 import org.eclipse.aether.repository.RemoteRepository;
index e16ef96f8324716b1a419cea1127545adb70b70c..664d5c6c0fc18fb861628ae0d0ffe03d0205badb 100644 (file)
@@ -23,13 +23,11 @@ import java.io.IOException;
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.net.URL;
-import java.util.Arrays;
 import java.util.Enumeration;
 import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Properties;
 import java.util.Set;
-
 import org.apache.karaf.features.internal.model.Features;
 import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecutionException;
@@ -39,7 +37,6 @@ import org.eclipse.aether.RepositorySystem;
 import org.eclipse.aether.RepositorySystemSession;
 import org.eclipse.aether.artifact.Artifact;
 import org.eclipse.aether.repository.RemoteRepository;
-import org.eclipse.aether.resolution.ArtifactResolutionException;
 import org.opendaylight.odlparent.karafutil.CustomBundleUrlStreamHandlerFactory;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -52,8 +49,10 @@ import org.slf4j.LoggerFactory;
  * @goal populate-local-repo
  * @phase prepare-package
  */
+// URL.setURLStreamHandlerFactory throws an Error directly, so we can’t do any better than this...
+@SuppressWarnings("checkstyle:IllegalCatch")
 public class PopulateLocalRepoMojo
-        extends AbstractMojo {
+    extends AbstractMojo {
     private static final Logger LOG = LoggerFactory.getLogger(PopulateLocalRepoMojo.class);
 
     static {
@@ -119,8 +118,8 @@ public class PopulateLocalRepoMojo
             Set<Features> features = new LinkedHashSet<>();
             readFeatureCfg(featureArtifacts, features);
             featureArtifacts.addAll(
-                    aetherUtil.resolveDependencies(MvnToAetherMapper.toAether(project.getDependencies()),
-                            new KarafFeaturesDependencyFilter()));
+                aetherUtil.resolveDependencies(MvnToAetherMapper.toAether(project.getDependencies()),
+                    new KarafFeaturesDependencyFilter()));
             features.addAll(FeatureUtil.readFeatures(featureArtifacts));
             // Do not provide FeatureUtil.featuresRepositoryToCoords(features)) as existingCoords
             // to findAllFeaturesRecursively, as those coords are not resolved yet, and it would lead to Bug 6187.
@@ -142,15 +141,14 @@ public class PopulateLocalRepoMojo
         }
     }
 
-    private void readFeatureCfg(Set<Artifact> artifacts, Set<Features> features) throws ArtifactResolutionException {
+    private void readFeatureCfg(Set<Artifact> artifacts, Set<Features> features) {
         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));
             String featuresRepositories = prop.getProperty("featuresRepositories");
-            List<String> result = Arrays.asList(featuresRepositories.split(","));
-            for (String mvnUrl : result) {
+            for (String mvnUrl : featuresRepositories.split(",")) {
                 String fixedUrl = mvnUrl.replace("${karaf.home}", karafHome);
                 if (fixedUrl.startsWith("file:")) {
                     try {
@@ -170,15 +168,15 @@ public class PopulateLocalRepoMojo
         }
     }
 
-    private Set<Artifact> readStartupProperties() throws ArtifactResolutionException {
+    private Set<Artifact> readStartupProperties() {
         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));
             Enumeration<Object> mvnUrls = prop.keys();
-            while(mvnUrls.hasMoreElements()) {
-                String mvnUrl = (String)mvnUrls.nextElement();
+            while (mvnUrls.hasMoreElements()) {
+                String mvnUrl = (String) mvnUrls.nextElement();
                 Artifact artifact = aetherUtil.resolveArtifact(FeatureUtil.toCoord(new URL(mvnUrl)));
                 artifacts.add(artifact);
             }