forked from Tencent/tinker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck.gradle
188 lines (167 loc) · 5.09 KB
/
check.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
if (project == rootProject) {
task('checkAll') {
group 'verification'
doFirst {
logger.lifecycle 'Run checkAll task'
}
outputs.upToDateWhen { false }
}
task('checkIncremental') {
group 'verification'
doFirst {
logger.lifecycle 'Run checkIncremental task'
}
outputs.upToDateWhen { false }
}
return
}
// ----------
// Changed Files
// ----------
def reportsDir = "${rootProject.buildDir}/reports/${project.name}"
def projectHeader = project.path.replaceAll(':', '/').substring(1)
logger.lifecycle "Analyze code of module '${project.path}':"
logger.lifecycle "Reading changed files..."
if (!project.ext.has('filesChanged')) {
project.ext.filesChanged = []
if ("jenkins" == System.env.BUILDER_MODEL) {
logger.lifecycle 'Check MR changed files'
def inputFile = 'changed_file_list.txt'
if (project.hasProperty('changed_files')) { inputFile = project.properties['changed_files'] }
def file = rootProject.file(inputFile)
if (file.exists()) {
file.eachLine {
if (it.startsWith(projectHeader)) project.ext.filesChanged << it
}
}
} else {
logger.lifecycle 'Check git-diff changed files'
String command = "git diff --name-only --diff-filter=ACMRTUXB ${projectHeader}"
String changeInfo = command.execute(null, rootProject.rootDir).text.trim()
if (changeInfo && !changeInfo.isEmpty()) {
project.ext.filesChanged = changeInfo.split("\n").toList()
}
}
}
if (filesChanged.size() == 0) {
logger.lifecycle "No files changed found, skip analyzing."
} else {
logger.lifecycle "Files changed found:"
filesChanged.each { project.logger.lifecycle it }
}
// ----------
// CheckStyle, :checkstyleAll, :checkstyleIncremental
// ----------
def checkStyleConfig = rootProject.file('checkstyle.xml')
if (checkStyleConfig.exists()) {
if (!project.plugins.hasPlugin('checkstyle')) {
apply plugin: 'checkstyle'
}
checkstyle {
configFile checkStyleConfig
configProperties.checkstyleSuppressionsPath = rootProject.file("suppressions.xml").absolutePath
toolVersion '8.19'
ignoreFailures true
showViolations true
}
task('checkstyleAll', type: Checkstyle) {
group 'verification'
classpath = files()
source 'src/main'
include '**/*.java'
exclude '**/gen/**'
reports {
html { enabled = false }
xml {
enabled = true
destination file("$reportsDir/checkstyle.xml")
}
}
outputs.upToDateWhen { false }
}
if (filesChanged.size > 0) {
def task = task('checkstyleIncremental', type: Checkstyle) {
group 'verification'
classpath = files()
source 'src'
exclude '**/gen/**'
exclude '**/test/**'
exclude '**/*.gradle'
exclude '**/proto/*.java'
exclude '**/protobuf/*.java'
exclude '**/com/google/**/*.java'
for (String item: filesChanged) {
if (item.contains('src/')) {
include "**/${item.substring(item.lastIndexOf('src/') + 'src/'.length())}"
}
}
reports {
html { enabled = false }
xml {
enabled = true
destination file("$reportsDir/checkstyle.xml")
}
}
outputs.upToDateWhen { false }
}
}
project.afterEvaluate {
tasks.findByName('checkstyleAll')?.with { rootProject.tasks.findByName('checkAll')?.finalizedBy(it) }
tasks.findByName('checkstyleIncremental')?.with { rootProject.tasks.findByName('checkIncremental')?.finalizedBy(it) }
}
} else {
logger.lifecycle "Can not find CheckStyle config file, skip."
}
//apply plugin: 'pmd'
//
//pmd {
// toolVersion '5.4.0'
//}
//
//task pmd(type: Pmd) {
// targetJdk = TargetJdk.VERSION_1_7
//
// description 'Run pmd'
// group 'verification'
//
// // If ruleSets is not empty, it seems to contain some
// // defaults which override rules in the ruleset file...
// ruleSets = []
// ruleSetFiles = rootProject.files('pmd-ruleset.xml')
// source = fileTree('src/main/java')
// ignoreFailures = false
//
// reports {
// xml.enabled = false
// html.enabled = true
// }
//}
//
//check.dependsOn('pmd')
//apply plugin: 'findbugs'
//
//def classTree = 'build/intermediates/classes/debug'
//
//if (project.plugins.hasPlugin('java')) {
// classTree = 'build/classes'
//}
//task findbugs(type: FindBugs) {
//
// description 'Run findbugs'
// group 'verification'
//
// classes = fileTree(classTree)
// source = fileTree('src/main/java/')
// classpath = files()
//
// effort = 'default'
//
// excludeFilter = rootProject.file("findbugs-exclude.xml")
//
// reports {
// xml.enabled = false
// html.enabled = true
// }
// ignoreFailures = true
//}
//check.dependsOn('findbugs')