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:org.eclipse.birt.report.designer.internal.ui.ide.adapters.IDEClassPathBlock.java

License:Open Source License

private int getType(IDECPListElement element) {
    int kind = element.getEntryKind();
    if (kind == IClasspathEntry.CPE_VARIABLE) {
        return VAR_TYPE;
    } else if (kind == IClasspathEntry.CPE_PROJECT) {
        return PROJECT_TYPE;
    } else if (kind == IClasspathEntry.CPE_LIBRARY) {
        IResource resource = element.getResource();
        if (resource instanceof IFile) {
            return JAR_TYPE;
        }/*www.j av a  2  s  .co m*/
        if (resource instanceof IContainer) {
            return FOL_TYPE;
        }

        IPath path = element.getPath();

        File file = path.toFile();
        if (file.isFile()) {
            return EXTJAR_TYPE;
        } else {
            return ADDFOL_TYPE;
        }
    }

    return UNKNOW_TYPE;
}

From source file:org.eclipse.birt.report.designer.internal.ui.ide.adapters.IDECPListElement.java

License:Open Source License

private IClasspathEntry newClasspathEntry() {

    IClasspathAttribute[] extraAttributes = new IClasspathAttribute[0];
    switch (fEntryKind) {
    case IClasspathEntry.CPE_SOURCE:
        return JavaCore.newSourceEntry(fPath, null, null, null, extraAttributes);
    case IClasspathEntry.CPE_LIBRARY: {
        return JavaCore.newLibraryEntry(fPath, null, null, null, extraAttributes, isExported());
    }//from w ww. j  av a2 s  .  c  o  m
    case IClasspathEntry.CPE_PROJECT: {
        return JavaCore.newProjectEntry(fPath, null, false, extraAttributes, isExported());
    }
    case IClasspathEntry.CPE_CONTAINER: {
        return JavaCore.newContainerEntry(fPath, null, extraAttributes, isExported());
    }
    case IClasspathEntry.CPE_VARIABLE: {
        return JavaCore.newVariableEntry(fPath, null, null, null, extraAttributes, isExported());
    }
    default:
        return null;
    }
}

From source file:org.eclipse.birt.report.designer.internal.ui.ide.adapters.IDECPListLabelProvider.java

License:Open Source License

public String getCPListElementText(IDECPListElement cpentry) {
    IPath path = cpentry.getPath();//from  ww  w. j av a2s .  c o m
    switch (cpentry.getEntryKind()) {
    case IClasspathEntry.CPE_LIBRARY: {
        IResource resource = cpentry.getResource();
        if (resource instanceof IContainer) {
            StringBuffer buf = new StringBuffer(getPathLabel(path, false));
            buf.append(' ');
            buf.append(fClassLabel);
            if (!resource.exists()) {
                buf.append(' ');
                if (cpentry.isMissing()) {
                    buf.append(fMissing);
                } else {
                    buf.append(fNewLabel);
                }
            }
            return buf.toString();
        } else {
            String label = getPathString(path, resource == null);
            if (cpentry.isMissing()) {
                label = label + ' ' + fMissing;
            }
            return label;
        }
    }
    case IClasspathEntry.CPE_VARIABLE: {
        String label = getVariableString(path);
        if (cpentry.isMissing()) {
            label = label + ' ' + fMissing;
        }
        return label;
    }
    case IClasspathEntry.CPE_PROJECT:
        String label = path.lastSegment();
        if (cpentry.isMissing()) {
            label = label + ' ' + fMissing;
        }
        return label;
    case IClasspathEntry.CPE_SOURCE: {
        String pathLabel = getPathLabel(path, false);
        StringBuffer buf = new StringBuffer(pathLabel);

        IResource resource = cpentry.getResource();
        if (resource != null && !resource.exists()) {
            buf.append(' ');
            if (cpentry.isMissing()) {
                buf.append(fMissing);
            } else {
                buf.append(fNewLabel);
            }
        } else if (cpentry.getOrginalPath() == null) {
            buf.append(' ');
            buf.append(fNewLabel);
        }
        return buf.toString();
    }
    default:
        // pass
    }
    return Messages.getString("IDECPListLabelProvider.unknown"); //$NON-NLS-1$
}

From source file:org.eclipse.birt.report.designer.internal.ui.ide.adapters.IDECPListLabelProvider.java

License:Open Source License

private Image getCPListElementBaseImage(IDECPListElement cpentry) {
    switch (cpentry.getEntryKind()) {
    case IClasspathEntry.CPE_LIBRARY:
        IResource res = cpentry.getResource();
        if (res == null) {
            if (isArchivePath(cpentry.getPath(), false)) {
                return ReportPlatformUIImages.getImage(IReportGraphicConstants.ICON_NODE_EXTJAR);
            } else {
                return ReportPlatformUIImages.getImage(IReportGraphicConstants.ICON_NODE_EXTFOL);
            }/*from   www  .j  a v a  2s . c o m*/
        } else if (res instanceof IFile) {
            return ReportPlatformUIImages.getImage(IReportGraphicConstants.ICON_NODE_JAR);
        } else {
            return ReportPlatformUIImages.getImage(IReportGraphicConstants.ICON_NODE_FOL);
        }
    case IClasspathEntry.CPE_PROJECT:
        return ReportPlugin.getDefault().getWorkbench().getSharedImages()
                .getImage(IDE.SharedImages.IMG_OBJ_PROJECT);
    case IClasspathEntry.CPE_VARIABLE:
        return ReportPlatformUIImages.getImage(IReportGraphicConstants.ICON_NODE_VARIABLE);
    default:
        return null;
    }
}

From source file:org.eclipse.birt.report.designer.internal.ui.ide.adapters.IDEReportClasspathResolver.java

License:Open Source License

private List<String> resolveClasspathEntries(IClasspathEntry[] classpathEntries, boolean needExported,
        IJavaProject project) {/*from ww  w  .  j  ava 2  s. com*/
    ArrayList<String> newClassPath = new ArrayList<String>();
    IWorkspace space = ResourcesPlugin.getWorkspace();
    IWorkspaceRoot root = space.getRoot();
    for (int i = 0; i < classpathEntries.length; i++) {
        IClasspathEntry curr = classpathEntries[i];
        if (!needExported && !curr.isExported() && curr.getEntryKind() != IClasspathEntry.CPE_VARIABLE) {
            continue;
        }
        IPath path = curr.getPath();
        //         if (curr.getEntryKind( ) == IClasspathEntry.CPE_VARIABLE)
        //         {
        //            path = JavaCore.getClasspathVariable( path.segment( 0 ) );
        //         }
        //         else
        //         {
        path = JavaCore.getResolvedClasspathEntry(curr).getPath();
        //         }

        if (project != null && curr.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
            try {
                IClasspathContainer contianer = JavaCore.getClasspathContainer(path, project);
                if (contianer != null && contianer.getKind() == IClasspathContainer.K_APPLICATION) {
                    IClasspathEntry[] entrys = contianer.getClasspathEntries();
                    List<String> list = resolveClasspathEntries(entrys, needExported, project);
                    for (int j = 0; j < list.size(); j++) {
                        addToList(newClassPath, list.get(j));
                    }
                }
            } catch (JavaModelException e) {
                //do nothing
            }
            continue;
        }
        if (curr.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
            path = curr.getOutputLocation();
        }
        if (path == null) {
            continue;
        }
        if (curr.getEntryKind() == IClasspathEntry.CPE_PROJECT) {
            if (root.findMember(path) instanceof IProject) {
                List<String> strs = getProjectClasspath((IProject) root.findMember(path), false, false);
                for (int j = 0; j < strs.size(); j++) {
                    addToList(newClassPath, strs.get(j));
                }
            }
        } else if (curr.getEntryKind() == IClasspathEntry.CPE_LIBRARY
                || curr.getEntryKind() == IClasspathEntry.CPE_VARIABLE
                || curr.getEntryKind() == IClasspathEntry.CPE_SOURCE) {

            boolean inWorkSpace = true;
            if (space == null || space.getRoot() == null) {
                inWorkSpace = false;
            }

            if (root.findMember(path) == null) {
                inWorkSpace = false;
            }

            if (inWorkSpace) {
                String absPath = getFullPath(path, root.findMember(path).getProject());

                //URL url = new URL( "file:///" + absPath );//$NON-NLS-1$//file:/
                //newClassPath.add( url.getPath( ) );
                newClassPath.add(absPath);
            } else {
                //                  newClassPath.add( curr.getPath( )
                //                        .toFile( )
                //                        .toURI( )
                //                        .toURL( ) );
                newClassPath.add(path.toFile().getAbsolutePath());
            }

        }

    }
    return newClassPath;
}

From source file:org.eclipse.buckminster.jdt.internal.ClasspathEmitter.java

License:Open Source License

private static void appendPaths(IJavaModel model, IProject project, String target, List<IPath> path,
        HashSet<IPath> seenPaths, HashSet<String> seenProjects, boolean atTop) throws CoreException {
    Logger log = Buckminster.getLogger();
    String projectName = project.getName();
    if (seenProjects.contains(projectName))
        return;// w  w w .ja  va 2 s  .  com
    seenProjects.add(projectName);
    log.debug("Emitting classpath for project %s...", projectName); //$NON-NLS-1$

    IJavaProject javaProject = model.getJavaProject(projectName);
    IClasspathEntry[] entries;
    if (javaProject == null || !javaProject.exists()) {
        // The project may still be a component that exports jar files.
        //
        BMClasspathContainer container = new BMClasspathContainer(project, target);
        entries = container.getClasspathEntries();
        log.debug(" not a java project, contains %d entries", Integer.valueOf(entries.length)); //$NON-NLS-1$
    } else {
        entries = (atTop && target != null) ? changeClasspathForTarget(javaProject, target)
                : javaProject.getResolvedClasspath(false);
        log.debug(" java project, contains %d entries", Integer.valueOf(entries.length)); //$NON-NLS-1$
    }

    for (IClasspathEntry entry : entries) {
        IPath entryPath;
        switch (entry.getEntryKind()) {
        case IClasspathEntry.CPE_LIBRARY:
            log.debug(" found library with path: %s", entry.getPath()); //$NON-NLS-1$
            if (!(atTop || entry.isExported())) {
                log.debug(" skipping path %s. It's neither at top nor exported", entry.getPath()); //$NON-NLS-1$
                continue;
            }

            entryPath = entry.getPath();
            break;
        case IClasspathEntry.CPE_SOURCE:
            entryPath = entry.getOutputLocation();
            if (entryPath == null) {
                // Uses default output location
                //
                IJavaProject proj = model.getJavaProject(entry.getPath().segment(0));
                if (proj == null)
                    continue;
                entryPath = proj.getOutputLocation();
            }
            log.debug(" found source with path: %s", entryPath); //$NON-NLS-1$
            break;
        case IClasspathEntry.CPE_PROJECT:
            projectName = entry.getPath().segment(0);
            log.debug(" found project: %s", projectName); //$NON-NLS-1$
            if (!(atTop || entry.isExported())) {
                log.debug(" skipping project %s. It's neither at top nor exported", projectName); //$NON-NLS-1$
                continue;
            }

            IProject conProject = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
            appendPaths(model, conProject, null, path, seenPaths, seenProjects, false);
            continue;
        default:
            throw BuckminsterException.fromMessage(Messages.unexpected_classpath_entry_kind);
        }

        IResource folder = ResourcesPlugin.getWorkspace().getRoot().findMember(entryPath);
        if (folder != null) {
            log.debug(" path %s is inside workspace, switching to %s", entryPath, folder.getLocation()); //$NON-NLS-1$
            entryPath = folder.getLocation();
        }

        if (!seenPaths.contains(entryPath)) {
            seenPaths.add(entryPath);
            path.add(entryPath);
            log.debug(" path %s added", entryPath); //$NON-NLS-1$
        }
    }
}

From source file:org.eclipse.buildship.core.workspace.internal.GradleClasspathContainerRuntimeClasspathEntryResolver.java

License:Open Source License

private void collectContainerRuntimeClasspath(IClasspathContainer container,
        List<IRuntimeClasspathEntry> result, boolean includeExportedEntriesOnly,
        LaunchConfigurationScope configurationScopes) throws CoreException {
    for (final IClasspathEntry cpe : container.getClasspathEntries()) {
        if (!includeExportedEntriesOnly || cpe.isExported()) {
            if (cpe.getEntryKind() == IClasspathEntry.CPE_LIBRARY && configurationScopes.isEntryIncluded(cpe)) {
                result.add(JavaRuntime.newArchiveRuntimeClasspathEntry(cpe.getPath()));
            } else if (cpe.getEntryKind() == IClasspathEntry.CPE_PROJECT) {
                Optional<IProject> candidate = findAccessibleJavaProject(cpe.getPath().segment(0));
                if (candidate.isPresent()) {
                    IJavaProject dependencyProject = JavaCore.create(candidate.get());
                    IRuntimeClasspathEntry projectRuntimeEntry = JavaRuntime
                            .newProjectRuntimeClasspathEntry(dependencyProject);
                    // add the project entry itself so that the source lookup can find the classes
                    // see https://github.com/eclipse/buildship/issues/383
                    result.add(projectRuntimeEntry);
                    Collections.addAll(result,
                            JavaRuntime.resolveRuntimeClasspathEntry(projectRuntimeEntry, dependencyProject));
                    collectContainerRuntimeClasspathIfPresent(dependencyProject, result, true,
                            configurationScopes);
                }//from www.  j  a v  a2s  .  c om
            }
        }
    }
}

From source file:org.eclipse.buildship.core.workspace.internal.LibraryFilter.java

License:Open Source License

private static IClasspathEntry[] filterLibraries(IClasspathEntry[] classpath) throws JavaModelException {
    return FluentIterable.from(Arrays.asList(classpath)).filter(new Predicate<IClasspathEntry>() {

        @Override/*  w  w w.ja  v  a  2  s. c o m*/
        public boolean apply(IClasspathEntry entry) {
            return entry.getEntryKind() != IClasspathEntry.CPE_LIBRARY;
        }
    }).toArray(IClasspathEntry.class);
}

From source file:org.eclipse.che.jdt.core.JavaCore.java

License:Open Source License

/**
 * Creates and returns a new classpath entry of kind <code>CPE_LIBRARY</code> for the JAR or folder
 * identified by the given absolute path. This specifies that all package fragments within the root
 * will have children of type <code>IClassFile</code>.
 * <p>/* w w w .java 2  s .co  m*/
 * A library entry is used to denote a prerequisite JAR or root folder containing binaries.
 * The target JAR can either be defined internally to the workspace (absolute path relative
 * to the workspace root), or externally to the workspace (absolute path in the file system).
 * The target root folder can also be defined internally to the workspace (absolute path relative
 * to the workspace root), or - since 3.4 - externally to the workspace (absolute path in the file system).
 * Since 3.5, the path to the library can also be relative to the project using ".." as the first segment.
 * <p>
 * e.g. Here are some examples of binary path usage<ul>
 *   <li><code> "c:\jdk1.2.2\jre\lib\rt.jar" </code> - reference to an external JAR on Windows</li>
 *   <li><code> "/Project/someLib.jar" </code> - reference to an internal JAR on Windows or Linux</li>
 *   <li><code> "/Project/classes/" </code> - reference to an internal binary folder on Windows or Linux</li>
 *   <li><code> "/home/usr/classes" </code> - reference to an external binary folder on Linux</li>
 *   <li><code> "../../lib/someLib.jar" </code> - reference to an external JAR that is a sibbling of the workspace on either platform</li>
 * </ul>
 * Note that on non-Windows platform, a path <code>"/some/lib.jar"</code> is ambiguous.
 * It can be a path to an external JAR (its file system path being <code>"/some/lib.jar"</code>)
 * or it can be a path to an internal JAR (<code>"some"</code> being a project in the workspace).
 * Such an ambiguity is solved when the classpath entry is used (e.g. in {@link org.eclipse.jdt.core.IJavaProject#getPackageFragmentRoots()}).
 * If the resource <code>"lib.jar"</code> exists in project <code>"some"</code>, then it is considered an
 * internal JAR. Otherwise it is an external JAR.
 * <p>Also note that this operation does not attempt to validate or access the
 * resources at the given paths.
 * </p><p>
 * The access rules determine the set of accessible class files
 * in the library. If the list of access rules is empty then all files
 * in this library are accessible.
 * See {@link IAccessRule} for a detailed description of access
 * rules.
 * </p>
 * <p>
 * The <code>extraAttributes</code> list contains name/value pairs that must be persisted with
 * this entry. If no extra attributes are provided, an empty array must be passed in.<br>
 * Note that this list should not contain any duplicate name.
 * </p>
 * <p>
 * The <code>isExported</code> flag indicates whether this entry is contributed to dependent
 * projects. If not exported, dependent projects will not see any of the classes from this entry.
 * If exported, dependent projects will concatenate the accessible files patterns of this entry with the
 * accessible files patterns of the projects, and they will concatenate the non accessible files patterns of this entry
 * with the non accessible files patterns of the project.
 * </p>
 * <p>
 * Since 3.5, if the libray is a ZIP archive, the "Class-Path" clause (if any) in the "META-INF/MANIFEST.MF" is read
 * and referenced ZIP archives are added to the {@link org.eclipse.jdt.core.IJavaProject#getResolvedClasspath(boolean) resolved classpath}.
 * </p>
 *
 * @param path the path to the library
 * @param sourceAttachmentPath the absolute path of the corresponding source archive or folder,
 *    or <code>null</code> if none. Note, since 3.0, an empty path is allowed to denote no source attachment.
 *   and will be automatically converted to <code>null</code>. Since 3.4, this path can also denote a path external
 *   to the workspace.
 * @param sourceAttachmentRootPath the location of the root of the source files within the source archive or folder
 *    or <code>null</code> if this location should be automatically detected.
 * @param accessRules the possibly empty list of access rules for this entry
 * @param extraAttributes the possibly empty list of extra attributes to persist with this entry
 * @param isExported indicates whether this entry is contributed to dependent
 *      projects in addition to the output location
 * @return a new library classpath entry
 * @since 3.1
 */
public static IClasspathEntry newLibraryEntry(IPath path, IPath sourceAttachmentPath,
        IPath sourceAttachmentRootPath, IAccessRule[] accessRules, IClasspathAttribute[] extraAttributes,
        boolean isExported) {

    if (path == null)
        throw new ClasspathEntry.AssertionFailedException("Library path cannot be null"); //$NON-NLS-1$
    if (accessRules == null) {
        accessRules = ClasspathEntry.NO_ACCESS_RULES;
    }
    if (extraAttributes == null) {
        extraAttributes = ClasspathEntry.NO_EXTRA_ATTRIBUTES;
    }
    boolean hasDotDot = ClasspathEntry.hasDotDot(path);
    if (!hasDotDot && !path.isAbsolute())
        throw new ClasspathEntry.AssertionFailedException("Path for IClasspathEntry must be absolute: " + path); //$NON-NLS-1$
    if (sourceAttachmentPath != null) {
        if (sourceAttachmentPath.isEmpty()) {
            sourceAttachmentPath = null; // treat empty path as none
        } else if (!sourceAttachmentPath.isAbsolute()) {
            throw new ClasspathEntry.AssertionFailedException("Source attachment path '" //$NON-NLS-1$
                    + sourceAttachmentPath + "' for IClasspathEntry must be absolute"); //$NON-NLS-1$
        }
    }
    return new ClasspathEntry(IPackageFragmentRoot.K_BINARY, IClasspathEntry.CPE_LIBRARY,
            //                hasDotDot ? path : JavaProject.canonicalizedPath(path),
            path, ClasspathEntry.INCLUDE_ALL, // inclusion patterns
            ClasspathEntry.EXCLUDE_NONE, // exclusion patterns
            sourceAttachmentPath, sourceAttachmentRootPath, null, // specific output folder
            isExported, accessRules, false, // no access rules to combine
            extraAttributes);
}

From source file:org.eclipse.che.jdt.internal.core.ClasspathEntry.java

License:Open Source License

/**
 * Returns a printable representation of this classpath entry.
 *///from  w  ww . ja va  2s.c  om
public String toString() {
    StringBuffer buffer = new StringBuffer();
    //      Object target = JavaModel.getTarget(getPath(), true);
    //      if (target instanceof File)
    buffer.append(getPath().toOSString());
    //      else
    //         buffer.append(String.valueOf(getPath()));
    buffer.append('[');
    switch (getEntryKind()) {
    case IClasspathEntry.CPE_LIBRARY:
        buffer.append("CPE_LIBRARY"); //$NON-NLS-1$
        break;
    case IClasspathEntry.CPE_PROJECT:
        buffer.append("CPE_PROJECT"); //$NON-NLS-1$
        break;
    case IClasspathEntry.CPE_SOURCE:
        buffer.append("CPE_SOURCE"); //$NON-NLS-1$
        break;
    case IClasspathEntry.CPE_VARIABLE:
        buffer.append("CPE_VARIABLE"); //$NON-NLS-1$
        break;
    case IClasspathEntry.CPE_CONTAINER:
        buffer.append("CPE_CONTAINER"); //$NON-NLS-1$
        break;
    }
    buffer.append("]["); //$NON-NLS-1$
    switch (getContentKind()) {
    case IPackageFragmentRoot.K_BINARY:
        buffer.append("K_BINARY"); //$NON-NLS-1$
        break;
    case IPackageFragmentRoot.K_SOURCE:
        buffer.append("K_SOURCE"); //$NON-NLS-1$
        break;
    case ClasspathEntry.K_OUTPUT:
        buffer.append("K_OUTPUT"); //$NON-NLS-1$
        break;
    }
    buffer.append(']');
    if (getSourceAttachmentPath() != null) {
        buffer.append("[sourcePath:"); //$NON-NLS-1$
        buffer.append(getSourceAttachmentPath());
        buffer.append(']');
    }
    if (getSourceAttachmentRootPath() != null) {
        buffer.append("[rootPath:"); //$NON-NLS-1$
        buffer.append(getSourceAttachmentRootPath());
        buffer.append(']');
    }
    buffer.append("[isExported:"); //$NON-NLS-1$
    buffer.append(this.isExported);
    buffer.append(']');
    IPath[] patterns = this.inclusionPatterns;
    int length;
    if ((length = patterns == null ? 0 : patterns.length) > 0) {
        buffer.append("[including:"); //$NON-NLS-1$
        for (int i = 0; i < length; i++) {
            buffer.append(patterns[i]);
            if (i != length - 1) {
                buffer.append('|');
            }
        }
        buffer.append(']');
    }
    patterns = this.exclusionPatterns;
    if ((length = patterns == null ? 0 : patterns.length) > 0) {
        buffer.append("[excluding:"); //$NON-NLS-1$
        for (int i = 0; i < length; i++) {
            buffer.append(patterns[i]);
            if (i != length - 1) {
                buffer.append('|');
            }
        }
        buffer.append(']');
    }
    if (this.accessRuleSet != null) {
        buffer.append('[');
        buffer.append(this.accessRuleSet.toString(false/*on one line*/));
        buffer.append(']');
    }
    if (this.entryKind == CPE_PROJECT) {
        buffer.append("[combine access rules:"); //$NON-NLS-1$
        buffer.append(this.combineAccessRules);
        buffer.append(']');
    }
    if (getOutputLocation() != null) {
        buffer.append("[output:"); //$NON-NLS-1$
        buffer.append(getOutputLocation());
        buffer.append(']');
    }
    if ((length = this.extraAttributes == null ? 0 : this.extraAttributes.length) > 0) {
        buffer.append("[attributes:"); //$NON-NLS-1$
        for (int i = 0; i < length; i++) {
            buffer.append(this.extraAttributes[i]);
            if (i != length - 1) {
                buffer.append(',');
            }
        }
        buffer.append(']');
    }
    return buffer.toString();
}