@@ -9,6 +9,9 @@ import repo.build.RepoBuildException
9
9
import java.util.concurrent.ConcurrentHashMap
10
10
import java.util.concurrent.ConcurrentMap
11
11
import java.util.concurrent.Executors
12
+ import java.util.concurrent.LinkedBlockingQueue
13
+ import java.util.concurrent.ThreadPoolExecutor
14
+ import java.util.concurrent.TimeUnit
12
15
13
16
/**
14
17
* @author Markelov Ruslan markelov@jet.msk.su
@@ -60,39 +63,50 @@ class Build {
60
63
61
64
Set<MavenArtifactRef > tasks = new HashSet<> (buildStates. keySet())
62
65
63
- def pool = Executors . newFixedThreadPool(context. getParallel())
64
- while (! tasks. isEmpty()) {
65
- def iter = tasks. iterator()
66
- while (iter. hasNext()) {
67
- def key = iter. next()
68
- def component = componentMap. get(key)
69
- def deps = buildDeps. get(key)
70
- if (! deps. any { buildStates. get(it) != BuildState . SUCCESS }) {
71
- pool. execute {
72
- // build component
73
- try {
74
- def pomFile = new File (component. basedir, ' pom.xml' )
75
- Maven . execute(context, pomFile, [' clean' , ' install' ])
76
- buildStates. put(key, BuildState . SUCCESS )
77
- } catch (Exception e) {
78
- buildStates. put(key, BuildState . ERROR )
79
- context. setErrorFlag()
80
- context. addError(new RepoBuildException (" component ${ component.path} build ERROR" , e))
66
+ def executionQueue = new LinkedBlockingQueue<Runnable > ()
67
+ def pool = new ThreadPoolExecutor (context. getParallel(), context. getParallel(),
68
+ 0L , TimeUnit . MILLISECONDS ,
69
+ executionQueue)
70
+ try {
71
+ while (! tasks. isEmpty()) {
72
+ def iter = tasks. iterator()
73
+ while (iter. hasNext()) {
74
+ def key = iter. next()
75
+ def component = componentMap. get(key)
76
+ def deps = buildDeps. get(key)
77
+ if (! deps. any { buildStates. get(it) != BuildState . SUCCESS }) {
78
+ pool. execute {
79
+ // build component
80
+ try {
81
+ def pomFile = new File (component. basedir, ' pom.xml' )
82
+ try {
83
+ Maven . execute(context, pomFile, [' clean' ])
84
+ } catch (RepoBuildException ignore) {
85
+ }
86
+ Maven . execute(context, pomFile, [' install' ])
87
+ buildStates. put(key, BuildState . SUCCESS )
88
+ } catch (Exception e) {
89
+ buildStates. put(key, BuildState . ERROR )
90
+ context. setErrorFlag()
91
+ context. addError(new RepoBuildException (" component ${ component.path} build ERROR" , e))
92
+ }
81
93
}
94
+ iter. remove()
95
+ } else if (deps. any {
96
+ buildStates. get(it) == BuildState . DEPS_ERROR ||
97
+ buildStates. get(it) == BuildState . ERROR
98
+ }) {
99
+ buildStates. put(key, BuildState . DEPS_ERROR )
100
+ context. setErrorFlag()
101
+ context. addError(new RepoBuildException (" component ${ component.path} build DEPS_ERROR" ))
102
+ iter. remove()
82
103
}
83
- iter. remove()
84
- } else if (deps. any {
85
- buildStates. get(it) == BuildState . DEPS_ERROR ||
86
- buildStates. get(it) == BuildState . ERROR
87
- }) {
88
- buildStates. put(key, BuildState . DEPS_ERROR )
89
- context. setErrorFlag()
90
- context. addError(new RepoBuildException (" component ${ component.path} build DEPS_ERROR" ))
91
- iter. remove()
92
104
}
105
+ // throttle cpu
106
+ Thread . sleep(500L )
93
107
}
94
- // throttle cpu
95
- Thread . sleep( 500L )
108
+ } finally {
109
+ pool . shutdown( )
96
110
}
97
111
return ! context. getErrorFlag()
98
112
}
0 commit comments