@@ -7,31 +7,48 @@ import java.nio.file.Path
7
7
class CompilerClassPath (private val config : CompilerConfiguration ) : Closeable {
8
8
private val workspaceRoots = mutableSetOf<Path >()
9
9
private val classPath = mutableSetOf<Path >()
10
- var compiler = Compiler (classPath)
10
+ private val buildScriptClassPath = mutableSetOf<Path >()
11
+ var compiler = Compiler (classPath, buildScriptClassPath)
11
12
private set
12
13
13
14
init {
14
15
compiler.updateConfiguration(config)
15
16
}
16
17
17
18
private fun refresh () {
18
- val newClassPath = defaultClassPathResolver(workspaceRoots).classpathOrEmpty
19
+ val resolver = defaultClassPathResolver(workspaceRoots)
20
+ val newClassPath = resolver.classpathOrEmpty
21
+ val newBuildScriptClassPath = resolver.buildScriptClasspathOrEmpty
22
+ var refreshCompiler = false
19
23
20
24
if (newClassPath != classPath) {
21
- val added = newClassPath - classPath
22
- val removed = classPath - newClassPath
25
+ syncClassPath(classPath, newClassPath)
26
+ refreshCompiler = true
27
+ }
23
28
24
- logAdded(added)
25
- logRemoved(removed)
29
+ if (newBuildScriptClassPath != buildScriptClassPath) {
30
+ syncClassPath(buildScriptClassPath, newBuildScriptClassPath)
31
+ refreshCompiler = true
32
+ }
26
33
27
- classPath.removeAll(removed)
28
- classPath.addAll(added)
34
+ if (refreshCompiler) {
29
35
compiler.close()
30
- compiler = Compiler (classPath)
36
+ compiler = Compiler (classPath, buildScriptClassPath )
31
37
updateCompilerConfiguration()
32
38
}
33
39
}
34
40
41
+ private fun syncClassPath (dest : MutableSet <Path >, new : Set <Path >) {
42
+ val added = new - dest
43
+ val removed = dest - new
44
+
45
+ logAdded(added)
46
+ logRemoved(removed)
47
+
48
+ dest.removeAll(removed)
49
+ dest.addAll(added)
50
+ }
51
+
35
52
fun updateCompilerConfiguration () {
36
53
compiler.updateConfiguration(config)
37
54
}
@@ -61,7 +78,8 @@ class CompilerClassPath(private val config: CompilerConfiguration) : Closeable {
61
78
}
62
79
63
80
fun changedOnDisk (file : Path ) {
64
- if (file.fileName.toString() == " pom.xml" )
81
+ val name = file.fileName.toString()
82
+ if (name == " pom.xml" || name == " build.gradle" || name == " build.gradle.kts" )
65
83
refresh()
66
84
}
67
85
0 commit comments