Skip to content

Commit 28c1228

Browse files
committed
Update syncPaths
1 parent f3fc97f commit 28c1228

File tree

1 file changed

+9
-19
lines changed

1 file changed

+9
-19
lines changed

server/src/main/kotlin/org/javacs/kt/CompilerClassPath.kt

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@ import java.nio.file.Path
1515
class CompilerClassPath(private val config: CompilerConfiguration) : Closeable {
1616
private val workspaceRoots = mutableSetOf<Path>()
1717
private val javaSourcePath = mutableSetOf<Path>()
18-
val classPath = mutableSetOf<ClassPathEntry>()
1918
private val buildScriptClassPath = mutableSetOf<Path>()
19+
val classPath = mutableSetOf<ClassPathEntry>()
20+
2021
var compiler = Compiler(javaSourcePath, classPath.map { it.compiledJar }.toSet(), buildScriptClassPath)
2122
private set
23+
2224
private val async = AsyncExecutor()
2325

2426
init {
@@ -39,15 +41,15 @@ class CompilerClassPath(private val config: CompilerConfiguration) : Closeable {
3941
val newClassPath = resolver.classpathOrEmpty
4042
if (newClassPath != classPath) {
4143
synchronized(classPath) {
42-
syncClassPathEntries(classPath, newClassPath, "class path")
44+
syncPaths(classPath, newClassPath, "class path") { it.compiledJar }
4345
}
4446
refreshCompiler = true
4547
}
4648

4749
async.compute {
4850
val newClassPathWithSources = resolver.classpathWithSources
4951
synchronized(classPath) {
50-
syncClassPathEntries(classPath, newClassPathWithSources, "class path")
52+
syncPaths(classPath, newClassPathWithSources, "class path with sources") { it.compiledJar }
5153
}
5254
}
5355
}
@@ -56,7 +58,7 @@ class CompilerClassPath(private val config: CompilerConfiguration) : Closeable {
5658
LOG.info("Update build script path")
5759
val newBuildScriptClassPath = resolver.buildScriptClasspathOrEmpty
5860
if (newBuildScriptClassPath != buildScriptClassPath) {
59-
syncPaths(buildScriptClassPath, newBuildScriptClassPath, "class path")
61+
syncPaths(buildScriptClassPath, newBuildScriptClassPath, "build script class path") { it }
6062
refreshCompiler = true
6163
}
6264
}
@@ -71,25 +73,13 @@ class CompilerClassPath(private val config: CompilerConfiguration) : Closeable {
7173
return refreshCompiler
7274
}
7375

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-
8676
/** 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) {
8878
val added = new - dest
8979
val removed = dest - new
9080

91-
logAdded(added, name)
92-
logRemoved(removed, name)
81+
logAdded(added.map(toPath), name)
82+
logRemoved(removed.map(toPath), name)
9383

9484
dest.removeAll(removed)
9585
dest.addAll(added)

0 commit comments

Comments
 (0)