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

Commit

Permalink
Merge pull request #144 from novoda/taso/fix/detekt-rc10
Browse files Browse the repository at this point in the history
Fix detekt rc10 integration
  • Loading branch information
mr-archano authored Nov 8, 2018
2 parents d7ef84d + 7d3d1dd commit 03cd383
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 37 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.novoda.staticanalysis.internal.detekt
import com.novoda.staticanalysis.StaticAnalysisExtension
import com.novoda.staticanalysis.Violations
import com.novoda.staticanalysis.internal.Configurator
import com.novoda.staticanalysis.internal.checkstyle.CollectCheckstyleViolationsTask
import org.gradle.api.GradleException
import org.gradle.api.NamedDomainObjectContainer
import org.gradle.api.Project
Expand All @@ -11,15 +12,17 @@ import org.gradle.api.Task
class DetektConfigurator implements Configurator {

private static final String DETEKT_PLUGIN = 'io.gitlab.arturbosch.detekt'
private static final String LAST_COMPATIBLE_DETEKT_VERSION = '1.0.0.RC9.2'
private static final String LAST_COMPATIBLE_DETEKT_VERSION = '1.0.0-RC10'
private static final String DETEKT_NOT_APPLIED = 'The Detekt plugin is configured but not applied. Please apply the plugin in your build script.\nFor more information see https://github.com/arturbosch/detekt.'
private static final String OUTPUT_NOT_DEFINED = 'Output not defined! To analyze the results, `output` needs to be defined in Detekt profile.'
private static final String DETEKT_CONFIGURATION_ERROR = "A problem occurred while configuring Detekt. Please make sure to use a compatible version (All versions up to $LAST_COMPATIBLE_DETEKT_VERSION)"
private static final String XML_REPORT_NOT_ENABLED = 'XML report must be enabled. Please make sure to enable "reports.xml" in your Detekt configuration'

private final Project project
private final Violations violations
private final Task evaluateViolations


static DetektConfigurator create(Project project,
NamedDomainObjectContainer<Violations> violationsContainer,
Task evaluateViolations) {
Expand All @@ -45,18 +48,31 @@ class DetektConfigurator implements Configurator {
}

def detekt = project.extensions.findByName('detekt')
setDefaultXmlReport(detekt)
config.delegate = detekt
config()

def collectViolations = configureToolTask(detekt)
evaluateViolations.dependsOn collectViolations
}
}

private CollectDetektViolationsTask configureToolTask(detekt) {

private void setDefaultXmlReport(detekt) {
if (detekt.hasProperty('reports')) {
detekt.reports {
xml.enabled = true
xml.destination = new File(project.buildDir, 'reports/detekt/detekt.xml')
}
}
}

private CollectCheckstyleViolationsTask configureToolTask(detekt) {
def detektTask = project.tasks.findByName('detekt')
if (detektTask?.hasProperty('reports')) {
def reports = detektTask.reports
if (!reports.xml.enabled) {
throw new IllegalStateException(XML_REPORT_NOT_ENABLED)
}
return createCollectViolationsTask(
violations,
detektTask,
Expand Down Expand Up @@ -89,8 +105,8 @@ class DetektConfigurator implements Configurator {
}
}

private CollectDetektViolationsTask createCollectViolationsTask(Violations violations, detektTask, File xmlReportFile, File htmlReportFile) {
project.tasks.create('collectDetektViolations', CollectDetektViolationsTask) { task ->
private CollectCheckstyleViolationsTask createCollectViolationsTask(Violations violations, detektTask, File xmlReportFile, File htmlReportFile) {
project.tasks.create('collectDetektViolations', CollectCheckstyleViolationsTask) { task ->
task.xmlReportFile = xmlReportFile
task.htmlReportFile = htmlReportFile
task.violations = violations
Expand Down
18 changes: 3 additions & 15 deletions plugin/src/test/fixtures/rules/detekt/detekt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,10 @@ build:
comments: 1

processors:
active: true
exclude:
# - 'FunctionCountProcessor'
# - 'PropertyCountProcessor'
# - 'ClassCountProcessor'
# - 'PackageCountProcessor'
# - 'KtFileCountProcessor'
active: false

console-reports:
active: true
exclude:
# - 'ProjectStatisticsReport'
# - 'ComplexityReport'
# - 'NotificationReport'
# - 'FindingsReport'
# - 'BuildFailureReport'
active: false

output-reports:
active: true
Expand Down Expand Up @@ -364,4 +352,4 @@ style:
active: false
WildcardImport:
active: true
excludeImports: 'java.util.*,kotlinx.android.synthetic.*'
excludeImports: 'java.util.*,kotlinx.android.synthetic.*'
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.novoda.staticanalysis.internal.detekt


import com.novoda.test.Fixtures
import com.novoda.test.TestProject
import com.novoda.test.TestProjectRule
Expand All @@ -14,12 +15,16 @@ import static com.novoda.test.LogsSubject.assertThat
class DetektNewIntegrationTest {

private static final String DETEKT_NOT_APPLIED = 'The Detekt plugin is configured but not applied. Please apply the plugin in your build script.'
private static final String XML_REPORT_NOT_ENABLED = 'XML report must be enabled. Please make sure to enable "reports.xml" in your Detekt configuration'


@Parameterized.Parameters(name = "{0} with Detekt: {1}")
static Iterable rules() {
return [
[TestProjectRule.forKotlinProject(), "1.0.0.RC9.2"],
[TestProjectRule.forAndroidKotlinProject(), "1.0.0.RC9.2"],
[TestProjectRule.forKotlinProject(), "1.0.0-RC10"],
[TestProjectRule.forAndroidKotlinProject(), "1.0.0-RC10"],
]*.toArray()
}

Expand All @@ -41,6 +46,20 @@ class DetektNewIntegrationTest {
assertThat(result.logs).contains(DETEKT_NOT_APPLIED)
}

@Test
void shouldFailBuildOnConfigurationWhenDetektConfiguredWithoutXmlReport() {
def result = projectRule.newProject()
.withPlugin("io.gitlab.arturbosch.detekt", detektVersion)
.withToolsConfig('''detekt {
reports {
xml.enabled = false
}
}''')
.buildAndFail('check')

assertThat(result.logs).contains(XML_REPORT_NOT_ENABLED)
}

@Test
void shouldFailBuildWhenDetektWarningsOverTheThreshold() {
def result = createProjectWithZeroThreshold(Fixtures.Detekt.SOURCES_WITH_WARNINGS)
Expand Down

0 comments on commit 03cd383

Please sign in to comment.