use of org.eclipse.jdt.internal.launching.StandardVMType in project eclipse.jdt.ls by eclipse.
the class JVMConfiguratorTest method testJVM.
@Test
public void testJVM() throws Exception {
try {
Preferences prefs = new Preferences();
Bundle bundle = Platform.getBundle(JavaLanguageServerTestPlugin.PLUGIN_ID);
URL url = FileLocator.toFileURL(bundle.getEntry("/fakejdk2/11a"));
File file = URIUtil.toFile(URIUtil.toURI(url));
String path = file.getAbsolutePath();
String javadoc = "file:///javadoc";
Set<RuntimeEnvironment> runtimes = new HashSet<>();
RuntimeEnvironment runtime = new RuntimeEnvironment();
runtime.setPath(path);
runtime.setName(ENVIRONMENT_NAME);
runtime.setJavadoc(javadoc);
runtime.setDefault(true);
assertTrue(runtime.isValid());
runtimes.add(runtime);
prefs.setRuntimes(runtimes);
file = runtime.getInstallationFile();
assertTrue(file != null && file.isDirectory());
IVMInstallType installType = JavaRuntime.getVMInstallType(StandardVMType.ID_STANDARD_VM_TYPE);
IStatus status = installType.validateInstallLocation(file);
assertTrue(status.toString(), status.isOK());
boolean changed = JVMConfigurator.configureJVMs(prefs);
assertTrue("A VM hasn't been changed", changed);
JobHelpers.waitForJobsToComplete();
IVMInstall vm = JVMConfigurator.findVM(runtime.getInstallationFile(), ENVIRONMENT_NAME);
assertNotNull(vm);
assertTrue(vm instanceof IVMInstall2);
String version = ((IVMInstall2) vm).getJavaVersion();
assertTrue(version.startsWith(JavaCore.VERSION_11));
StandardVMType svt = (StandardVMType) vm.getVMInstallType();
LibraryLocation[] libs = vm.getLibraryLocations();
assertNotNull(libs);
for (LibraryLocation lib : libs) {
assertEquals(runtime.getJavadocURL(), lib.getJavadocLocation());
}
IVMInstall newDefaultVM = JavaRuntime.getDefaultVMInstall();
assertNotEquals(originalVm, newDefaultVM);
assertEquals(vm, newDefaultVM);
IExecutionEnvironment environment = JVMConfigurator.getExecutionEnvironment(ENVIRONMENT_NAME);
assertNotNull(environment);
assertEquals(vm, environment.getDefaultVM());
} finally {
IVMInstall vm = JVMConfigurator.findVM(null, ENVIRONMENT_NAME);
if (vm != null) {
vm.getVMInstallType().disposeVMInstall(vm.getId());
}
}
IVMInstall vm = JVMConfigurator.findVM(null, ENVIRONMENT_NAME);
assertNull(vm);
}
use of org.eclipse.jdt.internal.launching.StandardVMType in project eclipse.jdt.ls by eclipse.
the class JVMConfigurator method configureJVMs.
public static boolean configureJVMs(Preferences preferences, JavaClientConnection connection) throws CoreException {
boolean changed = false;
boolean defaultVMSet = false;
Set<RuntimeEnvironment> runtimes = preferences.getRuntimes();
for (RuntimeEnvironment runtime : runtimes) {
if (runtime.isValid()) {
File file = runtime.getInstallationFile();
if (file != null && file.isDirectory()) {
URL javadocURL = runtime.getJavadocURL();
IPath sourcePath = runtime.getSourcePath();
IVMInstall vm = findVM(file, runtime.getName());
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
IVMInstallType macInstallType = JavaRuntime.getVMInstallType(MAC_OSX_VM_TYPE);
if (macInstallType != null) {
installType = macInstallType;
}
}
VMStandin vmStandin;
if (vm == null) {
long unique = System.currentTimeMillis();
while (installType.findVMInstall(String.valueOf(unique)) != null) {
unique++;
}
String vmId = String.valueOf(unique);
vmStandin = new VMStandin(installType, vmId);
changed = true;
} else {
vmStandin = new VMStandin(vm);
changed = changed || !runtime.getName().equals(vm.getName()) || !runtime.getInstallationFile().equals(vm.getInstallLocation());
}
IStatus status = installType.validateInstallLocation(file);
if (!status.isOK()) {
if (Objects.equals(file.getName(), "bin")) {
sendNotification(connection, "Invalid runtime for " + runtime.getName() + ": 'bin' should be removed from the path (" + runtime.getPath() + ").");
} else {
sendNotification(connection, "Invalid runtime for " + runtime.getName() + ": The path (" + runtime.getPath() + ") does not point to a JDK.");
}
JavaLanguageServerPlugin.log(status);
continue;
}
vmStandin.setName(runtime.getName());
vmStandin.setInstallLocation(file);
if (sourcePath != null || javadocURL != null) {
LibraryLocation[] libs;
if (vm != null && vm.getLibraryLocations() != null) {
libs = vm.getLibraryLocations();
} else {
StandardVMType svt = (StandardVMType) installType;
libs = svt.getDefaultLibraryLocations(file);
}
boolean libChanged = false;
if (libs != null) {
for (int i = 0; i < libs.length; i++) {
LibraryLocation lib = libs[i];
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;
}
}
if (libChanged) {
LibraryLocation[] newLibs = Arrays.copyOf(libs, libs.length);
vmStandin.setLibraryLocations(newLibs);
changed = true;
}
}
vm = vmStandin.convertToRealVM();
if (runtime.isDefault()) {
defaultVMSet = true;
if (!Objects.equals(vm, JavaRuntime.getDefaultVMInstall())) {
JavaLanguageServerPlugin.logInfo("Setting runtime " + runtime.getName() + "-" + runtime.getInstallationFile() + " as default global VM");
JavaRuntime.setDefaultVMInstall(vm, new NullProgressMonitor());
changed = true;
}
}
if (!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");
}
} else {
sendNotification(connection, "Invalid runtime for " + runtime.getName() + ": The path points to a missing or inaccessible folder (" + runtime.getPath() + ").");
JavaLanguageServerPlugin.logInfo("Invalid runtime: " + runtime);
}
}
}
if (!defaultVMSet) {
changed = configureDefaultVM(preferences.getJavaHome()) || changed;
}
if (changed) {
JavaLanguageServerPlugin.logInfo("JVM Runtimes changed, saving new configuration");
JavaRuntime.saveVMConfiguration();
}
return changed;
}
use of org.eclipse.jdt.internal.launching.StandardVMType in project eclipse.jdt.ls by eclipse.
the class GradleProjectImporter method startSynchronization.
protected IStatus startSynchronization(Path projectFolder, IProgressMonitor monitor) {
File location = projectFolder.toFile();
boolean shouldSynchronize = shouldSynchronize(location);
if (shouldSynchronize) {
BuildConfiguration build = getBuildConfiguration(projectFolder);
GradleBuild gradleBuild = GradleCore.getWorkspace().createBuild(build);
SynchronizationResult result = gradleBuild.synchronize(monitor);
IStatus resultStatus = result.getStatus();
if (isFailedStatus(resultStatus)) {
try {
BuildEnvironment environment = gradleBuild.withConnection(connection -> connection.getModel(BuildEnvironment.class), monitor);
GradleEnvironment gradleEnvironment = environment.getGradle();
String gradleVersion = gradleEnvironment.getGradleVersion();
File javaHome = getJavaHome(getPreferences());
String javaVersion;
if (javaHome == null) {
javaVersion = System.getProperty("java.version");
} else {
StandardVMType type = new StandardVMType();
javaVersion = type.readReleaseVersion(javaHome);
}
if (GradleCompatibilityChecker.isIncompatible(GradleVersion.version(gradleVersion), javaVersion)) {
Path projectName = projectFolder.getName(projectFolder.getNameCount() - 1);
String message = String.format("Can't use Java %s and Gradle %s to import Gradle project %s.", javaVersion, gradleVersion, projectName.toString());
String highestJavaVersion = GradleCompatibilityChecker.getHighestSupportedJava(GradleVersion.version(gradleVersion));
return new GradleCompatibilityStatus(resultStatus, message, projectFolder.toUri().toString(), highestJavaVersion);
}
} catch (Exception e) {
// Do nothing
}
}
return resultStatus;
}
return Status.OK_STATUS;
}
Aggregations