Skip to content

Commit

Permalink
DetectVMInstallationsJob: defer detection until needed.
Browse files Browse the repository at this point in the history
So that it does not run in jdt.core tests at all

eclipse-jdt/eclipse.jdt.core#1190
  • Loading branch information
EcljpseB0T authored and jukzi committed Aug 14, 2023
1 parent 6b56913 commit d79833b
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.core.runtime.preferences.DefaultScope;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.jdt.launching.IVMInstall;
import org.eclipse.jdt.launching.IVMInstall2;
import org.eclipse.jdt.launching.IVMInstallType;
Expand All @@ -40,20 +43,18 @@
* are not yet known by JDT to the VM registry (usually visible in the "Installed JREs"
* preference page)
*/
class DetectVMInstallationsJob extends Job {
public class DetectVMInstallationsJob extends Job {

private static final Object FAMILY = DetectVMInstallationsJob.class;

private final StandardVMType standardType;

DetectVMInstallationsJob() {
private DetectVMInstallationsJob() {
super(LaunchingMessages.lookupInstalledJVMs);
this.standardType = (StandardVMType)JavaRuntime.getVMInstallType(StandardVMType.ID_STANDARD_VM_TYPE);
}

@Override
protected IStatus run(IProgressMonitor monitor) {
Collection<File> candidates = computeCandidateVMs();
StandardVMType standardType = (StandardVMType) JavaRuntime.getVMInstallType(StandardVMType.ID_STANDARD_VM_TYPE);
Collection<File> candidates = computeCandidateVMs(standardType);
if (monitor.isCanceled()) {
return Status.CANCEL_STATUS;
}
Expand Down Expand Up @@ -125,7 +126,7 @@ private boolean isDuplicateName(String name) {
.anyMatch(name::equals);
}

private Collection<File> computeCandidateVMs() {
private Collection<File> computeCandidateVMs(StandardVMType standardType) {
// parent directories containing a collection of VM installations
Collection<File> rootDirectories = new HashSet<>();
if (!Platform.OS_WIN32.equals(Platform.getOS())) {
Expand Down Expand Up @@ -184,4 +185,14 @@ public boolean belongsTo(Object family) {
return family.equals(FAMILY);
}

public static void initialize() {
boolean forcedDisableVMDetection = Boolean.getBoolean("DetectVMInstallationsJob.disabled"); //$NON-NLS-1$
IEclipsePreferences instanceNode = InstanceScope.INSTANCE.getNode(LaunchingPlugin.getDefault().getBundle().getSymbolicName());
IEclipsePreferences defaultNode = DefaultScope.INSTANCE.getNode(LaunchingPlugin.getDefault().getBundle().getSymbolicName());
boolean defaultValue = defaultNode.getBoolean(LaunchingPlugin.PREF_DETECT_VMS_AT_STARTUP, true);
if (!forcedDisableVMDetection && instanceNode.getBoolean(LaunchingPlugin.PREF_DETECT_VMS_AT_STARTUP, defaultValue)) {
new DetectVMInstallationsJob().schedule();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
import org.eclipse.core.runtime.Plugin;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.core.runtime.preferences.DefaultScope;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChangeEvent;
import org.eclipse.core.runtime.preferences.InstanceScope;
Expand Down Expand Up @@ -583,14 +582,6 @@ public void saving(ISaveContext context1) throws CoreException {
ResourcesPlugin.getWorkspace().addResourceChangeListener(this, IResourceChangeEvent.PRE_DELETE | IResourceChangeEvent.PRE_CLOSE);
DebugPlugin.getDefault().getLaunchManager().addLaunchListener(this);
DebugPlugin.getDefault().addDebugEventListener(this);
boolean forcedDisableVMDetection = Boolean.getBoolean(DetectVMInstallationsJob.class.getSimpleName() + ".disabled"); //$NON-NLS-1$
IEclipsePreferences instanceNode = InstanceScope.INSTANCE.getNode(getBundle().getSymbolicName());
IEclipsePreferences defaultNode = DefaultScope.INSTANCE.getNode(getBundle().getSymbolicName());
boolean defaultValue = defaultNode.getBoolean(PREF_DETECT_VMS_AT_STARTUP, true);
if (!forcedDisableVMDetection && instanceNode.getBoolean(PREF_DETECT_VMS_AT_STARTUP, defaultValue)) {
new DetectVMInstallationsJob().schedule();
}

AdvancedSourceLookupSupport.start();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;

import javax.xml.parsers.DocumentBuilder;
Expand Down Expand Up @@ -79,6 +80,7 @@
import org.eclipse.jdt.internal.launching.CompositeId;
import org.eclipse.jdt.internal.launching.DefaultEntryResolver;
import org.eclipse.jdt.internal.launching.DefaultProjectClasspathEntry;
import org.eclipse.jdt.internal.launching.DetectVMInstallationsJob;
import org.eclipse.jdt.internal.launching.EEVMInstall;
import org.eclipse.jdt.internal.launching.EEVMType;
import org.eclipse.jdt.internal.launching.JREContainerInitializer;
Expand Down Expand Up @@ -328,7 +330,7 @@ public final class JavaRuntime {
public static final String CLASSPATH_ATTR_LIBRARY_PATH_ENTRY = LaunchingPlugin.getUniqueIdentifier() + ".CLASSPATH_ATTR_LIBRARY_PATH_ENTRY"; //$NON-NLS-1$

// lock for VM initialization
private static Object fgVMLock = new Object();
private static final Object fgVMLock = new Object();
private static boolean fgInitializingVMs = false;

private static HashSet<Object> fgVMTypes = null;
Expand All @@ -351,26 +353,26 @@ public final class JavaRuntime {
/**
* Default classpath and source path providers.
*/
private static IRuntimeClasspathProvider fgDefaultClasspathProvider = new StandardClasspathProvider();
private static IRuntimeClasspathProvider fgDefaultSourcePathProvider = new StandardSourcePathProvider();
private static final IRuntimeClasspathProvider fgDefaultClasspathProvider = new StandardClasspathProvider();
private static final IRuntimeClasspathProvider fgDefaultSourcePathProvider = new StandardSourcePathProvider();

/**
* VM change listeners
*/
private static ListenerList<IVMInstallChangedListener> fgVMListeners = new ListenerList<>();
private static final ListenerList<IVMInstallChangedListener> fgVMListeners = new ListenerList<>();

/**
* Cache of already resolved projects in container entries. Used to avoid
* cycles in project dependencies when resolving classpath container entries.
* Counters used to know when entering/exiting to clear cache
*/
private static ThreadLocal<List<IJavaProject>> fgProjects = new ThreadLocal<>(); // Lists
private static ThreadLocal<Integer> fgEntryCount = new ThreadLocal<>(); // Integers
private static final ThreadLocal<List<IJavaProject>> fgProjects = new ThreadLocal<>(); // Lists
private static final ThreadLocal<Integer> fgEntryCount = new ThreadLocal<>(); // Integers

/**
* Set of IDs of VMs contributed via vmInstalls extension point.
*/
private static Set<String> fgContributedVMs = new HashSet<>();
private static final Set<String> fgContributedVMs = ConcurrentHashMap.newKeySet();

/**
* This class contains only static methods, and is not intended
Expand Down Expand Up @@ -3268,8 +3270,7 @@ private static void initializeVMs() {
VMStandin vmStandin = (VMStandin) vmListIterator.next();
vmStandin.convertToRealVM();
}


DetectVMInstallationsJob.initialize();
} catch (IOException e) {
LaunchingPlugin.log(e);
}
Expand Down
5 changes: 0 additions & 5 deletions org.eclipse.jdt.launching/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,6 @@
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-surefire-plugin</artifactId>
<configuration>
<systemProperties>
<DetectVMInstallationsJob.disabled>true</DetectVMInstallationsJob.disabled>
</systemProperties>
</configuration>
</plugin>
</plugins>
</build>
Expand Down

0 comments on commit d79833b

Please sign in to comment.