@@ -19,7 +19,7 @@ import java.security.MessageDigest
19
19
// Logger which captures standard output or error streams to a buffer.
20
20
class StandardOutputErrorLogger implements StandardOutputListener {
21
21
// List of lines captured by this logger.
22
- private def outputList = []
22
+ private List< String > outputList = []
23
23
24
24
// Implements StandardOutputListener to capture a log message in
25
25
// outputList.
@@ -34,15 +34,15 @@ class StandardOutputErrorLogger implements StandardOutputListener {
34
34
35
35
// Install the logger on the standard output and error streams of a task and
36
36
// clear the internal buffer.
37
- def install (taskToLog ) {
37
+ void install (Task taskToLog ) {
38
38
outputList = []
39
39
taskToLog. logging. addStandardOutputListener(this )
40
40
taskToLog. logging. addStandardErrorListener(this )
41
41
}
42
42
43
43
// Remove the logger from the standard output and error streams of a task and
44
44
// clear the internal buffer.
45
- def uninstall (taskToLog ) {
45
+ void uninstall (Task taskToLog ) {
46
46
taskToLog. logging. removeStandardOutputListener(this )
47
47
taskToLog. logging. removeStandardErrorListener(this )
48
48
}
@@ -79,9 +79,6 @@ project.ext {
79
79
// Header in the download script's output that describes the set of artifacts
80
80
// that were modified from what the user requested.
81
81
modifiedArtifactsHeader = " Modified artifacts:"
82
-
83
- // Logger which captures the output of a task.
84
- standardOutputErrorLogger = new StandardOutputErrorLogger ()
85
82
}
86
83
87
84
// Generate a task to create the specified directory File.
@@ -162,7 +159,7 @@ def validateFilesMatch(taskToValidate, outputInputFileMap) {
162
159
taskToValidate, new Exception (
163
160
sprintf (" %s failed, unexpected output file(s)\n %s\n\n %s\n " ,
164
161
taskToValidate. name, mismatchingFiles. join(" \n " ),
165
- project . ext. standardOutputErrorLogger. output)))
162
+ taskToValidate . ext. standardOutputErrorLogger. output)))
166
163
}
167
164
}
168
165
@@ -177,7 +174,7 @@ def validateOutputFilesExist(taskToValidate) {
177
174
taskToValidate, new Exception (
178
175
sprintf (" %s failed, missing expected file(s)\n %s\n\n %s\n " ,
179
176
taskToValidate. name, missingFiles. join(" \n " ),
180
- project . ext. standardOutputErrorLogger. output)))
177
+ taskToValidate . ext. standardOutputErrorLogger. output)))
181
178
}
182
179
}
183
180
@@ -240,20 +237,25 @@ def createTestTask(taskName, taskDescription, packageSpecification,
240
237
type : GradleBuild ,
241
238
dependsOn : createDirectoryTask)
242
239
testTask. with {
240
+ // Logger which captures the output of a task.
241
+ // This doesn't work in parallel builds at the moment.
242
+ // https://github.com/gradle/gradle/issues/6068
243
+ ext. standardOutputErrorLogger = new StandardOutputErrorLogger ()
244
+
243
245
outputs. files movedOutputInputFileMap. keySet()
244
246
startParameter createStartParameters(packageSpecification,
245
247
targetDirFile)
246
248
buildFile project. ext. buildFile
247
249
dir project. ext. outputDir
248
- doFirst { project . ext. standardOutputErrorLogger. install(it) }
250
+ doFirst { ext. standardOutputErrorLogger. install(it) }
249
251
doLast {
250
- project . ext. standardOutputErrorLogger. uninstall(it)
252
+ ext. standardOutputErrorLogger. uninstall(it)
251
253
validateOutputFilesExist(it)
252
254
validateFilesMatch(it, movedOutputInputFileMap)
253
255
if (expectedScriptOutput != null ) {
254
- assert downloadScriptOutputToSectionsList(
255
- project . ext. standardOutputErrorLogger. output) ==
256
- expectedScriptOutput
256
+ List< String > parsedOutput = downloadScriptOutputToSectionsList(
257
+ ext. standardOutputErrorLogger. output)
258
+ assert parsedOutput == expectedScriptOutput
257
259
}
258
260
}
259
261
}
@@ -629,4 +631,18 @@ task testUnitTests(type: GradleBuild, dependsOn: copyTestScript) {
629
631
dir project. ext. outputDir
630
632
}
631
633
632
- project. defaultTasks = project. ext. testTaskNames
634
+ // Due to https://github.com/gradle/gradle/issues/6068 all test tasks
635
+ // must be run in serial at the moment so the following serializes all
636
+ // tasks.
637
+ // When the bug in Gradle is fixed the following code can be replaced with:
638
+ // project.defaultTasks = project.ext.testTaskNames
639
+ ext. testTaskNames. eachWithIndex { String taskName, int index ->
640
+ if (index == 0 ) return
641
+ project. getTasksByName(ext. testTaskNames[index - 1 ], false ). each {
642
+ Task previousTask ->
643
+ project. getTasksByName(taskName, false ). each { Task currentTask ->
644
+ previousTask. dependsOn(currentTask)
645
+ }
646
+ }
647
+ }
648
+ project. defaultTasks = [ext. testTaskNames[0 ]]
0 commit comments