Java Code Examples for org.eclipse.jdt.launching.IVMInstall#getInstallLocation()
The following examples show how to use
org.eclipse.jdt.launching.IVMInstall#getInstallLocation() .
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: JreDetector.java From google-cloud-eclipse with Apache License 2.0 | 6 votes |
@VisibleForTesting static boolean isDevelopmentKit(IExecutionEnvironmentsManager manager, IVMInstall install) { File root = install.getInstallLocation(); String executionEnvironment = determineExecutionEnvironment(manager, install); switch (executionEnvironment) { case JAVASE7: case JAVASE8: // JDKs on Windows, Linux, and MacOS all have lib/tools.jar File tools = new File(root, "lib/tools.jar"); return tools.exists(); case JAVASE9: case JAVASE10: // JDKs on Windows, Linux, and MacOS all have jmods/java.compiler.mod File compilerModule = new File(root, "jmods/java.compiler.jmod"); return compilerModule.exists(); default: logger.log(Level.WARNING, "Unknown Java installation type: " + executionEnvironment); return false; } }
Example 2
Source File: ProjectCommand.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
/** * Gets the project settings. * * @param uri * Uri of the source/class file that needs to be queried. * @param settingKeys * the settings we want to query, for example: * ["org.eclipse.jdt.core.compiler.compliance", * "org.eclipse.jdt.core.compiler.source"]. * Besides the options defined in JavaCore, the following keys can also be used: * - "org.eclipse.jdt.ls.core.vm.location": Get the location of the VM assigned to build the given Java project * @return A <code>Map<string, string></code> with all the setting keys and * their values. * @throws CoreException * @throws URISyntaxException */ public static Map<String, String> getProjectSettings(String uri, List<String> settingKeys) throws CoreException, URISyntaxException { IJavaProject javaProject = getJavaProjectFromUri(uri); Map<String, String> settings = new HashMap<>(); for (String key : settingKeys) { switch(key) { case VM_LOCATION: IVMInstall vmInstall = JavaRuntime.getVMInstall(javaProject); if (vmInstall == null) { continue; } File location = vmInstall.getInstallLocation(); if (location == null) { continue; } settings.putIfAbsent(key, location.getAbsolutePath()); break; default: settings.putIfAbsent(key, javaProject.getOption(key, true)); break; } } return settings; }
Example 3
Source File: ResolveJavaExecutableHandler.java From java-debug with Eclipse Public License 1.0 | 5 votes |
/** * Resolve the java executable path from the project's java runtime. */ public static String resolveJavaExecutable(List<Object> arguments) throws Exception { try { String mainClass = (String) arguments.get(0); String projectName = (String) arguments.get(1); IJavaProject targetProject = null; if (StringUtils.isNotBlank(projectName)) { targetProject = JdtUtils.getJavaProject(projectName); } else { List<IJavaProject> targetProjects = ResolveClasspathsHandler.getJavaProjectFromType(mainClass); if (!targetProjects.isEmpty()) { targetProject = targetProjects.get(0); } } if (targetProject == null) { return null; } IVMInstall vmInstall = JavaRuntime.getVMInstall(targetProject); if (vmInstall == null || vmInstall.getInstallLocation() == null) { return null; } File exe = findJavaExecutable(vmInstall.getInstallLocation()); if (exe == null) { return null; } return exe.getAbsolutePath(); } catch (CoreException e) { logger.log(Level.SEVERE, "Failed to resolve java executable: " + e.getMessage(), e); } return null; }
Example 4
Source File: JVMConfigurator.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
@Override public void defaultVMInstallChanged(IVMInstall previous, IVMInstall current) { if (Objects.equals(previous, current)) { return; } String prev = (previous == null) ? null : previous.getId() + "-" + previous.getInstallLocation(); String curr = (current == null) ? null : current.getId() + "-" + current.getInstallLocation(); JavaLanguageServerPlugin.logInfo("Default VM Install changed from " + prev + " to " + curr); //Reset global compliance settings AbstractVMInstall jvm = (AbstractVMInstall) current; long jdkLevel = CompilerOptions.versionToJdkLevel(jvm.getJavaVersion()); String compliance = CompilerOptions.versionFromJdkLevel(jdkLevel); Hashtable<String, String> options = JavaCore.getOptions(); JavaCore.setComplianceOptions(compliance, options); JavaCore.setOptions(options); IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects(); for (IProject project : projects) { if (!ProjectUtils.isVisibleProject(project) && ProjectUtils.isJavaProject(project)) { IJavaProject javaProject = JavaCore.create(project); configureJVMSettings(javaProject, current); } ProjectsManager projectsManager = JavaLanguageServerPlugin.getProjectsManager(); if (projectsManager != null) { //TODO Only trigger update if the project uses the default JVM JavaLanguageServerPlugin.logInfo("defaultVMInstallChanged -> force update of " + project.getName()); projectsManager.updateProject(project, true); } } }
Example 5
Source File: GradleProjectImporter.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
public static BuildConfiguration getBuildConfiguration(Path rootFolder) { GradleDistribution distribution = getGradleDistribution(rootFolder); IVMInstall javaDefaultRuntime = JavaRuntime.getDefaultVMInstall(); File javaHome; Preferences preferences = getPreferences(); if (javaDefaultRuntime != null && javaDefaultRuntime.getVMRunner(ILaunchManager.RUN_MODE) != null) { javaHome = javaDefaultRuntime.getInstallLocation(); } else { String javaHomeStr = preferences.getJavaHome(); javaHome = javaHomeStr == null ? null : new File(javaHomeStr); } File gradleUserHome = getGradleUserHomeFile(); List<String> gradleArguments = preferences.getGradleArguments(); List<String> gradleJvmArguments = preferences.getGradleJvmArguments(); boolean offlineMode = preferences.isImportGradleOfflineEnabled(); boolean overrideWorkspaceConfiguration = !(distribution instanceof WrapperGradleDistribution) || offlineMode || (gradleArguments != null && !gradleArguments.isEmpty()) || (gradleJvmArguments != null && !gradleJvmArguments.isEmpty()) || gradleUserHome != null || javaHome != null; // @formatter:off BuildConfiguration build = BuildConfiguration.forRootProjectDirectory(rootFolder.toFile()) .overrideWorkspaceConfiguration(overrideWorkspaceConfiguration) .gradleDistribution(distribution) .javaHome(javaHome) .arguments(gradleArguments) .gradleUserHome(gradleUserHome) .jvmArguments(gradleJvmArguments) .offlineMode(offlineMode) .build(); // @formatter:on return build; }
Example 6
Source File: ProjectCommandTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
@Test public void testGetProjectVMInstallation() throws Exception { importProjects("maven/salut2"); IProject project = WorkspaceHelper.getProject("salut2"); String uriString = project.getFile("src/main/java/foo/Bar.java").getLocationURI().toString(); List<String> settingKeys = Arrays.asList(ProjectCommand.VM_LOCATION); Map<String, String> options = ProjectCommand.getProjectSettings(uriString, settingKeys); IJavaProject javaProject = ProjectCommand.getJavaProjectFromUri(uriString); IVMInstall vmInstall = JavaRuntime.getVMInstall(javaProject); assertNotNull(vmInstall); File location = vmInstall.getInstallLocation(); assertNotNull(location); assertEquals(location.getAbsolutePath(), options.get(ProjectCommand.VM_LOCATION)); }