-
Notifications
You must be signed in to change notification settings - Fork 54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added separate goals for check and verify (fixes #114) #405
Merged
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
invoker.goals = clean verify | ||
|
||
# The expected result of the build, possible values are "success" (default) and "failure" | ||
invoker.buildResult = failure |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
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. | ||
--> | ||
|
||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>spotbugs-maven-plugin.it</groupId> | ||
<artifactId>common</artifactId> | ||
<version>testing</version> | ||
<relativePath>../common.xml</relativePath> | ||
</parent> | ||
<artifactId>check</artifactId> | ||
<name>check</name> | ||
<packaging>jar</packaging> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>com.github.spotbugs</groupId> | ||
<artifactId>spotbugs-maven-plugin</artifactId> | ||
<configuration> | ||
<xmlOutput>true</xmlOutput> | ||
<failOnError>true</failOnError> | ||
<debug>@spotbugsTestDebug@</debug> | ||
<threshold>High</threshold> | ||
</configuration> | ||
<executions> | ||
<execution> | ||
<id>run-analysis</id> | ||
<phase>process-classes</phase> | ||
<goals> | ||
<goal>spotbugs</goal> | ||
</goals> | ||
</execution> | ||
<execution> | ||
<id>process-results</id> | ||
<goals> | ||
<goal>verify</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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' ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
invoker.goals = clean verify | ||
|
||
# The expected result of the build, possible values are "success" (default) and "failure" | ||
invoker.buildResult = success |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
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. | ||
--> | ||
|
||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>spotbugs-maven-plugin.it</groupId> | ||
<artifactId>common</artifactId> | ||
<version>testing</version> | ||
<relativePath>../common.xml</relativePath> | ||
</parent> | ||
<artifactId>check</artifactId> | ||
<name>check</name> | ||
<packaging>jar</packaging> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>com.github.spotbugs</groupId> | ||
<artifactId>spotbugs-maven-plugin</artifactId> | ||
<configuration> | ||
<xmlOutput>true</xmlOutput> | ||
<failOnError>false</failOnError> | ||
<debug>@spotbugsTestDebug@</debug> | ||
<threshold>High</threshold> | ||
</configuration> | ||
<executions> | ||
<execution> | ||
<id>run-analysis</id> | ||
<phase>process-classes</phase> | ||
<goals> | ||
<goal>spotbugs</goal> | ||
</goals> | ||
</execution> | ||
<execution> | ||
<id>process-results</id> | ||
<goals> | ||
<goal>verify</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
src/main/groovy/org/codehaus/mojo/spotbugs/CheckMojo.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <a href="https://spotbugs.readthedocs.io/en/latest/" class="externalLink">SpotBugs Manual.</a>. | ||
* | ||
* @since 2.0 | ||
*/ | ||
@Mojo( name = "check", defaultPhase = LifecyclePhase.VERIFY, requiresDependencyResolution = ResolutionScope.TEST, requiresProject = true, threadSafe = true) | ||
@Execute( goal = "spotbugs") | ||
class CheckMojo extends BaseViolationCheckMojo { | ||
} |
37 changes: 37 additions & 0 deletions
37
src/main/groovy/org/codehaus/mojo/spotbugs/VerifyMojo.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
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, <b>without</b> 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 <a href="https://spotbugs.readthedocs.io/en/latest/" class="externalLink">SpotBugs Manual.</a>. | ||
* | ||
* @since 4.7 | ||
*/ | ||
@Mojo( name = "verify", defaultPhase = LifecyclePhase.VERIFY, requiresDependencyResolution = ResolutionScope.TEST, requiresProject = true, threadSafe = true) | ||
class VerifyMojo extends BaseViolationCheckMojo { | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure about the naming, though, might be confusing to some
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@crizzis I'm ok with changes overall but need a couple things that I think will help. First, bump since to 4.7 and we will target 4.7. Second, can you use more description from original #114 to highlight why this exists. That I think will help others to understand as looking simply at the source was confusing to me as the purpose. After reading the original issue and looking at the integration tests did I put it together so I think that will be usefule here to help put that together.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done and done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thank you, merging.