Skip to content

Commit b7011c8

Browse files
committed
Don't cache search classpath, only build it when looking for a class
Fixes processing#4748 Libraries imported in opened sketches will be still locked by latest preprocessed CompilationUnit. Otherwise we would have to copy library jars somewhere else so they can be available to CompilationUnit while Contribution Manager updates original unlocked jars.
1 parent 8902ed1 commit b7011c8

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

java/src/processing/mode/java/pdex/PDEX.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package processing.mode.java.pdex;
22

33
import com.google.classpath.ClassPath;
4+
import com.google.classpath.ClassPathFactory;
45
import com.google.classpath.RegExpResourceFilter;
56

67
import org.eclipse.jdt.core.compiler.IProblem;
@@ -44,6 +45,7 @@
4445
import java.util.concurrent.ScheduledExecutorService;
4546
import java.util.concurrent.ScheduledFuture;
4647
import java.util.concurrent.TimeUnit;
48+
import java.util.concurrent.atomic.AtomicReference;
4749
import java.util.function.Consumer;
4850
import java.util.function.Predicate;
4951
import java.util.regex.Pattern;
@@ -1106,6 +1108,8 @@ private void handleSketchProblems(PreprocessedSketch ps) {
11061108
}
11071109
}
11081110

1111+
AtomicReference<ClassPath> searchClassPath = new AtomicReference<>(null);
1112+
11091113
if (problems.isEmpty()) {
11101114
List<Problem> cuProblems = Arrays.stream(iproblems)
11111115
// Filter Warnings if they are not enabled
@@ -1129,7 +1133,8 @@ private void handleSketchProblems(PreprocessedSketch ps) {
11291133

11301134
// Handle import suggestions
11311135
if (JavaMode.importSuggestEnabled && isUndefinedTypeProblem(iproblem)) {
1132-
ClassPath cp = ps.searchClassPath;
1136+
ClassPath cp = searchClassPath.updateAndGet(prev -> prev != null ?
1137+
prev : new ClassPathFactory().createFromPaths(ps.searchClassPathArray));
11331138
String[] s = suggCache.computeIfAbsent(iproblem.getArguments()[0],
11341139
name -> getImportSuggestions(cp, name));
11351140
p.setImportSuggestions(s);

java/src/processing/mode/java/pdex/PreprocessedSketch.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public class PreprocessedSketch {
2626
public final ClassPath classPath;
2727
public final URLClassLoader classLoader;
2828

29-
public final ClassPath searchClassPath;
29+
public final String[] searchClassPathArray;
3030

3131
public final int[] tabStartOffsets;
3232

@@ -206,7 +206,7 @@ public static class Builder {
206206
public ClassPath classPath;
207207
public URLClassLoader classLoader;
208208

209-
public ClassPath searchClassPath;
209+
public String[] searchClassPathArray;
210210

211211
public int[] tabStartOffsets = new int[0];
212212

@@ -242,7 +242,7 @@ private PreprocessedSketch(Builder b) {
242242
classPath = b.classPath;
243243
classLoader = b.classLoader;
244244

245-
searchClassPath = b.searchClassPath;
245+
searchClassPathArray = b.searchClassPathArray;
246246

247247
tabStartOffsets = b.tabStartOffsets;
248248

java/src/processing/mode/java/pdex/PreprocessingService.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ private PreprocessedSketch preprocessSketch(PreprocessedSketch prevResult) {
341341

342342
boolean rebuildClassPath = reloadCodeFolder || rebuildLibraryClassPath ||
343343
prevResult.classLoader == null || prevResult.classPath == null ||
344-
prevResult.classPathArray == null || prevResult.searchClassPath == null;
344+
prevResult.classPathArray == null || prevResult.searchClassPathArray == null;
345345

346346
if (reloadCodeFolder) {
347347
codeFolderClassPath = buildCodeFolderClassPath(sketch);
@@ -381,13 +381,12 @@ private PreprocessedSketch preprocessSketch(PreprocessedSketch prevResult) {
381381
searchClassPath.addAll(coreLibraryClassPath);
382382
searchClassPath.addAll(codeFolderClassPath);
383383

384-
String[] searchClassPathArray = searchClassPath.stream().toArray(String[]::new);
385-
result.searchClassPath = classPathFactory.createFromPaths(searchClassPathArray);
384+
result.searchClassPathArray = searchClassPath.stream().toArray(String[]::new);
386385
}
387386
} else {
388387
result.classLoader = prevResult.classLoader;
389388
result.classPath = prevResult.classPath;
390-
result.searchClassPath = prevResult.searchClassPath;
389+
result.searchClassPathArray = prevResult.searchClassPathArray;
391390
result.classPathArray = prevResult.classPathArray;
392391
}
393392
}

0 commit comments

Comments
 (0)