Skip to content
This repository has been archived by the owner on Feb 11, 2022. It is now read-only.

findbugs up-to-date checks #148

Merged
merged 1 commit into from
Nov 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@ package com.novoda.staticanalysis.internal
import com.novoda.staticanalysis.Violations
import org.gradle.api.DefaultTask
import org.gradle.api.tasks.InputFile
import org.gradle.api.tasks.PathSensitive
import org.gradle.api.tasks.TaskAction

import static org.gradle.api.tasks.PathSensitivity.RELATIVE

abstract class CollectViolationsTask extends DefaultTask {

@InputFile
@PathSensitive(RELATIVE)
private File xmlReportFile
private File htmlReportFile
private Violations violations
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,30 @@
package com.novoda.staticanalysis.internal.findbugs

import org.gradle.api.tasks.InputFile
import org.gradle.api.tasks.JavaExec
import org.gradle.api.tasks.OutputFile
import org.gradle.api.tasks.PathSensitive

import static org.gradle.api.tasks.PathSensitivity.RELATIVE

class GenerateFindBugsHtmlReport extends JavaExec {

@InputFile
@PathSensitive(RELATIVE)
File xmlReportFile
@OutputFile
@PathSensitive(RELATIVE)
File htmlReportFile

GenerateFindBugsHtmlReport() {
onlyIf { xmlReportFile?.exists() }
}

@Override
void exec() {
if (xmlReportFile?.exists()) {
main = 'edu.umd.cs.findbugs.PrintingBugReporter'
standardOutput = new FileOutputStream(htmlReportFile)
args '-html', xmlReportFile
super.exec()
}
main = 'edu.umd.cs.findbugs.PrintingBugReporter'
standardOutput = new FileOutputStream(htmlReportFile)
args '-html', xmlReportFile
super.exec()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import static com.novoda.test.TestProjectSubject.assumeThat
class FindbugsIntegrationTest {

@Parameterized.Parameters(name = "{0}")
public static Iterable<TestProjectRule> rules() {
static Iterable<TestProjectRule> rules() {
return [TestProjectRule.forJavaProject(), TestProjectRule.forAndroidProject()]
}

Expand All @@ -29,7 +29,7 @@ class FindbugsIntegrationTest {
}

@Test
public void shouldFailBuildWhenFindbugsWarningsOverTheThreshold() {
void shouldFailBuildWhenFindbugsWarningsOverTheThreshold() {
TestProject.Result result = projectRule.newProject()
.withSourceSet('debug', SOURCES_WITH_LOW_VIOLATION, SOURCES_WITH_MEDIUM_VIOLATION)
.withPenalty('''{
Expand All @@ -45,7 +45,7 @@ class FindbugsIntegrationTest {
}

@Test
public void shouldFailBuildAfterSecondRunWhenFindbugsWarningsStillOverTheThreshold() {
void shouldFailBuildAfterSecondRunWhenFindbugsWarningsStillOverTheThreshold() {
def project = projectRule.newProject()
.withSourceSet('debug', SOURCES_WITH_LOW_VIOLATION, SOURCES_WITH_MEDIUM_VIOLATION)
.withPenalty('''{
Expand All @@ -68,7 +68,7 @@ class FindbugsIntegrationTest {
}

@Test
public void shouldDetectMoreWarningsWhenEffortIsMaxAndReportLevelIsLow() {
void shouldDetectMoreWarningsWhenEffortIsMaxAndReportLevelIsLow() {
TestProject.Result result = projectRule.newProject()
.withSourceSet('debug', SOURCES_WITH_LOW_VIOLATION, SOURCES_WITH_MEDIUM_VIOLATION)
.withPenalty('''{
Expand All @@ -84,7 +84,7 @@ class FindbugsIntegrationTest {
}

@Test
public void shouldFailBuildWhenFindbugsErrorsOverTheThreshold() {
void shouldFailBuildWhenFindbugsErrorsOverTheThreshold() {
TestProject.Result result = projectRule.newProject()
.withSourceSet('debug', SOURCES_WITH_HIGH_VIOLATION)
.withPenalty('''{
Expand All @@ -100,7 +100,7 @@ class FindbugsIntegrationTest {
}

@Test
public void shouldNotFailBuildWhenNoFindbugsWarningsOrErrorsEncounteredAndNoThresholdTrespassed() {
void shouldNotFailBuildWhenNoFindbugsWarningsOrErrorsEncounteredAndNoThresholdTrespassed() {
TestProject.Result result = projectRule.newProject()
.withPenalty('''{
maxErrors = 0
Expand All @@ -114,7 +114,7 @@ class FindbugsIntegrationTest {
}

@Test
public void shouldNotFailBuildWhenFindbugsWarningsAndErrorsEncounteredAndNoThresholdTrespassed() {
void shouldNotFailBuildWhenFindbugsWarningsAndErrorsEncounteredAndNoThresholdTrespassed() {
TestProject.Result result = projectRule.newProject()
.withSourceSet('debug', SOURCES_WITH_LOW_VIOLATION, SOURCES_WITH_MEDIUM_VIOLATION)
.withSourceSet('release', SOURCES_WITH_HIGH_VIOLATION)
Expand All @@ -132,7 +132,7 @@ class FindbugsIntegrationTest {
}

@Test
public void shouldNotFailBuildWhenFindbugsConfiguredToNotIgnoreFailures() {
void shouldNotFailBuildWhenFindbugsConfiguredToNotIgnoreFailures() {
projectRule.newProject()
.withSourceSet('debug', SOURCES_WITH_LOW_VIOLATION, SOURCES_WITH_MEDIUM_VIOLATION)
.withSourceSet('release', SOURCES_WITH_HIGH_VIOLATION)
Expand All @@ -145,7 +145,7 @@ class FindbugsIntegrationTest {
}

@Test
public void shouldNotFailBuildWhenFindbugsNotConfigured() {
void shouldNotFailBuildWhenFindbugsNotConfigured() {
projectRule.newProject()
.withSourceSet('debug', SOURCES_WITH_LOW_VIOLATION, SOURCES_WITH_MEDIUM_VIOLATION)
.withSourceSet('release', SOURCES_WITH_HIGH_VIOLATION)
Expand All @@ -157,7 +157,7 @@ class FindbugsIntegrationTest {
}

@Test
public void shouldNotFailBuildWhenFindbugsConfiguredToExcludePattern() {
void shouldNotFailBuildWhenFindbugsConfiguredToExcludePattern() {
TestProject.Result result = projectRule.newProject()
.withSourceSet('debug', SOURCES_WITH_LOW_VIOLATION)
.withSourceSet('release', SOURCES_WITH_HIGH_VIOLATION, SOURCES_WITH_MEDIUM_VIOLATION)
Expand All @@ -174,7 +174,7 @@ class FindbugsIntegrationTest {
}

@Test
public void shouldNotFailBuildWhenFindbugsConfiguredToIgnoreFaultySourceFolder() {
void shouldNotFailBuildWhenFindbugsConfiguredToIgnoreFaultySourceFolder() {
TestProject.Result result = projectRule.newProject()
.withSourceSet('debug', SOURCES_WITH_LOW_VIOLATION, SOURCES_WITH_MEDIUM_VIOLATION)
.withSourceSet('release', SOURCES_WITH_HIGH_VIOLATION)
Expand All @@ -190,7 +190,8 @@ class FindbugsIntegrationTest {
result.buildFileUrl('reports/findbugs/debug.html'))
}

public void shouldNotFailBuildWhenFindbugsConfiguredToIgnoreFaultyJavaSourceSets() {
@Test
void shouldNotFailBuildWhenFindbugsConfiguredToIgnoreFaultyJavaSourceSets() {
TestProject project = projectRule.newProject()
assumeThat(project).isJavaProject()

Expand All @@ -210,7 +211,7 @@ class FindbugsIntegrationTest {
}

@Test
public void shouldNotFailBuildWhenFindbugsConfiguredToIgnoreFaultyAndroidSourceSets() {
void shouldNotFailBuildWhenFindbugsConfiguredToIgnoreFaultyAndroidSourceSets() {
TestProject project = projectRule.newProject()
assumeThat(project).isAndroidProject()

Expand All @@ -234,7 +235,7 @@ class FindbugsIntegrationTest {
}

@Test
public void shouldCollectDuplicatedFindbugsWarningsAndErrorsAcrossAndroidVariantsForSharedSourceSets() {
void shouldCollectDuplicatedFindbugsWarningsAndErrorsAcrossAndroidVariantsForSharedSourceSets() {
TestProject project = projectRule.newProject()
assumeThat(project).isAndroidProject()

Expand All @@ -254,7 +255,7 @@ class FindbugsIntegrationTest {
}

@Test
public void shouldSkipFindbugsTasksForIgnoredFaultyJavaSourceSets() {
void shouldSkipFindbugsTasksForIgnoredFaultyJavaSourceSets() {
TestProject project = projectRule.newProject()
assumeThat(project).isJavaProject()

Expand All @@ -275,7 +276,7 @@ class FindbugsIntegrationTest {
}

@Test
public void shouldSkipFindbugsTasksForIgnoredFaultyAndroidSourceSets() {
void shouldSkipFindbugsTasksForIgnoredFaultyAndroidSourceSets() {
TestProject project = projectRule.newProject()
assumeThat(project).isAndroidProject()

Expand Down Expand Up @@ -304,7 +305,7 @@ class FindbugsIntegrationTest {
}

@Test
public void shouldProvideNoClassesToFindbugsTaskWhenNoJavaSourcesToAnalyse() {
void shouldProvideNoClassesToFindbugsTaskWhenNoJavaSourcesToAnalyse() {
TestProject project = projectRule.newProject()
assumeThat(project).isJavaProject()

Expand All @@ -323,7 +324,7 @@ class FindbugsIntegrationTest {
}

@Test
public void shouldProvideNoClassesToFindbugsTaskWhenNoAndroidSourcesToAnalyse() {
void shouldProvideNoClassesToFindbugsTaskWhenNoAndroidSourcesToAnalyse() {
TestProject project = projectRule.newProject()
assumeThat(project).isAndroidProject()

Expand Down Expand Up @@ -359,6 +360,25 @@ class FindbugsIntegrationTest {
.build('check')
}

@Test
void shouldBeUpToDateWhenCheckTaskRunsAgain() {
def project = projectRule.newProject()
.withSourceSet('debug', SOURCES_WITH_LOW_VIOLATION, SOURCES_WITH_MEDIUM_VIOLATION)
.withSourceSet('release', SOURCES_WITH_HIGH_VIOLATION)
.withPenalty('''{
maxErrors = 10
maxWarnings = 10
}''')
.withToolsConfig('findbugs {}')

project.build('check')

def result = project.build('check')

Truth.assertThat(result.outcome(':findbugsDebug')).isEqualTo(TaskOutcome.UP_TO_DATE)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯

Truth.assertThat(result.outcome(':generateFindbugsDebugHtmlReport')).isEqualTo(TaskOutcome.UP_TO_DATE)
}

/**
* The custom task created in the snippet below will check whether {@code Findbugs} tasks with
* empty {@code source} will have empty {@code classes} too. </p>
Expand Down