diff --git a/org.eclipse.jdt.launching/launching/org/eclipse/jdt/internal/launching/DetectVMInstallationsJob.java b/org.eclipse.jdt.launching/launching/org/eclipse/jdt/internal/launching/DetectVMInstallationsJob.java index cc5ebf5198..b3806578fb 100644 --- a/org.eclipse.jdt.launching/launching/org/eclipse/jdt/internal/launching/DetectVMInstallationsJob.java +++ b/org.eclipse.jdt.launching/launching/org/eclipse/jdt/internal/launching/DetectVMInstallationsJob.java @@ -17,6 +17,7 @@ import java.util.Collection; import java.util.Collections; import java.util.HashSet; +import java.util.List; import java.util.Objects; import java.util.Set; import java.util.stream.Collectors; @@ -82,7 +83,7 @@ public IStatus run(IProgressMonitor monitor) { VMStandin workingCopy = new VMStandin(standardType, f.getAbsolutePath()); workingCopy.setInstallLocation(f); String name = f.getName(); - int i = 1; + int i = 2; while (isDuplicateName(name)) { name = f.getName() + '(' + i++ + ')'; } @@ -103,7 +104,7 @@ public IStatus run(IProgressMonitor monitor) { } SubMonitor subMon = SubMonitor.convert(monitor, systemVM.getInstallLocation().getAbsolutePath(), 1); String name = systemVM.getName(); - int i = 1; + int i = 2; while (isDuplicateName(name)) { name = systemVM.getName() + '(' + i++ + ')'; } @@ -129,7 +130,9 @@ private boolean isDuplicateName(String name) { private Collection computeCandidateVMs(StandardVMType standardType) { // parent directories containing a collection of VM installations Collection rootDirectories = new HashSet<>(); - if (!Platform.OS_WIN32.equals(Platform.getOS())) { + if (Platform.OS_WIN32.equals(Platform.getOS())) { + computeWindowsCandidates(rootDirectories); + } else { rootDirectories.add(new File("/usr/lib/jvm")); //$NON-NLS-1$ } rootDirectories.add(new File(System.getProperty("user.home"), ".sdkman/candidates/java")); //$NON-NLS-1$ //$NON-NLS-2$ @@ -165,6 +168,18 @@ private Collection computeCandidateVMs(StandardVMType standardType) { .collect(Collectors.toCollection(HashSet::new)); } + private void computeWindowsCandidates(Collection rootDirectories) { + List progFiles = List.of("ProgramFiles", "ProgramFiles(x86)"); //$NON-NLS-1$//$NON-NLS-2$ + List subDirs = List.of("Eclipse Adoptium", "RedHat"); //$NON-NLS-1$//$NON-NLS-2$ + rootDirectories.addAll( + progFiles.stream() + .map(name -> System.getenv(name)) + .filter(Objects::nonNull) + .distinct() + .flatMap(progFilesDir -> subDirs.stream().map(subDir -> new File(progFilesDir, subDir))) + .collect(Collectors.toList())); + } + private static Set knownVMs() { return Stream.of(JavaRuntime.getVMInstallTypes()) .map(IVMInstallType::getVMInstalls) diff --git a/org.eclipse.jdt.launching/launching/org/eclipse/jdt/internal/launching/LaunchingMessages.properties b/org.eclipse.jdt.launching/launching/org/eclipse/jdt/internal/launching/LaunchingMessages.properties index 147ebb2e5c..dd09cad639 100644 --- a/org.eclipse.jdt.launching/launching/org/eclipse/jdt/internal/launching/LaunchingMessages.properties +++ b/org.eclipse.jdt.launching/launching/org/eclipse/jdt/internal/launching/LaunchingMessages.properties @@ -207,5 +207,5 @@ RunnerBootpathPError=Xbootclasspath/p option have been removed as not supported VMLogging_1=Restoring vm library location: VMLogging_2=Creating Library with Java Install path: VMLogging_3=Default Install retrieved: -lookupInstalledJVMs=Look up for installed JVMs +lookupInstalledJVMs=Detect installed JVMs configuringJVM=Configuring installed JVM {0} \ No newline at end of file