From 01d91de2265e55fab1b1e67171bd668146398017 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Mon, 17 Sep 2018 13:50:27 +0200 Subject: [PATCH] Fix warnings in yang-maven-plugin Fix spotbugs warnings and flip the switch. Change-Id: I69f2f65962af3a44b9205f1659af051a30c5133d Signed-off-by: Robert Varga --- yang/yang-maven-plugin/pom.xml | 7 +++++++ .../yangtools/yang2sources/plugin/YangProvider.java | 2 +- .../yang2sources/plugin/YangToSourcesMojo.java | 9 ++++++--- .../yang2sources/plugin/YangToSourcesProcessor.java | 13 ++++++++----- 4 files changed, 22 insertions(+), 9 deletions(-) diff --git a/yang/yang-maven-plugin/pom.xml b/yang/yang-maven-plugin/pom.xml index fe9bc31fa3..8a82270155 100644 --- a/yang/yang-maven-plugin/pom.xml +++ b/yang/yang-maven-plugin/pom.xml @@ -134,6 +134,13 @@ checkstyle.violationSeverity=error + + com.github.spotbugs + spotbugs-maven-plugin + + true + + diff --git a/yang/yang-maven-plugin/src/main/java/org/opendaylight/yangtools/yang2sources/plugin/YangProvider.java b/yang/yang-maven-plugin/src/main/java/org/opendaylight/yangtools/yang2sources/plugin/YangProvider.java index 016b6fecc3..9d4c972117 100644 --- a/yang/yang-maven-plugin/src/main/java/org/opendaylight/yangtools/yang2sources/plugin/YangProvider.java +++ b/yang/yang-maven-plugin/src/main/java/org/opendaylight/yangtools/yang2sources/plugin/YangProvider.java @@ -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()); diff --git a/yang/yang-maven-plugin/src/main/java/org/opendaylight/yangtools/yang2sources/plugin/YangToSourcesMojo.java b/yang/yang-maven-plugin/src/main/java/org/opendaylight/yangtools/yang2sources/plugin/YangToSourcesMojo.java index 7ad534a6de..8ecc6f230a 100644 --- a/yang/yang-maven-plugin/src/main/java/org/opendaylight/yangtools/yang2sources/plugin/YangToSourcesMojo.java +++ b/yang/yang-maven-plugin/src/main/java/org/opendaylight/yangtools/yang2sources/plugin/YangToSourcesMojo.java @@ -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); diff --git a/yang/yang-maven-plugin/src/main/java/org/opendaylight/yangtools/yang2sources/plugin/YangToSourcesProcessor.java b/yang/yang-maven-plugin/src/main/java/org/opendaylight/yangtools/yang2sources/plugin/YangToSourcesProcessor.java index 3501c7b657..a72079fe56 100644 --- a/yang/yang-maven-plugin/src/main/java/org/opendaylight/yangtools/yang2sources/plugin/YangToSourcesProcessor.java +++ b/yang/yang-maven-plugin/src/main/java/org/opendaylight/yangtools/yang2sources/plugin/YangToSourcesProcessor.java @@ -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); } } -- 2.36.6