-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Expand file tree
/
Copy pathinit-ci.gradle
More file actions
111 lines (79 loc) · 3.01 KB
/
Copy pathinit-ci.gradle
File metadata and controls
111 lines (79 loc) · 3.01 KB
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
import groovy.xml.XmlUtil
import java.util.concurrent.atomic.DoubleAdder
File testResultsDir = null
gradle.buildFinished {
gradle.rootProject.allprojects.each {
Project project ->
if (!project.ext.has("targetTaskName") || project.ext.has("reportWritten")) {
return
}
project.ext.reportWritten = true
_writeReport(
0.0d, "${project.path}:${project.ext.targetTaskName} was not executed. Please check the logs for details.", "", project.path, testResultsDir)
}
}
gradle.taskGraph.addTaskExecutionListener(
new TaskExecutionListener() {
void afterExecute(Task task, TaskState taskState) {
Project project = task.project
if (!project.ext.has("targetTaskName")) {
return
}
if (task.ext.has("startTime")) {
project.ext.compileDurationAdder.add((System.currentTimeMillis() - task.ext.startTime) / 1000.0d)
}
Throwable failure = taskState.failure
if ((task.name != project.ext.targetTaskName) && (failure == null)) {
return
}
double duration = project.ext.compileDurationAdder.sum()
project.ext.reportWritten = true
if (failure == null) {
_writeReport(duration, null, null, project.path, testResultsDir)
}
else {
StringWriter stringWriter = new StringWriter()
failure.printStackTrace(new PrintWriter(stringWriter))
_writeReport(duration, "${task.path} failed. Please check the logs for details.", stringWriter.toString(), project.path, testResultsDir)
}
}
void beforeExecute(Task task) {
if (task.project.ext.has("targetTaskName")) {
task.ext.startTime = System.currentTimeMillis()
}
}
})
gradle.taskGraph.whenReady {
TaskExecutionGraph taskGraph ->
taskGraph.allTasks.each {
Task task ->
if (!(task.name in ["assemble", "compileTestIntegrationJava"])) {
return
}
if (testResultsDir == null) {
testResultsDir = new File(gradle.rootProject.rootDir, "test-results")
testResultsDir.mkdirs()
}
Project project = task.project
project.ext.compileDurationAdder = new DoubleAdder()
project.ext.targetTaskName = task.name
}
}
private void _writeReport(
double duration, String failureMessage, String failureStacktrace, String projectPath, File testResultsDir) {
String className = "modules" + projectPath.replace(":", ".")
Date date = new Date()
int failureCount = (failureMessage == null) ? 0 : 1
String failureElementString = ""
if (failureMessage != null) {
failureElementString = "<failure message=\"${XmlUtil.escapeXml(failureMessage)}\">${XmlUtil.escapeXml(failureStacktrace ?: "")}</failure>"
}
File file = new File(testResultsDir, "TEST-${className}.xml")
file.text = """<?xml version="1.0" encoding="UTF-8"?>
<testsuite errors="${failureCount}" failures="${failureCount}" hostname="localhost" name="${className}" skipped="0" tests="1" time="${duration}" timestamp="${date.format("yyyy-MM-dd_kk:mm:ss")}">
<properties />
<testcase classname="${className}" name="assemble" time="${duration}">$failureElementString</testcase>
<system-out></system-out>
<system-err></system-err>
</testsuite>"""
}