List of usage examples for org.eclipse.jdt.core IPackageFragmentRoot getRawClasspathEntry
IClasspathEntry getRawClasspathEntry() throws JavaModelException;
From source file:org.eclipse.jst.j2ee.internal.archive.ConnectorComponentArchiveLoadAdapter.java
License:Open Source License
private IArchiveResource getNestedJar(IPackageFragmentRoot sourceRoot) throws JavaModelException, ArchiveOpenFailureException { IPath outputPath = sourceRoot.getRawClasspathEntry().getOutputLocation(); if (outputPath == null) { IProject project = vComponent.getProject(); try {//from ww w . j a va 2 s. co m if (project.hasNature(JavaCore.NATURE_ID)) { IJavaProject javaProject = JavaCore.create(project); outputPath = javaProject.getOutputLocation(); } } catch (CoreException e) { J2EEPlugin.logError(e); } if (outputPath == null) { return null; } } IFolder javaOutputFolder = ResourcesPlugin.getWorkspace().getRoot().getFolder(outputPath); indexClassesForOutputFolder(javaOutputFolder); IContainer sourceContainer = (IContainer) sourceRoot.getResource(); int sourceContainerSegmentCount = sourceContainer.getProjectRelativePath().segmentCount(); boolean isModuleRoot = knownDD.getProjectRelativePath().toString() .startsWith(sourceContainer.getProjectRelativePath().toString()); Set iFilesSet = new HashSet(); boolean foundJava = gatherFilesForJAR(iFilesSet, sourceContainer, isModuleRoot, false, sourceContainerSegmentCount); if (!isModuleRoot || foundJava) { List<IFile> iFilesList = Collections.list(Collections.enumeration(iFilesSet)); for (int i = 0; i < iFilesList.size(); i++) { filesHolder.removeIFile(iFilesList.get(i)); } IArchiveResource nestedArchive = createNestedArchive(iFilesList, sourceContainer, javaOutputFolder); return nestedArchive; } return null; }
From source file:org.eclipse.jst.j2ee.internal.jca.archive.operations.ConnectorComponentLoadStrategyImpl.java
License:Open Source License
private File getNestedJar(IPackageFragmentRoot sourceRoot) throws JavaModelException { IPath outputPath = sourceRoot.getRawClasspathEntry().getOutputLocation(); if (outputPath == null) { IProject project = vComponent.getProject(); try {//from ww w. j av a 2 s . c o m if (project.hasNature(JavaCore.NATURE_ID)) { IJavaProject javaProject = JavaCore.create(project); outputPath = javaProject.getOutputLocation(); } } catch (CoreException e) { Logger.getLogger().logError(e); } if (outputPath == null) { return null; } } IFolder javaOutputFolder = ResourcesPlugin.getWorkspace().getRoot().getFolder(outputPath); indexClassesForOutputFolder(javaOutputFolder); IContainer sourceContainer = (IContainer) sourceRoot.getResource(); int sourceContainerSegmentCount = sourceContainer.getProjectRelativePath().segmentCount(); boolean isModuleRoot = knownDD.getProjectRelativePath().toString() .startsWith(sourceContainer.getProjectRelativePath().toString()); Set iFilesSet = new HashSet(); boolean foundJava = gatherFilesForJAR(iFilesSet, sourceContainer, isModuleRoot, false, sourceContainerSegmentCount); if (!isModuleRoot || foundJava) { List iFilesList = Collections.list(Collections.enumeration(iFilesSet)); for (int i = 0; i < iFilesList.size(); i++) { filesHolder.removeIFile((IFile) iFilesList.get(i)); } File nestedArchive = createNestedArchive(iFilesList, sourceContainer, javaOutputFolder); return nestedArchive; } return null; }
From source file:org.eclipse.jst.j2ee.internal.project.J2EEProjectUtilities.java
License:Open Source License
/** * @deprecated use {@link JavaLiteUtilities#getJavaOutputContainer(IJavaProjectLite, IClasspathEntry)} * /* ww w . j ava2 s . co m*/ * {@link #getJavaOutputContainer(IJavaProjectLite, IClasspathEntry)} * @param project * @param sourceContainer * @return */ public static IContainer getOutputContainer(IProject project, IPackageFragmentRoot sourceContainer) { try { return JavaLiteUtilities.getJavaOutputContainer(JavaCoreLite.create(project), sourceContainer.getRawClasspathEntry()); } catch (JavaModelException e) { org.eclipse.jst.j2ee.internal.plugin.J2EEPlugin.logError(e); } return null; }
From source file:org.eclipse.jst.server.jetty.core.internal.wst.ModuleTraverser.java
License:Open Source License
private static Map getComponentClasspathDependencies(final IJavaProject javaProject, final boolean isWebApp) throws CoreException { // get the raw entries final Map referencedRawEntries = getRawComponentClasspathDependencies(javaProject); final Map validRawEntries = new HashMap(); // filter out non-valid referenced raw entries final Iterator i = referencedRawEntries.keySet().iterator(); while (i.hasNext()) { final IClasspathEntry entry = (IClasspathEntry) i.next(); final IClasspathAttribute attrib = (IClasspathAttribute) referencedRawEntries.get(entry); if (isValid(entry, attrib, isWebApp, javaProject.getProject())) { validRawEntries.put(entry, attrib); }//from ww w . jav a2 s.c o m } // if we have no valid raw entries, return empty map if (validRawEntries.isEmpty()) { return Collections.EMPTY_MAP; } // XXX Would like to replace the code below with use of a public JDT API that returns // the raw IClasspathEntry for a given resolved IClasspathEntry (see see https://bugs.eclipse.org/bugs/show_bug.cgi?id=183995) // The code must currently leverage IPackageFragmentRoot to determine this // mapping and, because IPackageFragmentRoots do not maintain IClasspathEntry data, a prior // call is needed to getResolvedClasspath() and the resolved IClasspathEntries have to be stored in a Map from IPath-to-IClasspathEntry to // support retrieval using the resolved IPackageFragmentRoot // retrieve the resolved classpath final IClasspathEntry[] entries = javaProject.getResolvedClasspath(true); final Map pathToResolvedEntry = new HashMap(); // store in a map from path to entry for (int j = 0; j < entries.length; j++) { pathToResolvedEntry.put(entries[j].getPath(), entries[j]); } final Map referencedEntries = new LinkedHashMap(); // grab all IPackageFragmentRoots final IPackageFragmentRoot[] roots = javaProject.getPackageFragmentRoots(); for (int j = 0; j < roots.length; j++) { final IPackageFragmentRoot root = roots[j]; final IClasspathEntry rawEntry = root.getRawClasspathEntry(); // is the raw entry valid? IClasspathAttribute attrib = (IClasspathAttribute) validRawEntries.get(rawEntry); if (attrib == null) { continue; } final IPath pkgFragPath = root.getPath(); final IClasspathEntry resolvedEntry = (IClasspathEntry) pathToResolvedEntry.get(pkgFragPath); final IClasspathAttribute resolvedAttrib = checkForComponentDependencyAttribute(resolvedEntry, DEPENDECYATTRIBUTETYPE_DEPENDENCY_OR_NONDEPENDENCY); // attribute for the resolved entry must either be unspecified or it must be the // dependency attribute for it to be included if (resolvedAttrib == null || resolvedAttrib.getName().equals(CLASSPATH_COMPONENT_DEPENDENCY)) { // filter out resolved entry if it doesn't pass the validation rules if (isValid(resolvedEntry, resolvedAttrib != null ? resolvedAttrib : attrib, isWebApp, javaProject.getProject())) { if (resolvedAttrib != null) { // if there is an attribute on the sub-entry, use that attrib = resolvedAttrib; } referencedEntries.put(resolvedEntry, attrib); } } } return referencedEntries; }
From source file:org.eclipse.m2e.jdt.internal.BuildPathManager.java
License:Open Source License
void attachSourcesAndJavadoc(IPackageFragmentRoot fragment, File sources, File javadoc, IProgressMonitor monitor) {/*from w w w . jav a 2s. c o m*/ IJavaProject javaProject = fragment.getJavaProject(); IPath srcPath = sources != null ? Path.fromOSString(sources.getAbsolutePath()) : null; String javaDocUrl = getJavaDocUrl(javadoc); try { IClasspathEntry[] cp = javaProject.getRawClasspath(); for (int i = 0; i < cp.length; i++) { IClasspathEntry entry = cp[i]; if (IClasspathEntry.CPE_LIBRARY == entry.getEntryKind() && entry.equals(fragment.getRawClasspathEntry())) { List<IClasspathAttribute> attributes = new ArrayList<IClasspathAttribute>( Arrays.asList(entry.getExtraAttributes())); if (srcPath == null) { // configure javadocs if available if (javaDocUrl != null) { attributes.add(JavaCore.newClasspathAttribute( IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME, javaDocUrl)); } } cp[i] = JavaCore.newLibraryEntry(entry.getPath(), srcPath, null, entry.getAccessRules(), // attributes.toArray(new IClasspathAttribute[attributes.size()]), // entry.isExported()); break; } } javaProject.setRawClasspath(cp, monitor); } catch (CoreException e) { log.error(e.getMessage(), e); } }
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). * /*w ww . ja v a2 s.c o m*/ * @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.ProjectApiDescription.java
License:Open Source License
@Override protected ManifestNode createNode(ManifestNode parentNode, IElementDescriptor element) { switch (element.getElementType()) { case IElementDescriptor.PACKAGE: try {//w ww . j a v a2 s .co 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.api.tools.util.tests.ApiBaselineManagerTests.java
License:Open Source License
/** * Tests that the output folder settings for a source folder cause the class * file containers to be updated/*from w w w . j av a2s. com*/ */ public void testWPUpdateOutputFolderSrcFolderChanged() throws Exception { IJavaProject project = getTestingProject(); IApiComponent component = getWorkspaceBaseline().getApiComponent(project.getElementName()); assertNotNull("the workspace component must exist", component); //$NON-NLS-1$ int before = component.getApiTypeContainers().length; ProjectUtils.addFolderToProject(project.getProject(), "bin3"); //$NON-NLS-1$ IContainer container = ProjectUtils.addFolderToProject(project.getProject(), "src2"); //$NON-NLS-1$ // add to bundle class path IBundleProjectService service = ProjectUtils.getBundleProjectService(); IBundleClasspathEntry next = service.newBundleClasspathEntry(new Path("src2"), new Path("bin3"), //$NON-NLS-1$//$NON-NLS-2$ new Path("next.jar")); //$NON-NLS-1$ ProjectUtils.addBundleClasspathEntry(project.getProject(), next); waitForAutoBuild(); // retrieve updated component component = getWorkspaceBaseline().getApiComponent(project.getElementName()); assertTrue("there must be one more container after the change", //$NON-NLS-1$ before < component.getApiTypeContainers().length); IPackageFragmentRoot root = project.getPackageFragmentRoot(container); assertTrue("the class file container for src2 must be 'bin3'", //$NON-NLS-1$ "bin3".equals(root.getRawClasspathEntry().getOutputLocation().toFile().getName())); //$NON-NLS-1$ }
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; }/*from w w w.jav a 2 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;/*from w ww . j av a2 s . c o m*/ 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); }