File: fix-GRADLE-2492.gradle

package info (click to toggle)
gradle 4.4.1-6
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 85,104 kB
  • sloc: java: 319,724; xml: 14,356; cpp: 4,200; ansic: 1,025; sh: 300; makefile: 60; asm: 17; jsp: 17; objc: 10
file content (29 lines) | stat: -rw-r--r-- 976 bytes parent folder | download | duplicates (4)
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
import java.util.concurrent.atomic.AtomicBoolean
import java.util.concurrent.locks.ReentrantLock

// Maven POM generation is not thread safe, so serialize all the Upload tasks we can use `--parallel`.
// https://issues.gradle.org/browse/GRADLE-2492
// When we start building with 2.3 and later we should remove this and just add a common output dir for all tasks and let Gradle serialize them
def lock = new ReentrantLock()
def available = lock.newCondition()
def busy = new AtomicBoolean()
def serializedTasks = []
allprojects {
    tasks.matching { it.name == "generatePom" || it instanceof Upload }.all {
        serializedTasks << it
        doFirst {
            lock.lock()
            while (busy.get()) {
                available.await()
            }
            busy.set(true)
        }
    }
}
gradle.taskGraph.afterTask {
    if (it in serializedTasks && lock.heldByCurrentThread) {
        busy.set(false)
        available.signal()
        lock.unlock()
    }
}