List of usage examples for org.eclipse.jdt.core IPackageFragmentRoot getKind
int getKind() throws JavaModelException;
From source file:org.eclipse.modisco.java.discoverer.AbstractDiscoverJavaModelFromProject.java
License:Open Source License
public static Set<IPackageFragmentRoot> computeRequiredLibraries(final IJavaProject project) throws JavaModelException { Set<IPackageFragmentRoot> libraries = new LinkedHashSet<IPackageFragmentRoot>(); // we keep package fragments which are binaries for (IPackageFragmentRoot lib : project.getPackageFragmentRoots()) { if (lib.exists() && lib.getKind() == IPackageFragmentRoot.K_BINARY) { libraries.add(lib);// w w w . ja va 2s . com } } return libraries; }
From source file:org.eclipse.modisco.java.discoverer.DiscoverJavaModelFromLibrary.java
License:Open Source License
public boolean isApplicableTo(final IPackageFragmentRoot packageFragmentRoot) { try {/* www. j a v a 2 s . c o m*/ return packageFragmentRoot.getKind() == IPackageFragmentRoot.K_BINARY; } catch (JavaModelException e) { MoDiscoLogger.logError(e, JavaActivator.getDefault()); return false; } }
From source file:org.eclipse.pde.api.tools.builder.tests.compatibility.ProjectTypeContainerTests.java
License:Open Source License
protected IPackageFragment[] getAllPackages() throws CoreException { IJavaProject project = JavaCore.create(getEnv().getProject("bundle.a")); //$NON-NLS-1$ IPackageFragmentRoot[] roots = project.getAllPackageFragmentRoots(); List<IPackageFragment> pkgs = new ArrayList<IPackageFragment>(); for (int i = 0; i < roots.length; i++) { IPackageFragmentRoot root = roots[i]; if (root.getKind() == IPackageFragmentRoot.K_SOURCE) { IJavaElement[] children = root.getChildren(); for (int j = 0; j < children.length; j++) { IPackageFragment frag = (IPackageFragment) children[j]; pkgs.add(frag);//from w w w. ja v a 2 s.c om collectAllPackages(frag, pkgs); } } } return pkgs.toArray(new IPackageFragment[pkgs.size()]); }
From source file:org.eclipse.pde.api.tools.internal.model.ProjectComponent.java
License:Open Source License
/** * Finds and returns an {@link IApiTypeContainer} for the specified source * folder, or <code>null</code> if it does not exist. If the source folder * shares an output location with a previous source folder, the output * location is shared (a new one is not created). * //from ww w . j av a 2s. com * @param location project relative path to the source folder * @return {@link IApiTypeContainer} or <code>null</code> */ private IApiTypeContainer getApiTypeContainer(String location, IApiComponent component) throws CoreException { if (this.fOutputLocationToContainer == null) { baselineDisposed(getBaseline()); } IResource res = fProject.getProject().findMember(new Path(location)); if (res != null) { IPackageFragmentRoot root = fProject.getPackageFragmentRoot(res); if (root.exists()) { if (root.getKind() == IPackageFragmentRoot.K_BINARY) { if (res.getType() == IResource.FOLDER) { // class file folder IPath location2 = res.getLocation(); IApiTypeContainer cfc = fOutputLocationToContainer.get(location2); if (cfc == null) { cfc = new ProjectTypeContainer(component, (IContainer) res); fOutputLocationToContainer.put(location2, cfc); } return cfc; } } else { IClasspathEntry entry = root.getRawClasspathEntry(); IPath outputLocation = entry.getOutputLocation(); if (outputLocation == null) { outputLocation = fProject.getOutputLocation(); } IApiTypeContainer cfc = fOutputLocationToContainer.get(outputLocation); if (cfc == null) { IPath projectFullPath = fProject.getProject().getFullPath(); IContainer container = null; if (projectFullPath.equals(outputLocation)) { // The project is its own output location container = fProject.getProject(); } else { container = fProject.getProject().getWorkspace().getRoot().getFolder(outputLocation); } cfc = new ProjectTypeContainer(component, container); fOutputLocationToContainer.put(outputLocation, cfc); } return cfc; } } } return null; }
From source file:org.eclipse.pde.api.tools.internal.model.ProjectComponent.java
License:Open Source License
/** * Returns the cached API type container for the given package fragment * root, or <code>null</code> if none. The given package fragment has to be * a SOURCE package fragment - this method is only used by the project API * description to obtain a class file corresponding to a compilation unit * when tag scanning (to resolve signatures). * /*from w ww .j a v a 2 s . co m*/ * @param root source package fragment root * @return API type container associated with the package fragment root, or * <code>null</code> if none */ public IApiTypeContainer getTypeContainer(IPackageFragmentRoot root) throws CoreException { if (root.getKind() == IPackageFragmentRoot.K_SOURCE) { getApiTypeContainers(); // ensure initialized IResource resource = root.getResource(); if (resource != null) { String location = resource.getProjectRelativePath().toString(); return getApiTypeContainer(location, this); } } return null; }
From source file:org.eclipse.pde.api.tools.internal.ProjectApiDescription.java
License:Open Source License
@Override protected ManifestNode createNode(ManifestNode parentNode, IElementDescriptor element) { switch (element.getElementType()) { case IElementDescriptor.PACKAGE: try {//from w w w .j a v a 2s .c o m IPackageDescriptor pkg = (IPackageDescriptor) element; IPackageFragmentRoot[] roots = getJavaProject().getPackageFragmentRoots(); List<IPackageFragment> fragments = new ArrayList<IPackageFragment>(1); for (int i = 0; i < roots.length; i++) { IPackageFragmentRoot root = roots[i]; IClasspathEntry entry = root.getRawClasspathEntry(); switch (entry.getEntryKind()) { case IClasspathEntry.CPE_SOURCE: case IClasspathEntry.CPE_LIBRARY: IPackageFragment fragment = root.getPackageFragment(pkg.getName()); if (fragment.exists()) { fragments.add(fragment); } break; default: if (!root.isArchive() && root.getKind() == IPackageFragmentRoot.K_BINARY) { // class file folder fragment = root.getPackageFragment(pkg.getName()); if (fragment.exists()) { fragments.add(fragment); } } } } if (fragments.isEmpty()) { return null; } else { return newPackageNode(fragments.toArray(new IPackageFragment[fragments.size()]), parentNode, element, VisibilityModifiers.PRIVATE, RestrictionModifiers.NO_RESTRICTIONS); } } catch (CoreException e) { return null; } case IElementDescriptor.TYPE: IReferenceTypeDescriptor descriptor = (IReferenceTypeDescriptor) element; try { IType type = null; String name = descriptor.getName(); if (parentNode instanceof PackageNode) { IPackageFragment[] fragments = ((PackageNode) parentNode).fFragments; for (int i = 0; i < fragments.length; i++) { IPackageFragment fragment = fragments[i]; if (fragment.getKind() == IPackageFragmentRoot.K_SOURCE) { ICompilationUnit unit = fragment.getCompilationUnit(name + ".java"); //$NON-NLS-1$ try { IResource resource = unit.getUnderlyingResource(); if (resource != null) { type = unit.getType(name); } } catch (JavaModelException jme) { // exception if the resource does not exist if (!jme.getJavaModelStatus().isDoesNotExist()) { throw jme; } } } else { IClassFile file = fragment.getClassFile(name + ".class"); //$NON-NLS-1$ if (file.exists()) { type = file.getType(); } } } } else if (parentNode instanceof TypeNode) { type = ((TypeNode) parentNode).fType.getType(name); } if (type != null) { return newTypeNode(type, parentNode, element, VISIBILITY_INHERITED, RestrictionModifiers.NO_RESTRICTIONS); } } catch (CoreException e) { return null; } return null; default: break; } return super.createNode(parentNode, element); }
From source file:org.eclipse.pde.internal.core.ClasspathComputer.java
License:Open Source License
private static void addSourceFolder(IBuildEntry buildEntry, IProject project, HashSet<IPath> paths, ArrayList<IClasspathEntry> result) throws CoreException { String[] folders = buildEntry.getTokens(); for (int j = 0; j < folders.length; j++) { String folder = folders[j]; IPath path = project.getFullPath().append(folder); if (paths.add(path)) { if (project.findMember(folder) == null) { CoreUtility.createFolder(project.getFolder(folder)); } else { IPackageFragmentRoot root = JavaCore.create(project).getPackageFragmentRoot(path.toString()); if (root.exists() && root.getKind() == IPackageFragmentRoot.K_BINARY) { result.add(root.getRawClasspathEntry()); continue; }/*w ww . j av a2 s . c o m*/ } result.add(JavaCore.newSourceEntry(path)); } } }
From source file:org.eclipse.pde.internal.core.ClasspathComputer.java
License:Open Source License
private static void addLibraryEntry(IProject project, IPluginLibrary library, IPath sourceAttachment, IClasspathAttribute[] attrs, ArrayList<IClasspathEntry> result) throws JavaModelException { String name = ClasspathUtilCore.expandLibraryName(library.getName()); IResource jarFile = project.findMember(name); if (jarFile == null) return;/*w w w. j a v a 2 s. c om*/ IPackageFragmentRoot root = JavaCore.create(project).getPackageFragmentRoot(jarFile); if (root.exists() && root.getKind() == IPackageFragmentRoot.K_BINARY) { IClasspathEntry oldEntry = root.getRawClasspathEntry(); // If we have the same binary root but new or different source, we should recreate the entry if ((sourceAttachment == null && oldEntry.getSourceAttachmentPath() != null) || (sourceAttachment != null && sourceAttachment.equals(oldEntry.getSourceAttachmentPath()))) { if (!result.contains(oldEntry)) { result.add(oldEntry); return; } } } IClasspathEntry entry = createClasspathEntry(project, jarFile, name, sourceAttachment, attrs, library.isExported()); if (!result.contains(entry)) result.add(entry); }
From source file:org.eclipse.pde.internal.ui.wizards.tools.ConvertJarsAction.java
License:Open Source License
/** * @see IActionDelegate#selectionChanged(IAction, ISelection) *//*from w ww . j a va 2 s . com*/ public void selectionChanged(IAction action, ISelection s) { boolean enabled = true; if (s instanceof IStructuredSelection) { selection = (IStructuredSelection) s; if (selection.size() == 0) return; Iterator<?> i = selection.iterator(); while (i.hasNext()) { Object obj = i.next(); if (obj instanceof IPackageFragmentRoot) { try { IPackageFragmentRoot packageFragment = (IPackageFragmentRoot) obj; if (packageFragment.getKind() == IPackageFragmentRoot.K_BINARY) { if (PDE.hasPluginNature(packageFragment.getJavaProject().getProject())) { if (packageFragment.getRawClasspathEntry() .getEntryKind() == IClasspathEntry.CPE_LIBRARY) continue; } } } catch (JavaModelException e) { } } enabled = false; break; } } else { enabled = false; this.selection = null; } action.setEnabled(enabled); }
From source file:org.eclipse.recommenders.internal.coordinates.rcp.EclipseDependencyListener.java
License:Open Source License
private Set<DependencyInfo> searchForAllDependenciesOfProject(final IJavaProject javaProject) { Set<DependencyInfo> dependencies = Sets.newHashSet(); Set<IPackageFragmentRoot> jreRoots = jrePackageFragmentRoots.get(getDependencyInfoForProject(javaProject)); try {/* ww w . j av a2s. co m*/ for (final IPackageFragmentRoot packageFragmentRoot : javaProject.getAllPackageFragmentRoots()) { if (!jreRoots.contains(packageFragmentRoot) && packageFragmentRoot instanceof JarPackageFragmentRoot) { DependencyInfo dependencyInfo = createDependencyInfoForJar(packageFragmentRoot); dependencies.add(dependencyInfo); } else if (packageFragmentRoot.getKind() == IPackageFragmentRoot.K_SOURCE && packageFragmentRoot.getJavaProject() != null) { DependencyInfo dependencyInfo = DependencyInfos .createDependencyInfoForProject(packageFragmentRoot.getJavaProject()); dependencies.add(dependencyInfo); } } } catch (JavaModelException e) { Logs.log(LogMessages.ERROR_FAILED_TO_SEARCH_FOR_PROJECT_DEPENDENCIES, e, javaProject); } return dependencies; }