This repository has been archived by the owner on Feb 11, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 28
/
CheckstyleConfigurator.groovy
89 lines (76 loc) · 3.25 KB
/
CheckstyleConfigurator.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
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.plugins.quality.Checkstyle
import org.gradle.api.plugins.quality.CheckstyleExtension
class CheckstyleConfigurator extends CodeQualityConfigurator<Checkstyle, CheckstyleExtension> {
static CheckstyleConfigurator create(Project project,
NamedDomainObjectContainer<Violations> violationsContainer,
Task evaluateViolations) {
Violations violations = violationsContainer.maybeCreate('Checkstyle')
return new CheckstyleConfigurator(project, violations, evaluateViolations)
}
private CheckstyleConfigurator(Project project,
Violations violations,
Task evaluateViolations) {
super(project, violations, evaluateViolations)
}
@Override
protected String getToolName() {
'checkstyle'
}
@Override
protected Class<CheckstyleExtension> getExtensionClass() {
CheckstyleExtension
}
@Override
protected Action<CheckstyleExtension> getDefaultConfiguration() {
new Action<CheckstyleExtension>() {
@Override
void execute(CheckstyleExtension checkstyleExtension) {
checkstyleExtension.toolVersion = '7.1.2'
}
}
}
@Override
protected Class<Checkstyle> getTaskClass() {
Checkstyle
}
@Override
protected void configureAndroidVariant(variant) {
project.with {
variant.sourceSets.each { sourceSet ->
def taskName = "checkstyle${sourceSet.name.capitalize()}"
Checkstyle task = tasks.findByName(taskName)
if (task == null) {
task = tasks.create(taskName, Checkstyle)
task.with {
description = "Run Checkstyle analysis for ${sourceSet.name} classes"
source = sourceSet.java.srcDirs
classpath = files("$buildDir/intermediates/classes/")
exclude '**/*.kt'
}
}
sourceFilter.applyTo(task)
task.mustRunAfter variant.javaCompile
}
}
}
@Override
protected void configureReportEvaluation(Checkstyle checkstyle, Violations violations) {
checkstyle.showViolations = false
checkstyle.ignoreFailures = true
checkstyle.metaClass.getLogger = { QuietLogger.INSTANCE }
def collectViolations = createCollectViolationsTask(checkstyle, violations)
evaluateViolations.dependsOn collectViolations
collectViolations.dependsOn checkstyle
}
private CollectCheckstyleViolationsTask createCollectViolationsTask(Checkstyle checkstyle, Violations violations) {
def task = project.tasks.maybeCreate("collect${checkstyle.name.capitalize()}Violations", CollectCheckstyleViolationsTask)
task.xmlReportFile = checkstyle.reports.xml.destination
task.violations = violations
task
}
}