4646 */
4747public 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 () {
@@ -129,14 +134,7 @@ private boolean isDuplicateName(String name) {
129134
130135 private Collection <File > computeCandidateVMs (StandardVMType standardType ) {
131136 // parent directories containing a collection of VM installations
132- Collection <File > rootDirectories = new HashSet <>();
133- if (Platform .OS_WIN32 .equals (Platform .getOS ())) {
134- computeWindowsCandidates (rootDirectories );
135- } else {
136- rootDirectories .add (new File ("/usr/lib/jvm" )); //$NON-NLS-1$
137- }
138- rootDirectories .add (new File (System .getProperty ("user.home" ), ".sdkman/candidates/java" )); //$NON-NLS-1$ //$NON-NLS-2$
139- rootDirectories .add (new File (miseDataDir (), "installs/java" )); //$NON-NLS-1$
137+ Collection <File > rootDirectories = List .of (new File ("/opt/java" )); //$NON-NLS-1$
140138
141139 Set <File > directories = rootDirectories .stream ().filter (File ::isDirectory )
142140 .map (dir -> dir .listFiles (File ::isDirectory ))
@@ -168,38 +166,6 @@ private Collection<File> computeCandidateVMs(StandardVMType standardType) {
168166 .collect (Collectors .toCollection (HashSet ::new ));
169167 }
170168
171- private void computeWindowsCandidates (Collection <File > rootDirectories ) {
172- List <String > progFiles = List .of ("ProgramFiles" , "ProgramFiles(x86)" ); //$NON-NLS-1$//$NON-NLS-2$
173- List <String > subDirs = List .of ("Eclipse Adoptium" , "RedHat" ); //$NON-NLS-1$//$NON-NLS-2$
174- rootDirectories .addAll (
175- progFiles .stream ()
176- .map (name -> System .getenv (name ))
177- .filter (Objects ::nonNull )
178- .distinct ()
179- .flatMap (progFilesDir -> subDirs .stream ().map (subDir -> new File (progFilesDir , subDir )))
180- .collect (Collectors .toList ()));
181- }
182-
183- private static File miseDataDir () {
184- String miseDataDir = System .getenv ("MISE_DATA_DIR" ); //$NON-NLS-1$
185- return miseDataDir != null ? new File (miseDataDir ) : new File (xdgDataHome (), "mise" ); //$NON-NLS-1$
186- }
187-
188- private static File xdgDataHome () {
189- String xdgDataHome = System .getenv ("XDG_DATA_HOME" ); //$NON-NLS-1$
190- if (Platform .OS_WIN32 .equals (Platform .getOS ())) {
191- if (xdgDataHome == null ) {
192- xdgDataHome = System .getenv ("LOCALAPPDATA" ); //$NON-NLS-1$
193- }
194- if (xdgDataHome == null ) {
195- return new File (System .getProperty ("user.home" ), "AppData/Local" ); //$NON-NLS-1$ //$NON-NLS-2$
196- }
197- } else if (xdgDataHome == null ) {
198- return new File (System .getProperty ("user.home" ), ".local/share" ); //$NON-NLS-1$ //$NON-NLS-2$
199- }
200- return new File (xdgDataHome );
201- }
202-
203169 private static Set <File > knownVMs () {
204170 return Stream .of (JavaRuntime .getVMInstallTypes ())
205171 .map (IVMInstallType ::getVMInstalls )
@@ -222,11 +188,20 @@ public boolean belongsTo(Object family) {
222188 }
223189
224190 public static void initialize () {
225- boolean forcedDisableVMDetection = Boolean .getBoolean ("DetectVMInstallationsJob.disabled" ); //$NON-NLS-1$
191+ boolean forcedDisableVMDetection = Boolean .getBoolean (PROPERTY_DETECT_VM_INSTALLATIONS_JOB_DISABLED );
192+ if (forcedDisableVMDetection ) {
193+ // early exit no need to read preferences!
194+ return ;
195+ }
196+ if (System .getProperty (PROPERTY_DETECT_VM_INSTALLATIONS_JOB_DISABLED ) == null && Boolean .parseBoolean (System .getenv (ENV_CI ))) {
197+ // exit because no explicit value for the property was given and we are running in a CI environment
198+ return ;
199+ }
200+ // finally look what is defined in the preferences
226201 IEclipsePreferences instanceNode = InstanceScope .INSTANCE .getNode (LaunchingPlugin .getDefault ().getBundle ().getSymbolicName ());
227202 IEclipsePreferences defaultNode = DefaultScope .INSTANCE .getNode (LaunchingPlugin .getDefault ().getBundle ().getSymbolicName ());
228203 boolean defaultValue = defaultNode .getBoolean (LaunchingPlugin .PREF_DETECT_VMS_AT_STARTUP , true );
229- if (! forcedDisableVMDetection && instanceNode .getBoolean (LaunchingPlugin .PREF_DETECT_VMS_AT_STARTUP , defaultValue )) {
204+ if (instanceNode .getBoolean (LaunchingPlugin .PREF_DETECT_VMS_AT_STARTUP , defaultValue )) {
230205 new DetectVMInstallationsJob ().schedule ();
231206 }
232207 }
0 commit comments