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:com.ebmwebsourcing.petals.common.internal.provisional.utils.JavaUtils.java

License:Open Source License

/**
 * Populates an {@link ExportableClassPath} instance from a class path entry.
 * @param result the {@link ExportableClassPath} instance to populate
 * @param entry a class path entry/* ww  w  .ja  v a 2  s  .c om*/
 * @param monitor the progress monitor
 */
private static void updateExportableResult(ExportableClassPath result, IClasspathEntry entry,
        IProgressMonitor monitor) {

    switch (entry.getEntryKind()) {

    case IClasspathEntry.CPE_PROJECT:
        String projectName = entry.getPath().toString();
        IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
        IJavaProject jProject = JavaCore.create(project);

        ExportableClassPath subResult = getExportableClasspath(jProject, monitor);
        result.implementationJars.addAll(subResult.implementationJars);
        result.libraryJars.addAll(subResult.libraryJars);
        monitor.worked(1);
        break;

    case IClasspathEntry.CPE_LIBRARY:
        IPath path = entry.getPath();
        if (path != null) {
            File f = path.toFile();
            if (f.exists()) {
                if (f.getName().endsWith(".zip") || f.getName().endsWith(".jar"))
                    result.libraryJars.add(f);
            }
        }
        break;

    case IClasspathEntry.CPE_VARIABLE:
        entry = JavaCore.getResolvedClasspathEntry(entry);
        if (entry != null)
            updateExportableResult(result, entry, monitor);

        break;
    }
}

From source file:com.google.inject.tools.ideplugin.eclipse.EclipseJavaProject.java

License:Apache License

private List<String> expandClasspath(IClasspathEntry[] entries, String projectName, String projectLocation)
        throws Exception {
    final List<String> args = new ArrayList<String>();
    IResource presource;//from  w w w  .j av a 2 s . c om
    String resourceLocation;
    String path;
    for (IClasspathEntry entry : entries) {
        switch (entry.getEntryKind()) {
        case IClasspathEntry.CPE_CONTAINER:
            IClasspathContainer container = JavaCore.getClasspathContainer(entry.getPath(), project);
            args.addAll(expandClasspath(container.getClasspathEntries(), projectName, projectLocation));
            break;
        case IClasspathEntry.CPE_SOURCE:
            IResource resource = ResourcesPlugin.getWorkspace().getRoot().findMember(entry.getPath());
            path = resource.getLocation().makeAbsolute().toOSString();
            if (path.startsWith("/" + projectName)) {
                args.add(path.replaceFirst("/" + projectName, projectLocation));
            } else {
                args.add(path);
            }
            break;
        case IClasspathEntry.CPE_LIBRARY:
            path = entry.getPath().makeAbsolute().toOSString();
            if (path.startsWith("/" + projectName)) {
                args.add(path.replaceFirst("/" + projectName, projectLocation));
            } else {
                args.add(path);
            }
            break;
        case IClasspathEntry.CPE_PROJECT:
            presource = ResourcesPlugin.getWorkspace().getRoot().findMember(entry.getPath());
            resourceLocation = presource.getLocation().makeAbsolute().toOSString();
            String outputLocation = resourceLocation;
            args.add(outputLocation.replaceFirst(presource.getName(), resourceLocation));
            break;
        case IClasspathEntry.CPE_VARIABLE:
            break;
        default:
            //never happens
        }
    }
    return args;
}

From source file:com.ibm.research.tours.content.url.delegates.ClassFileTextRegionURLTourElementDelegate.java

License:Open Source License

private void init() {
    IPackageFragmentRoot root = null;/* ww w  .j  a v a  2s  .  co  m*/
    root = JavaModelUtil.getPackageFragmentRoot(fFile);

    IClasspathEntry entry = null;
    try {
        entry = root.getRawClasspathEntry();
    } catch (JavaModelException e) {
        e.printStackTrace();
    }

    if (entry != null && entry.getEntryKind() == IClasspathEntry.CPE_VARIABLE) {
        IPath path = entry.getPath().makeRelative();
    }
}

From source file:com.iw.plugins.spindle.ant.AntScriptGenerator.java

License:Mozilla Public License

/**
 * We need to collect and filter the list of classpath roots, src and binary.
 * We need to separate jars containing javax.servet.* classes and ignore the
 * JRE classpath container setting altogether.
 * //from   w w w .j  av  a  2  s.  c  o  m
 * @param monitor a progress monitor
 */
private void resolveProjectClasspath(IProgressMonitor monitor) {
    ArrayList resolvedEntries = new ArrayList();
    IJavaProject jproject = null;
    try {
        jproject = fTapestryProject.getJavaProject();
        IClasspathEntry[] entries = jproject.getRawClasspath();
        // we need to ignore JRE entires and collect all of the other entries!
        // don't separate src from binary roots at this time.
        for (int i = 0; i < entries.length; i++) {
            switch (entries[i].getEntryKind()) {
            case IClasspathEntry.CPE_VARIABLE:

                IClasspathEntry resolvedEntry = null;
                try {
                    resolvedEntry = JavaCore.getResolvedClasspathEntry(entries[i]);
                } catch (org.eclipse.jdt.internal.core.Assert.AssertionFailedException e) {
                    UIPlugin.log(e);
                }
                if (resolvedEntry != null)
                    resolvedEntries.add(resolvedEntry);
                break;

            case IClasspathEntry.CPE_CONTAINER:

                //We don't care about the JRE!
                if ("".equals(entries[i].getPath()))
                    break;

                IClasspathContainer container = JavaCore.getClasspathContainer(entries[i].getPath(), jproject);

                if (container == null)
                    break;

                IClasspathEntry[] containerEntries = container.getClasspathEntries();
                if (containerEntries == null)
                    break;

                // container was bound
                for (int j = 0, containerLength = containerEntries.length; j < containerLength; j++) {
                    IClasspathEntry cEntry = containerEntries[j];
                    //              if (generateMarkerOnError)
                    //              {
                    //                IJavaModelStatus containerStatus =
                    // ClasspathEntry.validateClasspathEntry(
                    //                    jproject,
                    //                    cEntry,
                    //                    false,
                    //                    true /* recurse */);
                    //                if (!containerStatus.isOK())
                    //                  createClasspathProblemMarker(containerStatus);
                    //              }
                    // if container is exported, then its nested entries must in turn
                    // be exported (21749)
                    resolvedEntries.add(cEntry);
                }
                break;

            default:
                resolvedEntries.add(entries[i]);
            }
        }
    } catch (CoreException e) {
        UIPlugin.log(e);
    }
    if (jproject == null)
        return;

}

From source file:com.legstar.eclipse.plugin.schemagen.wizards.JavaToXsdWizardPage.java

License:Open Source License

/**
 * Given classpath entries from a java project, populate a list of
 * collections./*from w  ww.j  a v  a 2  s.  c om*/
 * 
 * @param selectedPathElementsLocations the output path locations
 * @param classPathEntries the java project class path entries
 * @param javaProject the java project
 * @throws JavaModelException if invalid classpath
 */
private void addPathElements(final List<String> selectedPathElementsLocations,
        final IClasspathEntry[] classPathEntries, final IJavaProject javaProject) throws JavaModelException {

    IClasspathEntry jreEntry = JavaRuntime.getDefaultJREContainerEntry();
    IPath projectPath = javaProject.getProject().getLocation();

    for (int i = 0; i < classPathEntries.length; i++) {
        IClasspathEntry classpathEntry = classPathEntries[i];
        String pathElementLocation = null;
        switch (classpathEntry.getEntryKind()) {
        case IClasspathEntry.CPE_LIBRARY:
            pathElementLocation = classpathEntry.getPath().toOSString();
            break;
        case IClasspathEntry.CPE_CONTAINER:
            /* No need for the default jre */
            if (classpathEntry.equals(jreEntry)) {
                break;
            }
            /* Resolve container into class path entries */
            IClasspathContainer classpathContainer = JavaCore.getClasspathContainer(classpathEntry.getPath(),
                    javaProject);
            addPathElements(selectedPathElementsLocations, classpathContainer.getClasspathEntries(),
                    javaProject);
            break;
        case IClasspathEntry.CPE_VARIABLE:
            pathElementLocation = JavaCore.getResolvedVariablePath(classpathEntry.getPath()).toOSString();
            break;
        case IClasspathEntry.CPE_SOURCE:
            /*
             * If source has no specific output, use the project default
             * one
             */
            IPath outputLocation = classpathEntry.getOutputLocation();
            if (outputLocation == null) {
                outputLocation = javaProject.getOutputLocation();
            }
            pathElementLocation = projectPath.append(outputLocation.removeFirstSegments(1)).toOSString();
            break;
        default:
            break;
        }

        if (pathElementLocation != null && !selectedPathElementsLocations.contains(pathElementLocation)) {
            selectedPathElementsLocations.add(pathElementLocation);
        }
    }
}

From source file:com.microsoft.javapkgbuild.Tasks.java

License:MIT License

private static String getClassPathType(IClasspathEntry cp) {
    switch (cp.getEntryKind()) {
    case IClasspathEntry.CPE_CONTAINER:
        return "con";
    case IClasspathEntry.CPE_LIBRARY:
        return "lib";
    case IClasspathEntry.CPE_PROJECT:
        return "proj";
    case IClasspathEntry.CPE_SOURCE:
        return "src";
    case IClasspathEntry.CPE_VARIABLE:
        return "var";
    default://  w w w. ja  v a  2 s  .  c  o m
        return "unexpected";
    }
}

From source file:com.microsoft.javapkgsrv.JavaElementLabelComposer.java

License:Open Source License

private static IClasspathEntry getClasspathEntry(IPackageFragmentRoot root) throws JavaModelException {
    IClasspathEntry rawEntry = root.getRawClasspathEntry();
    int rawEntryKind = rawEntry.getEntryKind();
    switch (rawEntryKind) {
    case IClasspathEntry.CPE_LIBRARY:
    case IClasspathEntry.CPE_VARIABLE:
    case IClasspathEntry.CPE_CONTAINER: // should not happen, see https://bugs.eclipse.org/bugs/show_bug.cgi?id=305037
        if (root.isArchive() && root.getKind() == IPackageFragmentRoot.K_BINARY) {
            IClasspathEntry resolvedEntry = root.getResolvedClasspathEntry();
            if (resolvedEntry.getReferencingEntry() != null)
                return resolvedEntry;
            else/*from   ww w .j a  v  a 2s . c  o m*/
                return rawEntry;
        }
    }
    return rawEntry;
}

From source file:com.microsoft.javapkgsrv.JavaElementLabelComposer.java

License:Open Source License

private boolean appendVariableLabel(IPackageFragmentRoot root, long flags) {
    try {//from   w w  w . j  av  a2 s  .  c  o  m
        IClasspathEntry rawEntry = root.getRawClasspathEntry();
        if (rawEntry.getEntryKind() == IClasspathEntry.CPE_VARIABLE) {
            IClasspathEntry entry = getClasspathEntry(root);
            if (entry.getReferencingEntry() != null) {
                return false; // not the variable entry itself, but a referenced entry
            }
            IPath path = rawEntry.getPath().makeRelative();

            if (getFlag(flags, REFERENCED_ROOT_POST_QUALIFIED)) {
                int segements = path.segmentCount();
                if (segements > 0) {
                    fBuffer.append(path.segment(segements - 1));
                    if (segements > 1) {
                        int offset = fBuffer.length();
                        fBuffer.append(CONCAT_STRING);
                        fBuffer.append(path.removeLastSegments(1).toOSString());
                    }
                } else {
                    fBuffer.append(path.toString());
                }
            } else {
                fBuffer.append(path.toString());
            }
            int offset = fBuffer.length();
            fBuffer.append(CONCAT_STRING);
            if (root.isExternal())
                fBuffer.append(root.getPath().toOSString());
            else
                fBuffer.append(root.getPath().makeRelative().toString());
            return true;
        }
    } catch (JavaModelException e) {
        // problems with class path, ignore (bug 202792)
        return false;
    }
    return false;
}

From source file:com.mountainminds.eclemma.core.ScopeUtils.java

License:Open Source License

/**
 * Remove all JRE runtime entries from the given set
 * /*from  w  ww . jav a 2 s. co m*/
 * @param scope
 *          set to filter
 * @return filtered set without JRE runtime entries
 */
public static Set<IPackageFragmentRoot> filterJREEntries(Collection<IPackageFragmentRoot> scope)
        throws JavaModelException {
    final Set<IPackageFragmentRoot> filtered = new HashSet<IPackageFragmentRoot>();
    for (final IPackageFragmentRoot root : scope) {
        final IClasspathEntry entry = root.getRawClasspathEntry();
        switch (entry.getEntryKind()) {
        case IClasspathEntry.CPE_SOURCE:
        case IClasspathEntry.CPE_LIBRARY:
        case IClasspathEntry.CPE_VARIABLE:
            filtered.add(root);
            break;
        case IClasspathEntry.CPE_CONTAINER:
            IClasspathContainer container = JavaCore.getClasspathContainer(entry.getPath(),
                    root.getJavaProject());
            if (container != null && container.getKind() == IClasspathContainer.K_APPLICATION) {
                filtered.add(root);
            }
            break;
        }
    }
    return filtered;
}

From source file:com.redhat.ceylon.eclipse.code.explorer.PackageExplorerContentProvider.java

License:Open Source License

@Override
protected Object[] getPackageFragmentRoots(IJavaProject project) throws JavaModelException {
    if (!project.getProject().isOpen())
        return NO_CHILDREN;

    List<Object> result = new ArrayList<Object>();

    IPackageFragmentRoot[] roots = project.getPackageFragmentRoots();
    for (int i = 0; i < roots.length; i++) {
        IPackageFragmentRoot root = roots[i];
        IClasspathEntry classpathEntry = root.getRawClasspathEntry();
        int entryKind = classpathEntry.getEntryKind();
        if (entryKind == IClasspathEntry.CPE_CONTAINER) {
            // all ClassPathContainers are added later
        } else if (fShowLibrariesNode
                && (entryKind == IClasspathEntry.CPE_LIBRARY || entryKind == IClasspathEntry.CPE_VARIABLE)) {
            IResource resource = root.getResource();
            if (resource != null && project.getResource().equals(resource.getParent())) {
                // show resource as child of project, see https://bugs.eclipse.org/bugs/show_bug.cgi?id=141906
                result.add(resource);/*from  ww  w .  j a  v  a2s . c  o m*/
            } else {
                // skip: will add the referenced library node later
            }
        } else {
            if (isProjectPackageFragmentRoot(root)) {
                // filter out package fragments that correspond to projects and
                // replace them with the package fragments directly
                Object[] fragments = getPackageFragmentRootContent(root);
                for (int j = 0; j < fragments.length; j++) {
                    result.add(fragments[j]);
                }
            } else {
                result.add(root);
            }
        }
    }

    if (fShowLibrariesNode) {
        result.add(new LibraryContainer(project));
    }

    // separate loop to make sure all containers are on the classpath (even empty ones)
    IClasspathEntry[] rawClasspath = project.getRawClasspath();
    for (int i = 0; i < rawClasspath.length; i++) {
        IClasspathEntry classpathEntry = rawClasspath[i];
        if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
            result.add(new ClassPathContainer(project, classpathEntry));
        }
    }
    Object[] resources = project.getNonJavaResources();
    for (int i = 0; i < resources.length; i++) {
        result.add(resources[i]);
    }
    return result.toArray();
}