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

Commit

Permalink
Make Findbugs Html report optional (#154)
Browse files Browse the repository at this point in the history
* Make html report optional for findbugs

* Put the feature in documentation

* Also use Closure on other configs

* Make the tests prettier

* Revert the changes to the test

* Update FindbugsIntegrationTest.groovy
  • Loading branch information
tasomaniac authored and mr-archano committed Dec 10, 2018
1 parent b0a478c commit fd4dee8
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 28 deletions.
1 change: 1 addition & 0 deletions docs/tools/findbugs.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ findbugs {
toolVersion // A string, most likely '3.0.1' — the latest Findbugs release (for a long time)
exclude // A fileTree, such as project.fileTree('src/test/java') to exclude Java unit tests
excludeFilter // A file containing the Findbugs exclusions, e.g., teamPropsFile('static-analysis/findbugs-excludes.xml')
htmlReportEnabled true // Control whether html report generation should be enabled. `true` by default.
includeVariants { variant -> ... } // A closure to determine which variants (for Android) to include
}
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,8 @@ abstract class CodeQualityConfigurator<T extends SourceTask, E extends CodeQuali
protected abstract Class<E> getExtensionClass()

protected Action<E> getDefaultConfiguration() {
new Action<E>() {
void execute(E ignored) {
// no op
}
return { ignored ->
// no op
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ package com.novoda.staticanalysis.internal.checkstyle
import com.novoda.staticanalysis.Violations
import com.novoda.staticanalysis.internal.CodeQualityConfigurator
import com.novoda.staticanalysis.internal.QuietLogger
import org.gradle.api.*
import org.gradle.api.Action
import org.gradle.api.NamedDomainObjectContainer
import org.gradle.api.Project
import org.gradle.api.Task
import org.gradle.api.plugins.quality.Checkstyle
import org.gradle.api.plugins.quality.CheckstyleExtension

Expand Down Expand Up @@ -34,11 +37,8 @@ class CheckstyleConfigurator extends CodeQualityConfigurator<Checkstyle, Checkst

@Override
protected Action<CheckstyleExtension> getDefaultConfiguration() {
new Action<CheckstyleExtension>() {
@Override
void execute(CheckstyleExtension checkstyleExtension) {
checkstyleExtension.toolVersion = '7.1.2'
}
return { extension ->
extension.toolVersion = '7.1.2'
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ package com.novoda.staticanalysis.internal.findbugs

import com.novoda.staticanalysis.Violations
import com.novoda.staticanalysis.internal.CodeQualityConfigurator
import org.gradle.api.*
import org.gradle.api.Action
import org.gradle.api.NamedDomainObjectContainer
import org.gradle.api.Project
import org.gradle.api.Task
import org.gradle.api.file.ConfigurableFileTree
import org.gradle.api.file.FileCollection
import org.gradle.api.plugins.quality.FindBugs
Expand All @@ -13,6 +16,8 @@ import java.nio.file.Path

class FindbugsConfigurator extends CodeQualityConfigurator<FindBugs, FindBugsExtension> {

protected boolean htmlReportEnabled = true

static FindbugsConfigurator create(Project project,
NamedDomainObjectContainer<Violations> violationsContainer,
Task evaluateViolations) {
Expand Down Expand Up @@ -48,11 +53,9 @@ class FindbugsConfigurator extends CodeQualityConfigurator<FindBugs, FindBugsExt

@Override
protected Action<FindBugsExtension> getDefaultConfiguration() {
new Action<FindBugsExtension>() {
@Override
void execute(FindBugsExtension findBugsExtension) {
findBugsExtension.toolVersion = '3.0.1'
}
return { extension ->
extension.ext.htmlReportEnabled = { boolean enabled -> this.htmlReportEnabled = enabled }
extension.toolVersion = '3.0.1'
}
}

Expand Down Expand Up @@ -134,11 +137,15 @@ class FindbugsConfigurator extends CodeQualityConfigurator<FindBugs, FindBugsExt
findBugs.reports.html.enabled = false

def collectViolations = createViolationsCollectionTask(findBugs, violations)
def generateHtmlReport = createHtmlReportTask(findBugs, collectViolations.xmlReportFile, collectViolations.htmlReportFile)

evaluateViolations.dependsOn collectViolations
collectViolations.dependsOn generateHtmlReport
generateHtmlReport.dependsOn findBugs

if (htmlReportEnabled) {
def generateHtmlReport = createHtmlReportTask(findBugs, collectViolations.xmlReportFile, collectViolations.htmlReportFile)
collectViolations.dependsOn generateHtmlReport
generateHtmlReport.dependsOn findBugs
} else {
collectViolations.dependsOn findBugs
}
}

private CollectFindbugsViolationsTask createViolationsCollectionTask(FindBugs findBugs, Violations violations) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,9 @@ class PmdConfigurator extends CodeQualityConfigurator<Pmd, PmdExtension> {

@Override
protected Action<PmdExtension> getDefaultConfiguration() {
new Action<PmdExtension>() {
@Override
void execute(PmdExtension pmdExtension) {
pmdExtension.toolVersion = '5.5.1'
pmdExtension.rulePriority = 5
}
return { extension ->
extension.toolVersion = '5.5.1'
extension.rulePriority = 5
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -351,11 +351,11 @@ class FindbugsIntegrationTest {
projectRule.newProject()
.withSourceSet('main', SOURCES_WITH_LOW_VIOLATION)
.withPenalty('none')
.withToolsConfig("""
.withToolsConfig("""
findbugs { }
findbugs {
ignoreFailures = false
}
}
""")
.build('check')
}
Expand All @@ -379,6 +379,18 @@ class FindbugsIntegrationTest {
Truth.assertThat(result.outcome(':generateFindbugsDebugHtmlReport')).isEqualTo(TaskOutcome.UP_TO_DATE)
}

@Test
void shouldNotGenerateHtmlWhenDisabled() {
def result = projectRule.newProject()
.withSourceSet('main', SOURCES_WITH_LOW_VIOLATION)
.withToolsConfig('''findbugs {
htmlReportEnabled false
}''')
.build('check')

Truth.assertThat(result.tasksPaths).doesNotContain(':generateFindbugsDebugHtmlReport')
}

/**
* 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

0 comments on commit fd4dee8

Please sign in to comment.