org.eclipse.jdt.launching.environments.IExecutionEnvironment Java Examples

The following examples show how to use org.eclipse.jdt.launching.environments.IExecutionEnvironment. 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: BuildPathSupport.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Returns the compliance options from the given EE. If the result is not <code>null</code>,
 * it contains at least these core options:
 * <ul>
 * <li>{@link JavaCore#COMPILER_COMPLIANCE}</li>
 * <li>{@link JavaCore#COMPILER_SOURCE}</li>
 * <li>{@link JavaCore#COMPILER_CODEGEN_TARGET_PLATFORM}</li>
 * <li>{@link JavaCore#COMPILER_PB_ASSERT_IDENTIFIER}</li>
 * <li>{@link JavaCore#COMPILER_PB_ENUM_IDENTIFIER}</li>
 * <li>{@link JavaCore#COMPILER_CODEGEN_INLINE_JSR_BYTECODE} for compliance levels 1.5 and greater</li>
 * </ul>
 * 
 * @param ee the EE, can be <code>null</code>
 * @return the options, or <code>null</code> if none
 * @since 3.5
 */
public static Map<String, String> getEEOptions(IExecutionEnvironment ee) {
	if (ee == null)
		return null;
	Map<String, String> eeOptions= ee.getComplianceOptions();
	if (eeOptions == null)
		return null;
	
	Object complianceOption= eeOptions.get(JavaCore.COMPILER_COMPLIANCE);
	if (!(complianceOption instanceof String))
		return null;

	// eeOptions can miss some options, make sure they are complete:
	HashMap<String, String> options= new HashMap<String, String>();
	JavaModelUtil.setComplianceOptions(options, (String)complianceOption);
	options.putAll(eeOptions);
	return options;
}
 
Example #3
Source File: ComplianceConfigurationBlock.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private IExecutionEnvironment getEE() {
	if (fProject == null)
		return null;
	
	try {
		IClasspathEntry[] entries= JavaCore.create(fProject).getRawClasspath();
		for (int i= 0; i < entries.length; i++) {
			IClasspathEntry entry= entries[i];
			if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
				String eeId= JavaRuntime.getExecutionEnvironmentId(entry.getPath());
				if (eeId != null) {
					return JavaRuntime.getExecutionEnvironmentsManager().getEnvironment(eeId);
				}
			}
		}
	} catch (CoreException e) {
		JavaPlugin.log(e);
	}
	return null;
}
 
Example #4
Source File: ComplianceConfigurationBlock.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private void updateComplianceFollowsEE() {
	if (fProject != null) {
		String complianceFollowsEE= DISABLED;
		IExecutionEnvironment ee= getEE();
		String label;
		if (ee != null) {
			complianceFollowsEE= getComplianceFollowsEE(ee);
			label= Messages.format(PreferencesMessages.ComplianceConfigurationBlock_compliance_follows_EE_with_EE_label, ee.getId());
		} else {
			label= PreferencesMessages.ComplianceConfigurationBlock_compliance_follows_EE_label;
		}
		Link checkBoxLink= getCheckBoxLink(INTR_COMPLIANCE_FOLLOWS_EE);
		if (checkBoxLink != null) {
			checkBoxLink.setText(label);
		}
		setValue(INTR_COMPLIANCE_FOLLOWS_EE, complianceFollowsEE);
	}
}
 
Example #5
Source File: NewJavaProjectWizardPageOne.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private String getDefaultEEName() {
	IVMInstall defaultVM= JavaRuntime.getDefaultVMInstall();

	IExecutionEnvironment[] environments= JavaRuntime.getExecutionEnvironmentsManager().getExecutionEnvironments();
	if (defaultVM != null) {
		for (int i= 0; i < environments.length; i++) {
			IVMInstall eeDefaultVM= environments[i].getDefaultVM();
			if (eeDefaultVM != null && defaultVM.getId().equals(eeDefaultVM.getId()))
				return environments[i].getId();
		}
	}

	String defaultCC=JavaModelUtil.VERSION_LATEST;
	if (defaultVM instanceof IVMInstall2)
		defaultCC= JavaModelUtil.getCompilerCompliance((IVMInstall2)defaultVM, defaultCC);

	for (int i= 0; i < environments.length; i++) {
		String eeCompliance= JavaModelUtil.getExecutionEnvironmentCompliance(environments[i]);
		if (defaultCC.endsWith(eeCompliance))
			return environments[i].getId();
	}

	return "JavaSE-1.7"; //$NON-NLS-1$
}
 
Example #6
Source File: JavaModelUtil.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public static String getExecutionEnvironmentCompliance(IExecutionEnvironment executionEnvironment) {
	Map<String, String> complianceOptions= executionEnvironment.getComplianceOptions();
	if (complianceOptions != null) {
		Object compliance= complianceOptions.get(JavaCore.COMPILER_COMPLIANCE);
		if (compliance instanceof String)
			return (String)compliance;
	}
	
	// fallback:
	String desc= executionEnvironment.getId();
	if (desc.indexOf(JavaCore.VERSION_1_8) != -1) {
		return JavaCore.VERSION_1_8;
	} else if (desc.indexOf(JavaCore.VERSION_1_7) != -1) {
		return JavaCore.VERSION_1_7;
	} else if (desc.indexOf(JavaCore.VERSION_1_6) != -1) {
		return JavaCore.VERSION_1_6;
	} else if (desc.indexOf(JavaCore.VERSION_1_5) != -1) {
		return JavaCore.VERSION_1_5;
	} else if (desc.indexOf(JavaCore.VERSION_1_4) != -1) {
		return JavaCore.VERSION_1_4;
	}
	return JavaCore.VERSION_1_3;
}
 
Example #7
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 #8
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 #9
Source File: JREContainerProvider.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * @return an {@link Iterable} of BREE that have a configured default VM<br>
 *         or have a strictly compatible installed JRE (aka "perfect match")
 * @since 2.9
 */
public static Iterable<String> getConfiguredBREEs() {
	final Set<IVMInstall> vms = Sets.newHashSet();
	for (IVMInstallType vmType : JavaRuntime.getVMInstallTypes()) {
		vms.addAll(Arrays.asList(vmType.getVMInstalls()));
	}
	Iterable<IExecutionEnvironment> supportedEEs = filter(
			Arrays.asList(JavaRuntime.getExecutionEnvironmentsManager().getExecutionEnvironments()),
			new Predicate<IExecutionEnvironment>() {
				@Override
				public boolean apply(final IExecutionEnvironment ee) {
					return ee.getDefaultVM() != null || any(vms, new Predicate<IVMInstall>() {
						@Override
						public boolean apply(IVMInstall vm) {
							return ee.isStrictlyCompatible(vm);
						}
					});
				}
			});
	return transform(supportedEEs, new Function<IExecutionEnvironment, String>() {
		@Override
		public String apply(IExecutionEnvironment input) {
			return input.getId();
		}
	});
}
 
Example #10
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 #11
Source File: JREContainerProvider.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @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 #12
Source File: MainProjectWizardPage.java    From sarl with Apache License 2.0 5 votes vote down vote up
private void fillExecutionEnvironments(ComboDialogField comboField) {
	String selectedItem = getLastSelectedEE();
	int selectionIndex = comboField.getSelectionIndex();
	if (this.useEEJRE.isSelected()) {
		if (selectionIndex != -1) {
			// paranoia
			selectedItem = comboField.getItems()[selectionIndex];
		}
	}

	this.installedEEs = JavaRuntime.getExecutionEnvironmentsManager().getExecutionEnvironments();
	Arrays.sort(this.installedEEs, new Comparator<IExecutionEnvironment>() {
		@Override
		public int compare(IExecutionEnvironment arg0, IExecutionEnvironment arg1) {
			return Policy.getComparator().compare(arg0.getId(), arg1.getId());
		}
	});
	// find new index
	selectionIndex = -1;
	final String[] eeLabels = new String[this.installedEEs.length];
	this.eeCompliance = new String[this.installedEEs.length];
	for (int i = 0; i < this.installedEEs.length; i++) {
		eeLabels[i] = this.installedEEs[i].getId();
		if (selectedItem != null && eeLabels[i].equals(selectedItem)) {
			selectionIndex = i;
		}
		this.eeCompliance[i] = JavaModelUtil.getExecutionEnvironmentCompliance(this.installedEEs[i]);
	}
	comboField.setItems(eeLabels);
	if (selectionIndex == -1) {
		comboField.selectItem(getDefaultEEName());
	} else {
		comboField.selectItem(selectedItem);
	}
}
 
Example #13
Source File: JreDetectorTest.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
@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 #14
Source File: MainProjectWizardPage.java    From sarl with Apache License 2.0 5 votes vote down vote up
private String getDefaultEEName() {
	final IVMInstall defaultVM = JavaRuntime.getDefaultVMInstall();

	final IExecutionEnvironment[] environments = JavaRuntime.getExecutionEnvironmentsManager()
			.getExecutionEnvironments();
	if (defaultVM != null) {
		for (int i = 0; i < environments.length; i++) {
			final IVMInstall eeDefaultVM = environments[i].getDefaultVM();
			if (eeDefaultVM != null && defaultVM.getId().equals(eeDefaultVM.getId())) {
				return environments[i].getId();
			}
		}
	}

	final String defaultCC;
	if (defaultVM instanceof IVMInstall2) {
		defaultCC = JavaModelUtil.getCompilerCompliance((IVMInstall2) defaultVM, SARLVersion.MINIMAL_JDK_VERSION_IN_SARL_PROJECT_CLASSPATH);
	} else {
		defaultCC = SARLVersion.MINIMAL_JDK_VERSION_IN_SARL_PROJECT_CLASSPATH;
	}

	for (int i = 0; i < environments.length; i++) {
		final String eeCompliance = JavaModelUtil.getExecutionEnvironmentCompliance(environments[i]);
		if (defaultCC.endsWith(eeCompliance)) {
			return environments[i].getId();
		}
	}

	return SARLVersion.MINIMAL_JDK_VERSION_IN_SARL_PROJECT_CLASSPATH;
}
 
Example #15
Source File: WizardNewXtextProjectCreationPage.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected void fillBreeCombo(Combo comboToFill) {
	Set<String> brees = Sets.newLinkedHashSet();
	Set<String> availableBrees = Sets.newHashSet();
	for (IExecutionEnvironment ee : JavaRuntime.getExecutionEnvironmentsManager().getExecutionEnvironments()) {
		availableBrees.add(ee.getId());
	}
	for (JavaVersion supportedVersion : JavaVersion.values()) {
		if (supportedVersion.isAtLeast(JavaVersion.JAVA6)) {
			String bree = supportedVersion.getBree();
			if (availableBrees.contains(bree))
				brees.add(bree);
		}
	}
	String[] array = brees.toArray(new String[] {});
	String selectionMemento = comboToFill.getText();
	comboToFill.setItems(array);
	int index = comboToFill.indexOf(selectionMemento);
	String defaultBree = JREContainerProvider.getDefaultBREE();
	if (index < 0) {
		if (brees.contains(defaultBree)) {
			comboToFill.select(comboToFill.indexOf(defaultBree));
		} else {
			comboToFill.select(array.length - 1);
		}
	}
	comboToFill.select(index);
}
 
Example #16
Source File: ReorgCorrectionsSubProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private boolean isEEOnClasspath(IExecutionEnvironment ee) throws JavaModelException {
	IPath eePath= JavaRuntime.newJREContainerPath(ee);
	
	for (IClasspathEntry entry: fProject.getRawClasspath()) {
		if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER && entry.getPath().equals(eePath))
			return true;
	}
	return false;
}
 
Example #17
Source File: ReorgCorrectionsSubProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public Object getAdditionalProposalInfo(IProgressMonitor monitor) {
	StringBuffer message= new StringBuffer();
	if (fChangeOnWorkspace) {
		message.append(Messages.format(CorrectionMessages.ReorgCorrectionsSubProcessor_required_compliance_changeworkspace_description, fRequiredVersion));
	} else {
		message.append(Messages.format(CorrectionMessages.ReorgCorrectionsSubProcessor_required_compliance_changeproject_description, fRequiredVersion));
	}

	try {
		IVMInstall install= JavaRuntime.getVMInstall(fProject); // can be null
		if (fChangeOnWorkspace) {
			IVMInstall vmInstall= findRequiredOrGreaterVMInstall();
			if (vmInstall != null) {
				IVMInstall defaultVM= JavaRuntime.getDefaultVMInstall(); // can be null
				if (defaultVM != null && !defaultVM.equals(install)) {
					message.append(CorrectionMessages.ReorgCorrectionsSubProcessor_50_compliance_changeProjectJREToDefault_description);
				}
				if (defaultVM == null || !isRequiredOrGreaterVMInstall(defaultVM)) {
					message.append(Messages.format(CorrectionMessages.ReorgCorrectionsSubProcessor_50_compliance_changeWorkspaceJRE_description, vmInstall.getName()));
				}
			}
		} else {
			IExecutionEnvironment bestEE= findBestMatchingEE();
			if (bestEE != null) {
				if (install == null || !isEEOnClasspath(bestEE)) {
					message.append(Messages.format(CorrectionMessages.ReorgCorrectionsSubProcessor_50_compliance_changeProjectJRE_description, bestEE.getId()));
				}
			}
		}
	} catch (CoreException e) {
		// ignore
	}
	return message.toString();
}
 
Example #18
Source File: ReorgCorrectionsSubProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
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 #19
Source File: NewJavaProjectWizardPageOne.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private void fillExecutionEnvironments(ComboDialogField comboField) {
	String selectedItem= getLastSelectedEE();
	int selectionIndex= -1;
	if (fUseEEJRE.isSelected()) {
		selectionIndex= comboField.getSelectionIndex();
		if (selectionIndex != -1) {// paranoia
			selectedItem= comboField.getItems()[selectionIndex];
		}
	}

	fInstalledEEs= JavaRuntime.getExecutionEnvironmentsManager().getExecutionEnvironments();
	Arrays.sort(fInstalledEEs, new Comparator<IExecutionEnvironment>() {
		public int compare(IExecutionEnvironment arg0, IExecutionEnvironment arg1) {
			return Policy.getComparator().compare(arg0.getId(), arg1.getId());
		}
	});
	selectionIndex= -1;//find new index
	String[] eeLabels= new String[fInstalledEEs.length];
	fEECompliance= new String[fInstalledEEs.length];
	for (int i= 0; i < fInstalledEEs.length; i++) {
		eeLabels[i]= fInstalledEEs[i].getId();
		if (selectedItem != null && eeLabels[i].equals(selectedItem)) {
			selectionIndex= i;
		}
		fEECompliance[i]= JavaModelUtil.getExecutionEnvironmentCompliance(fInstalledEEs[i]);
	}
	comboField.setItems(eeLabels);
	if (selectionIndex == -1) {
		comboField.selectItem(getDefaultEEName());
	} else {
		comboField.selectItem(selectedItem);
	}
}
 
Example #20
Source File: JREContainerProvider.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @since 2.9
 */
public static IClasspathEntry getJREContainerEntry(String bree) {
	IClasspathEntry jreContainerEntry = getDefaultJREContainerEntry();
	IExecutionEnvironment ee = JavaRuntime.getExecutionEnvironmentsManager().getEnvironment(bree);
	if (ee != null) {
		return JavaCore.newContainerEntry(newJREContainerPath(ee));
	}
	return jreContainerEntry;
}
 
Example #21
Source File: ProjectCreator.java    From txtUML with Eclipse Public License 1.0 5 votes vote down vote up
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 #22
Source File: AbstractXtendUITestCase.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
protected void setJavaVersion(JavaVersion javaVersion) throws Exception {
	IJavaProject javaProject = JavaProjectSetupUtil.findJavaProject(WorkbenchTestHelper.TESTPROJECT_NAME);
	Pair<String,Boolean> result = WorkbenchTestHelper.changeBree(javaProject, javaVersion);
	IExecutionEnvironment execEnv = JavaRuntime.getExecutionEnvironmentsManager().getEnvironment(result.getKey());
	Assume.assumeNotNull("Execution environment not found for: " + javaVersion.getLabel(), execEnv);
	Assume.assumeTrue("No compatible VM was found for: " + javaVersion.getLabel(),
			execEnv.getCompatibleVMs().length > 0);
	if(result.getValue()) {
		WorkbenchTestHelper.makeCompliantFor(javaProject, javaVersion);
		IResourcesSetupUtil.reallyWaitForAutoBuild();
	}
}
 
Example #23
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 #24
Source File: JVMConfigurator.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
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 #25
Source File: ProjectClasspathFactory.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
protected IPath newJREContainerPath(final IExecutionEnvironment executionEnvironment) {
    return JavaRuntime.newJREContainerPath(executionEnvironment);
}
 
Example #26
Source File: ProjectClasspathFactory.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
protected IExecutionEnvironment javaRuntimeEnvironment() {
    return JavaRuntime.getExecutionEnvironmentsManager().getEnvironment("JavaSE-1.8");
}
 
Example #27
Source File: ComplianceConfigurationBlock.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Sets the default compliance values derived from the chosen level or restores the user
 * compliance settings.
 * 
 * @param rememberOld if <code>true</code>, the current compliance settings are remembered as
 *            user settings. If <code>false</code>, overwrite the current settings.
 * @param oldComplianceLevel the previous compliance level
 */
private void updateComplianceDefaultSettings(boolean rememberOld, String oldComplianceLevel) {
	String assertAsId, enumAsId, source, target;
	boolean isDefault= checkValue(INTR_DEFAULT_COMPLIANCE, DEFAULT_CONF);
	boolean isFollowEE= checkValue(INTR_COMPLIANCE_FOLLOWS_EE, DEFAULT_CONF);
	String complianceLevel= getValue(PREF_COMPLIANCE);

	if (isDefault || isFollowEE) {
		if (rememberOld) {
			if (oldComplianceLevel == null) {
				oldComplianceLevel= complianceLevel;
			}

			fRememberedUserCompliance[IDX_ASSERT_AS_IDENTIFIER]= getValue(PREF_PB_ASSERT_AS_IDENTIFIER);
			fRememberedUserCompliance[IDX_ENUM_AS_IDENTIFIER]= getValue(PREF_PB_ENUM_AS_IDENTIFIER);
			fRememberedUserCompliance[IDX_SOURCE_COMPATIBILITY]= getValue(PREF_SOURCE_COMPATIBILITY);
			fRememberedUserCompliance[IDX_CODEGEN_TARGET_PLATFORM]= getValue(PREF_CODEGEN_TARGET_PLATFORM);
			fRememberedUserCompliance[IDX_COMPLIANCE]= oldComplianceLevel;
		}
		
		if (isFollowEE) {
			IExecutionEnvironment ee= getEE();
			Map<String, String> eeOptions= BuildPathSupport.getEEOptions(ee);
			if (eeOptions == null)
				return;
			
			assertAsId= eeOptions.get(PREF_PB_ASSERT_AS_IDENTIFIER.getName());
			enumAsId= eeOptions.get(PREF_PB_ENUM_AS_IDENTIFIER.getName());
			source= eeOptions.get(PREF_SOURCE_COMPATIBILITY.getName());
			target= eeOptions.get(PREF_CODEGEN_TARGET_PLATFORM.getName());
			
			setValue(PREF_COMPLIANCE, eeOptions.get(PREF_COMPLIANCE.getName()));
			String inlineJSR= eeOptions.get(PREF_CODEGEN_INLINE_JSR_BYTECODE.getName());
			if (inlineJSR != null) {
				setValue(PREF_CODEGEN_INLINE_JSR_BYTECODE, inlineJSR);
			}
			
		} else {
			//TODO: use JavaModelUtil.setComplianceOptions(new HashMap(), complianceLevel);
			if (VERSION_1_4.equals(complianceLevel)) {
				assertAsId= WARNING;
				enumAsId= WARNING;
				source= VERSION_1_3;
				target= VERSION_1_2;
			} else if (VERSION_1_5.equals(complianceLevel)) {
				assertAsId= ERROR;
				enumAsId= ERROR;
				source= VERSION_1_5;
				target= VERSION_1_5;
			} else if (VERSION_1_6.equals(complianceLevel)) {
				assertAsId= ERROR;
				enumAsId= ERROR;
				source= VERSION_1_6;
				target= VERSION_1_6;
			} else if (VERSION_1_7.equals(complianceLevel)) {
				assertAsId= ERROR;
				enumAsId= ERROR;
				source= VERSION_1_7;
				target= VERSION_1_7;
			} else if (VERSION_1_8.equals(complianceLevel)) {
				assertAsId= ERROR;
				enumAsId= ERROR;
				source= VERSION_1_8;
				target= VERSION_1_8;
			} else {
				assertAsId= IGNORE;
				enumAsId= IGNORE;
				source= VERSION_1_3;
				target= VERSION_1_1;
			}
		}
	} else {
		if (rememberOld && complianceLevel.equals(fRememberedUserCompliance[IDX_COMPLIANCE])) {
			assertAsId= fRememberedUserCompliance[IDX_ASSERT_AS_IDENTIFIER];
			enumAsId= fRememberedUserCompliance[IDX_ENUM_AS_IDENTIFIER];
			source= fRememberedUserCompliance[IDX_SOURCE_COMPATIBILITY];
			target= fRememberedUserCompliance[IDX_CODEGEN_TARGET_PLATFORM];
		} else {
			updateInlineJSREnableState();
			updateAssertEnumAsIdentifierEnableState();
			updateStoreMethodParamNamesEnableState();
			return;
		}
	}
	setValue(PREF_PB_ASSERT_AS_IDENTIFIER, assertAsId);
	setValue(PREF_PB_ENUM_AS_IDENTIFIER, enumAsId);
	setValue(PREF_SOURCE_COMPATIBILITY, source);
	setValue(PREF_CODEGEN_TARGET_PLATFORM, target);
	updateControls();
	updateInlineJSREnableState();
	updateAssertEnumAsIdentifierEnableState();
	updateStoreMethodParamNamesEnableState();
}
 
Example #28
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();
}
 
Example #29
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 #30
Source File: ComplianceConfigurationBlock.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 3 votes vote down vote up
/**
 * Evaluate if the builds path contains an execution environment and the current compliance
 * settings follow the EE options.
 * 
 * @param ee the EE, or <code>null</code> if none available
 * @return {@link #DEFAULT_CONF} if the compliance follows the EE, or {@link #USER_CONF} if the
 *         settings differ, or {@link #DISABLED} if there's no EE at all
 */
private String getComplianceFollowsEE(IExecutionEnvironment ee) {
	Map<String, String> options= BuildPathSupport.getEEOptions(ee);
	if (options == null)
		return DISABLED;
	
	return checkDefaults(PREFS_COMPLIANCE, options);
}