Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Allow multiple jdk registration for one runtime environment #3107

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@
import java.net.URL;
import java.util.Arrays;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;

import org.apache.commons.lang3.StringUtils;
import org.eclipse.core.resources.IProject;
Expand Down Expand Up @@ -73,7 +75,7 @@ public static boolean configureDefaultVM(String javaHome) throws CoreException {
return false;
}

IVMInstall vm = findVM(jvmHome, null);
IVMInstall vm = findVM(jvmHome);
if (vm == null) {
IVMInstallType installType = JavaRuntime.getVMInstallType(StandardVMType.ID_STANDARD_VM_TYPE);
if (installType == null || installType.getVMInstalls().length == 0) {
Expand Down Expand Up @@ -109,13 +111,19 @@ public static boolean configureJVMs(Preferences preferences, JavaClientConnectio
boolean changed = false;
boolean defaultVMSet = false;
Set<RuntimeEnvironment> runtimes = preferences.getRuntimes();
for (RuntimeEnvironment runtime : runtimes) {
if (runtime.isValid()) {
Map<String, List<RuntimeEnvironment>> environments = runtimes
.stream()
.filter(RuntimeEnvironment::isValid)
.collect(Collectors.groupingBy(RuntimeEnvironment::getName));
for (String environmentName : environments.keySet()) {
List<RuntimeEnvironment> envRuntimes = environments.get(environmentName);
for (int i = 0; i < envRuntimes.size(); i++) {
RuntimeEnvironment runtime = envRuntimes.get(i);
File file = runtime.getInstallationFile();
if (file != null && file.isDirectory()) {
URL javadocURL = runtime.getJavadocURL();
IPath sourcePath = runtime.getSourcePath();
IVMInstall vm = findVM(file, runtime.getName());
IVMInstall vm = findVM(file);
IVMInstallType installType = JavaRuntime.getVMInstallType(StandardVMType.ID_STANDARD_VM_TYPE);
if (installType == null || installType.getVMInstalls().length == 0) {
// https://github.com/eclipse/eclipse.jdt.ls/issues/1646
Expand Down Expand Up @@ -163,13 +171,13 @@ public static boolean configureJVMs(Preferences preferences, JavaClientConnectio
}
boolean libChanged = false;
if (libs != null) {
for (int i = 0; i < libs.length; i++) {
LibraryLocation lib = libs[i];
for (int j = 0; j < libs.length; j++) {
LibraryLocation lib = libs[j];
IPath systemSourcePath = sourcePath != null ? sourcePath : lib.getSystemLibrarySourcePath();
URL javadocLocation = javadocURL != null ? javadocURL : lib.getJavadocLocation();
LibraryLocation newLib = new LibraryLocation(lib.getSystemLibraryPath(), systemSourcePath, lib.getPackageRootPath(), javadocLocation, lib.getIndexLocation(), lib.getExternalAnnotationsPath());
libChanged = libChanged || !newLib.equals(lib);
libs[i] = newLib;
libs[j] = newLib;
}
}
if (libChanged) {
Expand All @@ -187,7 +195,7 @@ public static boolean configureJVMs(Preferences preferences, JavaClientConnectio
changed = true;
}
}
if (!setDefaultEnvironmentVM(vm, runtime.getName())) {
if (i == 0 && !setDefaultEnvironmentVM(vm, runtime.getName())) {
sendNotification(connection, "Invalid runtime for " + runtime.getName() + ": Runtime at '" + runtime.getPath() + "' is not compatible with the '" + runtime.getName() + "' environment.");
JavaLanguageServerPlugin.logError("Runtime at '" + runtime.getPath() + "' is not compatible with the '" + runtime.getName() + "' environment");
}
Expand Down Expand Up @@ -261,14 +269,11 @@ public static IExecutionEnvironment getExecutionEnvironment(String name) {
return null;
}

public static IVMInstall findVM(File file, String name) {
public static IVMInstall findVM(File file) {
IVMInstallType[] types = JavaRuntime.getVMInstallTypes();
for (IVMInstallType type : types) {
IVMInstall[] installs = type.getVMInstalls();
for (IVMInstall install : installs) {
if (name != null && name.equals(install.getName())) {
return install;
}
if (file != null && file.equals(install.getInstallLocation())) {
return install;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.Objects;

import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
Expand Down Expand Up @@ -109,14 +110,8 @@ public boolean equals(Object obj) {
return false;
}
RuntimeEnvironment other = (RuntimeEnvironment) obj;
if (name == null) {
if (other.name != null) {
return false;
}
} else if (!name.equals(other.name)) {
return false;
}
return true;
return Objects.equals(name, other.name) &&
Objects.equals(path, other.path);
}

public boolean isValid() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1215,7 +1215,7 @@ public static Preferences createFrom(Map<String, Object> configuration) {
prefs.setStaticImportOnDemandThreshold(staticOnDemandThreshold);

List<?> runtimeList = getList(configuration, JAVA_CONFIGURATION_RUNTIMES, JAVA_CONFIGURATION_RUNTIMES_DEFAULT);
Set<RuntimeEnvironment> runtimes = new HashSet<>();
Set<RuntimeEnvironment> runtimes = new LinkedHashSet<>();
boolean[] hasDefault = { false };
for (Object object : runtimeList) {
if (object instanceof Map<?, ?> map) {
Expand Down
Loading