From 11798afebb42d08e1f366d16167b0058a88a963b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Siersze=C5=84?= Date: Tue, 15 Feb 2022 18:03:27 +0100 Subject: [PATCH 1/3] Added separate goals for check and verify (fixes #114) --- README.md | 7 +++ src/it/verify-fail/invoker.properties | 4 ++ src/it/verify-fail/pom.xml | 59 +++++++++++++++++++ src/it/verify-fail/verify.groovy | 18 ++++++ src/it/verify/invoker.properties | 4 ++ src/it/verify/pom.xml | 59 +++++++++++++++++++ src/it/verify/verify.groovy | 50 ++++++++++++++++ ...o.groovy => BaseViolationCheckMojo.groovy} | 11 +--- .../codehaus/mojo/spotbugs/CheckMojo.groovy | 37 ++++++++++++ .../codehaus/mojo/spotbugs/VerifyMojo.groovy | 35 +++++++++++ 10 files changed, 274 insertions(+), 10 deletions(-) create mode 100644 src/it/verify-fail/invoker.properties create mode 100644 src/it/verify-fail/pom.xml create mode 100644 src/it/verify-fail/verify.groovy create mode 100644 src/it/verify/invoker.properties create mode 100644 src/it/verify/pom.xml create mode 100644 src/it/verify/verify.groovy rename src/main/groovy/org/codehaus/mojo/spotbugs/{SpotbugsViolationCheckMojo.groovy => BaseViolationCheckMojo.groovy} (96%) create mode 100644 src/main/groovy/org/codehaus/mojo/spotbugs/CheckMojo.groovy create mode 100644 src/main/groovy/org/codehaus/mojo/spotbugs/VerifyMojo.groovy diff --git a/README.md b/README.md index 59742bde..d7614fd0 100644 --- a/README.md +++ b/README.md @@ -63,3 +63,10 @@ Run gui with a specific version ``` mvn com.github.spotbugs:spotbugs-maven-plugin:4.0.0:gui ``` + +## Contributing ## + +Run integration tests +``` +mvn clean install -P run-its -DtestSrc=remote +``` diff --git a/src/it/verify-fail/invoker.properties b/src/it/verify-fail/invoker.properties new file mode 100644 index 00000000..bf0b3fc5 --- /dev/null +++ b/src/it/verify-fail/invoker.properties @@ -0,0 +1,4 @@ +invoker.goals = clean verify + +# The expected result of the build, possible values are "success" (default) and "failure" +invoker.buildResult = failure diff --git a/src/it/verify-fail/pom.xml b/src/it/verify-fail/pom.xml new file mode 100644 index 00000000..fdfe5776 --- /dev/null +++ b/src/it/verify-fail/pom.xml @@ -0,0 +1,59 @@ + + + + + 4.0.0 + + spotbugs-maven-plugin.it + common + testing + ../common.xml + + check + check + jar + + + + com.github.spotbugs + spotbugs-maven-plugin + + true + true + @spotbugsTestDebug@ + High + + + + run-analysis + process-classes + + spotbugs + + + + process-results + + verify + + + + + + + diff --git a/src/it/verify-fail/verify.groovy b/src/it/verify-fail/verify.groovy new file mode 100644 index 00000000..c509ec22 --- /dev/null +++ b/src/it/verify-fail/verify.groovy @@ -0,0 +1,18 @@ +/* + * 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. + */ + +File buildLog = new File( basedir, 'build.log' ) +assert buildLog.text.contains( '[ERROR] High: Found reliance on default encoding in UserMistakes' ) diff --git a/src/it/verify/invoker.properties b/src/it/verify/invoker.properties new file mode 100644 index 00000000..878b37e9 --- /dev/null +++ b/src/it/verify/invoker.properties @@ -0,0 +1,4 @@ +invoker.goals = clean verify + +# The expected result of the build, possible values are "success" (default) and "failure" +invoker.buildResult = success diff --git a/src/it/verify/pom.xml b/src/it/verify/pom.xml new file mode 100644 index 00000000..e2e69cb6 --- /dev/null +++ b/src/it/verify/pom.xml @@ -0,0 +1,59 @@ + + + + + 4.0.0 + + spotbugs-maven-plugin.it + common + testing + ../common.xml + + check + check + jar + + + + com.github.spotbugs + spotbugs-maven-plugin + + true + false + @spotbugsTestDebug@ + High + + + + run-analysis + process-classes + + spotbugs + + + + process-results + + verify + + + + + + + diff --git a/src/it/verify/verify.groovy b/src/it/verify/verify.groovy new file mode 100644 index 00000000..ae8effc6 --- /dev/null +++ b/src/it/verify/verify.groovy @@ -0,0 +1,50 @@ +/* + * 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 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 '***************************' + +def path = new XmlSlurper().parse(spotbugXdoc) + +xNodes = path.depthFirst().collect{ it } +def xdocErrors = xNodes.findAll {it.name() == 'BugInstance'}.size() +println "BugInstance size is ${xdocErrors}" + +assert xdocErrors == spotbugsXmlErrors diff --git a/src/main/groovy/org/codehaus/mojo/spotbugs/SpotbugsViolationCheckMojo.groovy b/src/main/groovy/org/codehaus/mojo/spotbugs/BaseViolationCheckMojo.groovy similarity index 96% rename from src/main/groovy/org/codehaus/mojo/spotbugs/SpotbugsViolationCheckMojo.groovy rename to src/main/groovy/org/codehaus/mojo/spotbugs/BaseViolationCheckMojo.groovy index 197f1246..8f02039b 100644 --- a/src/main/groovy/org/codehaus/mojo/spotbugs/SpotbugsViolationCheckMojo.groovy +++ b/src/main/groovy/org/codehaus/mojo/spotbugs/BaseViolationCheckMojo.groovy @@ -46,16 +46,7 @@ import org.apache.maven.shared.transfer.artifact.resolve.ArtifactResolver import org.codehaus.plexus.resource.ResourceManager import org.codehaus.plexus.util.FileUtils -/** - * Fail the build if there were any SpotBugs violations in the source code. - * An XML report is put out by default in the target directory with the errors. - * To see more documentation about SpotBugs' options, please see the SpotBugs Manual.. - * - * @since 2.0 - */ -@Mojo( name = "check", defaultPhase = LifecyclePhase.VERIFY, requiresDependencyResolution = ResolutionScope.TEST, requiresProject = true, threadSafe = true) -@Execute( goal = "spotbugs") -class SpotbugsViolationCheckMojo extends AbstractMojo { +abstract class BaseViolationCheckMojo extends AbstractMojo { /** * Location where generated html will be created. diff --git a/src/main/groovy/org/codehaus/mojo/spotbugs/CheckMojo.groovy b/src/main/groovy/org/codehaus/mojo/spotbugs/CheckMojo.groovy new file mode 100644 index 00000000..f37c9e49 --- /dev/null +++ b/src/main/groovy/org/codehaus/mojo/spotbugs/CheckMojo.groovy @@ -0,0 +1,37 @@ +package org.codehaus.mojo.spotbugs + +import org.apache.maven.plugins.annotations.Execute +import org.apache.maven.plugins.annotations.LifecyclePhase +import org.apache.maven.plugins.annotations.Mojo +import org.apache.maven.plugins.annotations.ResolutionScope + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ + +/** + * Fail the build if there were any SpotBugs violations in the source code. + * An XML report is put out by default in the target directory with the errors. + * To see more documentation about SpotBugs' options, please see the SpotBugs Manual.. + * + * @since 2.0 + */ +@Mojo( name = "check", defaultPhase = LifecyclePhase.VERIFY, requiresDependencyResolution = ResolutionScope.TEST, requiresProject = true, threadSafe = true) +@Execute( goal = "spotbugs") +class CheckMojo extends BaseViolationCheckMojo { +} diff --git a/src/main/groovy/org/codehaus/mojo/spotbugs/VerifyMojo.groovy b/src/main/groovy/org/codehaus/mojo/spotbugs/VerifyMojo.groovy new file mode 100644 index 00000000..53be7a58 --- /dev/null +++ b/src/main/groovy/org/codehaus/mojo/spotbugs/VerifyMojo.groovy @@ -0,0 +1,35 @@ +package org.codehaus.mojo.spotbugs + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 org.apache.maven.plugins.annotations.LifecyclePhase +import org.apache.maven.plugins.annotations.Mojo +import org.apache.maven.plugins.annotations.ResolutionScope + +/** + * Fail the build if any SpotBugs violations can be found in a preexisting {@code spotBugs.xml} file. + * Note that unlike the {@code check} goal, this goal only reads existing XML reports, without actually performing SpotBugs analysis. + * To see more documentation about SpotBugs' options, please see the SpotBugs Manual.. + * + * @since 4.5 + */ +@Mojo( name = "verify", defaultPhase = LifecyclePhase.VERIFY, requiresDependencyResolution = ResolutionScope.TEST, requiresProject = true, threadSafe = true) +class VerifyMojo extends BaseViolationCheckMojo { +} From ee540228077b6d04cb7b1ad75c2107303bddf4f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Siersze=C5=84?= Date: Sat, 16 Apr 2022 12:17:19 +0200 Subject: [PATCH 2/3] chore(verify): Since tag bump --- src/main/groovy/org/codehaus/mojo/spotbugs/VerifyMojo.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/groovy/org/codehaus/mojo/spotbugs/VerifyMojo.groovy b/src/main/groovy/org/codehaus/mojo/spotbugs/VerifyMojo.groovy index 53be7a58..f3bbf9e6 100644 --- a/src/main/groovy/org/codehaus/mojo/spotbugs/VerifyMojo.groovy +++ b/src/main/groovy/org/codehaus/mojo/spotbugs/VerifyMojo.groovy @@ -28,7 +28,7 @@ import org.apache.maven.plugins.annotations.ResolutionScope * Note that unlike the {@code check} goal, this goal only reads existing XML reports, without actually performing SpotBugs analysis. * To see more documentation about SpotBugs' options, please see the SpotBugs Manual.. * - * @since 4.5 + * @since 4.7 */ @Mojo( name = "verify", defaultPhase = LifecyclePhase.VERIFY, requiresDependencyResolution = ResolutionScope.TEST, requiresProject = true, threadSafe = true) class VerifyMojo extends BaseViolationCheckMojo { From f29d7b3e249cd491c58f8c72f2606c6f3f68055e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Siersze=C5=84?= Date: Sat, 16 Apr 2022 12:19:11 +0200 Subject: [PATCH 3/3] feat(verify): Updated Javadoc --- src/main/groovy/org/codehaus/mojo/spotbugs/VerifyMojo.groovy | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/groovy/org/codehaus/mojo/spotbugs/VerifyMojo.groovy b/src/main/groovy/org/codehaus/mojo/spotbugs/VerifyMojo.groovy index f3bbf9e6..5cde89d1 100644 --- a/src/main/groovy/org/codehaus/mojo/spotbugs/VerifyMojo.groovy +++ b/src/main/groovy/org/codehaus/mojo/spotbugs/VerifyMojo.groovy @@ -25,7 +25,9 @@ import org.apache.maven.plugins.annotations.ResolutionScope /** * Fail the build if any SpotBugs violations can be found in a preexisting {@code spotBugs.xml} file. - * Note that unlike the {@code check} goal, this goal only reads existing XML reports, without actually performing SpotBugs analysis. + * Note that unlike the {@code check} goal, this goal only reads existing XML reports, without actually performing SpotBugs analysis. + * This way, it is possible to split the analysis and verification into lifecycle phases of one's choosing. + * One use case for that is running multiple code analyzers at once and only failing the build at a later stage, so that all of them have a chance to run. * To see more documentation about SpotBugs' options, please see the SpotBugs Manual.. * * @since 4.7