Java Code Examples for org.eclipse.jdt.core.JavaCore#newProjectEntry()

The following examples show how to use org.eclipse.jdt.core.JavaCore#newProjectEntry() . 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: Importer.java    From hybris-commerce-eclipse-plugin with Apache License 2.0 6 votes vote down vote up
/**
 * We need to add all hybris projects to the build path of each project so that all configured extensions will be on the Eclipse classpath and the extensions will be loaded correctly
 * @return
 */
private void addAllHybrisProjectsToBuildPathForCustomProjects(IProgressMonitor monitor) throws JavaModelException {
	monitor.setTaskName("Fixing build path");
	Set<IProject> customProjects = FixProjectsUtils.getAllCustomerProjects();
	monitor.beginTask("Fixing build path", customProjects.size());
	int i = 0;
	for (IProject sourceProject : customProjects) {
				
		if (sourceProject.isOpen()) {
			IJavaProject javaSourceProject = JavaCore.create(sourceProject);
			List<IClasspathEntry> entries = new LinkedList<IClasspathEntry>(
					Arrays.asList(javaSourceProject.getRawClasspath()));

			for (IProject targetProject : FixProjectsUtils.getAllPlatformProjects()) {
				if (!sourceProject.equals(targetProject)) {
					IClasspathEntry entry = JavaCore.newProjectEntry(targetProject.getFullPath(), true);
					addToListIfNotExisting(entries, entry);
				}
			}
			FixProjectsUtils.setClasspath(entries.toArray(new IClasspathEntry[entries.size()]), javaSourceProject,
					monitor);
			monitor.internalWorked(i++);
		}
		}
}
 
Example 2
Source File: FixProjectsUtils.java    From hybris-commerce-eclipse-plugin with Apache License 2.0 6 votes vote down vote up
public static void addToClassPath(IResource res, int type, IJavaProject javaProject, IProgressMonitor monitor) throws JavaModelException
{
	Set<IClasspathEntry> entries = new HashSet<IClasspathEntry>(Arrays.asList(javaProject.getRawClasspath()));
	IClasspathEntry entry = null;
	switch (type) {
	case IClasspathEntry.CPE_SOURCE: 
		entry = JavaCore.newSourceEntry(res.getFullPath());
		break;
	case IClasspathEntry.CPE_LIBRARY: 
		entry = JavaCore.newLibraryEntry(res.getFullPath(), null, null, true);
		break;
	case IClasspathEntry.CPE_PROJECT: 
		entry = JavaCore.newProjectEntry(res.getFullPath(), true);
		break;
	}
		
	entries.add(entry);
	setClasspath(entries.toArray(new IClasspathEntry[entries.size()]), javaProject, monitor);
}
 
Example 3
Source File: GWTRuntimeTest.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Tests that we find an {@link com.google.gdt.eclipse.core.sdk.Sdk} on the
 * gwt-user project.
 *
 * @throws Exception
 */
public void testFindSdkFor_GwtUserProject() throws Exception {
  GwtRuntimeTestUtilities.importGwtSourceProjects();
  try {
    IJavaModel javaModel = JavaCore.create(ResourcesPlugin.getWorkspace().getRoot());
    IJavaProject javaProject = javaModel.getJavaProject("gwt-user");
    GwtSdk sdk = GwtSdk.findSdkFor(javaProject);
    IClasspathEntry gwtUserEntry =
        JavaCore.newSourceEntry(
            javaModel.getJavaProject("gwt-user").getPath().append("core/src"),
            new IPath[] {new Path("**/super/**")});
    /*
     * NOTE: Passing null for the IClasspathAttribute array tickles a bug in
     * eclipse 3.3.
     */
    IClasspathEntry gwtDevEntry =
        JavaCore.newProjectEntry(javaModel.getJavaProject("gwt-dev").getPath(), null, false,
            new IClasspathAttribute[0] /* */, false);
    IClasspathEntry[] expected = new IClasspathEntry[] {gwtUserEntry, gwtDevEntry};
    assertEquals(expected, sdk.getClasspathEntries());
  } finally {
    GwtRuntimeTestUtilities.removeGwtSourceProjects();
  }
}
 
Example 4
Source File: GWTProjectsRuntime.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public IClasspathEntry[] getClasspathEntries() {
  IJavaProject devProject = findDevProject();
  IJavaProject userProject = findUserProject();
  if (devProject != null && userProject != null) {
    return new IClasspathEntry[] {JavaCore.newProjectEntry(devProject.getPath()),
        JavaCore.newProjectEntry(userProject.getPath())};
  }

  return NO_ICLASSPATH_ENTRIES;
}
 
Example 5
Source File: IntegrationTest.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
@Test
public void testJavaChangeTriggersBuild() throws Exception {
	foo_project = createJavaProject("foo");
	IJavaProject zonkProject = createJavaProject("zonk");
	bar_project = createJavaProjectWithRootSrc("bar");

	addProjectReference(bar_project, zonkProject);
	IClasspathEntry classpathEntry = JavaCore.newProjectEntry(foo_project.getPath(), true);
	workspace.addToClasspath(zonkProject, classpathEntry);

	IFolder javaPackage = foo_project.getProject().getFolder("src").getFolder("pack");
	javaPackage.create(true, true, null);
	IFile javaFile = javaPackage.getFile("Type.java");
	javaFile.create(new StringInputStream("package pack; public class Type {}"), true, monitor());

	IFolder dslFolder = bar_project.getProject().getFolder("src");
	IFile dslFile = dslFolder.getFile("Dsl.typesAssistTest");
	dslFile.create(new StringInputStream("default pack.Type"), true, monitor());

	build();
	assertEquals(printMarkers(dslFile), 0, countMarkers(dslFile));

	javaFile.setContents(new StringInputStream("package pack; class X {}"), true, true, null);

	build();
	// Xtext proxy validation and EObjectValidator proxy validation
	assertEquals(2, countMarkers(dslFile));

	javaFile.setContents(new StringInputStream("package pack; public class Type {}"), true, true, null);

	build();
	assertEquals(0, countMarkers(dslFile));

	workspace.removeClasspathEntry(zonkProject, classpathEntry);

	build();
	// Xtext proxy validation and EObjectValidator proxy validation
	assertEquals(2, countMarkers(dslFile));

	workspace.addToClasspath(zonkProject, classpathEntry);
	build();
	assertEquals(0, countMarkers(dslFile));
}
 
Example 6
Source File: JavaProjectFactory.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
@Override
protected void enhanceProject(IProject project, SubMonitor monitor, Shell shell) throws CoreException {
	super.enhanceProject(project, monitor, shell);
	if (builderIds.contains(JavaCore.BUILDER_ID)) {
		SubMonitor subMonitor = SubMonitor.convert(monitor, 10);
		try {
			subMonitor.subTask(Messages.JavaProjectFactory_ConfigureJavaProject + projectName);
			IJavaProject javaProject = JavaCore.create(project);
			List<IClasspathEntry> classpathEntries = new ArrayList<IClasspathEntry>();
			for (final IProject referencedProject : project.getReferencedProjects()) {
				final IClasspathEntry referencedProjectClasspathEntry = JavaCore.newProjectEntry(referencedProject
						.getFullPath());
				classpathEntries.add(referencedProjectClasspathEntry);
			}
			for (final String folderName : getFolders()) {
				final IFolder sourceFolder = project.getFolder(folderName);
				String outputFolderName = sourceFolderOutputs.get(folderName);
				final IClasspathEntry srcClasspathEntry = JavaCore.newSourceEntry(sourceFolder.getFullPath(),
						ClasspathEntry.INCLUDE_ALL, ClasspathEntry.EXCLUDE_NONE,
						outputFolderName == null ? null : project.getFolder(outputFolderName).getFullPath(),
						testSourceFolders.contains(folderName)
								? new IClasspathAttribute[] { JavaCore.newClasspathAttribute("test", "true") }
								: new IClasspathAttribute[0]);
				classpathEntries.add(srcClasspathEntry);
			}
			classpathEntries.addAll(extraClasspathEntries);

			IClasspathEntry defaultJREContainerEntry = getJreContainerEntry();
			classpathEntries.add(defaultJREContainerEntry);
			addMoreClasspathEntriesTo(classpathEntries);
			
			javaProject.setRawClasspath(classpathEntries.toArray(new IClasspathEntry[classpathEntries.size()]),
					subMonitor.newChild(1));
			javaProject.setOutputLocation(new Path("/" + project.getName() + "/" + defaultOutput), subMonitor.newChild(1));
			
			String executionEnvironmentId = JavaRuntime.getExecutionEnvironmentId(defaultJREContainerEntry.getPath());
			if (executionEnvironmentId != null) {
				BuildPathSupport.setEEComplianceOptions(javaProject, executionEnvironmentId, null);
			}
		} catch (JavaModelException e) {
			logger.error(e.getMessage(), e);
		}
	}
}
 
Example 7
Source File: RenameJavaProjectChange.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private IClasspathEntry createModifiedEntry(IClasspathEntry oldEntry) {
	return JavaCore.newProjectEntry(createNewPath(), oldEntry.getAccessRules(), oldEntry.combineAccessRules(), oldEntry.getExtraAttributes(), oldEntry.isExported());
}
 
Example 8
Source File: IDECPListElement.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
private IClasspathEntry newClasspathEntry( )
{

	IClasspathAttribute[] extraAttributes = new IClasspathAttribute[0];
	switch ( fEntryKind )
	{
		case IClasspathEntry.CPE_SOURCE :
			return JavaCore.newSourceEntry( fPath,
					null,
					null,
					null,
					extraAttributes );
		case IClasspathEntry.CPE_LIBRARY :
		{
			return JavaCore.newLibraryEntry( fPath,
					null,
					null,
					null,
					extraAttributes,
					isExported( ) );
		}
		case IClasspathEntry.CPE_PROJECT :
		{
			return JavaCore.newProjectEntry( fPath,
					null,
					false,
					extraAttributes,
					isExported( ) );
		}
		case IClasspathEntry.CPE_CONTAINER :
		{
			return JavaCore.newContainerEntry( fPath,
					null,
					extraAttributes,
					isExported( ) );
		}
		case IClasspathEntry.CPE_VARIABLE :
		{
			return JavaCore.newVariableEntry( fPath,
					null,
					null,
					null,
					extraAttributes,
					isExported( ) );
		}
		default :
			return null;
	}
}