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

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

Introduction

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

Prototype

int CPE_VARIABLE

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

Click Source Link

Document

Entry kind constant describing a classpath entry defined using a path that begins with a classpath variable reference.

Usage

From source file:org.key_project.util.jdt.JDTUtil.java

License:Open Source License

/**
 * Returns the {@link IResource}s of the given {@link IClasspathEntry}.
 * @param javaProject The actual {@link IJavaProject} that provides the {@link IClasspathEntry}.
 * @param entry The given {@link IClasspathEntry}.
 * @param alreadyHandledProjects The already handled {@link IProject} that don't need to be analysed again.
 * @return The found {@link IResource}s.
 * @throws JavaModelException //  ww  w  .j  a v a2  s. c o  m
 */
private static List<IResource> getResourceFor(IJavaProject javaProject, IClasspathEntry entry, int expectedKind,
        Set<IProject> alreadyHandledProjects) throws JavaModelException {
    if (entry != null) {
        if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER
                || entry.getEntryKind() == IClasspathEntry.CPE_SOURCE
                || entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY
                || entry.getEntryKind() == IClasspathEntry.CPE_VARIABLE) {
            List<IResource> result = new LinkedList<IResource>();
            IPackageFragmentRoot[] roots = javaProject.findPackageFragmentRoots(entry);
            for (IPackageFragmentRoot root : roots) {
                if (root.getKind() == expectedKind) {
                    if (root.getResource() != null) {
                        if (root.getResource().getLocationURI() != null) {
                            result.add(root.getResource());
                        }
                    } else if (root.getPath() != null) {
                        IResource resource = ResourcesPlugin.getWorkspace().getRoot()
                                .findMember(root.getPath());
                        if (resource != null && resource.exists()) {
                            result.add(resource);
                        }
                    }
                }
            }
            return result; // Ignore containers
        } else if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT) {
            Assert.isNotNull(entry.getPath());
            IResource project = ResourcesPlugin.getWorkspace().getRoot().findMember(entry.getPath());
            Assert.isTrue(project instanceof IProject);
            if (!alreadyHandledProjects.contains(project)) {
                return getSourceResources((IProject) project, alreadyHandledProjects);
            } else {
                return null; // Project was already analyzed, no need to do it again.
            }
        } else {
            Assert.isTrue(false, "Unknown content kind \"" + entry.getContentKind()
                    + "\" of class path entry \"" + entry + "\".");
            return null;
        }
    } else {
        return null;
    }
}

From source file:org.key_project.util.jdt.JDTUtil.java

License:Open Source License

/**
 * Returns the locations of the given {@link IClasspathEntry}.
 * @param javaProject The actual {@link IJavaProject} that provides the {@link IClasspathEntry}.
 * @param entry The given {@link IClasspathEntry}.
 * @param alreadyHandledProjects The already handled {@link IProject} that don't need to be analysed again.
 * @return The found locations.//from  w  w  w  .j  a va  2  s .c o m
 * @throws JavaModelException 
 */
private static List<File> getLocationFor(IJavaProject javaProject, IClasspathEntry entry, int expectedKind,
        Set<IProject> alreadyHandledProjects) throws JavaModelException {
    if (entry != null) {
        if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER
                || entry.getEntryKind() == IClasspathEntry.CPE_SOURCE
                || entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY
                || entry.getEntryKind() == IClasspathEntry.CPE_VARIABLE) {
            List<File> result = new LinkedList<File>();
            IPackageFragmentRoot[] roots = javaProject.findPackageFragmentRoots(entry);
            for (IPackageFragmentRoot root : roots) {
                if (root.getKind() == expectedKind) {
                    if (root.getResource() != null) {
                        if (root.getResource().getLocationURI() != null) {
                            result.add(ResourceUtil.getLocation(root.getResource()));
                        }
                    } else if (root.getPath() != null) {
                        File location = new File(root.getPath().toString());
                        if (location.exists()) {
                            result.add(location);
                        }
                    }
                }
            }
            return result; // Ignore containers
        } else if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT) {
            Assert.isNotNull(entry.getPath());
            IResource project = ResourcesPlugin.getWorkspace().getRoot().findMember(entry.getPath());
            Assert.isTrue(project instanceof IProject);
            if (!alreadyHandledProjects.contains(project)) {
                return getSourceLocations((IProject) project, alreadyHandledProjects);
            } else {
                return null; // Project was already analyzed, no need to do it again.
            }
        } else {
            Assert.isTrue(false, "Unknown content kind \"" + entry.getContentKind()
                    + "\" of class path entry \"" + entry + "\".");
            return null;
        }
    } else {
        return null;
    }
}

From source file:org.neuro4j.studio.core.util.ClassloaderHelper.java

License:Apache License

private static void collectClasspathURLs(IJavaProject javaProject, List<URL> urls, Set<IJavaProject> visited,
        boolean isFirstProject) {
    if (visited.contains(javaProject))
        return;//from  w ww.j  ava 2  s  .  c  om
    visited.add(javaProject);
    IPath outPath = getJavaProjectOutputAbsoluteLocation(javaProject.getProject());
    if (outPath != null) {
        outPath = outPath.addTrailingSeparator();
        URL out = createFileURL(outPath);
        urls.add(out);

    }

    IClasspathEntry[] entries = null;
    try {
        entries = javaProject.getResolvedClasspath(true);
    } catch (JavaModelException e) {
        return;
    }
    IClasspathEntry entry;
    for (int i = 0; i < entries.length; i++) {
        entry = entries[i];
        switch (entry.getEntryKind()) {
        case IClasspathEntry.CPE_LIBRARY:
            collectClasspathEntryURL(entry, urls);
            break;
        case IClasspathEntry.CPE_CONTAINER:
        case IClasspathEntry.CPE_VARIABLE:
            collectClasspathEntryURL(entry, urls);
            break;
        case IClasspathEntry.CPE_PROJECT: {
            if (isFirstProject || entry.isExported())
                collectClasspathURLs(getJavaProject(entry), urls, visited, false);
            break;
        }
        }
    }
}

From source file:org.neuro4j.studio.core.util.ClassloaderHelper.java

License:Apache License

private static void collectClasspathIPath(IJavaProject javaProject, List<IPath> urls, Set<IJavaProject> visited,
        boolean isFirstProject) {
    if (visited.contains(javaProject))
        return;//  w  w w  .j  a va2  s .  co  m
    visited.add(javaProject);

    IClasspathEntry[] entries = null;
    try {
        entries = javaProject.getResolvedClasspath(true);
    } catch (JavaModelException e) {
        return;
    }
    IClasspathEntry entry;
    for (int i = 0; i < entries.length; i++) {
        entry = entries[i];
        switch (entry.getEntryKind()) {
        case IClasspathEntry.CPE_LIBRARY:
            addJarToList(entry.getPath(), urls);
            break;
        case IClasspathEntry.CPE_CONTAINER:
        case IClasspathEntry.CPE_SOURCE:
            break;
        case IClasspathEntry.CPE_VARIABLE:

            addJarToList(entry.getPath(), urls);
            break;
        case IClasspathEntry.CPE_PROJECT: {
            if (isFirstProject || entry.isExported())
                collectClasspathIPath(getJavaProject(entry), urls, visited, false);
            break;
        }
        }
    }
}

From source file:org.nuxeo.ide.sdk.java.ClasspathEditor.java

License:Open Source License

public void removeLibraries() {
    Iterator<IClasspathEntry> it = entries.iterator();
    while (it.hasNext()) {
        IClasspathEntry entry = it.next();
        switch (entry.getEntryKind()) {
        case IClasspathEntry.CPE_LIBRARY:
        case IClasspathEntry.CPE_VARIABLE:
            it.remove();//from w w w  .j  a v  a2s  . co  m
            dirty = true;
        }
    }
}

From source file:org.nuxeo.ide.sdk.java.ClasspathEditor.java

License:Open Source License

/**
 * Removing classpath entries that are in already in the containers. This
 * method is intended to be called after a mvn eclipse:eclipse
 */// w  w  w  .  j  a v  a  2 s .  co  m
protected void removeDuplicates() {

    // classpath index
    Map<String, IClasspathEntry> cpIndex = new HashMap<String, IClasspathEntry>();
    List<IClasspathEntry> duplicateEntries = new ArrayList<IClasspathEntry>();
    for (IClasspathEntry each : entries) {
        if (each.getEntryKind() != IClasspathEntry.CPE_VARIABLE) {
            continue;
        }
        String key;
        try {
            key = artifactKey(each);
        } catch (Exception cause) {
            UI.showWarning("cannot compute artifact key for " + each + ", skipping");
            continue;
        }
        if (cpIndex.containsKey(key)) {
            UI.showWarning("classpath contains duplicate entries for " + key + ", keeping last " + each);
            duplicateEntries.add(each);
            continue;
        }
        cpIndex.put(key, each);
    }
    entries.removeAll(duplicateEntries);

    // sdk index
    Collection<String> sdkIndex = new ArrayList<String>();
    sdkIndex.addAll(NuxeoSDK.getDefault().getArtifactIndex().getIndex().values());
    sdkIndex.addAll(NuxeoSDK.getDefault().getTestArtifactIndex().getIndex().values());

    // cleanup
    for (String each : sdkIndex) {
        String key = artifactKey(each);
        if (cpIndex.containsKey(key)) {
            IClasspathEntry entry = cpIndex.get(key);
            entries.remove(entry);
            dirty = true;
        }
    }
}

From source file:org.objectstyle.wolips.jrebel.utils.WOProjectClassLoader.java

License:BSD License

private void addURLs(IJavaProject javaProject, boolean exportsOnly) {
    if (!javaProjects.contains(javaProject)) {
        javaProjects.add(javaProject);// ww w  . j  a va2s . co  m

        try {
            // Add default output location
            addURL(javaProject.getOutputLocation());

            // Add each classpath entry
            IClasspathEntry[] classpathEntries = javaProject.getResolvedClasspath(true);
            for (IClasspathEntry classpathEntry : classpathEntries) {
                if (classpathEntry.isExported() || !exportsOnly) {
                    switch (classpathEntry.getEntryKind()) {

                    // Recurse on projects
                    case IClasspathEntry.CPE_PROJECT:
                        IProject project = javaProject.getProject().getWorkspace().getRoot()
                                .getProject(classpathEntry.getPath().toString());
                        IJavaProject javaProj = JavaCore.create(project);
                        if (javaProj != null) {
                            addURLs(javaProj, true);
                        }
                        break;

                    // Library
                    case IClasspathEntry.CPE_LIBRARY:
                        addURL(classpathEntry);
                        break;

                    // Only Source entries with custom output location need to be added
                    case IClasspathEntry.CPE_SOURCE:
                        IPath outputLocation = classpathEntry.getOutputLocation();
                        if (outputLocation != null) {
                            addURL(outputLocation);
                        }
                        break;

                    // Variable and Container entries should not be happening, because
                    // we've asked for resolved entries.
                    case IClasspathEntry.CPE_VARIABLE:
                    case IClasspathEntry.CPE_CONTAINER:
                        break;
                    }
                }
            }
        } catch (JavaModelException e) {
            e.printStackTrace();
            // log.debug("MalformedURLException occurred: " + e.getLocalizedMessage(),e);
        }
    }
}

From source file:org.openquark.cal.eclipse.embedded.EmbeddedClasspathVariableInitializer.java

License:Open Source License

/**
 * Attempt to update the project's build classpath with the EmbeddedCal runtime
 * library./*from w  w w .  j a  v a 2 s  . c om*/
 * 
 * Borrowed from AspectJUIPlugin.addAjrtToBuildPath()
 * 
 * @param project
 */
public static void addEmbeddedrtToBuildPath(IProject project) {
    IJavaProject javaProject = JavaCore.create(project);
    try {
        IClasspathEntry[] originalCP = javaProject.getRawClasspath();

        // check to see if classpath entry already exists
        for (final IClasspathEntry classpathEntry : originalCP) {
            if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_VARIABLE) {
                if (classpathEntry.getPath().toString().equals(EMBEDDED_CAL_RT_LIB)) {
                    // found
                    return;
                }
            }
        }

        IClasspathEntry embeddedrtVAR = JavaCore.newVariableEntry(new Path(EMBEDDED_CAL_RT_LIB), null, null);

        // Update the raw classpath with the new embeddedrtCP entry.
        int originalCPLength = originalCP.length;
        IClasspathEntry[] newCP = new IClasspathEntry[originalCPLength + 1];
        System.arraycopy(originalCP, 0, newCP, 0, originalCPLength);
        newCP[originalCPLength] = embeddedrtVAR;
        javaProject.setRawClasspath(newCP, new NullProgressMonitor());
    } catch (JavaModelException e) {
    }
}

From source file:org.org.eclipse.core.utils.jdt.tools.JavaProjectClasspathHelper.java

License:Open Source License

private static boolean isVariableEntry(IClasspathEntry classpathEntry) {
    return classpathEntry.getEntryKind() == IClasspathEntry.CPE_VARIABLE;
}

From source file:org.org.eclipse.dws.core.internal.bridges.ProjectInteractionHelper.java

License:Open Source License

/**
 * Gets the classpath entries./*from ww  w.java 2  s  .  co m*/
 * 
 * @param javaProject the java project
 * 
 * @return the classpath entries
 */
public static Set<DWSClasspathEntryDescriptor> getClasspathEntries(IJavaProject javaProject) {
    Set<DWSClasspathEntryDescriptor> classpathEntryDescriptors = new LinkedHashSet<DWSClasspathEntryDescriptor>();
    try {
        if (javaProject.exists()) {
            for (IClasspathEntry classpathEntry : javaProject.getRawClasspath()) {
                DWSClasspathEntryDescriptor classpathEntryDescriptor = new DWSClasspathEntryDescriptor();
                classpathEntryDescriptor
                        .setEncodedClasspathEntry(javaProject.encodeClasspathEntry(classpathEntry));
                classpathEntryDescriptor.setPath(classpathEntry.getPath().toPortableString());
                classpathEntryDescriptor.setProjectName(javaProject.getElementName());
                IJavaModelStatus javaModelStatus = JavaConventions.validateClasspathEntry(javaProject,
                        classpathEntry, false);
                classpathEntryDescriptor.setValid(classpathEntry.getEntryKind() == IClasspathEntry.CPE_LIBRARY
                        || classpathEntry.getEntryKind() == IClasspathEntry.CPE_VARIABLE
                                && javaModelStatus.isOK());
                classpathEntryDescriptors.add(classpathEntryDescriptor);
            }
        }
    } catch (JavaModelException e) {
        throw new JavaProjectInteractionException(
                "An error occured while scanning for classpath entries in project:" + javaProject, e);
    }
    return classpathEntryDescriptors;
}