Skip to content

Commit 0998673

Browse files
author
Stewart Miles
committed
Worked around bug in Gradle 5.1.x
Gradle now runs task execution in parallel by default but due to gradle/gradle#6068 it's not possible to capture stdout / stderr from individual tasks which breaks download_artifacts_test.gradle. This commit modifies the test to run all tasks serially, prepares for the Gradle bug to be fixed and cleans up the output a little when tests fail. #145 Bug: 113575309 Change-Id: Ifee400beaa4544b3d9145cce51b69125ffc1f5b9
1 parent 06b6358 commit 0998673

File tree

1 file changed

+30
-14
lines changed

1 file changed

+30
-14
lines changed

source/PlayServicesResolver/scripts/download_artifacts_test.gradle

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import java.security.MessageDigest
1919
// Logger which captures standard output or error streams to a buffer.
2020
class StandardOutputErrorLogger implements StandardOutputListener {
2121
// List of lines captured by this logger.
22-
private def outputList = []
22+
private List<String> outputList = []
2323

2424
// Implements StandardOutputListener to capture a log message in
2525
// outputList.
@@ -34,15 +34,15 @@ class StandardOutputErrorLogger implements StandardOutputListener {
3434

3535
// Install the logger on the standard output and error streams of a task and
3636
// clear the internal buffer.
37-
def install(taskToLog) {
37+
void install(Task taskToLog) {
3838
outputList = []
3939
taskToLog.logging.addStandardOutputListener(this)
4040
taskToLog.logging.addStandardErrorListener(this)
4141
}
4242

4343
// Remove the logger from the standard output and error streams of a task and
4444
// clear the internal buffer.
45-
def uninstall(taskToLog) {
45+
void uninstall(Task taskToLog) {
4646
taskToLog.logging.removeStandardOutputListener(this)
4747
taskToLog.logging.removeStandardErrorListener(this)
4848
}
@@ -79,9 +79,6 @@ project.ext {
7979
// Header in the download script's output that describes the set of artifacts
8080
// that were modified from what the user requested.
8181
modifiedArtifactsHeader = "Modified artifacts:"
82-
83-
// Logger which captures the output of a task.
84-
standardOutputErrorLogger = new StandardOutputErrorLogger()
8582
}
8683

8784
// Generate a task to create the specified directory File.
@@ -162,7 +159,7 @@ def validateFilesMatch(taskToValidate, outputInputFileMap) {
162159
taskToValidate, new Exception(
163160
sprintf("%s failed, unexpected output file(s)\n%s\n\n%s\n",
164161
taskToValidate.name, mismatchingFiles.join("\n"),
165-
project.ext.standardOutputErrorLogger.output)))
162+
taskToValidate.ext.standardOutputErrorLogger.output)))
166163
}
167164
}
168165

@@ -177,7 +174,7 @@ def validateOutputFilesExist(taskToValidate) {
177174
taskToValidate, new Exception(
178175
sprintf("%s failed, missing expected file(s)\n%s\n\n%s\n",
179176
taskToValidate.name, missingFiles.join("\n"),
180-
project.ext.standardOutputErrorLogger.output)))
177+
taskToValidate.ext.standardOutputErrorLogger.output)))
181178
}
182179
}
183180

@@ -240,20 +237,25 @@ def createTestTask(taskName, taskDescription, packageSpecification,
240237
type: GradleBuild,
241238
dependsOn: createDirectoryTask)
242239
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+
243245
outputs.files movedOutputInputFileMap.keySet()
244246
startParameter createStartParameters(packageSpecification,
245247
targetDirFile)
246248
buildFile project.ext.buildFile
247249
dir project.ext.outputDir
248-
doFirst { project.ext.standardOutputErrorLogger.install(it) }
250+
doFirst { ext.standardOutputErrorLogger.install(it) }
249251
doLast {
250-
project.ext.standardOutputErrorLogger.uninstall(it)
252+
ext.standardOutputErrorLogger.uninstall(it)
251253
validateOutputFilesExist(it)
252254
validateFilesMatch(it, movedOutputInputFileMap)
253255
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
257259
}
258260
}
259261
}
@@ -629,4 +631,18 @@ task testUnitTests(type: GradleBuild, dependsOn: copyTestScript) {
629631
dir project.ext.outputDir
630632
}
631633

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

Comments
 (0)