diff --git a/src/it/exclude-multi-list/invoker.properties b/src/it/exclude-multi-list/invoker.properties new file mode 100644 index 00000000..7fbf7d99 --- /dev/null +++ b/src/it/exclude-multi-list/invoker.properties @@ -0,0 +1,4 @@ +invoker.goals = clean compile site + +# The expected result of the build, possible values are "success" (default) and "failure" +invoker.buildResult = success diff --git a/src/it/exclude-multi-list/pom.xml b/src/it/exclude-multi-list/pom.xml new file mode 100644 index 00000000..2c700c8e --- /dev/null +++ b/src/it/exclude-multi-list/pom.xml @@ -0,0 +1,61 @@ + + + + + 4.0.0 + + spotbugs-maven-plugin.it + common + testing + ../common.xml + + excludeFile-multi-list + excludeFile-multi-list + jar + + + + spotbugs-maven-plugin.it + build-tools + testing + + + + + true + + + org.apache.maven.plugins + maven-jxr-plugin + @jxrPluginVersion@ + + + com.github.spotbugs + spotbugs-maven-plugin + + true + true + + whizbang/lib-filter.xml + filters/lib-filter2.xml + + + + + + diff --git a/src/it/exclude-multi-list/verify.groovy b/src/it/exclude-multi-list/verify.groovy new file mode 100644 index 00000000..80d3f179 --- /dev/null +++ b/src/it/exclude-multi-list/verify.groovy @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2006-2020 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import groovy.xml.XmlSlurper + +File spotbugsHtml = new File(basedir, 'target/site/spotbugs.html') +assert spotbugsHtml.exists() + +File spotbugXdoc = new File(basedir, 'target/spotbugs.xml') +assert spotbugXdoc.exists() + +File spotbugXml = new File(basedir, 'target/spotbugsXml.xml') +assert spotbugXml.exists() + + +println '***************************' +println "Checking HTML file" +println '***************************' + +def xhtmlParser = new XmlSlurper(); +xhtmlParser.setFeature("http://apache.org/xml/features/disallow-doctype-decl", false) +xhtmlParser.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false) +def path = xhtmlParser.parse( spotbugsHtml ) +//*[@id="contentBox"]/div[2]/table/tbody/tr[2]/td[2] +def spotbugsErrors = path.body.'**'.find {div -> div.@id == 'contentBox'}.section[1].table.tr[1].td[1].toInteger() +println "Error Count is ${spotbugsErrors}" + + +println '**********************************' +println "Checking Spotbugs Native XML file" +println '**********************************' + +path = new XmlSlurper().parse(spotbugXml) + +allNodes = path.depthFirst().collect{ it } +def spotbugsXmlErrors = allNodes.findAll {it.name() == 'BugInstance'}.size() +println "BugInstance size is ${spotbugsXmlErrors}" + + +println '***************************' +println "Checking xDoc file" +println '***************************' + +path = new XmlSlurper().parse(spotbugXdoc) + +allNodes = path.depthFirst().collect{ it } +def xdocErrors = allNodes.findAll {it.name() == 'BugInstance'}.size() +println "BugInstance size is ${xdocErrors}" + + +assert xdocErrors == spotbugsXmlErrors + +assert spotbugsErrors == spotbugsXmlErrors diff --git a/src/main/groovy/org/codehaus/mojo/spotbugs/SpotBugsMojo.groovy b/src/main/groovy/org/codehaus/mojo/spotbugs/SpotBugsMojo.groovy index 5ff6438f..949ae593 100644 --- a/src/main/groovy/org/codehaus/mojo/spotbugs/SpotBugsMojo.groovy +++ b/src/main/groovy/org/codehaus/mojo/spotbugs/SpotBugsMojo.groovy @@ -330,6 +330,28 @@ class SpotBugsMojo extends AbstractMavenReport implements SpotBugsPluginsTrait { @Parameter(property = "spotbugs.excludeFilterFile") String excludeFilterFile + /** + *

+ * File name for exclude filter files. Bugs matching the filters are not reported. + *

+ * + *

+ * This is an alternative to <excludeFilterFile> which allows multiple + * files to be specified as separate elements in a pom. + *

+ * + *

+ * This parameter is resolved as resource, URL, then file. If successfully + * resolved, the contents of the configuration is copied into the + * ${project.build.directory} + * directory before being passed to Spotbugs as a filter file. + *

+ * + * @since 4.7.0.1-SNAPSHOT + */ + @Parameter(property = "spotbugs.excludeFilterFiles") + List excludeFilterFiles + /** *

* File names of the baseline files. Bugs found in the baseline files won't be reported. @@ -961,6 +983,16 @@ class SpotBugsMojo extends AbstractMavenReport implements SpotBugsPluginsTrait { } + if (excludeFilterFiles) { + log.debug(" Adding Exclude Filter Files ") + + excludeFilterFiles.each { excludeFilter -> + args << "-exclude" + args << resourceHelper.getResourceFile(excludeFilter.trim()) + } + + } + if (excludeBugsFile) { log.debug(" Adding Exclude Bug Files (Baselines)") String[] excludeFiles = excludeBugsFile.split(SpotBugsInfo.COMMA)