Java Code Examples for org.eclipse.jdt.core.IClasspathEntry#isExported()

The following examples show how to use org.eclipse.jdt.core.IClasspathEntry#isExported() . 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: RefactoringScopeFactory.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
private static void addReferencingProjects(IJavaProject focus, Set<IJavaProject> projects) throws JavaModelException {
	IProject[] referencingProjects = focus.getProject().getReferencingProjects();
	for (int i = 0; i < referencingProjects.length; i++) {
		IJavaProject candidate = JavaCore.create(referencingProjects[i]);
		if (candidate == null || projects.contains(candidate) || !candidate.exists()) {
			continue; // break cycle
		}
		IClasspathEntry entry = getReferencingClassPathEntry(candidate, focus);
		if (entry != null) {
			projects.add(candidate);
			if (entry.isExported()) {
				addReferencingProjects(candidate, projects);
			}
		}
	}
}
 
Example 2
Source File: RefactoringScopeFactory.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
private static void addRelatedReferencing(IJavaProject focus, Set<IJavaProject> projects) throws CoreException {
	IProject[] referencingProjects = focus.getProject().getReferencingProjects();
	for (int i = 0; i < referencingProjects.length; i++) {
		IJavaProject candidate = JavaCore.create(referencingProjects[i]);
		if (candidate == null || projects.contains(candidate) || !candidate.exists()) {
			continue; // break cycle
		}
		IClasspathEntry entry = getReferencingClassPathEntry(candidate, focus);
		if (entry != null) {
			projects.add(candidate);
			if (entry.isExported()) {
				addRelatedReferencing(candidate, projects);
				addRelatedReferenced(candidate, projects);
			}
		}
	}
}
 
Example 3
Source File: RefactoringScopeFactory.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
private static void addRelatedReferenced(IJavaProject focus, Set<IJavaProject> projects) throws CoreException {
	IProject[] referencedProjects = focus.getProject().getReferencedProjects();
	for (int i = 0; i < referencedProjects.length; i++) {
		IJavaProject candidate = JavaCore.create(referencedProjects[i]);
		if (candidate == null || projects.contains(candidate) || !candidate.exists()) {
			continue; // break cycle
		}
		IClasspathEntry entry = getReferencingClassPathEntry(focus, candidate);
		if (entry != null) {
			projects.add(candidate);
			if (entry.isExported()) {
				addRelatedReferenced(candidate, projects);
				addRelatedReferencing(candidate, projects);
			}
		}
	}
}
 
Example 4
Source File: RefactoringScopeFactory.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
private static IClasspathEntry getReferencingClassPathEntry(IJavaProject referencingProject, IJavaProject referencedProject) throws JavaModelException {
	IClasspathEntry result = null;
	IPath path = referencedProject.getProject().getFullPath();
	IClasspathEntry[] classpath = referencingProject.getResolvedClasspath(true);
	for (int i = 0; i < classpath.length; i++) {
		IClasspathEntry entry = classpath[i];
		if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT && path.equals(entry.getPath())) {
			if (entry.isExported()) {
				return entry;
			}
			// Consider it as a candidate. May be there is another entry that is
			// exported.
			result = entry;
		}
	}
	return result;
}
 
Example 5
Source File: RefactoringScopeFactory.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private static void addRelatedReferencing(IJavaProject focus, Set<IJavaProject> projects) throws CoreException {
	IProject[] referencingProjects= focus.getProject().getReferencingProjects();
	for (int i= 0; i < referencingProjects.length; i++) {
		IJavaProject candidate= JavaCore.create(referencingProjects[i]);
		if (candidate == null || projects.contains(candidate) || !candidate.exists())
			continue; // break cycle
		IClasspathEntry entry= getReferencingClassPathEntry(candidate, focus);
		if (entry != null) {
			projects.add(candidate);
			if (entry.isExported()) {
				addRelatedReferencing(candidate, projects);
				addRelatedReferenced(candidate, projects);
			}
		}
	}
}
 
Example 6
Source File: RefactoringScopeFactory.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private static void addRelatedReferenced(IJavaProject focus, Set<IJavaProject> projects) throws CoreException {
	IProject[] referencedProjects= focus.getProject().getReferencedProjects();
	for (int i= 0; i < referencedProjects.length; i++) {
		IJavaProject candidate= JavaCore.create(referencedProjects[i]);
		if (candidate == null || projects.contains(candidate) || !candidate.exists())
			continue; // break cycle
		IClasspathEntry entry= getReferencingClassPathEntry(focus, candidate);
		if (entry != null) {
			projects.add(candidate);
			if (entry.isExported()) {
				addRelatedReferenced(candidate, projects);
				addRelatedReferencing(candidate, projects);
			}
		}
	}
}
 
Example 7
Source File: RefactoringScopeFactory.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private static IClasspathEntry getReferencingClassPathEntry(IJavaProject referencingProject, IJavaProject referencedProject) throws JavaModelException {
	IClasspathEntry result= null;
	IPath path= referencedProject.getProject().getFullPath();
	IClasspathEntry[] classpath= referencingProject.getResolvedClasspath(true);
	for (int i= 0; i < classpath.length; i++) {
		IClasspathEntry entry= classpath[i];
		if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT && path.equals(entry.getPath())) {
			if (entry.isExported())
				return entry;
			// Consider it as a candidate. May be there is another entry that is
			// exported.
			result= entry;
		}
	}
	return result;
}
 
Example 8
Source File: JdtClasspathUriResolver.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
private URI findResourceInProjectRoot(IJavaProject javaProject, String path, Set<String> visited) throws CoreException {
	boolean includeAll = visited.isEmpty();
	if (visited.add(javaProject.getElementName())) {
		IProject project = javaProject.getProject();
		IResource resourceFromProjectRoot = project.findMember(path);
		if (resourceFromProjectRoot != null && resourceFromProjectRoot.exists()) {
			return createPlatformResourceURI(resourceFromProjectRoot);
		}
		for(IClasspathEntry entry: javaProject.getResolvedClasspath(true)) {
			if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT) {
				if (includeAll || entry.isExported()) {
					IResource referencedProject = project.getWorkspace().getRoot().findMember(entry.getPath());
					if (referencedProject != null && referencedProject.getType() == IResource.PROJECT) {
						IJavaProject referencedJavaProject = JavaCore.create((IProject) referencedProject);
						if (referencedJavaProject.exists()) {
							URI result = findResourceInProjectRoot(referencedJavaProject, path, visited);
							if (result != null) {
								return result;
							}
						}
					}
					break;
				}
			}
		}
	}
	return null;
}
 
Example 9
Source File: Importer.java    From hybris-commerce-eclipse-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * Make sure all the relevant backoffice jars are exported
 * 
 * @param monitor
 * @param javaProject
 * @throws JavaModelException
 */
private void fixBackofficeJars(IProgressMonitor monitor, IJavaProject javaProject) throws JavaModelException
{
	if (javaProject.getProject().getName().equalsIgnoreCase("backoffice"))
	{
		List<IClasspathEntry> entries = new LinkedList<IClasspathEntry>();
		IClasspathEntry[] classPathEntries = javaProject.getRawClasspath();
		boolean change = false;
		for (IClasspathEntry classpathEntry : classPathEntries) {
			// fix jar files
			if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
				if (classpathEntry.getPath().toString().contains("/backoffice/web/webroot/WEB-INF/lib/backoffice-core-") || 
						classpathEntry.getPath().toString().contains("/backoffice/web/webroot/WEB-INF/lib/backoffice-widgets-") ||
						classpathEntry.getPath().toString().contains("/backoffice/web/webroot/WEB-INF/lib/cockpitframework-") ||
						classpathEntry.getPath().toString().contains("/backoffice/web/webroot/WEB-INF/lib/cockpitcore-") ||
						classpathEntry.getPath().toString().contains("/backoffice/web/webroot/WEB-INF/lib/cockpittesting-") ||
						classpathEntry.getPath().toString().contains("/backoffice/web/webroot/WEB-INF/lib/cockpitwidgets-") ||
						classpathEntry.getPath().toString().contains("/backoffice/web/webroot/WEB-INF/lib/cockpit-") ||
						classpathEntry.getPath().toString().contains("/backoffice/web/webroot/WEB-INF/lib/zk") ||
						classpathEntry.getPath().toString().contains("/backoffice/web/webroot/WEB-INF/lib/zul-") ||
						classpathEntry.getPath().toString().contains("/backoffice/web/webroot/WEB-INF/lib/zcommon-"))
				{
					if (!classpathEntry.isExported())
					{
						change = true;
						IClasspathEntry clonedEntry = JavaCore.newLibraryEntry(classpathEntry.getPath(), classpathEntry.getSourceAttachmentPath(), classpathEntry.getSourceAttachmentRootPath(), classpathEntry.getAccessRules(), classpathEntry.getExtraAttributes(), true);
						entries.add(clonedEntry);
						continue;
					}			
				}
			}
			entries.add(classpathEntry);	
		}
		if (change)
		{
			FixProjectsUtils.setClasspath(entries.toArray(new IClasspathEntry[entries.size()]), javaProject, monitor);	
		}
	}
}
 
Example 10
Source File: RefactoringScopeFactory.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private static void addReferencingProjects(IJavaProject focus, Set<IJavaProject> projects) throws JavaModelException {
	IProject[] referencingProjects= focus.getProject().getReferencingProjects();
	for (int i= 0; i < referencingProjects.length; i++) {
		IJavaProject candidate= JavaCore.create(referencingProjects[i]);
		if (candidate == null || projects.contains(candidate) || !candidate.exists())
			continue; // break cycle
		IClasspathEntry entry= getReferencingClassPathEntry(candidate, focus);
		if (entry != null) {
			projects.add(candidate);
			if (entry.isExported())
				addReferencingProjects(candidate, projects);
		}
	}
}
 
Example 11
Source File: JdtTypeProvider.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * @see JavaProject computePackageFragmentRoots(IClasspathEntry, ObjectVector, HashSet, IClasspathEntry, boolean, boolean, java.util.Map)
 */
private void collectSourcePackageFragmentRoots(JavaProject javaProject, HashSet<String> rootIDs, IClasspathEntry referringEntry, ObjectVector result) throws JavaModelException {
	if (referringEntry == null){
		rootIDs.add(javaProject.rootID());
	} else if (rootIDs.contains(javaProject.rootID())) {
		return;
	}
	IWorkspaceRoot workspaceRoot = javaProject.getProject().getWorkspace().getRoot();
	for(IClasspathEntry entry: javaProject.getResolvedClasspath()) {
		switch(entry.getEntryKind()) {
			case IClasspathEntry.CPE_PROJECT:
				if (referringEntry != null && !entry.isExported())
					return;
				
				IPath pathToProject = entry.getPath();
				IResource referencedProject = workspaceRoot.findMember(pathToProject);
				if (referencedProject != null && referencedProject.getType() == IResource.PROJECT) {
					IProject casted = (IProject) referencedProject;
					if (JavaProject.hasJavaNature(casted)) {
						rootIDs.add(javaProject.rootID());
						JavaProject referencedJavaProject = (JavaProject) JavaCore.create(casted);
						collectSourcePackageFragmentRoots(referencedJavaProject, rootIDs, entry, result);
					}
				}
				break;
			case IClasspathEntry.CPE_SOURCE:
				// inlined from org.eclipse.jdt.internal.core.JavaProject
				// .computePackageFragmentRoots(IClasspathEntry, ObjectVector, HashSet, IClasspathEntry, boolean, boolean, Map)
				IPath projectPath = javaProject.getProject().getFullPath();
				IPath entryPath = entry.getPath();
				if (projectPath.isPrefixOf(entryPath)){
					Object target = JavaModel.getTarget(entryPath, true/*check existency*/);
					if (target != null) {
						if (target instanceof IFolder || target instanceof IProject){
							IPackageFragmentRoot root = javaProject.getPackageFragmentRoot((IResource)target);
							result.add(root);
						}
					}
				}
				break;
		}
	}
}
 
Example 12
Source File: ClasspathChange.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private int classpathContains(IClasspathEntry[] list, IClasspathEntry entry) {
	IPath[] exclusionPatterns = entry.getExclusionPatterns();
	IPath[] inclusionPatterns = entry.getInclusionPatterns();
	int listLen = list == null ? 0 : list.length;
	nextEntry: for (int i = 0; i < listLen; i++) {
		IClasspathEntry other = list[i];
		if (other.getContentKind() == entry.getContentKind()
			&& other.getEntryKind() == entry.getEntryKind()
			&& other.isExported() == entry.isExported()
			&& other.getPath().equals(entry.getPath())) {
				// check custom outputs
				IPath entryOutput = entry.getOutputLocation();
				IPath otherOutput = other.getOutputLocation();
				if (entryOutput == null) {
					if (otherOutput != null)
						continue;
				} else {
					if (!entryOutput.equals(otherOutput))
						continue;
				}

				// check inclusion patterns
				IPath[] otherIncludes = other.getInclusionPatterns();
				if (inclusionPatterns != otherIncludes) {
				    if (inclusionPatterns == null) continue;
					int includeLength = inclusionPatterns.length;
					if (otherIncludes == null || otherIncludes.length != includeLength)
						continue;
					for (int j = 0; j < includeLength; j++) {
						// compare toStrings instead of IPaths
						// since IPath.equals is specified to ignore trailing separators
						if (!inclusionPatterns[j].toString().equals(otherIncludes[j].toString()))
							continue nextEntry;
					}
				}
				// check exclusion patterns
				IPath[] otherExcludes = other.getExclusionPatterns();
				if (exclusionPatterns != otherExcludes) {
				    if (exclusionPatterns == null) continue;
					int excludeLength = exclusionPatterns.length;
					if (otherExcludes == null || otherExcludes.length != excludeLength)
						continue;
					for (int j = 0; j < excludeLength; j++) {
						// compare toStrings instead of IPaths
						// since IPath.equals is specified to ignore trailing separators
						if (!exclusionPatterns[j].toString().equals(otherExcludes[j].toString()))
							continue nextEntry;
					}
				}
				return i;
		}
	}
	return -1;
}