Skip to content

Commit a3c0c22

Browse files
Bananeweizenjukzi
authored andcommitted
Detect Windows JVMs
The JDK detection mechanism doesn't find much on Windows. Have it find the default installation directories of Adoptium and RedHat. Further providers can easily be added without changing the code logic. Also let duplicate VM names start with index 2, not 1. And finally improve the job name.
1 parent 6cab2be commit a3c0c22

2 files changed

Lines changed: 19 additions & 4 deletions

File tree

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

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import java.util.Collection;
1818
import java.util.Collections;
1919
import java.util.HashSet;
20+
import java.util.List;
2021
import java.util.Objects;
2122
import java.util.Set;
2223
import 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)

org.eclipse.jdt.launching/launching/org/eclipse/jdt/internal/launching/LaunchingMessages.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,5 +207,5 @@ RunnerBootpathPError=Xbootclasspath/p option have been removed as not supported
207207
VMLogging_1=Restoring vm library location:
208208
VMLogging_2=Creating Library with Java Install path:
209209
VMLogging_3=Default Install retrieved:
210-
lookupInstalledJVMs=Look up for installed JVMs
210+
lookupInstalledJVMs=Detect installed JVMs
211211
configuringJVM=Configuring installed JVM {0}

0 commit comments

Comments
 (0)