@@ -15,10 +15,12 @@ import java.nio.file.Path
15
15
class CompilerClassPath (private val config : CompilerConfiguration ) : Closeable {
16
16
private val workspaceRoots = mutableSetOf<Path >()
17
17
private val javaSourcePath = mutableSetOf<Path >()
18
- val classPath = mutableSetOf<ClassPathEntry >()
19
18
private val buildScriptClassPath = mutableSetOf<Path >()
19
+ val classPath = mutableSetOf<ClassPathEntry >()
20
+
20
21
var compiler = Compiler (javaSourcePath, classPath.map { it.compiledJar }.toSet(), buildScriptClassPath)
21
22
private set
23
+
22
24
private val async = AsyncExecutor ()
23
25
24
26
init {
@@ -39,15 +41,15 @@ class CompilerClassPath(private val config: CompilerConfiguration) : Closeable {
39
41
val newClassPath = resolver.classpathOrEmpty
40
42
if (newClassPath != classPath) {
41
43
synchronized(classPath) {
42
- syncClassPathEntries (classPath, newClassPath, " class path" )
44
+ syncPaths (classPath, newClassPath, " class path" ) { it.compiledJar }
43
45
}
44
46
refreshCompiler = true
45
47
}
46
48
47
49
async.compute {
48
50
val newClassPathWithSources = resolver.classpathWithSources
49
51
synchronized(classPath) {
50
- syncClassPathEntries (classPath, newClassPathWithSources, " class path" )
52
+ syncPaths (classPath, newClassPathWithSources, " class path with sources " ) { it.compiledJar }
51
53
}
52
54
}
53
55
}
@@ -56,7 +58,7 @@ class CompilerClassPath(private val config: CompilerConfiguration) : Closeable {
56
58
LOG .info(" Update build script path" )
57
59
val newBuildScriptClassPath = resolver.buildScriptClasspathOrEmpty
58
60
if (newBuildScriptClassPath != buildScriptClassPath) {
59
- syncPaths(buildScriptClassPath, newBuildScriptClassPath, " class path" )
61
+ syncPaths(buildScriptClassPath, newBuildScriptClassPath, " build script class path" ) { it }
60
62
refreshCompiler = true
61
63
}
62
64
}
@@ -71,25 +73,13 @@ class CompilerClassPath(private val config: CompilerConfiguration) : Closeable {
71
73
return refreshCompiler
72
74
}
73
75
74
- /* * Synchronizes the given two class path entry sets and logs the differences. */
75
- private fun syncClassPathEntries (dest : MutableSet <ClassPathEntry >, new : Set <ClassPathEntry >, name : String ) {
76
- val added = new - dest
77
- val removed = dest - new
78
-
79
- logAdded(added.map { it.compiledJar }, name)
80
- logRemoved(removed.map { it.compiledJar }, name)
81
-
82
- dest.removeAll(removed)
83
- dest.addAll(added)
84
- }
85
-
86
76
/* * Synchronizes the given two path sets and logs the differences. */
87
- private fun syncPaths (dest : MutableSet <Path >, new : Set <Path >, name : String ) {
77
+ private fun < T > syncPaths (dest : MutableSet <T >, new : Set <T >, name : String , toPath : ( T ) -> Path ) {
88
78
val added = new - dest
89
79
val removed = dest - new
90
80
91
- logAdded(added, name)
92
- logRemoved(removed, name)
81
+ logAdded(added.map(toPath) , name)
82
+ logRemoved(removed.map(toPath) , name)
93
83
94
84
dest.removeAll(removed)
95
85
dest.addAll(added)
0 commit comments