From b453e9b187669914209f9c855ae02982dd58f591 Mon Sep 17 00:00:00 2001 From: Svilen Valkanov Date: Fri, 2 Feb 2018 15:16:24 +0200 Subject: [PATCH] Update to spotbugs-maven-plugin 3.1.1 Includes also: - change the spotbugs-maven-plugin to the official fork; - update the namespace of the properties; - rename all files that were using FindBugs to SpotBugs; - update the documentation. Signed-off-by: Svilen Valkanov --- docs/maven-plugin.md | 48 ++++---- ...dBugsChecker.java => SpotBugsChecker.java} | 111 +++++++++--------- ...ugsVisitors.java => SpotBugsVisitors.java} | 4 +- .../configuration/findbugs.properties | 11 -- .../configuration/spotbugs.properties | 11 ++ .../{findbugs => spotbugs}/exclude.xml | 0 .../{findbugs => spotbugs}/include.xml | 0 .../{findbugs => spotbugs}/visitors.xml | 0 8 files changed, 92 insertions(+), 93 deletions(-) rename sat-plugin/src/main/java/org/openhab/tools/analysis/tools/{FindBugsChecker.java => SpotBugsChecker.java} (66%) rename sat-plugin/src/main/java/org/openhab/tools/analysis/tools/internal/{FindBugsVisitors.java => SpotBugsVisitors.java} (90%) delete mode 100644 sat-plugin/src/main/resources/configuration/findbugs.properties create mode 100644 sat-plugin/src/main/resources/configuration/spotbugs.properties rename sat-plugin/src/main/resources/rulesets/{findbugs => spotbugs}/exclude.xml (100%) rename sat-plugin/src/main/resources/rulesets/{findbugs => spotbugs}/include.xml (100%) rename sat-plugin/src/main/resources/rulesets/{findbugs => spotbugs}/visitors.xml (100%) diff --git a/docs/maven-plugin.md b/docs/maven-plugin.md index 7f70f9b0..0b3947ab 100644 --- a/docs/maven-plugin.md +++ b/docs/maven-plugin.md @@ -1,6 +1,6 @@ # Usage -The Static Code Analysis Tools is a Maven plugin that executes the Maven plugins for FindBugs, Checkstyle and PMD and generates a merged .html report. +The Static Code Analysis Tools is a Maven plugin that executes the Maven plugins for SpotBugs, Checkstyle and PMD and generates a merged .html report. Add the following profiles to your pom.xml: @@ -20,7 +20,7 @@ Add the following profiles to your pom.xml: checkstyle pmd - findbugs + spotbugs report @@ -58,11 +58,11 @@ The summary report can be found in the root target directory: ![Summary report](images/summary-report.PNG "Summary-report") - The build will fail if a problem with high priority is found by some of the Maven plugins for PMD, Checkstyle and FindBugs. Each of the plugins has its own way to prioritize the detected problems: + The build will fail if a problem with high priority is found by some of the Maven plugins for PMD, Checkstyle and SpotBugs. Each of the plugins has its own way to prioritize the detected problems: - for PMD - the build will fail when a rule with Priority "1" is found; - for Checkstyle - a rule with severity="Error"; - - for Findbugs - any Matcher with Rank between 1 and 4. + - for SpotBugs - any Matcher with Rank between 1 and 4. ## Maven plugin goals and parameters @@ -70,7 +70,7 @@ The Static Analysis tool includes several goals: - [pmd](#sat-pluginpmd); - [checkstyle](#sat-plugincheckstyle); -- [findbugs](#sat-pluginfindbugs); +- [spotbugs](#sat-pluginspotbugs); - [report](#sat-pluginreport). Below you can find detailed information what each goal does and how it can be configured. @@ -103,27 +103,27 @@ Parameters: | **checkstylePlugins** | List | A list with artifacts that contain additional checks for Checkstyle | | **checkstyleProperties** | String | Relative path of the properties file to use in the ruleset to configure specific checks | -### sat-plugin:findbugs +### sat-plugin:spotbugs Description: - Executes the `spotbugs-maven-plugin` goal `findbugs` with a ruleset file and configuration properties + Executes the `spotbugs-maven-plugin` goal `spotbugs` with a ruleset file and configuration properties Parameters: | Name | Type| Description | | ------ | ------| -------- | -| **findbugsRuleset** | String | Relative path to the XML that specifies the bug detectors which should be run. If not set the default file will be used| -| **findbugsInclude** | String | Relative path to the XML that specifies the bug instances that will be included in the report. If not set the default file will be used| -| **findbugsExclude** | String | Relative path to the XML that specifies the bug instances that will be excluded from the report. If not set the default file will be used| -| **maven.spotbugs.version** | String | The version of the spotbugs-maven-plugin that will be used (default value is **3.0.6**)| -| **spotbugs.version** | String | The version of SpotBugs that will be used (default value is **3.1.0-RC3**)| -| **findbugsPlugins** | List | A list with artifacts that contain additional detectors/patterns for FindBugs | +| **spotbugsRuleset** | String | Relative path to the XML that specifies the bug detectors which should be run. If not set the default file will be used| +| **spotbugsInclude** | String | Relative path to the XML that specifies the bug instances that will be included in the report. If not set the default file will be used| +| **spotbugsExclude** | String | Relative path to the XML that specifies the bug instances that will be excluded from the report. If not set the default file will be used| +| **maven.spotbugs.version** | String | The version of the spotbugs-maven-plugin that will be used (default value is **3.1.1**)| +| **spotbugs.version** | String | The version of SpotBugs that will be used (default value is **3.1.1**)| +| **spotbugsPlugins** | List | A list with artifacts that contain additional detectors/patterns for SpotBugs | | **findbugs.slf4j.version** | String | The version of the findbugs-slf4j plugin that will be used (default value is **1.2.4**)| ### sat-plugin:report Description: - Transforms the results from FindBugs, Checkstyle and PMD into a single HTML Report with XSLT + Transforms the results from SpotBugs, Checkstyle and PMD into a single HTML Report with XSLT Parameters: @@ -138,7 +138,7 @@ Parameters: Different sets of checks can be executed on different types of projects. -The tool executes different checks on OSGi bundles and ESH Bindings. It uses default configuration files for FindBugs, Checkstyle and PMD that are stored in the `src/main/resources/configuration`. +The tool executes different checks on OSGi bundles and ESH Bindings. It uses default configuration files for SpotBugs, Checkstyle and PMD that are stored in the `src/main/resources/configuration`. If you want to use a custom set of rules you will have to set the configuration parameters for the individual MOJOs. An example configuration may look like this; @@ -150,16 +150,16 @@ If you want to use a custom set of rules you will have to set the configuration build-tools/checkstyle/binding.xml build-tools/checkstyle/suppressions.xml build-tools/pmd/binding.xml - build-tools/findbugs/binding.xml - build-tools/findbugs/exclude.xml - build-tools/findbugs/visitors.xml + build-tools/spotbugs/binding.xml + build-tools/spotbugs/exclude.xml + build-tools/spotbugs/visitors.xml ``` Information about the syntax of the configuration files (except the `visitors.xml`) can be found on the web pages of the individual plugins. -The `visitors.xml` contains a list with FindBugs visitors (bug detectors) and has the following syntax: +The `visitors.xml` contains a list with SpotBugs visitors (bug detectors) and has the following syntax: ``` @@ -171,22 +171,20 @@ The `visitors.xml` contains a list with FindBugs visitors (bug detectors) and ha ### Individual plugin customization -Each of the Maven plugins that are used (for FindBugs, Checkstyle and PMD) are configured by setting user properties that are located in the `src/main/resources/configuration` directory. +Each of the Maven plugins that are used (for SpotBugs, Checkstyle and PMD) are configured by setting user properties that are located in the `src/main/resources/configuration` directory. You can refer to the following links for more configuration options for the specific Maven plugins: - https://maven.apache.org/plugins/maven-pmd-plugin/check-mojo.html; - https://maven.apache.org/plugins-archives/maven-checkstyle-plugin-2.16/checkstyle-mojo.html; -- http://gleclaire.github.io/findbugs-maven-plugin/check-mojo.html. +- https://spotbugs.github.io/spotbugs-maven-plugin/spotbugs-mojo.html. ## Reuse Checks -PMD, Checkstyle and FindBugs come with a set of custom rules that can be used directly in a rule set. +PMD, Checkstyle and SpotBugs come with a set of custom rules that can be used directly in a rule set. Helpful resources with lists of the available checks and information how to use them: - for PMD - https://pmd.github.io/pmd-5.4.0/pmd-java/rules/index.html; - for Checkstyle - http://checkstyle.sourceforge.net/checks.html; -- for FindBugs - Keep in mind that the process for adding a check in FindBugs contains two steps: - - First you should open the link with [BugDescriptors](http://findbugs.sourceforge.net/bugDescriptions.html), choose the bug that you want to detect and create a Match in `src/main/resources/rulesets/findbugs/YOUR_RULESET`; - - Next you should find the Detector that finds the Bug that you have selected above (you can use [this list](https://github.com/findbugsproject/findbugs/blob/d1e60f8dbeda0a454f2d497ef8dcb878fa8e3852/findbugs/etc/findbugs.xml)) and add the Detector in the `src/main/resources/configuration/findbugs.properties` under the property `visitors`. \ No newline at end of file +- for SpotBugs - http://spotbugs.readthedocs.io/en/latest/implement-plugin.html. \ No newline at end of file diff --git a/sat-plugin/src/main/java/org/openhab/tools/analysis/tools/FindBugsChecker.java b/sat-plugin/src/main/java/org/openhab/tools/analysis/tools/SpotBugsChecker.java similarity index 66% rename from sat-plugin/src/main/java/org/openhab/tools/analysis/tools/FindBugsChecker.java rename to sat-plugin/src/main/java/org/openhab/tools/analysis/tools/SpotBugsChecker.java index 0e536178..784e0f71 100644 --- a/sat-plugin/src/main/java/org/openhab/tools/analysis/tools/FindBugsChecker.java +++ b/sat-plugin/src/main/java/org/openhab/tools/analysis/tools/SpotBugsChecker.java @@ -33,13 +33,13 @@ import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.plugins.annotations.ResolutionScope; import org.codehaus.plexus.util.xml.Xpp3Dom; -import org.openhab.tools.analysis.tools.internal.FindBugsVisitors; +import org.openhab.tools.analysis.tools.internal.SpotBugsVisitors; import org.twdata.maven.mojoexecutor.MojoExecutor.Element; /** *

* Executes the - * spotbugs-maven-plugin + * spotbugs-maven-plugin * which is a fork of the * findbugs-maven-plugin * with a predefined ruleset file and configuration properties @@ -55,35 +55,35 @@ * */ -@Mojo(name = "findbugs", requiresDependencyResolution = ResolutionScope.COMPILE) -public class FindBugsChecker extends AbstractChecker { +@Mojo(name = "spotbugs", requiresDependencyResolution = ResolutionScope.COMPILE) +public class SpotBugsChecker extends AbstractChecker { /** * Relative path to the XML that specifies the bug detectors which should be run. If not set the * {@link #DEFAULT_VISITORS_XML} will be used */ - @Parameter(property = "findbugs.ruleset") - private String findbugsRuleset; + @Parameter(property = "spotbugs.ruleset") + private String spotbugsRuleset; /** * Relative path of the XML that specifies the bug instances that will be included from the report. If not set the * {@link #DEFAULT_INCLUDE_FILTER_XML} will be used */ - @Parameter(property = "findbugs.include") - private String findbugsInclude; + @Parameter(property = "spotbugs.include") + private String spotbugsInclude; /** ** Relative path of the XML that specifies the bug instances that will be excluded in the report. If not set the * {@link #DEFAULT_EXCLUDE_FILTER_XML} will be used */ - @Parameter(property = "findbugs.exclude") - private String findbugsExclude; + @Parameter(property = "spotbugs.exclude") + private String spotbugsExclude; /** * The version of the spotbugs-maven-plugin that will be used */ - @Parameter(property = "maven.spotbugs.version", defaultValue = "3.0.6") - private String spotBugsMavenPluginVersion; + @Parameter(property = "maven.spotbugs.version", defaultValue = "3.1.1") + private String spotbugsMavenPluginVersion; /** * The version of the findbugs-slf4j plugin that will be used @@ -94,95 +94,96 @@ public class FindBugsChecker extends AbstractChecker { /** * The version of the spotbugs that will be used */ - @Parameter(property = "spotbugs.version", defaultValue = "3.1.0") + @Parameter(property = "spotbugs.version", defaultValue = "3.1.1") private String spotBugsVersion; /** - * A list with artifacts that contain additional checks for FindBugs + * A list with artifacts that contain additional checks for SpotBugs */ @Parameter - private List findbugsPlugins = new ArrayList<>(); + private List spotbugsPlugins = new ArrayList<>(); /** * Location of the properties file that contains configuration options for the - * findbugs-maven-plugin + * spotbugs-maven-plugin */ - private static final String FINDBUGS_PROPERTIES_FILE = "configuration/findbugs.properties"; + private static final String SPOTBUGS_PROPERTIES_FILE = "configuration/spotbugs.properties"; - private static final String DEFAULT_EXCLUDE_FILTER_XML = "rulesets/findbugs/exclude.xml"; - private static final String DEFAULT_INCLUDE_FILTER_XML = "rulesets/findbugs/include.xml"; - private static final String DEFAULT_VISITORS_XML = "rulesets/findbugs/visitors.xml"; + private static final String DEFAULT_EXCLUDE_FILTER_XML = "rulesets/spotbugs/exclude.xml"; + private static final String DEFAULT_INCLUDE_FILTER_XML = "rulesets/spotbugs/include.xml"; + private static final String DEFAULT_VISITORS_XML = "rulesets/spotbugs/visitors.xml"; - private static final String SPOTBUGS_MAVEN_PLUGIN_GOAL = "findbugs"; + private static final String SPOTBUGS_PLUGIN_GROUP_ID = "com.github.spotbugs"; + private static final String SPOTBUGS_PLUGIN_ARTIFACT_ID = "spotbugs"; private static final String SPOTBUGS_MAVEN_PLUGIN_ARTIFACT_ID = "spotbugs-maven-plugin"; - private static final String SPOTBUGS_MAVEN_PLUGIN_GROUP_ID = "com.github.hazendaz.spotbugs"; + private static final String SPOTBUGS_MAVEN_PLUGIN_GOAL = "spotbugs"; /** - * Property in the findbugs-maven-plugin that is used to describe the path to the + * Property in the spotbugs-maven-plugin that is used to describe the path to the * include filter file used from the plugin. */ - private static final String FINDBUGS_INCLUDE_FILTER_USER_PROPERTY = "findbugs.includeFilterFile"; + private static final String SPOTBUGS_INCLUDE_FILTER_USER_PROPERTY = "spotbugs.includeFilterFile"; /** - * Property in the findbugs-maven-plugin that is used to describe the path to the + * Property in the spotbugs-maven-plugin that is used to describe the path to the * exclude filter file used from the plugin. */ - private static final String FINDBUGS_EXCLUDE_FILTER_USER_PROPERTY = "findbugs.excludeFilterFile"; + private static final String SPOTBUGS_EXCLUDE_FILTER_USER_PROPERTY = "spotbugs.excludeFilterFile"; /** - * Property in the findbugs-maven-plugin, that specifies a comma-separated list of bug detectors which should be + * Property in the spotbugs-maven-plugin, that specifies a comma-separated list of bug detectors which should be * run. The bug detectors are specified by their class names, without any package qualification. */ - private static final String FINDBUGS_VISITORS_PROPERTY = "findbugs.visitors"; + private static final String SPOTBUGS_VISITORS_PROPERTY = "spotbugs.visitors"; @Override public void execute() throws MojoExecutionException, MojoFailureException { Log log = getLog(); - Properties userProps = loadPropertiesFromFile(FINDBUGS_PROPERTIES_FILE); + Properties userProps = loadPropertiesFromFile(SPOTBUGS_PROPERTIES_FILE); // Load the include filter file - String includeLocation = getLocation(findbugsInclude, DEFAULT_INCLUDE_FILTER_XML); + String includeLocation = getLocation(spotbugsInclude, DEFAULT_INCLUDE_FILTER_XML); log.debug("Ruleset location is " + includeLocation); - userProps.setProperty(FINDBUGS_INCLUDE_FILTER_USER_PROPERTY, includeLocation); + userProps.setProperty(SPOTBUGS_INCLUDE_FILTER_USER_PROPERTY, includeLocation); // Load the exclude filter file - String excludeLocation = getLocation(findbugsExclude, DEFAULT_EXCLUDE_FILTER_XML); + String excludeLocation = getLocation(spotbugsExclude, DEFAULT_EXCLUDE_FILTER_XML); log.debug("Filter location is " + excludeLocation); - userProps.setProperty(FINDBUGS_EXCLUDE_FILTER_USER_PROPERTY, excludeLocation); + userProps.setProperty(SPOTBUGS_EXCLUDE_FILTER_USER_PROPERTY, excludeLocation); - String visitors = getVisitorsString(findbugsRuleset, DEFAULT_VISITORS_XML); - log.debug("FindBugs visitors " + visitors); - userProps.setProperty(FINDBUGS_VISITORS_PROPERTY, visitors); - String outputDir = userProps.getProperty("findbugs.report.dir"); + String visitors = getVisitorsString(spotbugsRuleset, DEFAULT_VISITORS_XML); + log.debug("SpotBugs visitors " + visitors); + userProps.setProperty(SPOTBUGS_VISITORS_PROPERTY, visitors); + String outputDir = userProps.getProperty("spotbugs.report.dir"); - // The tool itself is a FindBugs plugin - findbugsPlugins.add(dependency("org.openhab.tools.sat.custom-checks", "findbugs", plugin.getVersion())); + // The tool itself is a SpotBugs plugin + spotbugsPlugins.add(dependency("org.openhab.tools.sat.custom-checks", "findbugs", plugin.getVersion())); // Add dependency to the findbugs-slf4j plugin - findbugsPlugins.add(dependency("jp.skypencil.findbugs.slf4j", "bug-pattern", findBugsSlf4jPluginVersion)); - findbugsPlugins.forEach(logDependency()); + spotbugsPlugins.add(dependency("jp.skypencil.findbugs.slf4j", "bug-pattern", findBugsSlf4jPluginVersion)); + spotbugsPlugins.forEach(logDependency()); - // These configuration properties are not exposed from the findbugs-maven-plugin as user + // These configuration properties are not exposed from the spotbugs-maven-plugin as user // properties, so they have to be set direct in the configuration Xpp3Dom config = configuration(element("outputDirectory", outputDir), element("xmlOutputDirectory", outputDir), - element("findbugsXmlOutputDirectory", outputDir), getFindBugsPlugins(findbugsPlugins)); + element("spotbugsXmlOutputDirectory", outputDir), getSpotBugsPlugins(spotbugsPlugins)); - // If this dependency is missing, findbugs can not load the core plugin because of classpath + // If this dependency is missing, spotbugs can not load the core plugin because of classpath // issues - List findbugsDeps = new ArrayList<>(); - findbugsDeps.add(dependency("com.github.spotbugs", "spotbugs", spotBugsVersion)); - findbugsDeps.forEach(logDependency()); + List spotBugsDeps = new ArrayList<>(); + spotBugsDeps.add(dependency(SPOTBUGS_PLUGIN_GROUP_ID, SPOTBUGS_PLUGIN_ARTIFACT_ID, spotBugsVersion)); + spotBugsDeps.forEach(logDependency()); - executeCheck(SPOTBUGS_MAVEN_PLUGIN_GROUP_ID, SPOTBUGS_MAVEN_PLUGIN_ARTIFACT_ID, spotBugsMavenPluginVersion, - SPOTBUGS_MAVEN_PLUGIN_GOAL, config, findbugsDeps); + executeCheck(SPOTBUGS_PLUGIN_GROUP_ID, SPOTBUGS_MAVEN_PLUGIN_ARTIFACT_ID, spotbugsMavenPluginVersion, + SPOTBUGS_MAVEN_PLUGIN_GOAL, config, spotBugsDeps); - log.debug("FindBugs execution has been finished."); + log.debug("SpotBugs execution has been finished."); } /** - * Creates a "plugins" element used in the findbugs-maven-plugin configuration + * Creates a "plugins" element used in the spotbugs-maven-plugin configuration */ - private Element getFindBugsPlugins(List plugins) { + private Element getSpotBugsPlugins(List plugins) { List pluginList = new LinkedList<>(); // Add additional dependencies if (plugins != null) { @@ -220,13 +221,13 @@ private String getVisitorsString(String externalLocation, String defaultLocaiton // Serialize the content JAXBContext context; try { - context = JAXBContext.newInstance(FindBugsVisitors.class); + context = JAXBContext.newInstance(SpotBugsVisitors.class); Unmarshaller unmarschaller = context.createUnmarshaller(); - FindBugsVisitors visitors = (FindBugsVisitors) unmarschaller.unmarshal(stream); + SpotBugsVisitors visitors = (SpotBugsVisitors) unmarschaller.unmarshal(stream); return visitors.toString(); } catch (JAXBException e) { - getLog().warn("Unable to load FindBugs visitors", e); + getLog().warn("Unable to load SpotBugs visitors", e); return null; } } diff --git a/sat-plugin/src/main/java/org/openhab/tools/analysis/tools/internal/FindBugsVisitors.java b/sat-plugin/src/main/java/org/openhab/tools/analysis/tools/internal/SpotBugsVisitors.java similarity index 90% rename from sat-plugin/src/main/java/org/openhab/tools/analysis/tools/internal/FindBugsVisitors.java rename to sat-plugin/src/main/java/org/openhab/tools/analysis/tools/internal/SpotBugsVisitors.java index 0e28afdc..4907bd1c 100644 --- a/sat-plugin/src/main/java/org/openhab/tools/analysis/tools/internal/FindBugsVisitors.java +++ b/sat-plugin/src/main/java/org/openhab/tools/analysis/tools/internal/SpotBugsVisitors.java @@ -17,13 +17,13 @@ import org.apache.commons.lang3.StringUtils; /** - * A JAXB model of the FindBugs visitors XML file + * A JAXB model of the SpotBugs visitors XML file * * @author Svilen Valkanov * */ @XmlRootElement(name = "visitors") -public class FindBugsVisitors { +public class SpotBugsVisitors { @XmlElement List visitor = new ArrayList(); diff --git a/sat-plugin/src/main/resources/configuration/findbugs.properties b/sat-plugin/src/main/resources/configuration/findbugs.properties deleted file mode 100644 index 6b49d04e..00000000 --- a/sat-plugin/src/main/resources/configuration/findbugs.properties +++ /dev/null @@ -1,11 +0,0 @@ -findbugs.relaxed=true -findbugs.debug=false -findbugs.threshold=High -findbugs.effort=Min -findbugs.xmlOutput=true -findbugs.failOnError=false -findbugs.report.dir=target/code-analysis -findbugs.fork=false -outputEncoding=UTF-8 -findbugs.onlyAnalyze=org.openhab.-,org.eclipse.smarthome.- -findbugs.nested=false diff --git a/sat-plugin/src/main/resources/configuration/spotbugs.properties b/sat-plugin/src/main/resources/configuration/spotbugs.properties new file mode 100644 index 00000000..721f9826 --- /dev/null +++ b/sat-plugin/src/main/resources/configuration/spotbugs.properties @@ -0,0 +1,11 @@ +spotbugs.relaxed=true +spotbugs.debug=false +spotbugs.threshold=High +spotbugs.effort=Min +spotbugs.xmlOutput=true +spotbugs.failOnError=false +spotbugs.report.dir=target/code-analysis +spotbugs.fork=false +outputEncoding=UTF-8 +spotbugs.onlyAnalyze=org.openhab.-,org.eclipse.smarthome.- +spotbugs.nested=false diff --git a/sat-plugin/src/main/resources/rulesets/findbugs/exclude.xml b/sat-plugin/src/main/resources/rulesets/spotbugs/exclude.xml similarity index 100% rename from sat-plugin/src/main/resources/rulesets/findbugs/exclude.xml rename to sat-plugin/src/main/resources/rulesets/spotbugs/exclude.xml diff --git a/sat-plugin/src/main/resources/rulesets/findbugs/include.xml b/sat-plugin/src/main/resources/rulesets/spotbugs/include.xml similarity index 100% rename from sat-plugin/src/main/resources/rulesets/findbugs/include.xml rename to sat-plugin/src/main/resources/rulesets/spotbugs/include.xml diff --git a/sat-plugin/src/main/resources/rulesets/findbugs/visitors.xml b/sat-plugin/src/main/resources/rulesets/spotbugs/visitors.xml similarity index 100% rename from sat-plugin/src/main/resources/rulesets/findbugs/visitors.xml rename to sat-plugin/src/main/resources/rulesets/spotbugs/visitors.xml