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

Multiple config support for tools #93

Merged
merged 3 commits into from
Feb 25, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ class CheckstyleConfigurator extends CodeQualityConfigurator<Checkstyle, Checkst
}

private CollectCheckstyleViolationsTask createCollectViolationsTask(Checkstyle checkstyle, Violations violations) {
project.tasks.create("collect${checkstyle.name.capitalize()}Violations", CollectCheckstyleViolationsTask) { collectViolations ->
Copy link
Contributor Author

Choose a reason for hiding this comment

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

😞 Old version looks much better but unfortunately the same thing is not available for maybeCreate
And with does not make it better since with returns the last statement, I still need to return task manually.

collectViolations.xmlReportFile = checkstyle.reports.xml.destination
collectViolations.violations = violations
}
def task = project.tasks.maybeCreate("collect${checkstyle.name.capitalize()}Violations", CollectCheckstyleViolationsTask)
task.xmlReportFile = checkstyle.reports.xml.destination
task.violations = violations
task
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,18 @@ class FindbugsConfigurator extends CodeQualityConfigurator<FindBugs, FindBugsExt

@Override
protected void configureAndroidVariant(variant) {
FindBugs task = project.tasks.create("findbugs${variant.name.capitalize()}", QuietFindbugsPlugin.Task)
FindBugs task = project.tasks.maybeCreate("findbugs${variant.name.capitalize()}", QuietFindbugsPlugin.Task)
List<File> androidSourceDirs = variant.sourceSets.collect { it.javaDirectories }.flatten()
task.with {
description = "Run FindBugs analysis for ${variant.name} classes"
source = androidSourceDirs
classpath = variant.javaCompile.classpath
}
sourceFilter.applyTo(task)
task.conventionMapping.map("classes", {
task.conventionMapping.map("classes") {
List<String> includes = createIncludePatterns(task.source, androidSourceDirs)
getAndroidClasses(variant, includes)
})
}
task.dependsOn variant.javaCompile
}

Expand Down Expand Up @@ -140,19 +140,19 @@ class FindbugsConfigurator extends CodeQualityConfigurator<FindBugs, FindBugsExt
}

private CollectFindbugsViolationsTask createViolationsCollectionTask(FindBugs findBugs, Violations violations) {
project.tasks.create("collect${findBugs.name.capitalize()}Violations", CollectFindbugsViolationsTask) { collectViolations ->
collectViolations.xmlReportFile = findBugs.reports.xml.destination
collectViolations.violations = violations
}
def task = project.tasks.maybeCreate("collect${findBugs.name.capitalize()}Violations", CollectFindbugsViolationsTask)
task.xmlReportFile = findBugs.reports.xml.destination
task.violations = violations
task
}

private GenerateFindBugsHtmlReport createHtmlReportTask(FindBugs findBugs, File xmlReportFile, File htmlReportFile) {
project.tasks.create("generate${findBugs.name.capitalize()}HtmlReport", GenerateFindBugsHtmlReport) { generateHtmlReport ->
generateHtmlReport.xmlReportFile = xmlReportFile
generateHtmlReport.htmlReportFile = htmlReportFile
generateHtmlReport.classpath = findBugs.findbugsClasspath
generateHtmlReport.onlyIf { xmlReportFile?.exists() }
}
def task = project.tasks.maybeCreate("generate${findBugs.name.capitalize()}HtmlReport", GenerateFindBugsHtmlReport)
task.xmlReportFile = xmlReportFile
task.htmlReportFile = htmlReportFile
task.classpath = findBugs.findbugsClasspath
task.onlyIf { xmlReportFile?.exists() }
task
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@ class PmdConfigurator extends CodeQualityConfigurator<Pmd, PmdExtension> {
}

private CollectPmdViolationsTask createViolationsCollectionTask(Pmd pmd, Violations violations) {
project.tasks.create("collect${pmd.name.capitalize()}Violations", CollectPmdViolationsTask) { collectViolations ->
collectViolations.xmlReportFile = pmd.reports.xml.destination
collectViolations.violations = violations
}
def task = project.tasks.maybeCreate("collect${pmd.name.capitalize()}Violations", CollectPmdViolationsTask)
task.xmlReportFile = pmd.reports.xml.destination
task.violations = violations
task
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,22 @@ public class CheckstyleIntegrationTest {
result.buildFileUrl('reports/checkstyle/main.html'))
}

@Test
void shouldNotFailBuildWhenCheckstyleIsConfiguredMultipleTimes() {
projectRule.newProject()
.withSourceSet('main', Fixtures.Checkstyle.SOURCES_WITH_WARNINGS)
.withPenalty('none')
.withToolsConfig("""
checkstyle {
configFile new File('${Fixtures.Checkstyle.MODULES.path}')
}
checkstyle {
ignoreFailures = false
}
""")
.build('check', '--dry-run')
}

private static String checkstyle(String configFile, String... configs) {
"""checkstyle {
${configFile}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,20 @@ class FindbugsIntegrationTest {
Truth.assertThat(result.outcome(':checkFindbugsClasses')).isEqualTo(TaskOutcome.SUCCESS)
}

@Test
void shouldNotFailBuildWhenFindbugsIsConfiguredMultipleTimes() {
projectRule.newProject()
.withSourceSet('main', SOURCES_WITH_LOW_VIOLATION)
.withPenalty('none')
.withToolsConfig("""
findbugs { }
findbugs {
ignoreFailures = false
}
""")
.build('check')
}

/**
* 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
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,22 @@ public class PmdIntegrationTest {
assertThat(result.logs).doesNotContainPmdViolations()
}

@Test
void shouldNotFailBuildWhenPmdIsConfiguredMultipleTimes() {
projectRule.newProject()
.withSourceSet('main', Fixtures.Pmd.SOURCES_WITH_PRIORITY_1_VIOLATION)
.withPenalty('none')
.withToolsConfig("""
pmd {
ruleSetFiles = $DEFAULT_RULES
}
pmd {
ignoreFailures = false
}
""")
.build('check')
}

private String pmd(String rules, String... configs) {
"""pmd {
ruleSetFiles = $rules
Expand Down