diff --git a/pom.xml b/pom.xml index 087cbbd6..b34e2417 100644 --- a/pom.xml +++ b/pom.xml @@ -646,6 +646,7 @@
LICENSE_HEADER
**/*edu.umd.cs.findbugs.core.prefs + **/*.txt diff --git a/src/it/onlyAnalyzeFileSource/invoker.properties b/src/it/onlyAnalyzeFileSource/invoker.properties new file mode 100644 index 00000000..af4f3cdc --- /dev/null +++ b/src/it/onlyAnalyzeFileSource/invoker.properties @@ -0,0 +1,20 @@ +# +# Copyright 2005-2023 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. +# + +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/onlyAnalyzeFileSource/only-analyze.txt b/src/it/onlyAnalyzeFileSource/only-analyze.txt new file mode 100644 index 00000000..b5b43615 --- /dev/null +++ b/src/it/onlyAnalyzeFileSource/only-analyze.txt @@ -0,0 +1 @@ +BC_Unconfirmed_Cast diff --git a/src/it/onlyAnalyzeFileSource/pom.xml b/src/it/onlyAnalyzeFileSource/pom.xml new file mode 100644 index 00000000..f9acaa5c --- /dev/null +++ b/src/it/onlyAnalyzeFileSource/pom.xml @@ -0,0 +1,51 @@ + + + + + 4.0.0 + + spotbugs-maven-plugin.it + common + testing + ../common.xml + + onlyAnalyzeFileSource + onlyAnalyzeFileSource + jar + + true + + + org.apache.maven.plugins + maven-jxr-plugin + @jxrPluginVersion@ + + + com.github.spotbugs + spotbugs-maven-plugin + + true + true + file:only-analyze.txt + + + + + diff --git a/src/it/onlyAnalyzeFileSource/verify.groovy b/src/it/onlyAnalyzeFileSource/verify.groovy new file mode 100644 index 00000000..1d779d5b --- /dev/null +++ b/src/it/onlyAnalyzeFileSource/verify.groovy @@ -0,0 +1,69 @@ +/* + * Copyright 2005-2023 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 + +def effortLevel = 'default' + +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 '***************************' + +assert spotbugsHtml.text.contains( "" + effortLevel + "" ) + +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 9b7753c5..72db342d 100644 --- a/src/main/groovy/org/codehaus/mojo/spotbugs/SpotBugsMojo.groovy +++ b/src/main/groovy/org/codehaus/mojo/spotbugs/SpotBugsMojo.groovy @@ -38,6 +38,10 @@ import org.apache.maven.shared.transfer.artifact.resolve.ArtifactResolver import org.codehaus.plexus.resource.ResourceManager import org.codehaus.plexus.resource.loader.FileResourceLoader +import java.nio.file.Files +import java.nio.file.Paths +import java.util.stream.Collectors + /** * Generates a SpotBugs Report when the site plugin is run. * The HTML report is generated for site commands only. @@ -929,7 +933,9 @@ class SpotBugsMojo extends AbstractMavenReport implements SpotBugsPluginsTrait { if (onlyAnalyze) { args << "-onlyAnalyze" - args << onlyAnalyze + args << Arrays.stream(onlyAnalyze.split(",")).map { + it.startsWith("file:") ? Files.lines(Paths.get(it.substring(5))).collect(Collectors.joining(",")) : it + }.collect(Collectors.joining(",")) } if (includeFilterFile) {