-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathplugin-common.gradle
149 lines (125 loc) · 4.76 KB
/
plugin-common.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
/*
* Copyright 2017 ThoughtWorks, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
def gitRevision = { ->
def hashStdOut = new ByteArrayOutputStream()
exec {
commandLine "git", "log", "-n", "1", "--format=%H"
standardOutput = hashStdOut
}
return hashStdOut.toString().trim()
}
def releaseRevision = { ->
def hashStdOut = new ByteArrayOutputStream()
exec {
commandLine "git", "log", "--pretty=format:"
standardOutput = hashStdOut
}
return hashStdOut.size().toString()
}
project.ext.gitRevision = gitRevision()
project.ext.distVersion = releaseRevision()
sourceCompatibility = 1.8
targetCompatibility = 1.8
project.ext.color = [
ANSI_BOLD_WHITE: "\u001B[0;1m",
ANSI_RESET : "\u001B[0m",
ANSI_RED : "\u001B[31m",
ANSI_GREEN : "\u001B[32m",
ANSI_YELLOW : "\u001B[33m",
ANSI_WHITE : "\u001B[37m"
]
project.ext.symbols = [
CHECK_MARK : "\u2714",
NEUTRAL_FACE: "\u0CA0_\u0CA0",
X_MARK : "\u2718"
]
tasks.withType(JavaCompile) {
options.deprecation = true
options.encoding = 'utf-8'
options.warnings = true
options.compilerArgs << "-Xlint:all"
options.compilerArgs << "-Xlint:-serial"
}
tasks.withType(Test) {
maxParallelForks = 1
testLogging {
def previousFailed = false
exceptionFormat 'full'
beforeSuite { suite ->
if (suite.name.startsWith("Test Run") || suite.name.startsWith("Gradle Worker")) return
if (suite.parent != null && suite.className != null) {
println(project.color.ANSI_BOLD_WHITE + suite.name + project.color.ANSI_RESET)
}
}
beforeTest {
if (previousFailed) {
System.err.println("")
}
}
afterTest { descriptor, result ->
previousFailed = false
def executionTime = (result.endTime - result.startTime) / 1000
println(" ${resultIndicator(result)}$project.color.ANSI_RESET $descriptor.name $project.color.ANSI_YELLOW($executionTime seconds)$project.color.ANSI_RESET")
if (result.failedTestCount > 0) {
previousFailed = true
println('')
println(result.exception)
}
}
afterSuite { desc, result ->
if (desc.parent != null && desc.className != null) {
println("")
}
if (!desc.parent) { // will match the outermost suite
def failStyle = project.color.ANSI_RED
def skipStyle = project.color.ANSI_YELLOW
def summaryStyle = summaryStyle(result)
if (result.failedTestCount > 0) {
failStyle = project.color.ANSI_RED
}
if (result.skippedTestCount > 0) {
skipStyle = project.color.ANSI_YELLOW
}
println("--------------------------------------------------------------------------")
println("Results: $summaryStyle$result.resultType$project.color.ANSI_RESET ($result.testCount tests, $project.color.ANSI_GREEN$result.successfulTestCount passed$project.color.ANSI_RESET, $failStyle$result.failedTestCount failed$project.color.ANSI_RESET, $skipStyle$result.skippedTestCount skipped$project.color.ANSI_RESET)")
println("--------------------------------------------------------------------------")
}
}
}
}
private String summaryStyle(result) {
def summaryStyle = project.color.ANSI_WHITE
switch (result.resultType) {
case TestResult.ResultType.SUCCESS:
summaryStyle = project.color.ANSI_GREEN
break
case TestResult.ResultType.FAILURE:
summaryStyle = project.color.ANSI_RED
break
}
summaryStyle
}
private String resultIndicator(result) {
def indicator = project.color.ANSI_WHITE
if (result.failedTestCount > 0) {
indicator = project.color.ANSI_RED + project.symbols.X_MARK
} else if (result.skippedTestCount > 0) {
indicator = project.color.ANSI_YELLOW + project.symbols.NEUTRAL_FACE
} else {
indicator = project.color.ANSI_GREEN + project.symbols.CHECK_MARK
}
indicator
}