-
Notifications
You must be signed in to change notification settings - Fork 1
/
lint-summary.gradle
101 lines (77 loc) · 2.5 KB
/
lint-summary.gradle
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
90
91
92
93
94
95
96
97
98
99
100
101
/**
* To use this gradle script, apply it from the project you want to use it for,
* e.g.
*
* apply from: '../path/to/lint-summary.gradle'
*
* Invocations to any linting tasks will subsequently call to
* `android-lint-summary` and display the output of it at the end of the full
* build.
*/
task hasLintSummaryExecutable(type: Exec) {
commandLine "which", "android-lint-summary"
ignoreExitValue true
ext.hasExecutable = {
execResult?.getExitValue() == 0
}
}
task lintSummary(type: LintSummaryTask, dependsOn: hasLintSummaryExecutable) {
description "Print a summary of your lint issues"
group JavaBasePlugin.VERIFICATION_GROUP
outputs.upToDateWhen { false }
onlyIf { gradle.startParameter.colorOutput && hasLintSummaryExecutable.hasExecutable() }
}
afterEvaluate {
tasks.withType(tasks['lint'].class) {
finalizedBy lintSummary
}
gradle.addBuildListener lintSummary
}
class LintSummaryTask extends DefaultTask implements BuildListenerAdapter {
def stdout = new ByteArrayOutputStream()
@SuppressWarnings("GroovyUnusedDeclaration")
@TaskAction
public def action() {
def filePath = project.android.lintOptions.xmlOutput
if (filePath == null) {
// A best guess. There's a createOutputPath() in
// com.android.build.gradle.internal.dsl.LintOptions that's used to generate the full
// variant-specific output name, but I'd prefer to get the options object instead
// somehow.
filePath = [project.projectDir, "build", "outputs", "lint-results.xml"].join(File.separator)
}
project.exec {
commandLine "bash", "-c", "android-lint-summary", "-v", filePath
standardOutput = stdout
}
}
@Override
void buildFinished(BuildResult result) {
println stdout.toString()
if (state.skipped) {
println """
For prettier display of lint errors, install `android-lint-summary`.
echo "/home/phartig/tools/android-lint-summary" >> ~/.tools
sync-dottools.sh
Learn more at go/android-lint-summary.
""".stripMargin()
}
}
}
trait BuildListenerAdapter implements BuildListener {
@Override
void buildFinished(BuildResult result) {
}
@Override
void buildStarted(Gradle gradle) {
}
@Override
void projectsEvaluated(Gradle gradle) {
}
@Override
void projectsLoaded(Gradle gradle) {
}
@Override
void settingsEvaluated(Settings settings) {
}
}