List of usage examples for org.eclipse.jdt.core IClasspathEntry isExported
boolean isExported();
From source file:org.eclipse.jst.j2ee.internal.classpathdep.UpdateClasspathAttributesOperation.java
License:Open Source License
private IClasspathEntry getMatchingEntryIgnoreAttributes(final Map entries, final IClasspathEntry entry) { final Iterator i = entries.keySet().iterator(); while (i.hasNext()) { final IClasspathEntry e = (IClasspathEntry) i.next(); if (e.getEntryKind() == entry.getEntryKind() && e.getPath().equals(entry.getPath()) && e.isExported() == entry.isExported()) { return e; }//from ww w .j av a 2 s .c o m } return null; }
From source file:org.eclipse.jst.j2ee.internal.classpathdep.UpdateClasspathAttributesOperation.java
License:Open Source License
/** * Updates the specified Java project so that only the specified classpath entries have * the WTP component dependency attribute. * @param javaProject Target Java project. * @param entries Classpath entries that should have the component dependency attribute. Map from IClasspathEntry * to the IClasspathAttribute for the WTP classpath component dependency. * @param modifyComponentDep True if modifying the dependency attribute, false if modifying the non-dependency attribute. * @throws CoreException Thrown if an error is encountered. *//*from w w w .j av a 2 s . c o m*/ private void updateDependencyAttributes(final IJavaProject javaProject, final Map entriesWithAttrib, final boolean modifyComponentDep, final boolean isLegacyJ2EE) throws CoreException { if (javaProject == null || !javaProject.getProject().isAccessible()) { return; } final List updatedClasspath = new ArrayList(); final IClasspathEntry[] rawClasspath = javaProject.getRawClasspath(); boolean needToUpdateClasspath = false; IClasspathAttribute attrib = UpdateClasspathAttributeUtil.createDependencyAttribute(); if (!modifyComponentDep) { attrib = UpdateClasspathAttributeUtil.createNonDependencyAttribute(); } for (int i = 0; i < rawClasspath.length; i++) { IClasspathEntry entry = rawClasspath[i]; final int kind = entry.getEntryKind(); boolean hasAttribute = ClasspathDependencyUtil .checkForComponentDependencyAttribute(entry, modifyComponentDep ? DependencyAttributeType.CLASSPATH_COMPONENT_DEPENDENCY : DependencyAttributeType.CLASSPATH_COMPONENT_NONDEPENDENCY, isLegacyJ2EE) != null; boolean shouldHaveAttribute = entriesWithAttrib.containsKey(entry); boolean updateAttributes = false; IClasspathAttribute[] updatedAttributes = null; if (shouldHaveAttribute) { if (!hasAttribute) { // should have the attribute and currently missing it attrib = (IClasspathAttribute) entriesWithAttrib.get(entry); updatedAttributes = updateAttributes(entry.getExtraAttributes(), attrib, true); needToUpdateClasspath = true; updateAttributes = true; } } else if (hasAttribute) { // should not have the attribute and currently has it updatedAttributes = updateAttributes(entry.getExtraAttributes(), attrib, false); needToUpdateClasspath = true; updateAttributes = true; } if (updateAttributes) { switch (kind) { case IClasspathEntry.CPE_CONTAINER: entry = JavaCore.newContainerEntry(entry.getPath(), entry.getAccessRules(), updatedAttributes, entry.isExported()); break; case IClasspathEntry.CPE_LIBRARY: entry = JavaCore.newLibraryEntry(entry.getPath(), entry.getSourceAttachmentPath(), entry.getSourceAttachmentRootPath(), entry.getAccessRules(), updatedAttributes, entry.isExported()); break; case IClasspathEntry.CPE_VARIABLE: entry = JavaCore.newVariableEntry(entry.getPath(), entry.getSourceAttachmentPath(), entry.getSourceAttachmentRootPath(), entry.getAccessRules(), updatedAttributes, entry.isExported()); break; case IClasspathEntry.CPE_PROJECT: // although project entries are not yet supported, allow the attribute here and let the validator flag as an error entry = JavaCore.newProjectEntry(entry.getPath(), entry.getAccessRules(), entry.combineAccessRules(), updatedAttributes, entry.isExported()); break; case IClasspathEntry.CPE_SOURCE: // although source entries are not supported, allow the attribute here and let the validator flag as an error entry = JavaCore.newSourceEntry(entry.getPath(), entry.getInclusionPatterns(), entry.getExclusionPatterns(), entry.getOutputLocation(), updatedAttributes); break; } } updatedClasspath.add(entry); } if (needToUpdateClasspath) { final IClasspathEntry[] updatedCPArray = (IClasspathEntry[]) updatedClasspath .toArray(new IClasspathEntry[updatedClasspath.size()]); javaProject.setRawClasspath(updatedCPArray, null); } }
From source file:org.eclipse.jst.j2ee.internal.common.classpath.J2EEComponentClasspathContainer.java
License:Open Source License
private void update(LastUpdate restoreState) { if (restoreState != null) { // performance; restore state from last session lastUpdate = restoreState;//from www . j av a 2 s .c o m List<IClasspathEntry> entriesList = new ArrayList<IClasspathEntry>(); for (int i = 0; i < lastUpdate.paths.length; i++) { if (lastUpdate.paths[i] != null) { IClasspathEntry newEntry = createEntry(restoreState, i); entriesList.add(newEntry); } } entries = new IClasspathEntry[entriesList.size()]; for (int i = 0; i < entries.length; i++) { entries[i] = entriesList.get(i); } return; } IVirtualComponent component = ComponentCore.createComponent(javaProjectLite.getProject()); if (component == null) { return; } Integer key = null; if (!javaProjectLite.getProject().getFile(StructureEdit.MODULE_META_FILE_NAME).exists()) { Integer hashCode = new Integer(javaProjectLite.getProject().hashCode()); key = keys.get(hashCode); if (key == null) { keys.put(hashCode, hashCode); key = hashCode; } Integer retryCount = retries.get(key); if (retryCount == null) { retryCount = new Integer(1); } else if (retryCount.intValue() > MAX_RETRIES) { return; } else { retryCount = new Integer(retryCount.intValue() + 1); } retries.put(key, retryCount); J2EEComponentClasspathUpdater.getInstance().queueUpdate(javaProjectLite.getProject()); return; } IVirtualReference[] refs = component.getReferences(onlyManifestRefs); List<IVirtualReference> refsList = new ArrayList<IVirtualReference>(); Set<IVirtualComponent> refedComps = new HashSet<IVirtualComponent>(); refedComps.add(component); for (IVirtualReference ref : refs) { if (ref.getDependencyType() == IVirtualReference.DEPENDENCY_TYPE_USES) { refsList.add(ref); refedComps.add(ref.getReferencedComponent()); } } lastUpdate.baseRefCount = refsList.size(); List<IVirtualReference> earLibReferences = getBaseEARLibRefs(component); lastUpdate.baseLibRefCount = earLibReferences.size(); for (IVirtualReference earRef : earLibReferences) { IVirtualComponent earRefComp = earRef.getReferencedComponent(); // check if the referenced component is already visited - avoid cycles in the build path if (!refedComps.contains(earRefComp)) { // visit the referenced component refsList.add(earRef); refedComps.add(earRefComp); } } //iterate with i index because this list may be augmented during iteration for (int i = 0; i < refsList.size(); i++) { IVirtualComponent comp = refsList.get(i).getReferencedComponent(); if (comp.isBinary()) { IVirtualReference[] binaryRefs = comp.getReferences(); for (int j = 0; j < binaryRefs.length; j++) { if (!refedComps.contains(binaryRefs[j].getReferencedComponent())) { refsList.add(binaryRefs[j]); refedComps.add(binaryRefs[j].getReferencedComponent()); } } } } lastUpdate.refCount = refsList.size(); lastUpdate.isBinary = new boolean[lastUpdate.refCount]; lastUpdate.paths = new IPath[lastUpdate.refCount]; boolean isWeb = JavaEEProjectUtilities.isDynamicWebProject(component.getProject()); boolean shouldAdd = true; List<IClasspathEntry> entriesList = new ArrayList<IClasspathEntry>(); try { boolean useJDTToControlExport = J2EEComponentClasspathContainerUtils .getDefaultUseEARLibrariesJDTExport(); if (useJDTToControlExport) { //if the default is not enabled, then check whether the container is being exported IClasspathEntry[] rawEntries = javaProjectLite.readRawClasspath(); for (int i = 0; i < rawEntries.length; i++) { IClasspathEntry entry = rawEntries[i]; if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { if (entry.getPath().equals(CONTAINER_PATH)) { lastUpdate.exportEntries = entry.isExported(); break; } } } } IVirtualReference ref = null; IVirtualComponent comp = null; for (int i = 0; i < refsList.size(); i++) { ref = refsList.get(i); comp = ref.getReferencedComponent(); lastUpdate.isBinary[i] = comp.isBinary(); shouldAdd = !(isWeb && ref.getRuntimePath().equals(WEBLIB)); if (!shouldAdd) { continue; } if (lastUpdate.isBinary[i]) { if (comp instanceof VirtualArchiveComponent) { VirtualArchiveComponent archiveComp = (VirtualArchiveComponent) comp; if (archiveComp.getArchiveType().equals(VirtualArchiveComponent.CLASSPATHARCHIVETYPE)) { // do not process components dynamically computed from the Java classpath continue; } } lastUpdate.paths[i] = (IPath) comp.getAdapter(IPath.class); IClasspathEntry newEntry = createEntry(lastUpdate, i); entriesList.add(newEntry); } else { IProject project = comp.getProject(); lastUpdate.paths[i] = project.getFullPath(); IClasspathEntry newEntry = createEntry(lastUpdate, i); entriesList.add(newEntry); } } } finally { entries = new IClasspathEntry[entriesList.size()]; for (int i = 0; i < entries.length; i++) { entries[i] = entriesList.get(i); } J2EEComponentClasspathContainerStore.saveState(javaProjectLite.getProject().getName(), lastUpdate); } }
From source file:org.eclipse.jst.j2ee.internal.common.operations.UpdateJavaBuildPathOperation.java
License:Open Source License
protected void ensureClasspathEntryIsExported(List cp, IClasspathEntry entry) { if (entry.isExported()) return;//from w w w . ja v a2 s . c o m int index = getIndex(cp, entry); IClasspathEntry newEntry = null; switch (entry.getEntryKind()) { case IClasspathEntry.CPE_PROJECT: newEntry = JavaCore.newProjectEntry(entry.getPath(), true); break; case IClasspathEntry.CPE_LIBRARY: newEntry = JavaCore.newLibraryEntry(entry.getPath(), entry.getSourceAttachmentPath(), entry.getSourceAttachmentRootPath(), true); break; case IClasspathEntry.CPE_VARIABLE: newEntry = JavaCore.newVariableEntry(entry.getPath(), entry.getSourceAttachmentPath(), entry.getSourceAttachmentRootPath()); } cp.set(index, newEntry); }
From source file:org.eclipse.jst.j2ee.internal.dialogs.TypeJavaSearchScope.java
License:Open Source License
/** * Method add. This method filters out all the classpath entries of the * project which are not exported.//from ww w. j a va2s .c o m * * @param javaProject * @param includesPrereqProjects * @param visitedProjects * @throws JavaModelException */ public void add(IJavaProject javaProject, boolean includesPrereqProjects, HashSet visitedProjects) throws JavaModelException { IProject project = javaProject.getProject(); if (!project.isAccessible() || !visitedProjects.add(project)) return; this.addEnclosingProjectOrJar(project.getFullPath()); IClasspathEntry[] entries = javaProject.getResolvedClasspath(true); IJavaModel model = javaProject.getJavaModel(); for (int i = 0, length = entries.length; i < length; i++) { IClasspathEntry entry = entries[i]; if (includeExportedClassPathEntriesOnly()) { if (!entry.isExported() && entry.getEntryKind() != IClasspathEntry.CPE_SOURCE) continue; } switch (entry.getEntryKind()) { case IClasspathEntry.CPE_LIBRARY: IPath path = entry.getPath(); this.add(path, true); this.addEnclosingProjectOrJar(path); break; case IClasspathEntry.CPE_PROJECT: if (includesPrereqProjects) { this.add(model.getJavaProject(entry.getPath().lastSegment()), true, visitedProjects); } break; case IClasspathEntry.CPE_SOURCE: this.add(entry.getPath(), true); break; } } }
From source file:org.eclipse.jst.j2ee.internal.web.operations.ClasspathUtilities.java
License:Open Source License
static protected boolean entryExists(IClasspathEntry entry, IClasspathEntry[] col) { for (int i = 0; i < col.length; i++) { IClasspathEntry otherEntry = col[i]; if (entry.getContentKind() != otherEntry.getContentKind()) continue; if (entry.getEntryKind() != otherEntry.getEntryKind()) continue; if (entry.isExported() != otherEntry.isExported()) continue; if (!entry.getPath().equals(otherEntry.getPath())) continue; return true; }/* w ww. jav a2s .com*/ return false; }
From source file:org.eclipse.jst.j2ee.internal.web.operations.WebPropertiesUtil.java
License:Open Source License
/** * Update the classpath entries and Server Root Name for this web project only. * //from ww w . ja v a2s.co m * @param project * @param webContentName * @return */ public static void updateWebContentNamePropertiesOnly(IProject project, String webContentName, IProgressMonitor progressMonitor) throws CoreException { IPath newPath = new Path(webContentName); if (getModuleServerRoot(project).equals(newPath)) return; if (!getModuleServerRoot(project).equals(webContentName)) { // if (webModuleArtifact.isJ2EE) { // Update the library references IJavaProject javaProject = JemProjectUtilities.getJavaProject(project); IClasspathEntry[] classpath = javaProject.getRawClasspath(); IClasspathEntry[] newClasspath = new IClasspathEntry[classpath.length]; for (int i = 0; i < classpath.length; i++) { if (classpath[i].getEntryKind() == IClasspathEntry.CPE_LIBRARY) { IClasspathEntry library = classpath[i]; IPath libpath = library.getPath(); IPath modServerRootPath = getModuleServerRoot(project).getFullPath(); if (modServerRootPath.isPrefixOf(libpath)) { IPath prunedPath = libpath.removeFirstSegments(modServerRootPath.segmentCount()); IPath relWebContentPath = new Path(webContentName + "/" + prunedPath.toString()); //$NON-NLS-1$ IResource absWebContentPath = project.getFile(relWebContentPath); IPath srcAttachmentPath = library.getSourceAttachmentPath(); if (null != srcAttachmentPath) { prunedPath = srcAttachmentPath.removeFirstSegments(modServerRootPath.segmentCount()); } IResource absWebContentSrcAttachmentPath = project.getFile(relWebContentPath); newClasspath[i] = JavaCore.newLibraryEntry(absWebContentPath.getFullPath(), absWebContentSrcAttachmentPath.getFullPath(), library.getSourceAttachmentRootPath(), library.isExported()); } else { newClasspath[i] = classpath[i]; } } else { newClasspath[i] = classpath[i]; } // } // Set the java output folder IFolder outputFolder = project.getFolder(getModuleServerRoot(project).getFullPath()); javaProject.setRawClasspath(newClasspath, outputFolder.getFullPath(), new SubProgressMonitor(progressMonitor, 1)); } // update websettings // TODO add to WebArtifactEdit // webNature.setModuleServerRootName(webContentName); } }
From source file:org.eclipse.jst.jsp.core.taglib.ProjectDescription.java
License:Open Source License
void handleElementChanged(IJavaElementDelta delta) { if (fBuildPathIsDirty) { return;//from www. j a va2 s .c o m } // Logger.log(Logger.INFO_DEBUG, "IJavaElementDelta: " + delta); IJavaElement element = delta.getElement(); if (element.getElementType() == IJavaElement.JAVA_PROJECT) { IJavaElementDelta[] affectedChildren = delta.getAffectedChildren(); for (int i = 0; i < affectedChildren.length; i++) { handleElementChanged(affectedChildren[i]); } } if (element.getElementType() == IJavaElement.PACKAGE_FRAGMENT_ROOT && ((IPackageFragmentRoot) element).isArchive()) { time0 = System.currentTimeMillis(); if (element.getElementType() == IJavaElement.PACKAGE_FRAGMENT_ROOT && ((IPackageFragmentRoot) element).isExternal()) { } String libLocation = null; int taglibRecordEventKind = -1; if ((delta.getFlags() & IJavaElementDelta.F_ADDED_TO_CLASSPATH) > 0 || (delta.getFlags() & IJavaElementDelta.F_ARCHIVE_CONTENT_CHANGED) > 0 || (delta.getFlags() & IJavaElementDelta.F_REMOVED_FROM_CLASSPATH) > 0) { taglibRecordEventKind = ITaglibIndexDelta.CHANGED; if ((delta.getFlags() & IJavaElementDelta.F_ADDED_TO_CLASSPATH) > 0) { taglibRecordEventKind = ITaglibIndexDelta.ADDED; } else if ((delta.getFlags() & IJavaElementDelta.F_ARCHIVE_CONTENT_CHANGED) > 0) { taglibRecordEventKind = ITaglibIndexDelta.CHANGED; } else if ((delta.getFlags() & IJavaElementDelta.F_REMOVED_FROM_CLASSPATH) > 0) { taglibRecordEventKind = ITaglibIndexDelta.REMOVED; } IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(element.getPath()); if (file.isAccessible() && file.getLocation() != null) libLocation = file.getLocation().toString(); else libLocation = element.getPath().toString(); } if (libLocation != null) { boolean fragmentisExported = true; try { IClasspathEntry rawClasspathEntry = ((IPackageFragmentRoot) element).getRawClasspathEntry(); /* * null may also be returned for deletions depending on * resource/build path notification order. If it's null, * it's been deleted and whether it's exported won't * really matter */ if (rawClasspathEntry != null) { fragmentisExported = rawClasspathEntry.isExported(); } } catch (JavaModelException e) { // IPackageFragmentRoot not part of the build path } if ((delta.getFlags() & IJavaElementDelta.F_ADDED_TO_CLASSPATH) > 0) { fBuildPathEntryCount++; } else if ((delta.getFlags() & IJavaElementDelta.F_REMOVED_FROM_CLASSPATH) > 0) { fBuildPathEntryCount--; } updateClasspathLibrary(libLocation, taglibRecordEventKind, fragmentisExported); } if (_debugIndexTime) Logger.log(Logger.INFO, "processed build path delta for " + fProject.getName() + "(" //$NON-NLS-1$//$NON-NLS-2$ + element.getPath() + ") in " + (System.currentTimeMillis() - time0) + "ms"); //$NON-NLS-1$ } }
From source file:org.eclipse.jst.jsp.core.taglib.ProjectDescription.java
License:Open Source License
/** * @param entry/*from w ww . ja v a2 s . c om*/ */ private void indexClasspath(IClasspathEntry entry) { switch (entry.getEntryKind()) { case IClasspathEntry.CPE_CONTAINER: { IClasspathContainer container = (IClasspathContainer) entry; IClasspathEntry[] containedEntries = container.getClasspathEntries(); for (int i = 0; i < containedEntries.length; i++) { indexClasspath(containedEntries[i]); } } break; case IClasspathEntry.CPE_LIBRARY: { /* * Ignore libs in required projects that are not exported */ IPath libPath = entry.getPath(); if (!fClasspathJars.containsKey(libPath.toString())) { final File file = libPath.toFile(); if (file.exists()) { if (file.isDirectory()) { indexDirectory(file, entry.isExported()); } else { updateClasspathLibrary(libPath.toString(), ITaglibIndexDelta.ADDED, entry.isExported()); } } else { /* * Note: .jars on the classpath inside of the project * will have duplicate entries in the JAR references * table that will e returned to * getAvailableTaglibRecords(). */ IResource resource = ResourcesPlugin.getWorkspace().getRoot().findMember(libPath); if (resource != null && resource.isAccessible()) { if (resource.getType() == IResource.FILE) { if (resource.getLocation() != null) { updateClasspathLibrary(resource.getLocation().toString(), ITaglibIndexDelta.ADDED, entry.isExported()); } } else if (resource.getType() == IResource.FOLDER) { try { resource.accept(new Indexer(), 0); } catch (CoreException e) { Logger.logException(e); } } } } } } break; case IClasspathEntry.CPE_PROJECT: { /* * We're currently ignoring whether the project exports all of * its build path */ IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(entry.getPath().lastSegment()); if (project != null) { fClasspathProjects.add(project); } } break; case IClasspathEntry.CPE_SOURCE: { IPath path = entry.getPath(); try { IResource sourceFolder = ResourcesPlugin.getWorkspace().getRoot().findMember(path); // could be a bad .classpath file if (sourceFolder != null) { sourceFolder.accept(new Indexer(), 0); } } catch (CoreException e) { Logger.logException(e); } } break; case IClasspathEntry.CPE_VARIABLE: { IPath libPath = JavaCore.getResolvedVariablePath(entry.getPath()); if (libPath != null) { File file = libPath.toFile(); // file in filesystem if (file.exists() && !file.isDirectory()) { updateClasspathLibrary(libPath.toString(), ITaglibRecordEvent.ADDED, entry.isExported()); } else { // workspace file IFile jarFile = ResourcesPlugin.getWorkspace().getRoot().getFile(libPath); if (jarFile.isAccessible() && jarFile.getType() == IResource.FILE && jarFile.getLocation() != null) { String jarPathString = jarFile.getLocation().toString(); updateClasspathLibrary(jarPathString, ITaglibRecordEvent.ADDED, entry.isExported()); } } } } break; } }
From source file:org.eclipse.jst.jsp.core.taglib.ProjectDescription.java
License:Open Source License
void queueElementChanged(IJavaElementDelta delta) { try {// w w w .j av a 2 s . c o m LOCK.acquire(); IJavaElement element = delta.getElement(); if (element.getElementType() == IJavaElement.JAVA_PROJECT) { IJavaElementDelta[] affectedChildren = delta.getAffectedChildren(); for (int i = 0; i < affectedChildren.length; i++) { queueElementChanged(affectedChildren[i]); } } if (element.getElementType() == IJavaElement.PACKAGE_FRAGMENT_ROOT && ((IPackageFragmentRoot) element).isArchive()) { IPath path = element.getPath(); boolean fragmentisExported = true; try { IClasspathEntry rawClasspathEntry = ((IPackageFragmentRoot) element).getRawClasspathEntry(); /* * null may also be returned for deletions depending on * resource/build path notification order. If it's null, * it's been deleted and whether it's exported won't * really matter */ if (rawClasspathEntry != null) { fragmentisExported = rawClasspathEntry.isExported(); } } catch (JavaModelException e) { // IPackageFragmentRoot not part of the build path } String key = path.toString(); if ((delta.getFlags() & IJavaElementDelta.F_ADDED_TO_CLASSPATH) > 0) { fPackageFragmentRootsAdded.put(key, new PackageFragmentRootDelta(path, ITaglibIndexDelta.ADDED, fragmentisExported)); fPackageFragmentRootsChanged.remove(key); fPackageFragmentRootsRemoved.remove(key); fBuildPathEntryCount++; } else if ((delta.getFlags() & IJavaElementDelta.F_ARCHIVE_CONTENT_CHANGED) > 0) { fPackageFragmentRootsChanged.put(key, new PackageFragmentRootDelta(path, ITaglibIndexDelta.CHANGED, fragmentisExported)); } else if (((delta.getFlags() & IJavaElementDelta.F_REMOVED_FROM_CLASSPATH) > 0) && ((delta.getFlags() & IJavaElementDelta.F_REORDER) == 0)) { fPackageFragmentRootsAdded.remove(key); fPackageFragmentRootsChanged.remove(key); fPackageFragmentRootsRemoved.put(key, new PackageFragmentRootDelta(path, ITaglibIndexDelta.REMOVED, fragmentisExported)); fBuildPathEntryCount--; } } } finally { LOCK.release(); } fBuildPathJob.cancel(); fBuildPathJob.schedule(2000); }