forked from UNN-ITMM-Software/agile-course-practice-2019
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle
201 lines (172 loc) · 6.62 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
190
191
192
193
194
195
196
197
198
199
200
201
buildscript {
repositories {
mavenCentral()
}
}
plugins {
id "de.aaschmid.cpd" version "2.0"
id 'jacoco'
id 'com.github.kt3k.coveralls' version '2.8.4'
}
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.8.1'
// }
cpd {
language = 'java'
// toolVersion = '5.8.1'
encoding = 'UTF-8'
}
tasks.cpdCheck {
minimumTokenCount = 50
ignoreFailures = true
def reportName = temporaryDir.getAbsolutePath() + '/cpd.xml'
reports {
xml.enabled = true
xml.destination = file(reportName)
}
doFirst {
def root = allprojects.toArray()[0]
def fileTree = fileTree(root.getProjectDir())
fileTree.include "**/*.java"
source = fileTree.filter{ !it.path.contains('korniakov-kirill') }
// println "source: " + source.getFiles()
}
doLast {
println '*****************************************************'
println '**************** Copy/Paste Analysis ****************'
println '*****************************************************'
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 {
maven {
url 'https://jitpack.io'
mavenCentral()
}
}
dependencies {
testCompile 'junit:junit:4.11'
testCompile "org.mockito:mockito-core:1.+"
testCompile 'com.github.OleasterFramework.Oleaster:oleaster-runner:v0.3.4'
testCompile 'com.github.OleasterFramework.Oleaster:oleaster-matcher:v0.3.4'
compile group: 'com.fasterxml.jackson.core', name: 'jackson-core', version: '2.4.1'
compile group: 'com.fasterxml.jackson.core', name: 'jackson-annotations', version: '2.4.1'
compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.4.1'
}
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() + "/config/checkstyle/", "main.xml")
checkstyleTest.configFile = new File(rootDir.getAbsolutePath() + "/config/checkstyle/", "test.xml")
}
// pmd {
// pmdMain.ruleSetFiles = files(rootDir.getAbsolutePath() + "/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()
}
// KK 2019-10-13: don't understand the meaning of this case
// } else if (task.name == 'jacocoTestReport'
// && state.getExecuted() && state.getSkipped()
// && task.getProject().getName() != 'agile-course-practice') {
// println '[**************** \\(°□°)/ ****************]'
// throw new RuntimeException("jacocoTestReport: Cannot proceed w/o test report!")
} else if (task.name == 'jacocoRootReport' && state.failure) {
println '[**************** \\(°□°)/ ****************]'
throw new RuntimeException("jacocoRootReport: state = failure. 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
saveAsFile = true
sendToCoveralls = false
}
task jacocoRootReport(type: org.gradle.testing.jacoco.tasks.JacocoReport) {
dependsOn = subprojects.test
getSourceDirectories().from(files(subprojects.sourceSets.main.allSource.srcDirs))
getClassDirectories().from(files(subprojects.sourceSets.main.output))
getExecutionData().from(files(subprojects.jacocoTestReport.executionData))
reports {
html.enabled = true
xml.enabled = true
csv.enabled = false
xml.destination = file("${buildDir}/reports/jacoco/test/jacocoTestReport.xml")
}
afterEvaluate {
getClassDirectories().from(files(classDirectories.files.collect {
fileTree(dir: it, exclude: ['ru/unn/agile/*/view/*'])
}))
}
}