Enforce checkstyle in maven-plugin 78/58278/1
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 5 Jun 2017 18:57:47 +0000 (20:57 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Mon, 5 Jun 2017 18:59:49 +0000 (20:59 +0200)
Simple fixes to code and flip the switch.

Change-Id: I06bdd3d3e49c503c390a8cb46ecfeaa8fdf405d8
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
14 files changed:
yang/yang-maven-plugin-spi/pom.xml
yang/yang-maven-plugin-spi/src/main/java/org/opendaylight/yangtools/yang2sources/spi/BasicCodeGenerator.java
yang/yang-maven-plugin-spi/src/main/java/org/opendaylight/yangtools/yang2sources/spi/MavenProjectAware.java
yang/yang-maven-plugin/pom.xml
yang/yang-maven-plugin/src/main/java/org/opendaylight/yangtools/yang2sources/plugin/ConfigArg.java
yang/yang-maven-plugin/src/main/java/org/opendaylight/yangtools/yang2sources/plugin/GeneratedDirectories.java
yang/yang-maven-plugin/src/main/java/org/opendaylight/yangtools/yang2sources/plugin/Util.java
yang/yang-maven-plugin/src/main/java/org/opendaylight/yangtools/yang2sources/plugin/YangSourceFromFile.java
yang/yang-maven-plugin/src/main/java/org/opendaylight/yangtools/yang2sources/plugin/YangToSourcesMojo.java
yang/yang-maven-plugin/src/main/java/org/opendaylight/yangtools/yang2sources/plugin/YangToSourcesProcessor.java
yang/yang-maven-plugin/src/test/java/org/opendaylight/yangtools/yang2sources/plugin/GenerateSourcesTest.java
yang/yang-maven-plugin/src/test/java/org/opendaylight/yangtools/yang2sources/plugin/YangSourceInZipFileTest.java
yang/yang-maven-plugin/src/test/java/org/opendaylight/yangtools/yang2sources/plugin/YangToSourcesMojoTest.java
yang/yang-maven-plugin/src/test/java/org/opendaylight/yangtools/yang2sources/plugin/YangToSourcesProcessorTest.java

index 44ea54af986d04a99e378606c5ee1ca5c0d05197..a9e7ed2d0c6d1fd6fd967d260a756152fc3b7e70 100644 (file)
 
     <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.maven.plugins</groupId>
                 <artifactId>maven-jar-plugin</artifactId>
index ed95d919ce3ea94c664c47a579d94a3870cf8a2b..c50f176cd49ae6863f5883f9398a9f6419f9e0fb 100644 (file)
@@ -23,7 +23,7 @@ import org.opendaylight.yangtools.yang.model.api.SchemaContext;
  */
 public interface BasicCodeGenerator {
     /**
-     * Generate sources from provided {@link SchemaContext}
+     * Generate sources from provided {@link SchemaContext}.
      *
      * @param context
      *            parsed from YANG files
@@ -42,7 +42,7 @@ public interface BasicCodeGenerator {
             throws IOException;
 
     /**
-     * Generate sources from provided {@link SchemaContext}
+     * Generate sources from provided {@link SchemaContext}.
      *
      * @param context
      *            parsed from YANG files
@@ -54,7 +54,6 @@ public interface BasicCodeGenerator {
      * @param moduleResourcePathResolver
      *            Function converting a local module to the packaged resource path
      * @return collection of files that were generated from schema context
-     * @throws IOException
      */
     default Collection<File> generateSources(final SchemaContext context, final File outputBaseDir,
             final Set<Module> currentModules,
@@ -64,17 +63,13 @@ public interface BasicCodeGenerator {
 
     /**
      * Provided map contains all configuration that was set in pom for code
-     * generator in additionalConfiguration tag
-     *
-     * @param additionalConfiguration
+     * generator in additionalConfiguration tag.
      */
     void setAdditionalConfig(Map<String, String> additionalConfiguration);
 
     /**
      * Provided folder is marked as resources and its content will be packaged
-     * in resulting jar. Feel free to add necessary resources
-     *
-     * @param resourceBaseDir
+     * in resulting jar. Feel free to add necessary resources.
      */
     void setResourceBaseDir(File resourceBaseDir);
 }
index 602f78f04c431f82f092de5cd5f3a39ee1102390..2787ed5b6ca131d9c068f44b6033bf48bacb078b 100644 (file)
@@ -16,8 +16,6 @@ public interface MavenProjectAware {
     /**
      * Provided maven project object. Any additional information about current
      * maven project can be accessed from it.
-     *
-     * @param project
      */
     void setMavenProject(MavenProject project);
 }
index be9a03602aa24c69be1421a5c1e1a956eac59cae..c95023a0e75274e1671157addfe6cec5387557e0 100644 (file)
                     </execution>
                 </executions>
             </plugin>
+                       <plugin>
+                               <groupId>org.apache.maven.plugins</groupId>
+                               <artifactId>maven-checkstyle-plugin</artifactId>
+                               <configuration>
+                                       <propertyExpansion>checkstyle.violationSeverity=error</propertyExpansion>
+                               </configuration>
+                       </plugin>
         </plugins>
     </build>
 
index 341f2d47a621f94134f6d211d11d3918c4f0063e..0e8615a92861cb3bc9aad3a746d5bb193e285e1b 100644 (file)
@@ -14,7 +14,7 @@ import java.util.Map;
 import org.apache.maven.project.MavenProject;
 
 /**
- * Base complex configuration arguments
+ * Base complex configuration arguments.
  */
 public abstract class ConfigArg {
 
index 5fc303bfe927392e8ffb6a408f901628443c4b80..49371248d6658974c10bb4e1673241921972a2cf 100644 (file)
@@ -21,7 +21,7 @@ class GeneratedDirectories {
 
     private final File targetGeneratedSources;
 
-    public GeneratedDirectories(MavenProject project) {
+    GeneratedDirectories(MavenProject project) {
         this.targetGeneratedSources = new File(project.getBuild().getDirectory(), "generated-sources");
     }
 
index 28cb24d0dcc7b9ace841edfa872d54a57872d300..000ba17b03da051bed1549df75fd3e31bcecc39e 100644 (file)
@@ -45,7 +45,7 @@ import org.slf4j.LoggerFactory;
 final class Util {
 
     /**
-     * It isn't desirable to create instances of this class
+     * It isn't desirable to create instances of this class.
      */
     private Util() {
     }
@@ -54,7 +54,8 @@ final class Util {
 
     private static final Logger LOG = LoggerFactory.getLogger(Util.class);
 
-    static Collection<File> listFiles(final File root, final Collection<File> excludedFiles) throws FileNotFoundException {
+    static Collection<File> listFiles(final File root, final Collection<File> excludedFiles)
+            throws FileNotFoundException {
         if (!root.exists()) {
             LOG.warn("{} YANG source directory {} not found. No code will be generated.", YangToSourcesProcessor
                     .LOG_PREFIX, root.toString());
@@ -168,8 +169,8 @@ final class Util {
             if (artifact.getGroupId().equals(d.getGroupId()) && artifact.getArtifactId().equals(d.getArtifactId())) {
                 if (!(artifact.getVersion().equals(d.getVersion()))) {
                     LOG.warn("{} Dependency resolution conflict:", YangToSourcesProcessor.LOG_PREFIX);
-                    LOG.warn("{} '{}' dependency [{}] has different version than one declared in current project [{}]" +
-                                    ". It is recommended to fix this problem because it may cause compilation errors.",
+                    LOG.warn("{} '{}' dependency [{}] has different version than one declared in current project [{}]"
+                            + ". It is recommended to fix this problem because it may cause compilation errors.",
                             YangToSourcesProcessor.LOG_PREFIX, YangToSourcesMojo.PLUGIN_NAME, artifact, d);
                 }
             }
@@ -204,6 +205,7 @@ final class Util {
         }
     }
 
+    @SuppressWarnings("checkstyle:illegalCatch")
     static YangsInZipsResult findYangFilesInDependenciesAsStream(final MavenProject project)
             throws MojoFailureException {
         List<YangSourceFromDependency> yangsFromDependencies = new ArrayList<>();
@@ -256,16 +258,12 @@ final class Util {
     }
 
     /**
-     * Find all dependencies which contains yang sources
-     *
+     * Find all dependencies which contains yang sources.
      * Returns collection of YANG files and Zip files which contains YANG files.
      *
-     * FIXME: Rename to what class is actually doing.
-     *
-     * @param project
-     * @return
-     * @throws MojoFailureException
      */
+    //  FIXME: Rename to what class is actually doing.
+    @SuppressWarnings("checkstyle:illegalCatch")
     static Collection<File> findYangFilesInDependencies(final MavenProject project) throws MojoFailureException {
         final List<File> yangsFilesFromDependencies = new ArrayList<>();
 
index 4f4992790f8b07354851036a55215c66cccc6ecf..523ae55d61f86422af0935d29e13e1de0950552e 100644 (file)
@@ -17,7 +17,7 @@ class YangSourceFromFile extends YangSourceFromDependency {
 
     private final File source;
 
-    public YangSourceFromFile(File source) {
+    YangSourceFromFile(File source) {
         this.source = Preconditions.checkNotNull(source);
     }
 
index 6e38aa04447093275cb7a0125cf450d0b5c1d05f..311acc54953ee6af6c8f9d939c008fa25a08c721 100644 (file)
@@ -45,7 +45,8 @@ import org.sonatype.plexus.build.incremental.BuildContext;
  * </ol></li>
  * </ol>
  */
-@Mojo(name = "generate-sources", defaultPhase = LifecyclePhase.GENERATE_SOURCES, requiresDependencyResolution = ResolutionScope.COMPILE, requiresProject = true)
+@Mojo(name = "generate-sources", defaultPhase = LifecyclePhase.GENERATE_SOURCES,
+    requiresDependencyResolution = ResolutionScope.COMPILE, requiresProject = true)
 public final class YangToSourcesMojo extends AbstractMojo {
     public static final String PLUGIN_NAME = "org.opendaylight.yangtools:yang-maven-plugin";
 
@@ -82,15 +83,15 @@ public final class YangToSourcesMojo extends AbstractMojo {
     @Component
     private RepositorySystem repoSystem;
 
-    @Parameter( readonly = true, defaultValue = "${localRepository}" )
+    @Parameter(readonly = true, defaultValue = "${localRepository}")
     private ArtifactRepository localRepository;
 
-    @Parameter( readonly = true, defaultValue = "${project.remoteArtifactRepositories}" )
+    @Parameter(readonly = true, defaultValue = "${project.remoteArtifactRepositories}")
     private List<ArtifactRepository> remoteRepos;
 
     // When set to "true", then the execution of the plugin is disabled
-    @Parameter( property = "yang.skip" )
-    private String yang_skip;
+    @Parameter(property = "yang.skip")
+    private String yangSkip;
 
     public YangToSourcesMojo() {
     }
@@ -118,7 +119,7 @@ public final class YangToSourcesMojo extends AbstractMojo {
             yangToSourcesProcessor = new YangToSourcesProcessor(buildContext, yangFilesRootFile,
                     excludedFiles, codeGeneratorArgs, project, inspectDependencies);
         }
-        yangToSourcesProcessor.conditionalExecute("true".equals(yang_skip));
+        yangToSourcesProcessor.conditionalExecute("true".equals(yangSkip));
     }
 
     private static List<CodeGeneratorArg> processCodeGenerators(final CodeGeneratorArg[] codeGenerators) {
index 3389404a8071de1c4dccf474849f056e21d2c4c2..bb820517da207cd8a023d453120e48b0077e2db1 100644 (file)
@@ -118,6 +118,7 @@ class YangToSourcesProcessor {
         }
     }
 
+    @SuppressWarnings("checkstyle:illegalCatch")
     private ContextHolder processYang() throws MojoExecutionException {
         SchemaContext resolveSchemaContext;
         List<Closeable> closeables = new ArrayList<>();
@@ -220,8 +221,8 @@ class YangToSourcesProcessor {
         } catch (Exception e) {
             LOG.error("{} Unable to parse {} files from {}", LOG_PREFIX, Util.YANG_SUFFIX, yangFilesRootDir, e);
             Throwable rootCause = Throwables.getRootCause(e);
-            throw new MojoExecutionException(LOG_PREFIX + " Unable to parse " + Util.YANG_SUFFIX + " files from " +
-                    yangFilesRootDir, rootCause);
+            throw new MojoExecutionException(LOG_PREFIX + " Unable to parse " + Util.YANG_SUFFIX + " files from "
+                    yangFilesRootDir, rootCause);
         }
     }
 
@@ -261,8 +262,9 @@ class YangToSourcesProcessor {
     }
 
     /**
-     * Call generate on every generator from plugin configuration
+     * Call generate on every generator from plugin configuration.
      */
+    @SuppressWarnings("checkstyle:illegalCatch")
     private void generateSources(final ContextHolder context) throws MojoFailureException {
         if (codeGenerators.size() == 0) {
             LOG.warn("{} No code generators provided", LOG_PREFIX);
@@ -289,21 +291,21 @@ class YangToSourcesProcessor {
     }
 
     /**
-     * Instantiate generator from class and call required method
+     * Instantiate generator from class and call required method.
      */
     private void generateSourcesWithOneGenerator(final ContextHolder context, final CodeGeneratorArg codeGeneratorCfg)
             throws ClassNotFoundException, InstantiationException, IllegalAccessException, IOException {
 
         codeGeneratorCfg.check();
 
-        BasicCodeGenerator g = getInstance(codeGeneratorCfg.getCodeGeneratorClass(), BasicCodeGenerator.class);
+        final BasicCodeGenerator g = getInstance(codeGeneratorCfg.getCodeGeneratorClass(), BasicCodeGenerator.class);
         LOG.info("{} Code generator instantiated from {}", LOG_PREFIX, codeGeneratorCfg.getCodeGeneratorClass());
 
         final File outputDir = codeGeneratorCfg.getOutputBaseDir(project);
 
         if (outputDir == null) {
-            throw new NullPointerException("outputBaseDir is null. Please provide a valid outputBaseDir value in the " +
-                    "pom.xml");
+            throw new NullPointerException("outputBaseDir is null. Please provide a valid outputBaseDir value in the "
+                    "pom.xml");
         }
 
         project.addCompileSourceRoot(outputDir.getAbsolutePath());
@@ -337,7 +339,7 @@ class YangToSourcesProcessor {
     }
 
     /**
-     * Instantiate object from fully qualified class name
+     * Instantiate object from fully qualified class name.
      */
     private static <T> T getInstance(final String codeGeneratorClass, final Class<T> baseType) throws
             ClassNotFoundException, InstantiationException, IllegalAccessException {
index e53c53d6b150b85fd92bebad52d49bfd6541a078..17f5074f4920acffe04cfe65a59f67d6fc4ccea3 100644 (file)
@@ -93,8 +93,8 @@ public class GenerateSourcesTest {
         private static MavenProject project;
 
         @Override
-        public Collection<File> generateSources(final SchemaContext context, final File outputBaseDir, final Set<Module> currentModules)
-                throws IOException {
+        public Collection<File> generateSources(final SchemaContext context, final File outputBaseDir,
+                final Set<Module> currentModules) throws IOException {
             called++;
             outputDir = outputBaseDir;
             return Lists.newArrayList();
index 856c145f3a853a56cfda6d7abd4ccd6326d1d64a..d0e65d5125c900776bfa2a0b0338b2943b2f11af 100644 (file)
@@ -23,7 +23,7 @@ public class YangSourceInZipFileTest {
     public void yangSourceInZipFileTest() throws Exception {
         final ZipFile file = Mockito.mock(ZipFile.class);
         final ZipEntry entry = Mockito.mock(ZipEntry.class);
-        Mockito.when(entry.getSize()).thenReturn(519l);
+        Mockito.when(entry.getSize()).thenReturn(519L);
         final InputStream inputStream = Mockito.mock(InputStream.class);
         Mockito.when(file.getInputStream(entry)).thenReturn(inputStream);
         final YangSourceInZipFile yangSource = new YangSourceInZipFile(file, entry);
index 9e435e5d00894d6375b22597448ea941771cfd8a..df7cce503dd4ff7bcee96998c2da80d2edd5c6fe 100644 (file)
@@ -37,7 +37,7 @@ public class YangToSourcesMojoTest {
     private YangToSourcesProcessor proc;
 
     @Test
-    public void yangToSourceMojoTest() throws Exception{
+    public void yangToSourceMojoTest() throws Exception {
         Mockito.when(this.project.getPlugin(YangToSourcesMojo.PLUGIN_NAME)).thenReturn(this.plugin);
 
         this.mojo = new YangToSourcesMojo();
index 089ddd5d791e1ef7182adfcb536f408a20351372..93c64972842b7da9c8801dd1d9a8753540b9ac40 100644 (file)
@@ -30,7 +30,7 @@ public class YangToSourcesProcessorTest {
     private final YangProvider inspectDependencies = Mockito.mock(YangProvider.class);
 
     @Test
-    public void yangToSourcesProcessotTest(){
+    public void yangToSourcesProcessotTest() {
         Mockito.when(this.buildContext.getPath()).thenReturn("path");
         YangToSourcesProcessor processor = new YangToSourcesProcessor(buildContext, yangFilesRootDir,
             ImmutableList.of(), project, dep, inspectDependencies);