Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion org.eclipse.jdt.launching/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.jdt.launching; singleton:=true
Bundle-Version: 3.23.500.qualifier
Bundle-Version: 3.24.0.qualifier
Bundle-Activator: org.eclipse.jdt.internal.launching.LaunchingPlugin
Bundle-Vendor: %providerName
Bundle-Localization: plugin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Arrays;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
Expand Down Expand Up @@ -178,31 +177,16 @@ public static IVMInstall resolveVM(IExecutionEnvironment environment) {
}
IVMInstall vm = environment.getDefaultVM();
if (vm == null) {
IVMInstall[] installs = environment.getCompatibleVMs();
// take the first strictly compatible VM if there is no default
if (installs.length == 0 && LaunchingPlugin.DEBUG_JRE_CONTAINER) {
vm = environment.getCompatibleVM();
if (vm == null) {
LaunchingPlugin.trace("\t*** NO COMPATIBLE VMS ***"); //$NON-NLS-1$
return null;
}
for (int i = 0; i < installs.length; i++) {
IVMInstall install = installs[i];
if (environment.isStrictlyCompatible(install)) {
vm = install;
if (LaunchingPlugin.DEBUG_JRE_CONTAINER) {
LaunchingPlugin.trace("\tPerfect Match: " + vm.getName()); //$NON-NLS-1$
}
break;
}
}
//try the default VM install: https://bugs.eclipse.org/bugs/show_bug.cgi?id=371300
// if default vm is a match https://bugs.eclipse.org/bugs/show_bug.cgi?id=484026
if (vm == null && installs.length > 0 && Arrays.asList(installs).contains(JavaRuntime.getDefaultVMInstall())) {
vm = JavaRuntime.getDefaultVMInstall();
}
// use the first VM failing that
if (vm == null && installs.length > 0) {
vm = installs[0];
if (LaunchingPlugin.DEBUG_JRE_CONTAINER) {
LaunchingPlugin.trace("\tFirst Match: " + vm.getName()); //$NON-NLS-1$
if (LaunchingPlugin.DEBUG_JRE_CONTAINER) {
if (environment.isStrictlyCompatible(vm)) {
LaunchingPlugin.trace("\tPerfect Match: " + vm.getName()); //$NON-NLS-1$
} else {
LaunchingPlugin.trace("\tUse compatible VM: " + vm.getName()); //$NON-NLS-1$
}
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.internal.launching.LaunchingPlugin;
import org.eclipse.jdt.launching.IVMInstall;
import org.eclipse.jdt.launching.IVMInstall2;
import org.eclipse.jdt.launching.IVMInstallChangedListener;
import org.eclipse.jdt.launching.JavaRuntime;
import org.eclipse.jdt.launching.LibraryLocation;
Expand Down Expand Up @@ -210,6 +211,75 @@ public IVMInstall[] getCompatibleVMs() {
return fCompatibleVMs.toArray(new IVMInstall[fCompatibleVMs.size()]);
}

@Override
public IVMInstall getCompatibleVM() {
init();
if (fCompatibleVMs.isEmpty()) {
return null;
}
if (fCompatibleVMs.size() == 1) {
return fCompatibleVMs.get(0);
}
if (!fStrictlyCompatible.isEmpty()) {
// first lean to the default if it is strictly compatible
IVMInstall workspaceDefaultVMInstall = JavaRuntime.getDefaultVMInstall();
if (fStrictlyCompatible.contains(workspaceDefaultVMInstall)) {
return workspaceDefaultVMInstall;
}
return fStrictlyCompatible.iterator().next();
}
IVMInstall best = null;
java.lang.Runtime.Version bestVersion = null;
for (IVMInstall vm : fCompatibleVMs) {
java.lang.Runtime.Version vmVersion = getRuntimeVersion(vm);
if (isBetter(vmVersion, bestVersion)) {
bestVersion = vmVersion;
best = vm;
}
}
return best;
}

private boolean isBetter(java.lang.Runtime.Version version, java.lang.Runtime.Version other) {
if (other == null) {
return true;
}
if (version == null) {
return false;
}
if (version.feature() < other.feature()) {
// lower major (== feature) is better!
return true;
}
if (version.feature() > other.feature()) {
// higher is not better!
return false;
}
if (version.feature() == 1) {
// special case for java 1.x versions, lower minor (== interim) is better!
if (version.interim() < other.interim()) {
return true;
}
if (version.interim() > other.interim()) {
return false;
}
}
// when we are here we have equally good versions, e.g. two Java 11, we choose now the one that is better in the given interim/patch levels
// and can use the default compare of version
return version.compareTo(other) > 0;
}

private java.lang.Runtime.Version getRuntimeVersion(IVMInstall vm) {
if (vm instanceof IVMInstall2 vm2) {
try {
return Runtime.Version.parse(vm2.getJavaVersion());
} catch (RuntimeException e) {
// in this case we can't know the version...
}
}
return null;
}

/* (non-Javadoc)
* @see org.eclipse.jdt.launching.environments.IExecutionEnvironment#isStrictlyCompatible(org.eclipse.jdt.launching.IVMInstall)
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,19 @@ public interface IExecutionEnvironment {
*/
public IVMInstall[] getCompatibleVMs();

/**
* Return the vm that is best matching this environment that is:
*
* <ol>
* <li>if a strictly compatible is found this one is returned, if multiple are strictly compatible it picks one randomly</li>
* <li>in all other case it choose the one with the lowest version, if multiple match the same version it picks one randomly</li>
* </ol>
*
* @return the best compatible VM or <code>null</code> if none is found
* @since 3.24
*/
public IVMInstall getCompatibleVM();

/**
* Returns whether the specified VM install is strictly compatible with
* this environment. Returns <code>true</code> to indicate the VM install
Expand Down
2 changes: 1 addition & 1 deletion org.eclipse.jdt.launching/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
</parent>
<groupId>org.eclipse.jdt</groupId>
<artifactId>org.eclipse.jdt.launching</artifactId>
<version>3.23.500-SNAPSHOT</version>
<version>3.24.0-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>

<build>
Expand Down
Loading