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.ajdt.internal.ui.AspectJProjectPropertiesPage.java

License:Open Source License

protected List /*CPListElement*/ getEntriesInContainers(IProject project, IClasspathAttribute attribute) {
    try {// w  w  w.j av  a  2  s.  co  m
        IJavaProject jProject = JavaCore.create(project);
        // get the raw classpath of the project
        IClasspathEntry[] allEntries = jProject.getRawClasspath();
        List entriesWithAttribute = new ArrayList();
        for (int i = 0; i < allEntries.length; i++) {
            // for each container element, peek inside it
            if (allEntries[i].getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
                IClasspathContainer container = JavaCore.getClasspathContainer(allEntries[i].getPath(),
                        jProject);
                if (container != null && !(container instanceof JREContainer)) {
                    IClasspathEntry[] containerEntries = container.getClasspathEntries();
                    // bug 273770
                    //                     Set /*String*/ extraPathElements = AspectJCorePreferences.findExtraPathElements(allEntries[i], 
                    //                                     AspectJCorePreferences.isAspectPathAttribute(attribute));

                    for (int j = 0; j < containerEntries.length; j++) {
                        // iterate through each element and add 
                        //    to the path those that have the appropriate attribute
                        if (hasClasspathAttribute(containerEntries[j],
                                attribute) /*||
                                           AspectJCorePreferences.containsAsPathFragment(extraPathElements, containerEntries[j])*/) {
                            addContainerToAttribute(containerEntries[j], attribute, container);
                            entriesWithAttribute.add(containerEntries[j]);
                        }
                    }
                }
            }
        }
        return entriesWithAttribute;

    } catch (JavaModelException e) {
    }
    return Collections.EMPTY_LIST;
}

From source file:org.eclipse.ajdt.internal.ui.wizards.PathBlock.java

License:Open Source License

/**
 * Checks for duplicate entries on the inpath compared to the Java build
 * path/*  w ww. j av  a2 s. c om*/
 * 
 * This checks to make sure that duplicate entries are not being referred
 * to. For example, it is possible for the JUnit jar to be referred to
 * through a classpath variable as well as a classpath container. This
 * method checks for such duplicates
 * 
 * 1. if an inpath entry is on the build path, then remove it from checking
 * 2. resolve the remaining inpath entries 3. resolve the build path 4.
 * there should be no overlap
 */
private IJavaModelStatus checkForDuplicates(IJavaProject currJProject, IClasspathEntry[] entries) {
    try {
        Map<String, IClasspathEntry> allEntries = new HashMap<String, IClasspathEntry>(entries.length, 1.0f);
        for (int i = 0; i < entries.length; i++) {
            // ignore entries that are inside of a container
            if (getClasspathContainer(entries[i]) == null) {
                allEntries.put(entries[i].getPath().toPortableString(), entries[i]);
            }
        }

        IClasspathEntry[] rawProjectClasspath = currJProject.getRawClasspath();
        for (int i = 0; i < rawProjectClasspath.length; i++) {
            allEntries.remove(rawProjectClasspath[i].getPath().toPortableString());
        }

        IClasspathEntry[] resolvedProjectClasspath = currJProject.getResolvedClasspath(true);
        Map<String, IClasspathEntry> resolvedEntries = new HashMap<String, IClasspathEntry>();
        Iterator<IClasspathEntry> allEntriesIter = allEntries.values().iterator();
        while (allEntriesIter.hasNext()) {
            ClasspathEntry rawEntry = (ClasspathEntry) allEntriesIter.next();
            switch (rawEntry.entryKind) {
            case IClasspathEntry.CPE_SOURCE:
            case IClasspathEntry.CPE_LIBRARY:
            case IClasspathEntry.CPE_VARIABLE:
                IClasspathEntry resolvedEntry = JavaCore.getResolvedClasspathEntry(rawEntry);
                resolvedEntries.put(resolvedEntry.getPath().toPortableString(), resolvedEntry);
                break;
            case IClasspathEntry.CPE_CONTAINER:
                List containerEntries = AspectJCorePreferences.resolveClasspathContainer(rawEntry,
                        currJProject.getProject());

                for (Iterator containerIter = containerEntries.iterator(); containerIter.hasNext();) {
                    IClasspathEntry containerEntry = (IClasspathEntry) containerIter.next();
                    resolvedEntries.put(containerEntry.getPath().toPortableString(), containerEntry);
                }
                break;

            case IClasspathEntry.CPE_PROJECT:
                IProject thisProject = currJProject.getProject();
                IProject requiredProj = thisProject.getWorkspace().getRoot()
                        .getProject(rawEntry.getPath().makeRelative().toPortableString());
                if (!requiredProj.getName().equals(thisProject.getName()) && requiredProj.exists()) {
                    List containerEntries2 = AspectJCorePreferences.resolveDependentProjectClasspath(rawEntry,
                            requiredProj);
                    for (Iterator containerIter = containerEntries2.iterator(); containerIter.hasNext();) {
                        IClasspathEntry containerEntry = (IClasspathEntry) containerIter.next();
                        resolvedEntries.put(containerEntry.getPath().toPortableString(), containerEntry);
                    }

                }
                break;
            }
        }

        for (int i = 0; i < resolvedProjectClasspath.length; i++) {
            if (resolvedEntries.containsKey(resolvedProjectClasspath[i].getPath().toPortableString())) {
                // duplicate found.
                return new JavaModelStatus(IStatus.WARNING, IStatus.WARNING, currJProject,
                        currJProject.getPath(),
                        UIMessages.InPathBlock_DuplicateBuildEntry + resolvedProjectClasspath[i].getPath());
            }
        }

        return JavaModelStatus.VERIFIED_OK;
    } catch (JavaModelException e) {
        return new JavaModelStatus(e);
    }

}

From source file:org.eclipse.ajdt.internal.ui.wizards.PathBlock.java

License:Open Source License

private boolean updatePathRestrictions(IClasspathEntry[] entries, Map<IPath, String> restrictions,
        boolean isAspectPath) {
    String restrictionKind = isAspectPath ? AspectJCorePreferences.ASPECTPATH_RESTRICTION_ATTRIBUTE_NAME
            : AspectJCorePreferences.INPATH_RESTRICTION_ATTRIBUTE_NAME;

    boolean hasChanges = false;
    for (int i = 0; i < entries.length; i++) {
        if (entries[i].getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
            // restrictions only available on container entries

            if (restrictions.containsKey(entries[i].getPath())) {
                String restrictionStr = restrictions.get(entries[i].getPath());
                entries[i] = AspectJCorePreferences.updatePathRestrictions(entries[i], restrictionStr,
                        restrictionKind);
                hasChanges = true;/*  w  w  w . j av a  2s  . c o m*/
            }
        }
    }
    return hasChanges;
}

From source file:org.eclipse.ajdt.internal.ui.wizards.PathBlock.java

License:Open Source License

protected List<CPListElement> getExistingEntries(IClasspathEntry[] pathEntries) {
    List<CPListElement> newPath = new ArrayList<CPListElement>();
    for (int i = 0; i < pathEntries.length; i++) {
        IClasspathEntry curr = pathEntries[i];
        if (curr.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
            curr = AspectJCorePreferences.ensureHasAttribute(curr, getRestrictionPathAttrName(), "");
        }/* w w w .  jav a 2s. co  m*/
        newPath.add(CPListElement.createFromExisting(curr, fCurrJProject));
    }
    return newPath;
}

From source file:org.eclipse.ajdt.ui.AspectJUIPlugin.java

License:Open Source License

/**
 * Attempt to update the project's build classpath by removing any occurance
 * of the AspectJ runtime library.//from  ww w  . j  a  va 2s. c o  m
 * 
 * @param project
 */
public static void removeAjrtFromBuildPath(IProject project) {
    IJavaProject javaProject = JavaCore.create(project);
    try {
        IClasspathEntry[] originalCP = javaProject.getRawClasspath();
        ArrayList tempCP = new ArrayList();

        // Go through each current classpath entry one at a time. If it
        // is not a reference to the aspectjrt.jar then do not add it
        // to the collection of new classpath entries.
        for (int i = 0; i < originalCP.length; i++) {
            IPath path = originalCP[i].getPath();
            boolean keep = true;
            if (path.toOSString().endsWith("ASPECTJRT_LIB") //$NON-NLS-1$
                    || path.toOSString().endsWith("aspectjrt.jar")) { //$NON-NLS-1$
                keep = false;
            }
            if (originalCP[i].getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
                if (path.segment(0).equals(AspectJPlugin.ASPECTJRT_CONTAINER)) {
                    keep = false;
                }
            }
            if (keep) {
                tempCP.add(originalCP[i]);
            }
        } // end for

        // Set the classpath with only those elements that survived the
        // above filtration process.
        if (originalCP.length != tempCP.size()) {
            IClasspathEntry[] newCP = (IClasspathEntry[]) tempCP.toArray(new IClasspathEntry[tempCP.size()]);
            javaProject.setRawClasspath(newCP, new NullProgressMonitor());
        } // end if at least one classpath element removed
    } catch (JavaModelException e) {
    }
}

From source file:org.eclipse.ajdt.ui.tests.actions.RemoveAJNatureActionTest.java

License:Open Source License

public static boolean hasAjrtOnBuildPath(IProject project) throws CoreException {
    IJavaProject javaProject = JavaCore.create(project);
    IClasspathEntry[] originalCP = javaProject.getRawClasspath();

    // Go through each current classpath entry one at a time. If it
    // is not a reference to the aspectjrt.jar then do not add it
    // to the collection of new classpath entries.
    for (int i = 0; i < originalCP.length; i++) {
        IPath path = originalCP[i].getPath();
        if (path.toOSString().endsWith("ASPECTJRT_LIB") //$NON-NLS-1$
                || path.toOSString().endsWith("aspectjrt.jar")) { //$NON-NLS-1$
            return true;
        }/*from   w w  w  .  ja v  a  2s. co  m*/
        if (originalCP[i].getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
            if (path.segment(0).equals(AspectJPlugin.ASPECTJRT_CONTAINER)) {
                return true;
            }
        }
    } // end for
    return false;
}

From source file:org.eclipse.ajdt.ui.tests.utils.AJDTUtilsTest.java

License:Open Source License

private boolean hasAjrtOnBuildPath(IJavaProject javaProject) {
    try {// ww  w .  jav  a2 s.c om
        IClasspathEntry[] originalCP = javaProject.getRawClasspath();
        for (int i = 0; i < originalCP.length; i++) {
            if (originalCP[i].getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
                IPath path = originalCP[i].getPath();
                if (path.segment(0).equals(AspectJPlugin.ASPECTJRT_CONTAINER)) {
                    return true;
                }
            }
        }
    } catch (JavaModelException e) {
        e.printStackTrace();
    }
    return false;
}

From source file:org.eclipse.andmore.android.command.ConvertADTProject.java

License:Open Source License

@SuppressWarnings("restriction")
private void updateClasspathEntries(IJavaProject androidProject) throws JavaModelException {
    ArrayList<IClasspathEntry> newclasspathEntries = new ArrayList<IClasspathEntry>();

    IClasspathEntry[] classpathEntries = androidProject.getRawClasspath();
    for (IClasspathEntry classpathEntry : classpathEntries) {
        if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
            String classpathId = classpathEntry.getPath().toString();
            if (classpathId.equals(AndmoreAndroidConstants.ADT_CONTAINER_DEPENDENCIES)) {
                newclasspathEntries//www  . j  a  v a  2 s.com
                        .add(createNewAndmoreContainer(AndmoreAndroidConstants.CONTAINER_DEPENDENCIES));
            } else if (classpathId.equals(AndmoreAndroidConstants.ADT_CONTAINER_FRAMEWORK)) {
                newclasspathEntries.add(createNewAndmoreContainer(AndmoreAndroidConstants.CONTAINER_FRAMEWORK));
            } else if (classpathId.equals(AndmoreAndroidConstants.ADT_CONTAINER_PRIVATE_LIBRARIES)) {
                newclasspathEntries
                        .add(createNewAndmoreContainer(AndmoreAndroidConstants.CONTAINER_PRIVATE_LIBRARIES));
            } else {
                newclasspathEntries.add(classpathEntry);
            }

        } else {
            newclasspathEntries.add(classpathEntry);
        }
    }

    IClasspathEntry[] andmoreClasspathEntries = new IClasspathEntry[newclasspathEntries.size()];
    newclasspathEntries.toArray(andmoreClasspathEntries);
    androidProject.setRawClasspath(andmoreClasspathEntries, true, new NullProgressMonitor());

}

From source file:org.eclipse.andmore.internal.build.BuildHelper.java

License:Open Source License

/**
 * Computes all the project output and dependencies that must go into building the apk.
 *
 * @param resMarker/*from  www  .ja  v  a  2s.  c  o  m*/
 * @throws CoreException
 */
private void gatherPaths(ResourceMarker resMarker) throws CoreException {
    IWorkspaceRoot wsRoot = ResourcesPlugin.getWorkspace().getRoot();

    // get a java project for the project.
    IJavaProject javaProject = JavaCore.create(mProject);

    // get the output of the main project
    IPath path = javaProject.getOutputLocation();
    IResource outputResource = wsRoot.findMember(path);
    if (outputResource != null && outputResource.getType() == IResource.FOLDER) {
        mCompiledCodePaths.add(outputResource.getLocation().toOSString());
    }

    // we could use IJavaProject.getResolvedClasspath directly, but we actually
    // want to see the containers themselves.
    IClasspathEntry[] classpaths = javaProject.readRawClasspath();
    if (classpaths != null) {
        for (IClasspathEntry e : classpaths) {
            // ignore non exported entries, unless they're in the DEPEDENCIES container,
            // in which case we always want it (there may be some older projects that
            // have it as non exported).
            if (e.isExported() || (e.getEntryKind() == IClasspathEntry.CPE_CONTAINER
                    && e.getPath().toString().equals(AndmoreAndroidConstants.CONTAINER_DEPENDENCIES))) {
                handleCPE(e, javaProject, wsRoot, resMarker);
            }
        }
    }
}

From source file:org.eclipse.andmore.internal.build.BuildHelper.java

License:Open Source License

private void handleCPE(IClasspathEntry entry, IJavaProject javaProject, IWorkspaceRoot wsRoot,
        ResourceMarker resMarker) {/*from w  ww .  ja  v a2  s .c om*/

    // if this is a classpath variable reference, we resolve it.
    if (entry.getEntryKind() == IClasspathEntry.CPE_VARIABLE) {
        entry = JavaCore.getResolvedClasspathEntry(entry);
    }

    if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT) {
        IProject refProject = wsRoot.getProject(entry.getPath().lastSegment());
        try {
            // ignore if it's an Android project, or if it's not a Java Project
            if (refProject.hasNature(JavaCore.NATURE_ID)
                    && refProject.hasNature(AndmoreAndroidConstants.NATURE_DEFAULT) == false) {
                IJavaProject refJavaProject = JavaCore.create(refProject);

                // get the output folder
                IPath path = refJavaProject.getOutputLocation();
                IResource outputResource = wsRoot.findMember(path);
                if (outputResource != null && outputResource.getType() == IResource.FOLDER) {
                    mCompiledCodePaths.add(outputResource.getLocation().toOSString());
                }
            }
        } catch (CoreException exception) {
            // can't query the project nature? ignore
        }

    } else if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
        handleClasspathLibrary(entry, wsRoot, resMarker);
    } else if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
        // get the container
        try {
            IClasspathContainer container = JavaCore.getClasspathContainer(entry.getPath(), javaProject);
            // ignore the system and default_system types as they represent
            // libraries that are part of the runtime.
            if (container != null && container.getKind() == IClasspathContainer.K_APPLICATION) {
                IClasspathEntry[] entries = container.getClasspathEntries();
                for (IClasspathEntry cpe : entries) {
                    handleCPE(cpe, javaProject, wsRoot, resMarker);
                }
            }
        } catch (JavaModelException jme) {
            // can't resolve the container? ignore it.
            AndmoreAndroidPlugin.log(jme, "Failed to resolve ClasspathContainer: %s", entry.getPath());
        }
    }
}