forked from gitter-badger/agile-course-practice
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
189 lines (162 loc) · 5.98 KB
/
build.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
189
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'de.aaschmid.gradle.plugins:gradle-cpd-plugin:0.5'
classpath 'org.kt3k.gradle.plugin:coveralls-gradle-plugin:2.7.1'
}
}
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'cpd'
apply plugin: 'com.github.kt3k.coveralls'
allprojects {
apply plugin: 'jacoco'
}
repositories {
mavenCentral()
}
dependencies {
compile 'net.sourceforge.pmd:pmd:5.3.0'
}
cpd {
language = 'java'
toolVersion = '5.3.0'
encoding = 'UTF-8'
}
tasks.cpdCheck {
minimumTokenCount = 50
ignoreFailures = true
def reportName = temporaryDir.getAbsolutePath() + '/cpd.xml'
reports {
xml.enabled = true
xml.destination = reportName
}
doFirst {
println '*****************************************************'
println '**************** Copy/paste analysis ****************'
println '*****************************************************'
def root = allprojects.toArray()[0]
def fileTree = fileTree(root.getProjectDir())
fileTree.include "**/*.java"
source = fileTree.filter{ !it.path.contains('kornyakov-kirill') }
//println "source: " + source.getFiles()
}
doLast {
def copyPasted = new XmlParser().parse(reportName)
def rate = copyPasted.duplication.size()
println '*****************************************************'
println ' Copy/paste rate: ' + rate + ' times'
println '*****************************************************'
copyPasted.duplication.each {
d -> println '[**************** Found in: ****************]'
d.file.each {
f -> println f.'@path' + ':' + f.'@line'
}
println d.codefragment.text()
}
if (rate == 0) {
println '*****************************************************'
println ' Well done, no copy-paste detected! '
println '*****************************************************'
} else {
println '*****************************************************'
println ' FAIL: copy-paste detected! '
println ' Report: ' + reportName
println '*****************************************************'
throw new RuntimeException("Cannot proceed with non zero copy-paste rate!")
}
}
}
subprojects {
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'checkstyle'
apply plugin: 'pmd'
repositories {
mavenCentral()
}
dependencies {
testCompile 'junit:junit:4.11'
}
tasks.withType(JavaCompile) {
options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation"
options.compilerArgs << "-Werror"
}
test {
setMaxParallelForks Runtime.runtime.availableProcessors()
afterTest { desc, result ->
String suiteName = desc.className.substring(desc.className.lastIndexOf('.') + 1)
println "[${suiteName}]: ${result.resultType} in ${desc.name}"
}
}
checkstyle {
toolVersion = '7.2'
checkstyleMain.configFile = new File(rootDir.getAbsolutePath() + "/code/config/checkstyle/", "main.xml")
checkstyleTest.configFile = new File(rootDir.getAbsolutePath() + "/code/config/checkstyle/", "test.xml")
}
pmd {
pmdMain.ruleSetFiles = files(rootDir.getAbsolutePath() + "/code/config/pmd/rules.xml")
pmdTest.ruleSets = [ "java-basic", "java-braces" ]
}
gradle.taskGraph.beforeTask { Task task ->
if (task.name == 'jfxDeploy') {
task.enabled = false
}
}
gradle.taskGraph.afterTask { Task task, TaskState state ->
if ((task.name == 'pmdMain' || task.name == 'pmdTest') && state.failure) {
def outFile = task.name == 'pmdMain' ? 'main.xml' : 'test.xml'
def reportFile = file("${buildDir}/reports/pmd/${outFile}")
if (reportFile.exists()) {
def result = new XmlParser().parse(reportFile)
result.file.each { file ->
file.violation.each { violation ->
println "${file.'@name'}:${violation.'@beginline'}: ${violation.text()}"
}
}
reportFile.delete()
}
} else if (task.name == 'jacocoTestReport'
&& state.getExecuted() && state.getSkipped()
&& task.getProject().getName() != 'agile-course-practice') {
println '[**************** \\(°□°)/ ****************]'
throw new RuntimeException("Cannot proceed w/o test report!")
} else if (task.name == 'jacocoRootReport' && state.failure) {
println '[**************** \\(°□°)/ ****************]'
throw new RuntimeException("Cannot proceed w/o test report!")
}
}
jacocoTestReport {
reports {
html.enabled = true
xml.enabled = true
csv.enabled = false
}
}
}
coveralls {
sourceDirs = files(subprojects.sourceSets.main.allSource.srcDirs).files.absolutePath
}
task jacocoRootReport(type: org.gradle.testing.jacoco.tasks.JacocoReport) {
dependsOn = subprojects.test
sourceDirectories = files(subprojects.sourceSets.main.allSource.srcDirs)
classDirectories = files(subprojects.sourceSets.main.output)
executionData = files(subprojects.jacocoTestReport.executionData)
reports {
html.enabled = true
xml.enabled = true
csv.enabled = false
xml.destination = "${buildDir}/reports/jacoco/test/jacocoTestReport.xml"
}
afterEvaluate {
classDirectories = files(classDirectories.files.collect {
fileTree(dir: it, exclude: [
'ru/unn/agile/*/view/*'
]
)
})
}
}