|
46 | 46 | */ |
47 | 47 | public class DetectVMInstallationsJob extends Job { |
48 | 48 |
|
| 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 | + /** |
| 54 | + * Property that can be defined to control general behavior |
| 55 | + * <ul> |
| 56 | + * <li><code>DetectVMInstallationsJob.disabled = true</code> - automatic discovery is always disabled</li> |
| 57 | + * <li><code>DetectVMInstallationsJob.disabled = false</code> - check runs everywhere depending on preferences</li> |
| 58 | + * <li><code>DetectVMInstallationsJob.disabled</code> not specified - automatic discovery is disabled if environment variable <code>CI</code> has |
| 59 | + * value <code>true</code> otherwise runs depending on preferences</li> |
| 60 | + * </pre> |
| 61 | + */ |
| 62 | + private static final String PROPERTY_DETECT_VM_INSTALLATIONS_JOB_DISABLED = "DetectVMInstallationsJob.disabled"; //$NON-NLS-1$ |
49 | 63 | private static final Object FAMILY = DetectVMInstallationsJob.class; |
50 | 64 |
|
51 | 65 | public DetectVMInstallationsJob() { |
@@ -222,11 +236,19 @@ public boolean belongsTo(Object family) { |
222 | 236 | } |
223 | 237 |
|
224 | 238 | public static void initialize() { |
225 | | - boolean forcedDisableVMDetection = Boolean.getBoolean("DetectVMInstallationsJob.disabled"); //$NON-NLS-1$ |
| 239 | + if (Boolean.getBoolean(PROPERTY_DETECT_VM_INSTALLATIONS_JOB_DISABLED)) { |
| 240 | + // early exit no need to read preferences or check env variable! |
| 241 | + return; |
| 242 | + } |
| 243 | + if (System.getProperty(PROPERTY_DETECT_VM_INSTALLATIONS_JOB_DISABLED) == null && Boolean.parseBoolean(System.getenv(ENV_CI))) { |
| 244 | + // exit because no explicit value for the property was given and we are running in a CI environment |
| 245 | + return; |
| 246 | + } |
| 247 | + // finally look what is defined in the preferences |
226 | 248 | IEclipsePreferences instanceNode = InstanceScope.INSTANCE.getNode(LaunchingPlugin.getDefault().getBundle().getSymbolicName()); |
227 | 249 | IEclipsePreferences defaultNode = DefaultScope.INSTANCE.getNode(LaunchingPlugin.getDefault().getBundle().getSymbolicName()); |
228 | 250 | boolean defaultValue = defaultNode.getBoolean(LaunchingPlugin.PREF_DETECT_VMS_AT_STARTUP, true); |
229 | | - if (!forcedDisableVMDetection && instanceNode.getBoolean(LaunchingPlugin.PREF_DETECT_VMS_AT_STARTUP, defaultValue)) { |
| 251 | + if (instanceNode.getBoolean(LaunchingPlugin.PREF_DETECT_VMS_AT_STARTUP, defaultValue)) { |
230 | 252 | new DetectVMInstallationsJob().schedule(); |
231 | 253 | } |
232 | 254 | } |
|
0 commit comments