Java Code Examples for org.eclipse.core.resources.IProject#getReferencedProjects()

The following examples show how to use org.eclipse.core.resources.IProject#getReferencedProjects() . 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: ProjectModulesManager.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * @param project the project for which we want references.
 * @param referenced whether we want to get the referenced projects or the ones referencing this one.
 * @param memo (out) this is the place where all the projects will e available.
 *
 * Note: the project itself will not be added.
 */
private static void getProjectsRecursively(IProject project, boolean referenced, HashSet<IProject> memo) {
    IProject[] projects = null;
    try {
        if (project == null || !project.isOpen() || !project.exists()) {
            return;
        }
        if (referenced) {
            projects = project.getReferencedProjects();
        } else {
            projects = project.getReferencingProjects();
        }
    } catch (CoreException e) {
        //ignore (it's closed)
    }

    if (projects != null) {
        for (IProject p : projects) {
            if (!memo.contains(p)) {
                memo.add(p);
                getProjectsRecursively(p, referenced, memo);
            }
        }
    }
}
 
Example 2
Source File: SGenWizardPage2.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
protected List<IProject> getReferencedProjects(IProject project) {
	try {
		IProject[] referencedProjects = project.getReferencedProjects();
		return Arrays.asList(referencedProjects);
	} catch (CoreException e) {
		e.printStackTrace();
		return Collections.emptyList();
	}
}
 
Example 3
Source File: WorkspaceClassLoaderFactory.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
protected void addReferencedProjectsClasspaths(IProject project,
		List<URL> urls) {
	try {
		IProject[] referencedProjects = project.getReferencedProjects();
		for (IProject iProject : referencedProjects) {
			addClasspathEntries(iProject, urls);
		}
	} catch (CoreException e) {
		e.printStackTrace();
	}
}
 
Example 4
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 5
Source File: VerySimpleBuilder.java    From textuml with Eclipse Public License 1.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
protected IProject[] build(int kind, Map args, IProgressMonitor monitor) throws CoreException {
    IProject toBuild = getProject();

    // mark all referencing as needing rebuild
    for (IProject referencing : toBuild.getReferencingProjects())
        referencing.touch(monitor);

    // build location context
    IFileStore storeToBuild = EFS.getStore(toBuild.getLocationURI());
    LocationContext context = new LocationContext(storeToBuild);
    context.addSourcePath(storeToBuild, null);
    for (IProject referenced : toBuild.getReferencedProjects()) {
        URI referencedLocation = referenced.getLocationURI();
        if (referencedLocation != null) {
            IFileStore modelPathEntry = EFS.getStore(referencedLocation);
            context.addRelatedPath(modelPathEntry);
        }
    }

    removeMarkers(toBuild);
    IProblem[] problems = FrontEnd.getCompilationDirector().compile(null, null, context,
            ICompilationDirector.FULL_BUILD, monitor);
    toBuild.refreshLocal(IResource.DEPTH_INFINITE, null);
    Arrays.sort(problems, new Comparator<IProblem>() {
        public int compare(IProblem o1, IProblem o2) {
            if ((o1 instanceof InternalProblem) || (o2 instanceof InternalProblem)) {
                if (!(o1 instanceof InternalProblem))
                    return 1;
                if (!(o2 instanceof InternalProblem))
                    return -1;
                return 0;
            }
            int fileNameDelta = ((IFileStore) o1.getAttribute(IProblem.FILE_NAME)).toURI().compareTo(
                    ((IFileStore) o2.getAttribute(IProblem.FILE_NAME)).toURI());
            if (fileNameDelta != 0)
                return fileNameDelta;
            int lineNo1 = getLineNumber(o1);
            int lineNo2 = getLineNumber(o2);
            return lineNo1 - lineNo2;
        }

    });
    createMarkers(toBuild, problems);
    return null;
}