-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclean.gradle
75 lines (58 loc) · 1.69 KB
/
clean.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
/**
* author: qibin
*
* command: gradlew cl
*
* auto remove the build dir
*/
import java.util.concurrent.CountDownLatch
import java.util.concurrent.Executors
apply from: './setting_parser.gradle'
ext {
CLEAN_MAX_THREAD_COUNT = 20
}
//clean build dir
tasks.create(name: 'cl') << {
def root = file("./")
def collector = new Collector()
root.eachFile { item -> collect(item, collector) }
def threadCount = collector.size() > CLEAN_MAX_THREAD_COUNT ? CLEAN_MAX_THREAD_COUNT : collector.size()
println "collect ${collector.size()} modules and will open ${threadCount} threads to remove"
def countDownLatch = new CountDownLatch(collector.size())
def executor = Executors.newFixedThreadPool(threadCount)
collector.paths.each { item ->
executor.execute {
println "begin remove ${item}"
delete(item)
countDownLatch.countDown()
println "success remove ${item}"
}
}
countDownLatch.await()
println "clean success..."
}
def collect(File f, Collector collector) {
if (f.isDirectory()) {
if (isModuleBuildExists(f.absolutePath)) {
if (isProjectOpen(f.absolutePath)) {
collector.paths.add("${f.absolutePath}/build")
// println "remove ${f.absolutePath}/build"
// delete("${f.absolutePath}/build")
}
return
}
f.eachFile { item -> collect(item, collector) }
}
}
def isModuleBuildExists(String name) {
return file("${name}/build").exists()
}
class Collector {
List<String> paths
public Collector() {
paths = new ArrayList<>()
}
def size() {
return paths.size()
}
}