1717import java .util .Collection ;
1818import java .util .Collections ;
1919import java .util .HashSet ;
20+ import java .util .List ;
2021import java .util .Objects ;
2122import java .util .Set ;
2223import java .util .stream .Collectors ;
@@ -82,7 +83,7 @@ public IStatus run(IProgressMonitor monitor) {
8283 VMStandin workingCopy = new VMStandin (standardType , f .getAbsolutePath ());
8384 workingCopy .setInstallLocation (f );
8485 String name = f .getName ();
85- int i = 1 ;
86+ int i = 2 ;
8687 while (isDuplicateName (name )) {
8788 name = f .getName () + '(' + i ++ + ')' ;
8889 }
@@ -103,7 +104,7 @@ public IStatus run(IProgressMonitor monitor) {
103104 }
104105 SubMonitor subMon = SubMonitor .convert (monitor , systemVM .getInstallLocation ().getAbsolutePath (), 1 );
105106 String name = systemVM .getName ();
106- int i = 1 ;
107+ int i = 2 ;
107108 while (isDuplicateName (name )) {
108109 name = systemVM .getName () + '(' + i ++ + ')' ;
109110 }
@@ -129,7 +130,9 @@ private boolean isDuplicateName(String name) {
129130 private Collection <File > computeCandidateVMs (StandardVMType standardType ) {
130131 // parent directories containing a collection of VM installations
131132 Collection <File > rootDirectories = new HashSet <>();
132- if (!Platform .OS_WIN32 .equals (Platform .getOS ())) {
133+ if (Platform .OS_WIN32 .equals (Platform .getOS ())) {
134+ computeWindowsCandidates (rootDirectories );
135+ } else {
133136 rootDirectories .add (new File ("/usr/lib/jvm" )); //$NON-NLS-1$
134137 }
135138 rootDirectories .add (new File (System .getProperty ("user.home" ), ".sdkman/candidates/java" )); //$NON-NLS-1$ //$NON-NLS-2$
@@ -165,6 +168,18 @@ private Collection<File> computeCandidateVMs(StandardVMType standardType) {
165168 .collect (Collectors .toCollection (HashSet ::new ));
166169 }
167170
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+
168183 private static Set <File > knownVMs () {
169184 return Stream .of (JavaRuntime .getVMInstallTypes ())
170185 .map (IVMInstallType ::getVMInstalls )
0 commit comments