@@ -10,6 +10,7 @@ import java.io.File
10
10
import java.nio.file.FileSystems
11
11
import java.nio.file.Files
12
12
import java.nio.file.Path
13
+ import java.util.concurrent.CompletableFuture
13
14
14
15
/* *
15
16
* Manages the class path (compiled JARs, etc), the Java source path
@@ -51,36 +52,46 @@ class CompilerClassPath(
51
52
updateBuildScriptClassPath : Boolean = true,
52
53
updateJavaSourcePath : Boolean = true
53
54
): Boolean {
54
- // TODO: Fetch class path and build script class path concurrently (and asynchronously)
55
55
val resolver = defaultClassPathResolver(workspaceRoots, databaseService.db)
56
56
var refreshCompiler = updateJavaSourcePath
57
-
58
- if (updateClassPath) {
59
- val newClassPath = resolver.classpathOrEmpty
60
- if (newClassPath != classPath) {
61
- synchronized(classPath) {
62
- syncPaths(classPath, newClassPath, " class path" ) { it.compiledJar }
57
+ val asyncExecutor = AsyncExecutor ()
58
+
59
+ val classPathFuture = if (updateClassPath) {
60
+ asyncExecutor.compute {
61
+ val newClassPath = resolver.classpathOrEmpty
62
+ if (newClassPath != classPath) {
63
+ synchronized(classPath) {
64
+ syncPaths(classPath, newClassPath, " class path" ) { it.compiledJar }
65
+ }
66
+ refreshCompiler = true
63
67
}
64
- refreshCompiler = true
65
- }
66
68
67
- async.compute {
68
- val newClassPathWithSources = resolver.classpathWithSources
69
- synchronized(classPath) {
70
- syncPaths(classPath, newClassPathWithSources, " class path with sources" ) { it.compiledJar }
69
+ asyncExecutor.compute {
70
+ val newClassPathWithSources = resolver.classpathWithSources
71
+ synchronized(classPath) {
72
+ syncPaths(classPath, newClassPathWithSources, " class path with sources" ) { it.compiledJar }
73
+ }
71
74
}
72
75
}
76
+ } else {
77
+ CompletableFuture .completedFuture(null )
73
78
}
74
79
75
- if (updateBuildScriptClassPath) {
76
- LOG .info(" Update build script path" )
77
- val newBuildScriptClassPath = resolver.buildScriptClasspathOrEmpty
78
- if (newBuildScriptClassPath != buildScriptClassPath) {
79
- syncPaths(buildScriptClassPath, newBuildScriptClassPath, " build script class path" ) { it }
80
- refreshCompiler = true
80
+ val buildScriptClassPathFuture = if (updateBuildScriptClassPath) {
81
+ asyncExecutor.compute {
82
+ LOG .info(" Update build script path" )
83
+ val newBuildScriptClassPath = resolver.buildScriptClasspathOrEmpty
84
+ if (newBuildScriptClassPath != buildScriptClassPath) {
85
+ syncPaths(buildScriptClassPath, newBuildScriptClassPath, " build script class path" ) { it }
86
+ refreshCompiler = true
87
+ }
81
88
}
89
+ } else {
90
+ CompletableFuture .completedFuture(null )
82
91
}
83
92
93
+ CompletableFuture .allOf(classPathFuture, buildScriptClassPathFuture).join()
94
+
84
95
if (refreshCompiler) {
85
96
LOG .info(" Reinstantiating compiler" )
86
97
compiler.close()
@@ -98,6 +109,7 @@ class CompilerClassPath(
98
109
return refreshCompiler
99
110
}
100
111
112
+
101
113
/* * Synchronizes the given two path sets and logs the differences. */
102
114
private fun <T > syncPaths (dest : MutableSet <T >, new : Set <T >, name : String , toPath : (T ) -> Path ) {
103
115
val added = new - dest
0 commit comments