Java Code Examples for org.eclipse.jdt.launching.JavaRuntime#getVMInstallType()
The following examples show how to use
org.eclipse.jdt.launching.JavaRuntime#getVMInstallType() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GradleProjectImporterTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
@Test public void testJavaHome() throws Exception { Preferences prefs = JavaLanguageServerPlugin.getPreferencesManager().getPreferences(); String javaHomePreference = prefs.getJavaHome(); IVMInstall defaultVM = JavaRuntime.getDefaultVMInstall(); try { IVMInstallType installType = JavaRuntime.getVMInstallType(StandardVMType.ID_STANDARD_VM_TYPE); IVMInstall[] vms = installType.getVMInstalls(); IVMInstall vm = vms[0]; JavaRuntime.setDefaultVMInstall(vm, new NullProgressMonitor()); String javaHome = new File(TestVMType.getFakeJDKsLocation(), "11").getAbsolutePath(); prefs.setJavaHome(javaHome); IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); IPath rootFolder = root.getLocation().append("/projects/gradle/simple-gradle"); BuildConfiguration build = GradleProjectImporter.getBuildConfiguration(rootFolder.toFile().toPath()); assertEquals(vm.getInstallLocation().getAbsolutePath(), build.getJavaHome().get().getAbsolutePath()); } finally { prefs.setJavaHome(javaHomePreference); if (defaultVM != null) { JavaRuntime.setDefaultVMInstall(defaultVM, new NullProgressMonitor()); } } }
Example 2
Source File: JVMConfigurator.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
public static boolean configureDefaultVM(String javaHome) throws CoreException { if (StringUtils.isBlank(javaHome)) { return false; } File jvmHome = new File(javaHome); if (jvmHome.isDirectory()) { IVMInstall defaultVM = JavaRuntime.getDefaultVMInstall(); if (defaultVM != null && jvmHome.equals(defaultVM.getInstallLocation())) { return false; } } else { JavaLanguageServerPlugin.logInfo("java.home " + jvmHome + " is not a directory"); return false; } IVMInstall vm = findVM(jvmHome, null); if (vm == null) { IVMInstallType installType = JavaRuntime.getVMInstallType(StandardVMType.ID_STANDARD_VM_TYPE); long unique = System.currentTimeMillis(); while (installType.findVMInstall(String.valueOf(unique)) != null) { unique++; } String vmId = String.valueOf(unique); VMStandin vmStandin = new VMStandin(installType, vmId); String name = StringUtils.defaultIfBlank(jvmHome.getName(), "JRE"); vmStandin.setName(name); vmStandin.setInstallLocation(jvmHome); vm = vmStandin.convertToRealVM(); } JavaLanguageServerPlugin.logInfo("Setting java.home " + jvmHome + " as default global VM"); JavaRuntime.setDefaultVMInstall(vm, new NullProgressMonitor()); JDTUtils.setCompatibleVMs(vm.getId()); return true; }
Example 3
Source File: TestVMType.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
public static void setTestJREAsDefault(String vmId) throws CoreException { IVMInstallType vmInstallType = JavaRuntime.getVMInstallType(VMTYPE_ID); IVMInstall testVMInstall = vmInstallType.findVMInstall(vmId); if (!testVMInstall.equals(JavaRuntime.getDefaultVMInstall())) { // set the 1.8 test JRE as the new default JRE JavaRuntime.setDefaultVMInstall(testVMInstall, new NullProgressMonitor()); Hashtable<String, String> options = JavaCore.getOptions(); JavaCore.setComplianceOptions(vmId, options); JavaCore.setOptions(options); } JDTUtils.setCompatibleVMs(VMTYPE_ID); }