Skip to content

Commit

Permalink
Detect Windows JVMs
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Bananeweizen authored and jukzi committed Oct 18, 2024
1 parent 6cab2be commit a3c0c22
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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++ + ')';
}
Expand All @@ -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++ + ')';
}
Expand All @@ -129,7 +130,9 @@ private boolean isDuplicateName(String name) {
private Collection<File> computeCandidateVMs(StandardVMType standardType) {
// parent directories containing a collection of VM installations
Collection<File> 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$
Expand Down Expand Up @@ -165,6 +168,18 @@ private Collection<File> computeCandidateVMs(StandardVMType standardType) {
.collect(Collectors.toCollection(HashSet::new));
}

private void computeWindowsCandidates(Collection<File> rootDirectories) {
List<String> progFiles = List.of("ProgramFiles", "ProgramFiles(x86)"); //$NON-NLS-1$//$NON-NLS-2$
List<String> 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<File> knownVMs() {
return Stream.of(JavaRuntime.getVMInstallTypes())
.map(IVMInstallType::getVMInstalls)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}

0 comments on commit a3c0c22

Please sign in to comment.