Example usage for org.eclipse.jdt.core IClasspathEntry CPE_CONTAINER

List of usage examples for org.eclipse.jdt.core IClasspathEntry CPE_CONTAINER

Introduction

In this page you can find the example usage for org.eclipse.jdt.core IClasspathEntry CPE_CONTAINER.

Prototype

int CPE_CONTAINER

To view the source code for org.eclipse.jdt.core IClasspathEntry CPE_CONTAINER.

Click Source Link

Document

Entry kind constant describing a classpath entry representing a name classpath container.

Usage

From source file:org.eclipse.jst.j2ee.internal.classpathdep.ClasspathDependencyValidator.java

License:Open Source License

/**
 * Checks if the specified Java classpath entry is a valid WTP virtual component reference.
 * Does not check the runtime path./*from   w  ww.j a v  a2 s.  c  o  m*/
 * @param entry Raw or resolved classpath entry to validate. 
 * @param attrib The WTP classpath component dependency attribute. Null if it has not yet been set.
 * @param isWebApp True if the target project is associated with a web project.
 * @param project The parent project.
 * @param data Data required for validation. Can be computed once for the project and reused.
 * @return IMessages representing validation results.
 */
public static IMessage[] validateVirtualComponentEntry(final IClasspathEntry entry,
        final IClasspathAttribute attrib, final boolean isWebApp, final IProject project,
        final ClasspathDependencyValidatorData data) {
    List results = new ArrayList();
    if (entry == null) {
        return (IMessage[]) results.toArray(new IMessage[results.size()]);
    }

    final int kind = entry.getEntryKind();
    final boolean isFile = !ClasspathDependencyUtil.isClassFolderEntry(entry);

    if (kind == IClasspathEntry.CPE_PROJECT) {
        // Project cp entry
        // Allow faceted projects only, and not plain java projects
        boolean isFacetedProject = false;
        IProject referencedProject = ResourcesPlugin.getWorkspace().getRoot()
                .getProject(entry.getPath().toString());
        try {
            isFacetedProject = FacetedProjectFramework.isFacetedProject(referencedProject);
        } catch (CoreException ce) {
            //Ignore. Thrown when project metadata cannot be read. In that case we will treat the project as non faceted 
        }
        if (!isFacetedProject) {
            results.add(new Message("classpathdependencyvalidator", //$NON-NLS-1$
                    IMessage.HIGH_SEVERITY, ProjectClasspathEntry, new String[] { entry.getPath().toString() },
                    project));
            return (IMessage[]) results.toArray(new IMessage[results.size()]);
        }
    } else if (kind == IClasspathEntry.CPE_SOURCE) {

        // Source cp entry

        results.add(new Message("classpathdependencyvalidator", //$NON-NLS-1$
                IMessage.HIGH_SEVERITY, SourceEntry, new String[] { entry.getPath().toString() }, project));
        return (IMessage[]) results.toArray(new IMessage[results.size()]);
    } else if (kind == IClasspathEntry.CPE_CONTAINER) {

        // get the set of classpath container IDs that should be filtered
        List filteredIDs = ClasspathDependencyExtensions.get().getFilteredClasspathContainerIDs();
        final IPath path = entry.getPath();
        for (int i = 0; i < filteredIDs.size(); i++) {
            final String id = (String) filteredIDs.get(i);
            if (path.segment(0).equals(id)) {
                // filtered classpath container
                results.add(new Message("classpathdependencyvalidator", //$NON-NLS-1$
                        IMessage.HIGH_SEVERITY, FilteredContainer, new String[] { entry.getPath().toString() },
                        project));
                return (IMessage[]) results.toArray(new IMessage[results.size()]);
            }
        }

    } else if (kind == IClasspathEntry.CPE_LIBRARY) {
        if (!isFile) {
            final IContainer[] mappedClassFolders = data.getMappedClassFolders();
            final IResource resource = ClasspathDependencyUtil.getEntryResource(entry);
            if (resource != null) {
                final IPath fullClassFolderPath = resource.getFullPath();
                boolean alreadyMapped = false;
                for (int j = 0; j < mappedClassFolders.length; j++) {
                    if (fullClassFolderPath.equals(mappedClassFolders[j].getFullPath())) {
                        // entry resolves to same file as existing class folder mapping, skip
                        alreadyMapped = true;
                        break;
                    }
                }

                // Class folder reference; ensure this is not already mapped via the component file.
                if (alreadyMapped) {
                    results.add(new Message("classpathdependencyvalidator", //$NON-NLS-1$
                            IMessage.HIGH_SEVERITY, DuplicateClassFolderEntry,
                            new String[] { entry.getPath().toString() }, project));
                }
            }
        }
    }

    //       final IPath runtimePath = ClasspathDependencyUtil.getRuntimePath(attrib, isWebApp, !isFile);
    //       if (!isWebApp) {
    //          // only a ../ or / mapping is currently legal in a non-web context
    //          if (!(runtimePath.equals(IClasspathDependencyConstants.RUNTIME_MAPPING_INTO_CONTAINER_PATH) 
    //                || runtimePath.equals(IClasspathDependencyConstants.RUNTIME_MAPPING_INTO_COMPONENT_PATH))) { 
    //             results.add(new Message("classpathdependencyvalidator", //$NON-NLS-1$
    //                   IMessage.HIGH_SEVERITY, InvalidNonWebRuntimePath, new String[]{entry.getPath().toString(), runtimePath.toString()}, project));
    //          }
    //       } else {
    //          String pathStr = runtimePath.toString();
    //          // can only be ../, /WEB-INF/lib or /WEB-INF/classes
    //          if (!runtimePath.equals(IClasspathDependencyConstants.RUNTIME_MAPPING_INTO_CONTAINER_PATH) 
    //             && !runtimePath.equals(IClasspathDependencyConstants.WEB_INF_LIB_PATH)
    //             && !runtimePath.equals(IClasspathDependencyConstants.WEB_INF_CLASSES_PATH)) { 
    //             results.add(new Message("classpathdependencyvalidator", //$NON-NLS-1$
    //                   IMessage.HIGH_SEVERITY, InvalidWebRuntimePath, new String[]{entry.getPath().toString(), pathStr}, project));
    //          }
    //       }

    return (IMessage[]) results.toArray(new IMessage[results.size()]);
}

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.
 *//*  w w w.j a  v a 2 s . co  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;// w  ww .j  a v a2s  .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.classpath.J2EEComponentClasspathContainerUtils.java

License:Open Source License

public static IClasspathEntry getInstalledContainerEntry(IJavaProject jproj, IPath classpathContainerPath) {
    if (jproj.exists()) {
        IJavaProjectLite javaProjectLite = JavaCoreLite.create(jproj);
        IClasspathEntry[] cpes = javaProjectLite.readRawClasspath();
        for (int j = 0; j < cpes.length; j++) {
            final IClasspathEntry cpe = cpes[j];
            if (cpe.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
                if (cpe.getPath().equals(classpathContainerPath)) {
                    return cpe; // entry found
                }// www  . java2s . c o m
            }
        }
    }
    // entry not found
    return null;
}

From source file:org.eclipse.jst.j2ee.internal.common.classpath.WtpUserLibraryProviderInstallOperationConfig.java

License:Open Source License

@Override
public synchronized void init(final IFacetedProjectBase fproj, final IProjectFacetVersion fv,
        final ILibraryProvider provider) {
    super.init(fproj, fv, provider);

    this.includeWithApplicationEnabled = hasModuleFacet(fproj);

    final IProject project = fproj.getProject();

    if (project != null) {
        final IProjectFacet f = fv.getProjectFacet();

        final ILibraryProvider currentProvider = LibraryProviderFramework.getCurrentProvider(project, f);

        if (currentProvider == provider) {
            this.includeWithApplicationEnabled = false;

            final IJavaProject jproj = JavaCore.create(project);

            try {
                for (IClasspathEntry cpe : jproj.getRawClasspath()) {
                    if (cpe.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
                        final IPath path = cpe.getPath();

                        if (path.segmentCount() >= 2
                                && path.segment(0).equals(JavaCore.USER_LIBRARY_CONTAINER_ID)) {
                            for (IClasspathAttribute attr : cpe.getExtraAttributes()) {
                                if (attr.getName()
                                        .equals(IClasspathDependencyConstants.CLASSPATH_COMPONENT_DEPENDENCY)) {
                                    this.includeWithApplicationEnabled = true;
                                    break;
                                }/* www . j  a  v a2 s.co  m*/
                            }
                        }
                    }

                    if (this.includeWithApplicationEnabled) {
                        break;
                    }
                }
            } catch (CoreException e) {
                throw new RuntimeException(e);
            }
        }
    }

    this.includeWithApplicationSettingEnabled = (this.includeWithApplicationEnabled) ? true
            : hasModuleFacet(fproj);

    this.facetedProjectListener = new IFacetedProjectListener() {
        public void handleEvent(final IFacetedProjectEvent event) {
            final boolean moduleFaceted = hasModuleFacet(event.getWorkingCopy());
            setIncludeWithApplicationEnabled(moduleFaceted);
            setIncludeWithApplicationSettingEnabled(moduleFaceted);
        }
    };

    fproj.addListener(this.facetedProjectListener, IFacetedProjectEvent.Type.PROJECT_FACETS_CHANGED);
}

From source file:org.eclipse.jst.j2ee.internal.servertarget.ServerTargetHelper.java

License:Open Source License

public static List getExistingNonServerTargetClasspath(IProject project) {
    IJavaProject javaProject = null;/*from www .  j  a  v  a 2 s . c  o  m*/
    List list = new ArrayList();
    try {
        javaProject = (IJavaProject) project.getNature(JavaCore.NATURE_ID);
    } catch (Exception e) {
    }
    if (javaProject != null) {
        try {
            IClasspathEntry[] cp = javaProject.getRawClasspath();
            int size = cp.length;
            for (int i = 0; i < size; i++) {
                int entryKind = cp[i].getEntryKind();
                if (entryKind != IClasspathEntry.CPE_SOURCE && entryKind != IClasspathEntry.CPE_LIBRARY
                        && entryKind != IClasspathEntry.CPE_PROJECT
                        && (entryKind == IClasspathEntry.CPE_VARIABLE && isWASVariable(cp[i]))
                        && (entryKind != IClasspathEntry.CPE_CONTAINER
                                || !cp[i].getPath().segment(0).equals(SERVER_CONTAINER))) {
                    list.add(cp[i]);
                }
            }
        } catch (Exception e) {
        }
        return list;
    }
    return list;
}

From source file:org.eclipse.jst.j2ee.internal.ui.AddJavaBuildPathEntriesWizardFragment.java

License:Open Source License

public static String getClasspathEntryText(final IJavaProject jproj, final IClasspathEntry cpe) {
    final int type = cpe.getEntryKind();

    if (type == IClasspathEntry.CPE_CONTAINER) {
        try {//  www .j  a  v a2 s .  c  o  m
            final IClasspathContainer container = JavaCore.getClasspathContainer(cpe.getPath(), jproj);
            return container.getDescription();
        } catch (Exception e) {
            J2EEUIPlugin.logError(e);
        }
    } else if (type == IClasspathEntry.CPE_LIBRARY) {
        final IPath path = cpe.getPath();

        final StringBuilder buf = new StringBuilder();
        buf.append(path.lastSegment());
        buf.append(" - "); //$NON-NLS-1$
        buf.append(path.removeLastSegments(1).toOSString());

        return buf.toString();
    }

    return cpe.getPath().toPortableString();
}

From source file:org.eclipse.jst.j2ee.internal.ui.AddJavaBuildPathEntriesWizardFragment.java

License:Open Source License

public static Image getClasspathEntryImage(final IJavaProject jproj, final IClasspathEntry cpe) {
    final int type = cpe.getEntryKind();
    final String imgId;

    if (type == IClasspathEntry.CPE_CONTAINER) {
        imgId = ISharedImages.IMG_OBJS_LIBRARY;
    } else if (type == IClasspathEntry.CPE_LIBRARY) {
        imgId = ISharedImages.IMG_OBJS_JAR;
    } else if (type == IClasspathEntry.CPE_VARIABLE) {
        imgId = ISharedImages.IMG_OBJS_CLASSPATH_VAR_ENTRY;
    } else {//from   w  w  w . j a  va2  s.c om
        imgId = null;
    }

    return (imgId == null ? null : JavaUI.getSharedImages().getImage(imgId));
}

From source file:org.eclipse.jst.jsf.core.internal.jsflibraryconfig.JSFLibraryRegistryUtil.java

License:Open Source License

/**
 * Binds JSF Libraries to classpath containers when the library changes.
 * //from w w  w  .ja v  a  2 s .  c  om
 * This method will deal with library/cp container renames by removing the old classpath container and then adding.
 * 
 * @param oldId
 * @param newId
 * @param monitor
 * @throws JavaModelException
 */
public static void rebindClasspathContainerEntries(String oldId, String newId, IProgressMonitor monitor)
        throws JavaModelException {
    IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
    IJavaProject[] projects = JavaCore.create(root).getJavaProjects();
    IPath containerPath = new Path(JSFLibraryConfigurationHelper.JSF_LIBRARY_CP_CONTAINER_ID).append(newId);
    IPath oldContainerPath = new Path(JSFLibraryConfigurationHelper.JSF_LIBRARY_CP_CONTAINER_ID).append(oldId);

    JSFLibrary lib = JSFLibraryRegistryUtil.getInstance().getJSFLibraryRegistry().getJSFLibraryByID(newId);
    List affectedProjects = new ArrayList();
    boolean removeAndAddBecauseOfRename = (!oldId.equals(newId));
    // find all projects using the old container name...
    for (int i = 0; i < projects.length; i++) {
        IJavaProject project = projects[i];
        IClasspathEntry[] entries = project.getRawClasspath();
        for (int k = 0; k < entries.length; k++) {
            IClasspathEntry curr = entries[k];
            if (curr.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
                if (oldContainerPath.equals(curr.getPath())) {
                    affectedProjects.add(project);
                    break;
                }
            }
        }
    }

    if (!affectedProjects.isEmpty()) {
        IJavaProject[] affected = (IJavaProject[]) affectedProjects
                .toArray(new IJavaProject[affectedProjects.size()]);
        IClasspathContainer[] containers = new IClasspathContainer[affected.length];
        removeAndAddBecauseOfRename = (!oldId.equals(newId));
        if (removeAndAddBecauseOfRename) {//not very pretty... remove and add new container            
            IClasspathEntry newEntry = JavaCore.newContainerEntry(containerPath);
            for (int i = 0; i < affected.length; i++) {
                IJavaProject project = affected[i];
                IClasspathEntry[] entries = project.getRawClasspath();
                List keptEntries = new ArrayList();
                //keep all entries except the old one
                for (int k = 0; k < entries.length; k++) {
                    IClasspathEntry curr = entries[k];
                    if (curr.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
                        if (!oldContainerPath.equals(curr.getPath()))
                            keptEntries.add(curr);
                    } else {
                        keptEntries.add(curr);
                    }
                }
                // add new container entry
                keptEntries.add(newEntry);
                setRawClasspath(project, keptEntries, monitor);
            }

        } else {//rebind

            JSFLibraryClasspathContainer container = new JSFLibraryClasspathContainer(lib);
            containers[0] = container;

            JavaCore.setClasspathContainer(containerPath, affected, containers, monitor);
        }
    } else {
        if (monitor != null) {
            monitor.done();
        }
    }
}

From source file:org.eclipse.jst.jsf.core.internal.project.facet.LegacyJSFLibraryProviderDetector.java

License:Open Source License

/**
 * @param cpe/*from www . j a  v a  2  s .co m*/
 * @return true if the classpath entry is detected
 */
public static boolean detect(final IClasspathEntry cpe) {
    if (cpe.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
        final IPath path = cpe.getPath();

        if (isJSFLibraryContainer(path)) {
            String libId = path.lastSegment();
            JSFLibrary ref = JSFLibraryRegistryUtil.getInstance().getJSFLibraryRegistry()
                    .getJSFLibraryByID(libId);

            if (ref != null && ref.isImplementation()) {
                return true;
            }
        }
    }

    return false;
}