@@ -9,10 +9,14 @@ import java.net.URLClassLoader
99abstract class MuzzleAction : WorkAction <MuzzleWorkParameters > {
1010 companion object {
1111 private val lock = Any ()
12- private var bootCL: ClassLoader ? = null
13- private var toolCL: ClassLoader ? = null
12+ @Volatile
13+ private var lastBootCL: ClassLoader ? = null
14+ @Volatile
15+ private var lastToolCL: ClassLoader ? = null
1416 @Volatile
1517 private var lastBuildStamp: Long = 0
18+ @Volatile
19+ private var lastBuildPathCount: Int = 0
1620
1721 fun createClassLoader (cp : FileCollection , parent : ClassLoader = ClassLoader .getSystemClassLoader()): ClassLoader {
1822 val urls = cp.map { it.toURI().toURL() }.toTypedArray()
@@ -22,12 +26,21 @@ abstract class MuzzleAction : WorkAction<MuzzleWorkParameters> {
2226
2327 override fun execute () {
2428 val buildStamp = parameters.buildStartedTime.get()
25- if (bootCL == null || toolCL == null || lastBuildStamp < buildStamp) {
29+ val buildPathCount = parameters.bootstrapClassPath.count() + parameters.toolingClassPath.count()
30+ var bootCL : ClassLoader ? = lastBootCL
31+ var toolCL : ClassLoader ? = lastToolCL
32+ // cache boot and tool classloaders for each run; rebuild if either class-path is extended mid-build
33+ if (bootCL == null || toolCL == null || lastBuildStamp < buildStamp || lastBuildPathCount < buildPathCount) {
2634 synchronized(lock) {
27- if (bootCL == null || toolCL == null || lastBuildStamp < buildStamp) {
35+ bootCL = lastBootCL
36+ toolCL = lastToolCL
37+ if (bootCL == null || toolCL == null || lastBuildStamp < buildStamp || lastBuildPathCount < buildPathCount) {
2838 bootCL = createClassLoader(parameters.bootstrapClassPath)
2939 toolCL = createClassLoader(parameters.toolingClassPath, bootCL!! )
40+ lastBootCL = bootCL
41+ lastToolCL = toolCL
3042 lastBuildStamp = buildStamp
43+ lastBuildPathCount = buildPathCount
3144 }
3245 }
3346 }
0 commit comments