-
Notifications
You must be signed in to change notification settings - Fork 27
Fix detekt rc10 integration #144
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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) { | ||
|
@@ -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') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @tasomaniac does it mean we should warn users about this? is it possible that we read this value and then later the destination is amended lazily by Detekt? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So this means that we always set it by default. Detekt's lazy fallback will never be used. But that's fine because in case users but their |
||
} | ||
} | ||
} | ||
|
||
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, | ||
|
@@ -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 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,22 +29,10 @@ build: | |
comments: 1 | ||
|
||
processors: | ||
active: true | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed them since the test output will be cleaner without them. |
||
exclude: | ||
# - 'FunctionCountProcessor' | ||
# - 'PropertyCountProcessor' | ||
# - 'ClassCountProcessor' | ||
# - 'PackageCountProcessor' | ||
# - 'KtFileCountProcessor' | ||
active: false | ||
|
||
console-reports: | ||
active: true | ||
exclude: | ||
# - 'ProjectStatisticsReport' | ||
# - 'ComplexityReport' | ||
# - 'NotificationReport' | ||
# - 'FindingsReport' | ||
# - 'BuildFailureReport' | ||
active: false | ||
|
||
output-reports: | ||
active: true | ||
|
@@ -364,4 +352,4 @@ style: | |
active: false | ||
WildcardImport: | ||
active: true | ||
excludeImports: 'java.util.*,kotlinx.android.synthetic.*' | ||
excludeImports: 'java.util.*,kotlinx.android.synthetic.*' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does this mean "we support Detekt up to version X"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I keep updating this whenever I fix new problems :) To be honest, the problems so far were all very weird and were crashing earlier. It might be the case that this was never shown. 🤷
But anyways, it is nice to have.