-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathbuild.gradle
154 lines (132 loc) · 4.9 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
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'de.aaschmid.gradle.plugins:gradle-cpd-plugin:0.1'
classpath 'org.kt3k.gradle.plugin:coveralls-gradle-plugin:2.0.0'
}
}
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.1.0'
}
tasks.cpd {
doFirst {
println '[**************** Copy/paste analysis ****************]'
}
def reportName = 'cpd.xml'
reports {
xml.enabled = true
xml.destination = reportName
}
minimumTokenCount = 50
source files{ allprojects.findAll{ p -> p.hasProperty('sourceSets') }.collect { p -> p.sourceSets.collect { (it.java) } } }
.filter{ !it.path.contains('kornyakov-kirill') }
doLast {
def copyPasted = new XmlParser().parse(reportName)
def rate = copyPasted.duplication.size()
println 'Copy-paste rate: ' + rate + ' times'
copyPasted.duplication.each { d -> println '[**************** Found in: ****************]'
d.file.each { f -> println f.'@path' + ', started @' + f.'@line' + ' line' }
println d.codefragment.text() }
if (rate == 0) {
println '[**************** WELL DONE! ****************]'
println '[**************** ᕦ(ò‿ó)ᕤ ****************]'
} else {
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 {
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"
}
}