-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add spotbugs-annotations dependency automatically with compileOnly,
add new configuration quality.spotbugsAnnotations, enabled by default
- Loading branch information
Showing
5 changed files
with
113 additions
and
0 deletions.
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
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
70 changes: 70 additions & 0 deletions
70
...y/ru/vyarus/gradle/plugin/quality/tools/spotbugs/SpotbugsAnnotationsAppliedKitTest.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,70 @@ | ||
package ru.vyarus.gradle.plugin.quality.tools.spotbugs | ||
|
||
import org.gradle.testkit.runner.BuildResult | ||
import org.gradle.testkit.runner.TaskOutcome | ||
import ru.vyarus.gradle.plugin.quality.AbstractKitTest | ||
|
||
/** | ||
* @author Vyacheslav Rusakov | ||
* @since 01.02.2024 | ||
*/ | ||
class SpotbugsAnnotationsAppliedKitTest extends AbstractKitTest { | ||
|
||
def "Check spotbugs annotations applied"() { | ||
setup: | ||
build(""" | ||
plugins { | ||
id 'java' | ||
id 'ru.vyarus.quality' | ||
} | ||
quality { | ||
checkstyle false | ||
pmd false | ||
strict false | ||
} | ||
repositories { mavenCentral() } | ||
""") | ||
|
||
fileFromClasspath('src/main/java/sample/SBSuppressSample.java', '/ru/vyarus/gradle/plugin/quality/java/sample/SBSuppressSample.java') | ||
|
||
when: "run check task with java sources" | ||
BuildResult result = run('check') | ||
|
||
then: "all plugins detect violations" | ||
result.task(":check").outcome == TaskOutcome.SUCCESS | ||
result.output.contains('SpotBugs violations were found') | ||
result.output.contains('1 (0 / 1 / 0) SpotBugs violations were found in 1 files') | ||
!result.output.contains('NP_BOOLEAN_RETURN_NULL') | ||
result.output.contains('URF_UNREAD_FIELD') | ||
} | ||
|
||
def "Check spotbugs annotations not applied"() { | ||
setup: | ||
build(""" | ||
plugins { | ||
id 'java' | ||
id 'ru.vyarus.quality' | ||
} | ||
quality { | ||
checkstyle false | ||
pmd false | ||
strict false | ||
spotbugsAnnotations false | ||
} | ||
repositories { mavenCentral() } | ||
""") | ||
|
||
fileFromClasspath('src/main/java/sample/SBSuppressSample.java', '/ru/vyarus/gradle/plugin/quality/java/sample/SBSuppressSample.java') | ||
|
||
when: "run check task with java sources" | ||
BuildResult result = runFailed('compileJava') | ||
|
||
then: "all plugins detect violations" | ||
result.task(":compileJava").outcome == TaskOutcome.FAILED | ||
result.output.contains('src/main/java/sample/SBSuppressSample.java:8: error: cannot find symbol') | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/test/resources/ru/vyarus/gradle/plugin/quality/java/sample/SBSuppressSample.java
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,25 @@ | ||
package sample; | ||
|
||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; | ||
|
||
import java.util.ArrayDeque; | ||
import java.util.Deque; | ||
|
||
@SuppressFBWarnings("NP_BOOLEAN_RETURN_NULL") | ||
public class SBSuppressSample { | ||
|
||
private String sample; | ||
|
||
public SBSuppressSample(String sample) { | ||
this.sample = sample; | ||
} | ||
|
||
public static void main(String[] args) { | ||
final Deque res = new ArrayDeque(); | ||
System.out.println(res); | ||
} | ||
|
||
public Boolean someting() { | ||
return null; | ||
} | ||
} |