Fix warnings in yang-maven-plugin 48/76148/4
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 17 Sep 2018 11:50:27 +0000 (13:50 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Mon, 17 Sep 2018 12:07:49 +0000 (14:07 +0200)
Fix spotbugs warnings and flip the switch.

Change-Id: I69f2f65962af3a44b9205f1659af051a30c5133d
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
yang/yang-maven-plugin/pom.xml
yang/yang-maven-plugin/src/main/java/org/opendaylight/yangtools/yang2sources/plugin/YangProvider.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

index fe9bc31fa37b53a137b504c8d8a901d7a9b849ba..8a82270155061958862a0fcd218b7779df8d1eb1 100644 (file)
                     <propertyExpansion>checkstyle.violationSeverity=error</propertyExpansion>
                 </configuration>
             </plugin>
+            <plugin>
+                <groupId>com.github.spotbugs</groupId>
+                <artifactId>spotbugs-maven-plugin</artifactId>
+                <configuration>
+                    <failOnError>true</failOnError>
+                </configuration>
+            </plugin>
         </plugins>
     </build>
 
index 016b6fecc3d2e8728df93477a73df62f10cf9eaf..9d4c9721172288dde75000b0145c1bf3c234f276 100644 (file)
@@ -31,11 +31,11 @@ abstract class YangProvider {
             // copy project's src/main/yang/*.yang to ${project.builddir}/generated-sources/yang/META-INF/yang/
             // This honors setups like a Eclipse-profile derived one
             final File withMetaInf = new File(generatedYangDir, YangToSourcesProcessor.META_INF_YANG_STRING);
-            withMetaInf.mkdirs();
 
             for (YangTextSchemaSource source : modelsInProject) {
                 final String fileName = source.getIdentifier().toYangFilename();
                 final File file = new File(withMetaInf, fileName);
+                Files.createParentDirs(file);
 
                 source.copyTo(Files.asByteSink(file));
                 LOG.debug("Created file {} for {}", file, source.getIdentifier());
index 7ad534a6de0f245052e568d1b44546bc54079e82..8ecc6f230a75b337456239cd356753a0137627b4 100644 (file)
@@ -10,6 +10,7 @@ package org.opendaylight.yangtools.yang2sources.plugin;
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.collect.Collections2;
 import com.google.common.collect.ImmutableList;
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
 import java.io.File;
 import java.util.Arrays;
 import java.util.Collection;
@@ -95,10 +96,7 @@ public final class YangToSourcesMojo extends AbstractMojo {
     private String yangSkip;
 
     public YangToSourcesMojo() {
-    }
 
-    public void setProject(final MavenProject project) {
-        this.project = project;
     }
 
     @VisibleForTesting
@@ -106,7 +104,12 @@ public final class YangToSourcesMojo extends AbstractMojo {
         this.yangToSourcesProcessor = processor;
     }
 
+    public void setProject(final MavenProject project) {
+        this.project = project;
+    }
+
     @Override
+    @SuppressFBWarnings(value = "UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR", justification = "yangFilesRootDir")
     public void execute() throws MojoExecutionException, MojoFailureException {
         Util.checkClasspath(project, repoSystem, localRepository, remoteRepos);
 
index 3501c7b65727fb043529a3e612376c651a92512c..a72079fe56b712eb04658552a9eb5a9841524651 100644 (file)
@@ -40,6 +40,8 @@ import org.opendaylight.yangtools.yang.common.YangConstants;
 import org.opendaylight.yangtools.yang.model.parser.api.YangParser;
 import org.opendaylight.yangtools.yang.model.parser.api.YangParserException;
 import org.opendaylight.yangtools.yang.model.parser.api.YangParserFactory;
+import org.opendaylight.yangtools.yang.model.parser.api.YangSyntaxErrorException;
+import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceException;
 import org.opendaylight.yangtools.yang.model.repo.api.StatementParserMode;
 import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
 import org.opendaylight.yangtools.yang.parser.rfc7950.repo.ASTSchemaSource;
@@ -283,9 +285,9 @@ class YangToSourcesProcessor {
             LOG.info("{} Project model files found: {}", LOG_PREFIX, yangFilesInProject.size());
 
             final ProcessorModuleReactor reactor = new ProcessorModuleReactor(parser, sourcesInProject, dependencies);
-            LOG.debug("Initialized reactor {}", reactor, yangFilesInProject);
+            LOG.debug("Initialized reactor {} with {}", reactor, yangFilesInProject);
             return Optional.of(reactor);
-        } catch (Exception e) {
+        } catch (IOException | SchemaSourceException | YangSyntaxErrorException | RuntimeException e) {
             // MojoExecutionException is thrown since execution cannot continue
             LOG.error("{} Unable to parse YANG files from {}", LOG_PREFIX, yangFilesRootDir, e);
             Throwable rootCause = Throwables.getRootCause(e);
@@ -335,9 +337,10 @@ class YangToSourcesProcessor {
         }
 
         if (!thrown.isEmpty()) {
-            String message = " One or more code generators failed, including failed list(generatorClass=exception) ";
-            LOG.error("{}{}{}", LOG_PREFIX, message, thrown.toString());
-            throw new MojoFailureException(LOG_PREFIX + message + thrown.toString());
+            LOG.error("{} One or more code generators failed, including failed list(generatorClass=exception) {}",
+                LOG_PREFIX, thrown);
+            throw new MojoFailureException(LOG_PREFIX
+                + " One or more code generators failed, including failed list(generatorClass=exception) " + thrown);
         }
     }