Java Code Examples for org.eclipse.xtext.ui.testing.util.JavaProjectSetupUtil#addJreClasspathEntry()

The following examples show how to use org.eclipse.xtext.ui.testing.util.JavaProjectSetupUtil#addJreClasspathEntry() . 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: WorkbenchTestHelper.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
public static IProject createPluginProject(String name, JavaVersion javaVersion, String... requiredBundles) throws CoreException {
	Injector injector = XtendActivator.getInstance().getInjector(XtendActivator.ORG_ECLIPSE_XTEND_CORE_XTEND);
	PluginProjectFactory projectFactory = injector.getInstance(PluginProjectFactory.class);
	projectFactory.setProjectName(name);
	projectFactory.setProjectDefaultCharset(StandardCharsets.ISO_8859_1.name());
	projectFactory.setBreeToUse(getBree(javaVersion));
	projectFactory.addFolders(Collections.singletonList("src"));
	projectFactory.addBuilderIds(XtextProjectHelper.BUILDER_ID, JavaCore.BUILDER_ID, "org.eclipse.pde.ManifestBuilder",
			"org.eclipse.pde.SchemaBuilder");
	projectFactory.addProjectNatures(
			XtextProjectHelper.NATURE_ID, JavaCore.NATURE_ID, "org.eclipse.pde.PluginNature");
	projectFactory.addRequiredBundles(newArrayList(requiredBundles));
	IProject result = projectFactory.createProject(new NullProgressMonitor(), null);
	IJavaProject javaProject = JavaCore.create(result);
	if (javaVersion == null)
		JavaProjectSetupUtil.makeJava8Compliant(javaProject);
	else
		makeCompliantFor(javaProject, javaVersion);
	JavaProjectSetupUtil.addJreClasspathEntry(javaProject);
	return result;
}
 
Example 2
Source File: WorkbenchTestHelper.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * @return a {@link Pair}, where the <code>key</code> is the BREE that was set and the <code>value</code> indicates that the BREE was changed.
 */
public static Pair<String, Boolean> changeBree(IJavaProject javaProject, final JavaVersion javaVersion)
		throws Exception {
	final AtomicReference<String> bree = new AtomicReference<String>();
	boolean changed = changeManifest(javaProject.getProject(), new Function<MergeableManifest2, Boolean>() {
		@Override
		public Boolean apply(MergeableManifest2 mf) {
			mf.setBREE(getBree(javaVersion));
			return mf.isModified();
		}
	});
	if (changed) {
		JavaProjectSetupUtil.addJreClasspathEntry(javaProject, bree.get());
	}
	return Pair.of(bree.get(), changed);
}
 
Example 3
Source File: SameClassNamesTest.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
public IProject createPluginProject(final String name, final String... requiredBundles) throws CoreException {
  final PluginProjectFactory projectFactory = this.projectFactoryProvider.get();
  projectFactory.setProjectName(name);
  projectFactory.setBreeToUse(JREContainerProvider.PREFERRED_BREE);
  projectFactory.addFolders(Collections.<String>singletonList("src"));
  projectFactory.addBuilderIds(
    XtextProjectHelper.BUILDER_ID, 
    JavaCore.BUILDER_ID, 
    "org.eclipse.pde.ManifestBuilder", 
    "org.eclipse.pde.SchemaBuilder");
  projectFactory.addProjectNatures(
    XtextProjectHelper.NATURE_ID, JavaCore.NATURE_ID, "org.eclipse.pde.PluginNature");
  projectFactory.addRequiredBundles(((List<String>)Conversions.doWrapArray(requiredBundles)));
  projectFactory.addExportedPackages(Collections.<String>unmodifiableList(CollectionLiterals.<String>newArrayList("com.acme")));
  NullProgressMonitor _nullProgressMonitor = new NullProgressMonitor();
  final IProject result = projectFactory.createProject(_nullProgressMonitor, null);
  final IJavaProject javaProject = JavaCore.create(result);
  WorkbenchTestHelper.makeCompliantFor(javaProject, JavaVersion.JAVA8);
  JavaProjectSetupUtil.addJreClasspathEntry(javaProject);
  return result;
}
 
Example 4
Source File: MockJavaProjectProvider.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
public static IJavaProject createJavaProject(
		final String projectName, 
		String[] projectNatures) {

	IProject project = null;
	IJavaProject javaProject = null;
	try {
		project = IResourcesSetupUtil.root().getProject(projectName);
		deleteProject(project);

		javaProject = JavaCore.create(project);
		IProjectDescription projectDescription = ResourcesPlugin.getWorkspace().newProjectDescription(
				projectName);
		project.create(projectDescription, null);
		List<IClasspathEntry> classpathEntries = new ArrayList<IClasspathEntry>();
		projectDescription.setNatureIds(projectNatures);

		final ICommand java = projectDescription.newCommand();
		java.setBuilderName(JavaCore.BUILDER_ID);

		final ICommand manifest = projectDescription.newCommand();
		manifest.setBuilderName("org.eclipse.pde.ManifestBuilder");

		final ICommand schema = projectDescription.newCommand();
		schema.setBuilderName("org.eclipse.pde.SchemaBuilder");

		projectDescription.setBuildSpec(new ICommand[] { java, manifest, schema });

		project.open(null);
		project.setDescription(projectDescription, null);

		classpathEntries.add(JavaCore.newContainerEntry(new Path("org.eclipse.pde.core.requiredPlugins")));

		javaProject.setRawClasspath(classpathEntries.toArray(new IClasspathEntry[classpathEntries.size()]),
				null);
		JavaProjectSetupUtil.addJreClasspathEntry(javaProject);
		
		makeJava8Compliant(javaProject);

		javaProject.setOutputLocation(new Path("/" + projectName + "/bin"), null);
		createManifest(projectName, project);

		refreshExternalArchives(javaProject);
		refresh(javaProject);
	}
	catch (final Exception exception) {
		throw new RuntimeException(exception);
	}
	return javaProject ;
}