Skip to content

Commit

Permalink
Merge pull request #8193 from mbien/stabilize-multisourcerootprovider…
Browse files Browse the repository at this point in the history
…-test

Stabilize MultiSourceRootProviderTest
  • Loading branch information
mbien authored Feb 7, 2025
2 parents 868e71f + 380dacf commit 12ad0e7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import java.beans.PropertyChangeSupport;
import java.io.File;
import java.io.IOException;
import java.lang.ref.Reference;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -65,7 +64,6 @@
import org.openide.filesystems.FileRenameEvent;
import org.openide.filesystems.FileUtil;
import org.openide.filesystems.URLMapper;
import org.openide.util.NbBundle.Messages;
import org.openide.util.RequestProcessor;
import org.openide.util.RequestProcessor.Task;
import org.openide.util.Utilities;
Expand All @@ -84,9 +82,7 @@ public class MultiSourceRootProvider implements ClassPathProvider {
public static boolean DISABLE_MULTI_SOURCE_ROOT = Boolean.getBoolean("java.disable.multi.source.root");
public static boolean SYNCHRONOUS_UPDATES = false;

private static final Set<String> MODULAR_DIRECTORY_OPTIONS = new HashSet<>(Arrays.asList(
"--module-path", "-p"
));
private static final Set<String> MODULAR_DIRECTORY_OPTIONS = Set.of("--module-path", "-p");

//TODO: the cache will probably be never cleared, as the ClassPath/value refers to the key(?)
private Map<FileObject, ClassPath> file2SourceCP = new WeakHashMap<>();
Expand All @@ -108,10 +104,10 @@ boolean isSupportedFile(FileObject file) {
return true;
}

Set<FileObject> registeredRootsCopy;
List<FileObject> registeredRootsCopy;

synchronized (registeredRoots) {
registeredRootsCopy = registeredRoots;
registeredRootsCopy = new ArrayList<>(registeredRoots);
}

for (FileObject existingRoot : registeredRootsCopy) {
Expand All @@ -125,6 +121,9 @@ boolean isSupportedFile(FileObject file) {

@Override
public ClassPath findClassPath(FileObject file, String type) {
if (SYNCHRONOUS_UPDATES) {
WORKER.post(() -> {}).waitFinished(); // flush tasks for tests (assumes threadpool size == 1)
}
if (!isSupportedFile(file)) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
package org.netbeans.modules.java.file.launcher.queries;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.Writer;
import java.net.URI;
Expand All @@ -34,15 +33,12 @@
import org.netbeans.api.java.classpath.JavaClassPathConstants;
import org.netbeans.api.java.source.TestUtilities;
import org.netbeans.junit.NbTestCase;
import org.netbeans.modules.java.file.launcher.SingleSourceFileUtil;
import org.netbeans.modules.java.file.launcher.spi.SingleFileOptionsQueryImplementation;
import org.netbeans.modules.java.file.launcher.spi.SingleFileOptionsQueryImplementation.Result;
import org.openide.filesystems.FileObject;
import org.openide.filesystems.FileUtil;
import org.openide.util.ChangeSupport;
import org.openide.util.Exceptions;
import org.openide.util.Lookup;
import org.openide.util.NbBundle;
import org.openide.util.lookup.Lookups;
import org.openide.util.lookup.ProxyLookup;

Expand Down

0 comments on commit 12ad0e7

Please sign in to comment.