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

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

Introduction

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

Prototype

int CPE_LIBRARY

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

Click Source Link

Document

Entry kind constant describing a classpath entry identifying a library.

Usage

From source file:com.liferay.ide.server.remote.ModuleTraverser.java

License:Open Source License

private static boolean isClassFolderEntry(final IClasspathEntry entry) {
    if (entry == null || entry.getEntryKind() != IClasspathEntry.CPE_LIBRARY) {
        return false;
    }// w w w .j  a v a2 s.  co  m
    // does the path refer to a file or a folder?
    final IPath entryPath = entry.getPath();
    IPath entryLocation = entryPath;
    final IResource resource = ResourcesPlugin.getWorkspace().getRoot().findMember(entryPath);
    if (resource != null) {
        entryLocation = resource.getLocation();
    }
    boolean isFile = true; // by default, assume a jar file
    if (entryLocation.toFile().isDirectory()) {
        isFile = false;
    }
    return !isFile;
}

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

License:MIT License

public static void exportReferences(String projectName, String outputFileName) throws JavaModelException {
    try {//w  w  w  .j a  v a  2 s  .c om
        IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
        IProject project = workspaceRoot.getProject(projectName);
        IJavaProject javaProject = JavaCore.create(project);

        DocumentBuilderFactory xFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = xFactory.newDocumentBuilder();
        Document doc = builder.newDocument();

        Element mainRoot = doc.createElement("classpath");
        mainRoot.setAttribute("projectName", projectName);
        doc.appendChild(mainRoot);

        IClasspathEntry[] classPathList = javaProject.getResolvedClasspath(true);
        for (IClasspathEntry cp : classPathList) {
            Element cpNode = doc.createElement("classpathentry");
            cpNode.setAttribute("path", cp.getPath().toOSString());
            cpNode.setAttribute("kind", getClassPathType(cp));
            cpNode.setAttribute("exported", Boolean.toString(cp.isExported()));

            IPath sourceFolder = cp.getSourceAttachmentPath();
            if (cp.getEntryKind() == IClasspathEntry.CPE_LIBRARY && sourceFolder != null)
                cpNode.setAttribute("sourcepath", sourceFolder.toOSString());

            mainRoot.appendChild(cpNode);
        }

        Transformer transformer = TransformerFactory.newInstance().newTransformer();
        transformer.setOutputProperty(OutputKeys.INDENT, "yes");
        DOMSource source = new DOMSource(doc);

        FileOutputStream fos = new FileOutputStream(outputFileName);
        StreamResult outFile = new StreamResult(fos);
        transformer.transform(source, outFile);
        fos.close();

        System.out.println("Output file is: " + outputFileName);
    } catch (Exception e) {
        e.printStackTrace(System.err);
    }
}

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  om
        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// w ww.ja v a  2s.  c  o m
                return rawEntry;
        }
    }
    return rawEntry;
}

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

License:Open Source License

/**
 * Remove all JRE runtime entries from the given set
 * //from  ww  w . j  a  v a  2  s.c o 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.nginious.http.plugin.ServerManager.java

License:Apache License

private boolean updateProjectWithPluginVersion(IProject project) {
    logger.log("ENTER ServerManager.updateProjectWithPluginVersion project={0}", project);

    try {//from  ww  w. j a v  a  2 s  .  com
        URL apiJar = NginiousPlugin.getApiJar();
        String filePath = apiJar.toString();
        filePath = filePath.substring(5);
        Path apiJarPath = new Path(filePath);

        IJavaProject javaProject = JavaCore.create(project);
        IClasspathEntry[] entries = javaProject.getRawClasspath();
        ArrayList<IClasspathEntry> newEntries = new ArrayList<IClasspathEntry>();
        boolean changed = false;

        for (IClasspathEntry entry : entries) {
            if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
                IPath path = entry.getPath();

                if (path.lastSegment() != null && path.lastSegment().endsWith("nginious-api.jar")) {
                    changed = true;
                    entry = JavaCore.newLibraryEntry(apiJarPath, null, null);
                }
            }

            newEntries.add(entry);
        }

        if (changed) {
            IProgressMonitor progress = new NullProgressMonitor();
            entries = newEntries.toArray(new IClasspathEntry[newEntries.size()]);
            javaProject.setRawClasspath(entries, progress);
            javaProject.save(progress, true);
        }

        logger.log("EXIT ServerManager.updateProjectWithPluginVersion changed={0}", changed);
        return changed;
    } catch (JavaModelException e) {
        logger.log("ServerManager.updateProkectWithPluginVersion exception", e);
        return false;
    } catch (IOException e) {
        logger.log("ServerManager.updateProkectWithPluginVersion exception", e);
        return false;
    }
}

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 w w  w  .  java  2 s. 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();
}

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

License:Open Source License

@Override
protected Object internalGetParent(Object element) {
    if (!fIsFlatLayout && element instanceof IPackageFragment) {
        return getHierarchicalPackageParent((IPackageFragment) element);
    } else if (element instanceof IPackageFragmentRoot) {
        // since we insert logical package containers we have to fix
        // up the parent for package fragment roots so that they refer
        // to the container and containers refer to the project
        IPackageFragmentRoot root = (IPackageFragmentRoot) element;

        try {//from  w  w w  .j av  a 2 s .c  o  m
            IClasspathEntry entry = root.getRawClasspathEntry();
            int entryKind = entry.getEntryKind();
            if (entryKind == IClasspathEntry.CPE_CONTAINER) {
                return new ClassPathContainer(root.getJavaProject(), entry);
            } else if (fShowLibrariesNode && (entryKind == IClasspathEntry.CPE_LIBRARY
                    || entryKind == IClasspathEntry.CPE_VARIABLE)) {
                return new LibraryContainer(root.getJavaProject());
            }
        } catch (JavaModelException e) {
            // fall through
        }
    } else if (element instanceof PackageFragmentRootContainer) {
        return ((PackageFragmentRootContainer) element).getJavaProject();
    }
    return super.internalGetParent(element);
}

From source file:com.redhat.ceylon.eclipse.code.preferences.CeylonBuildPathsBlock.java

License:Open Source License

private int getPageIndex(int entryKind) {
    switch (entryKind) {
    case IClasspathEntry.CPE_CONTAINER:
    case IClasspathEntry.CPE_LIBRARY:
    case IClasspathEntry.CPE_VARIABLE:
        return 2;
    case IClasspathEntry.CPE_PROJECT:
        return 1;
    case IClasspathEntry.CPE_SOURCE:
        return 0;
    }// w  w w . jav  a2 s . c o m
    return 0;
}

From source file:com.redhat.ceylon.eclipse.core.classpath.CeylonClasspathUtil.java

License:Apache License

/**
 * Just a verbatim copy of the internal Eclipse function:
 * org.eclipse.jdt.internal.corext.javadoc
 * .JavaDocLocations#getLibraryJavadocLocation(IClasspathEntry)
 * //from   w ww . j a va  2  s . c om
 * @param entry
 * @return
 */
public static URL getLibraryJavadocLocation(IClasspathEntry entry) {
    if (entry == null) {
        throw new IllegalArgumentException("Entry must not be null"); //$NON-NLS-1$
    }

    int kind = entry.getEntryKind();
    if (kind != IClasspathEntry.CPE_LIBRARY && kind != IClasspathEntry.CPE_VARIABLE) {
        throw new IllegalArgumentException("Entry must be of kind CPE_LIBRARY or " + "CPE_VARIABLE"); //$NON-NLS-1$
    }

    IClasspathAttribute[] extraAttributes = entry.getExtraAttributes();
    for (int i = 0; i < extraAttributes.length; i++) {
        IClasspathAttribute attrib = extraAttributes[i];
        if (IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME.equals(attrib.getName())) {
            try {
                return new URL(attrib.getValue());
            } catch (MalformedURLException e) {
                return null;
            }
        }
    }
    return null;
}