Java Code Examples for org.eclipse.jdt.launching.environments.IExecutionEnvironment#getCompatibleVMs()

The following examples show how to use org.eclipse.jdt.launching.environments.IExecutionEnvironment#getCompatibleVMs() . 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 vote down vote up
/** 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 2
Source File: JavaProjectSetupUtil.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
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 3
Source File: JavaProjectSetupUtil.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
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: JVMConfigurator.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
private static boolean setDefaultEnvironmentVM(IVMInstall vm, String name) {
	IExecutionEnvironment environment = getExecutionEnvironment(name);
	if (environment != null) {
		if (Objects.equals(vm, environment.getDefaultVM())) {
			return true;
		}
		IVMInstall[] compatibleVMs = environment.getCompatibleVMs();
		for (IVMInstall compatibleVM : compatibleVMs) {
			if (compatibleVM.equals(vm)) {
				if (!environment.isStrictlyCompatible(vm)) {
					JavaLanguageServerPlugin.logInfo("Runtime at '" + vm.getInstallLocation().toString() + "' is not strictly compatible with the '" + name + "' environment");
				}
				JavaLanguageServerPlugin.logInfo("Setting " + compatibleVM.getInstallLocation() + " as '" + name + "' environment (id:" + compatibleVM.getId() + ")");
				environment.setDefaultVM(compatibleVM);
				return true;
			}
		}
	}
	return false;
}
 
Example 5
Source File: JDTUtils.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
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 6
Source File: JavaRuntimeUtils.java    From google-cloud-eclipse with Apache License 2.0 4 votes vote down vote up
/**
 * 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 7
Source File: ProjectsManager.java    From eclipse.jdt.ls with Eclipse Public License 2.0 4 votes vote down vote up
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();
}