Skip to content

Commit 76ef9f6

Browse files
committed
Do not automatically detect JVMs on CI systems
Automatic detection on CI systems can cause a lot of trouble (e.g. memory consumption, time to read the jvms, old jvms lingering around) and is generally not useful as a CI has usually a dedicated and fixed setup to run with. This adds a check for the common 'CI' environment variable that is usually defined by all usual CI/CD pipelines to indicate a job is running on a CI server to skip the detection regardless of preferences configuration. If one absolutely want the feature even for CI, the system-property 'DetectVMInstallationsJob.disabled' can be set to false to restore previous behavior.
1 parent a639856 commit 76ef9f6

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

org.eclipse.jdt.launching/launching/org/eclipse/jdt/internal/launching/DetectVMInstallationsJob.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@
4646
*/
4747
public class DetectVMInstallationsJob extends Job {
4848

49+
/**
50+
* CI is a common variable defined in CI/CDI servers like Jenkins, Gitlab, Github, ... to indicate it is a CI environment
51+
*/
52+
private static final String ENV_CI = "CI"; //$NON-NLS-1$
53+
private static final String PROPERTY_DETECT_VM_INSTALLATIONS_JOB_DISABLED = "DetectVMInstallationsJob.disabled"; //$NON-NLS-1$
4954
private static final Object FAMILY = DetectVMInstallationsJob.class;
5055

5156
public DetectVMInstallationsJob() {
@@ -222,11 +227,20 @@ public boolean belongsTo(Object family) {
222227
}
223228

224229
public static void initialize() {
225-
boolean forcedDisableVMDetection = Boolean.getBoolean("DetectVMInstallationsJob.disabled"); //$NON-NLS-1$
230+
boolean forcedDisableVMDetection = Boolean.getBoolean(PROPERTY_DETECT_VM_INSTALLATIONS_JOB_DISABLED);
231+
if (forcedDisableVMDetection) {
232+
// early exit no need to read preferences!
233+
return;
234+
}
235+
if (System.getProperty(PROPERTY_DETECT_VM_INSTALLATIONS_JOB_DISABLED) == null && Boolean.parseBoolean(System.getenv(ENV_CI))) {
236+
// exit because no explicit value for the property was given and we are running in a CI environment
237+
return;
238+
}
239+
// finally look what is defined in the preferences
226240
IEclipsePreferences instanceNode = InstanceScope.INSTANCE.getNode(LaunchingPlugin.getDefault().getBundle().getSymbolicName());
227241
IEclipsePreferences defaultNode = DefaultScope.INSTANCE.getNode(LaunchingPlugin.getDefault().getBundle().getSymbolicName());
228242
boolean defaultValue = defaultNode.getBoolean(LaunchingPlugin.PREF_DETECT_VMS_AT_STARTUP, true);
229-
if (!forcedDisableVMDetection && instanceNode.getBoolean(LaunchingPlugin.PREF_DETECT_VMS_AT_STARTUP, defaultValue)) {
243+
if (instanceNode.getBoolean(LaunchingPlugin.PREF_DETECT_VMS_AT_STARTUP, defaultValue)) {
230244
new DetectVMInstallationsJob().schedule();
231245
}
232246
}

0 commit comments

Comments
 (0)