org.eclipse.jdt.launching.environments.IExecutionEnvironmentsManager Java Examples
The following examples show how to use
org.eclipse.jdt.launching.environments.IExecutionEnvironmentsManager.
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: JreDetector.java From google-cloud-eclipse with Apache License 2.0 | 6 votes |
/** Return the best Execution Environment ID for the given VM. */ @VisibleForTesting static String determineExecutionEnvironment( IExecutionEnvironmentsManager manager, IVMInstall install) { // A VM may be marked for several Java execution environments (e.g., a Java 9 VM is compatible // with Java 8 and Java 7). So check the EEs in order of most recent to oldest to return the // most specific possible. for (String environmentId : JAVASE_BY_RECENCY) { IExecutionEnvironment environment = manager.getEnvironment(environmentId); if (environment == null) { continue; } if (environment.getDefaultVM() == install) { return environment.getId(); } for (IVMInstall vm : environment.getCompatibleVMs()) { if (vm == install) { return environmentId; } } } return "UNKNOWN"; }
Example #3
Source File: JavaProjectSetupUtil.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
public static void makeJava7Default() { if (!isJava7Default) { IExecutionEnvironmentsManager manager = JavaRuntime.getExecutionEnvironmentsManager(); IExecutionEnvironment[] environments = manager.getExecutionEnvironments(); for (int i = 0; i < environments.length; i++) { IExecutionEnvironment environment = environments[i]; if (environment.getId().equals("JavaSE-1.6") && environment.getDefaultVM() == null) { IVMInstall[] compatibleVMs = environment.getCompatibleVMs(); for (IVMInstall ivmInstall : compatibleVMs) { if (ivmInstall instanceof IVMInstall2) { IVMInstall2 install2 = (IVMInstall2) ivmInstall; if (install2.getJavaVersion().startsWith("1.7")) { environment.setDefaultVM(ivmInstall); } } } } } isJava7Default = true; } }
Example #4
Source File: JavaProjectSetupUtil.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
public static void makeJava7Default() { if (!isJava7Default) { IExecutionEnvironmentsManager manager = JavaRuntime.getExecutionEnvironmentsManager(); IExecutionEnvironment[] environments = manager.getExecutionEnvironments(); for (int i = 0; i < environments.length; i++) { IExecutionEnvironment environment = environments[i]; if (environment.getId().equals("JavaSE-1.6") && environment.getDefaultVM() == null) { IVMInstall[] compatibleVMs = environment.getCompatibleVMs(); for (IVMInstall ivmInstall : compatibleVMs) { if (ivmInstall instanceof IVMInstall2) { IVMInstall2 install2 = (IVMInstall2) ivmInstall; if (install2.getJavaVersion().startsWith("1.7")) { environment.setDefaultVM(ivmInstall); } } } } } isJava7Default = true; } }
Example #5
Source File: JreDetectorTest.java From google-cloud-eclipse with Apache License 2.0 | 5 votes |
@Before public void setUp() throws IOException { javase7 = mock(IExecutionEnvironment.class, "JavaSE-1.7"); when(javase7.getId()).thenReturn("JavaSE-1.7"); javase8 = mock(IExecutionEnvironment.class, "JavaSE-1.8"); when(javase8.getId()).thenReturn("JavaSE-1.8"); javase9 = mock(IExecutionEnvironment.class, "JavaSE-9"); when(javase9.getId()).thenReturn("JavaSE-9"); javase10 = mock(IExecutionEnvironment.class, "JavaSE-10"); when(javase10.getId()).thenReturn("JavaSE-10"); manager = mock(IExecutionEnvironmentsManager.class); Map<String, IExecutionEnvironment> environments = new HashMap<>(); environments.put(javase7.getId(), javase7); environments.put(javase8.getId(), javase8); environments.put(javase9.getId(), javase9); environments.put(javase10.getId(), javase10); when(manager.getEnvironment(anyString())) .thenAnswer(invocation -> environments.get(invocation.getArgumentAt(0, String.class))); jre7 = mockOldJre("JRE7"); jdk7 = mockOldJdk("JDK7"); jre8 = mockOldJre("JRE8"); jdk8 = mockOldJdk("JDK8"); jre9 = mockModuleJre("JRE9"); jdk9 = mockModuleJdk("JDK9"); jre10 = mockModuleJre("JRE10"); jdk10 = mockModuleJdk("JDK10"); when(javase7.getDefaultVM()).thenReturn(jre7); when(javase7.getCompatibleVMs()) .thenReturn(new IVMInstall[] {jre7, jdk7, jre8, jdk8, jre9, jdk9, jre10, jdk10}); when(javase8.getDefaultVM()).thenReturn(jre8); when(javase8.getCompatibleVMs()) .thenReturn(new IVMInstall[] {jre8, jdk8, jre9, jdk9, jre10, jdk10}); when(javase9.getDefaultVM()).thenReturn(jre9); when(javase9.getCompatibleVMs()).thenReturn(new IVMInstall[] {jre9, jdk9, jre10, jdk10}); when(javase10.getDefaultVM()).thenReturn(jre10); when(javase10.getCompatibleVMs()).thenReturn(new IVMInstall[] {jre10, jdk10}); }
Example #6
Source File: JREContainerProvider.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
/** * @since 2.6 */ public static IPath getDefaultJREContainerPath() { if (defaultVMInstall() != null) { IExecutionEnvironmentsManager executionEnvironmentsManager = JavaRuntime.getExecutionEnvironmentsManager(); IExecutionEnvironment[] executionEnvironments = executionEnvironmentsManager.getExecutionEnvironments(); for (IExecutionEnvironment executionEnvironment : executionEnvironments) { if (executionEnvironment.isStrictlyCompatible(defaultVMInstall())) { return newJREContainerPath(executionEnvironment); } } } return newPreferredContainerPath(); }
Example #7
Source File: JVMConfigurator.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
public static IExecutionEnvironment getExecutionEnvironment(String name) { IExecutionEnvironmentsManager manager = JavaRuntime.getExecutionEnvironmentsManager(); IExecutionEnvironment[] environments = manager.getExecutionEnvironments(); for (IExecutionEnvironment environment : environments) { if (environment.getId().equals(name)) { return environment; } } return null; }
Example #8
Source File: JDTUtils.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
public static void setCompatibleVMs(String id) { // update all environments compatible to use the test JRE IExecutionEnvironmentsManager manager = JavaRuntime.getExecutionEnvironmentsManager(); IExecutionEnvironment[] environments = manager.getExecutionEnvironments(); for (IExecutionEnvironment environment : environments) { IVMInstall[] compatibleVMs = environment.getCompatibleVMs(); for (IVMInstall compatibleVM : compatibleVMs) { if (id.equals(compatibleVM.getVMInstallType().getId()) && compatibleVM.getVMInstallType().findVMInstall(compatibleVM.getId()) != null && !compatibleVM.equals(environment.getDefaultVM()) // Fugly way to ensure the lowest VM version is set: && (environment.getDefaultVM() == null || compatibleVM.getId().compareTo(environment.getDefaultVM().getId()) < 0)) { environment.setDefaultVM(compatibleVM); } } } }
Example #9
Source File: ProjectCreator.java From txtUML with Eclipse Public License 1.0 | 5 votes |
public static void addProjectSettings(IProject project, ProjectSettings settings, boolean includeStdLib) throws JavaModelException { IJavaProject javaProject = JavaCore.create(project); List<IClasspathEntry> entries = new ArrayList<IClasspathEntry>(); IExecutionEnvironmentsManager executionEnvironmentsManager = JavaRuntime.getExecutionEnvironmentsManager(); IExecutionEnvironment[] executionEnvironments = executionEnvironmentsManager.getExecutionEnvironments(); for (IExecutionEnvironment iExecutionEnvironment : executionEnvironments) { if (iExecutionEnvironment.getId().equals(settings.executionEnviromentID)) { entries.add(JavaCore.newContainerEntry(JavaRuntime.newJREContainerPath(iExecutionEnvironment))); break; } } IPackageFragmentRoot packageRoot = javaProject.getPackageFragmentRoot(settings.source); IPackageFragmentRoot packageRootSrcGen = javaProject.getPackageFragmentRoot(settings.sourcegen); entries.add(JavaCore.newContainerEntry(RuntimeLibraryContainerInitializer.LIBRARY_PATH)); if (includeStdLib) { entries.add(JavaCore.newSourceEntry(STDLIB_PATH)); } entries.add(JavaCore.newSourceEntry(packageRoot.getPath())); entries.add(JavaCore.newSourceEntry(packageRootSrcGen.getPath())); javaProject.setRawClasspath(entries.toArray(new IClasspathEntry[entries.size()]), null); javaProject.setOutputLocation(settings.output.getFullPath(), null); }
Example #10
Source File: ReorgCorrectionsSubProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private IExecutionEnvironment findBestMatchingEE() { IExecutionEnvironmentsManager eeManager= JavaRuntime.getExecutionEnvironmentsManager(); IExecutionEnvironment[] ees= eeManager.getExecutionEnvironments(); IExecutionEnvironment bestEE= null; String bestEECompliance= null; for (int i= 0; i < ees.length; i++) { IExecutionEnvironment ee= ees[i]; String eeCompliance= JavaModelUtil.getExecutionEnvironmentCompliance(ee); String eeId= ee.getId(); if (fRequiredVersion.equals(eeCompliance)) { if (eeId.startsWith("J") && eeId.endsWith(fRequiredVersion)) { //$NON-NLS-1$ bestEE= ee; break; // perfect match } } else if (JavaModelUtil.isVersionLessThan(eeCompliance, fRequiredVersion)) { continue; // no match } else { // possible match if (bestEE != null) { if (! eeId.startsWith("J")) { //$NON-NLS-1$ continue; // avoid taking e.g. OSGi profile if a Java profile is available } if (JavaModelUtil.isVersionLessThan(bestEECompliance, eeCompliance)) { continue; // the other one is the least matching } } } // found a new best bestEE= ee; bestEECompliance= eeCompliance; } return bestEE; }
Example #11
Source File: JreDetector.java From google-cloud-eclipse with Apache License 2.0 | 4 votes |
/** Return {@code true} if the VM installation appears to be a JDK. */ public static boolean isDevelopmentKit(IVMInstall install) { IExecutionEnvironmentsManager manager = JavaRuntime.getExecutionEnvironmentsManager(); return isDevelopmentKit(manager, install); }
Example #12
Source File: JavaRuntimeUtils.java From google-cloud-eclipse with Apache License 2.0 | 4 votes |
/** * Return {@code true} if we have a Java 8 compatible VM available. Intended for use with * {@link org.junit.Assume}. */ public static boolean hasJavaSE8() { IExecutionEnvironmentsManager manager = JavaRuntime.getExecutionEnvironmentsManager(); IExecutionEnvironment java8 = manager.getEnvironment("JavaSE-1.8"); return java8 != null && java8.getCompatibleVMs().length > 0; }
Example #13
Source File: ProjectsManager.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 4 votes |
private String getWorkspaceInfo() { StringBuilder b = new StringBuilder(); b.append("Projects:\n"); for (IProject project : getWorkspaceRoot().getProjects()) { b.append(project.getName()).append(": ").append(project.getLocation().toOSString()).append('\n'); if (ProjectUtils.isJavaProject(project)) { IJavaProject javaProject = JavaCore.create(project); try { b.append(" resolved classpath:\n"); IClasspathEntry[] cpEntries = javaProject.getRawClasspath(); for (IClasspathEntry cpe : cpEntries) { b.append(" ").append(cpe.getPath().toString()).append('\n'); if (cpe.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { IPackageFragmentRoot[] roots = javaProject.findPackageFragmentRoots(cpe); for (IPackageFragmentRoot root : roots) { b.append(" ").append(root.getPath().toString()).append('\n'); } } } } catch (CoreException e) { // ignore } } else { b.append(" non-Java project\n"); } } b.append("Java Runtimes:\n"); IVMInstall defaultVMInstall = JavaRuntime.getDefaultVMInstall(); b.append(" default: "); if (defaultVMInstall != null) { b.append(defaultVMInstall.getInstallLocation().toString()); } else { b.append("-"); } IExecutionEnvironmentsManager eem = JavaRuntime.getExecutionEnvironmentsManager(); for (IExecutionEnvironment ee : eem.getExecutionEnvironments()) { IVMInstall[] vms = ee.getCompatibleVMs(); b.append(" ").append(ee.getDescription()).append(": "); if (vms.length > 0) { b.append(vms[0].getInstallLocation().toString()); } else { b.append("-"); } b.append("\n"); } return b.toString(); }