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:io.sarl.eclipse.util.JavaClasspathParser.java

License:Apache License

/**
 * Decodes one XML element with the XML stream.
 *
 * @param element/*from  w ww  .  ja v a 2 s .  c  om*/
 *            - the considered element
 * @param projectName
 *            - the name of project containing the .classpath file
 * @param projectRootAbsoluteFullPath
 *            - he path to project containing the .classpath file
 * @param unknownElements
 *            - map of unknown elements
 * @return the set of CLasspath ENtries extracted from the considered element
 */
@SuppressWarnings({ "checkstyle:npathcomplexity", "checkstyle:cyclomaticcomplexity" })
public static IClasspathEntry elementDecode(Element element, String projectName,
        IPath projectRootAbsoluteFullPath, Map<IPath, UnknownXmlElements> unknownElements) {
    final IPath projectPath = projectRootAbsoluteFullPath;
    final NamedNodeMap attributes = element.getAttributes();
    final NodeList children = element.getChildNodes();
    final boolean[] foundChildren = new boolean[children.getLength()];
    final String kindAttr = removeAttribute(ClasspathEntry.TAG_KIND, attributes);
    final String pathAttr = removeAttribute(ClasspathEntry.TAG_PATH, attributes);

    // ensure path is absolute
    IPath path = new Path(pathAttr);
    final int kind = kindFromString(kindAttr);
    if (kind != IClasspathEntry.CPE_VARIABLE && kind != IClasspathEntry.CPE_CONTAINER && !path.isAbsolute()) {
        if (!(path.segmentCount() > 0 && path.segment(0).equals(ClasspathEntry.DOT_DOT))) {
            path = projectPath.append(path);
        }
    }
    // source attachment info (optional)
    IPath sourceAttachmentPath = element.hasAttribute(ClasspathEntry.TAG_SOURCEPATH)
            ? new Path(removeAttribute(ClasspathEntry.TAG_SOURCEPATH, attributes))
            : null;
    if (kind != IClasspathEntry.CPE_VARIABLE && sourceAttachmentPath != null
            && !sourceAttachmentPath.isAbsolute()) {
        sourceAttachmentPath = projectPath.append(sourceAttachmentPath);
    }
    final IPath sourceAttachmentRootPath = element.hasAttribute(ClasspathEntry.TAG_ROOTPATH)
            ? new Path(removeAttribute(ClasspathEntry.TAG_ROOTPATH, attributes))
            : null;

    // exported flag (optional)
    final boolean isExported = removeAttribute(ClasspathEntry.TAG_EXPORTED, attributes).equals("true"); //$NON-NLS-1$

    // inclusion patterns (optional)
    IPath[] inclusionPatterns = decodePatterns(attributes, ClasspathEntry.TAG_INCLUDING);
    if (inclusionPatterns == null) {
        inclusionPatterns = ClasspathEntry.INCLUDE_ALL;
    }

    // exclusion patterns (optional)
    IPath[] exclusionPatterns = decodePatterns(attributes, ClasspathEntry.TAG_EXCLUDING);
    if (exclusionPatterns == null) {
        exclusionPatterns = ClasspathEntry.EXCLUDE_NONE;
    }

    // access rules (optional)
    NodeList attributeList = getChildAttributes(ClasspathEntry.TAG_ACCESS_RULES, children, foundChildren);
    IAccessRule[] accessRules = decodeAccessRules(attributeList);

    // backward compatibility
    if (accessRules == null) {
        accessRules = getAccessRules(inclusionPatterns, exclusionPatterns);
    }

    // combine access rules (optional)
    final boolean combineAccessRestrictions = !removeAttribute(ClasspathEntry.TAG_COMBINE_ACCESS_RULES,
            attributes).equals("false"); //$NON-NLS-1$

    // extra attributes (optional)
    attributeList = getChildAttributes(ClasspathEntry.TAG_ATTRIBUTES, children, foundChildren);
    final IClasspathAttribute[] extraAttributes = decodeExtraAttributes(attributeList);

    // custom output location
    final IPath outputLocation = element.hasAttribute(ClasspathEntry.TAG_OUTPUT)
            ? projectPath.append(removeAttribute(ClasspathEntry.TAG_OUTPUT, attributes))
            : null;

    String[] unknownAttributes = null;
    ArrayList<String> unknownChildren = null;

    if (unknownElements != null) {
        // unknown attributes
        final int unknownAttributeLength = attributes.getLength();
        if (unknownAttributeLength != 0) {
            unknownAttributes = new String[unknownAttributeLength * 2];
            for (int i = 0; i < unknownAttributeLength; i++) {
                final Node attribute = attributes.item(i);
                unknownAttributes[i * 2] = attribute.getNodeName();
                unknownAttributes[i * 2 + 1] = attribute.getNodeValue();
            }
        }

        // unknown children
        for (int i = 0, length = foundChildren.length; i < length; i++) {
            if (!foundChildren[i]) {
                final Node node = children.item(i);
                if (node.getNodeType() != Node.ELEMENT_NODE) {
                    continue;
                }
                if (unknownChildren == null) {
                    unknownChildren = new ArrayList<>();
                }
                final StringBuffer buffer = new StringBuffer();
                decodeUnknownNode(node, buffer);
                unknownChildren.add(buffer.toString());
            }
        }
    }

    // recreate the CP entry
    IClasspathEntry entry = null;
    switch (kind) {

    case IClasspathEntry.CPE_PROJECT:
        /*
         * IPackageFragmentRoot.K_SOURCE, IClasspathEntry.CPE_PROJECT, path, ClasspathEntry.INCLUDE_ALL, // inclusion patterns
         * ClasspathEntry.EXCLUDE_NONE, // exclusion patterns null, // source attachment null, // source attachment root null, // specific output
         * folder
         */
        entry = new ClasspathEntry(IPackageFragmentRoot.K_SOURCE, IClasspathEntry.CPE_PROJECT, path,
                ClasspathEntry.INCLUDE_ALL, ClasspathEntry.EXCLUDE_NONE, null, null, null, isExported,
                accessRules, combineAccessRestrictions, extraAttributes);
        break;
    case IClasspathEntry.CPE_LIBRARY:
        entry = JavaCore.newLibraryEntry(path, sourceAttachmentPath, sourceAttachmentRootPath, accessRules,
                extraAttributes, isExported);
        break;
    case IClasspathEntry.CPE_SOURCE:
        // must be an entry in this project or specify another project
        final String projSegment = path.segment(0);
        if (projSegment != null && projSegment.equals(projectName)) {
            // this project
            entry = JavaCore.newSourceEntry(path, inclusionPatterns, exclusionPatterns, outputLocation,
                    extraAttributes);
        } else {
            if (path.segmentCount() == 1) {
                // another project
                entry = JavaCore.newProjectEntry(path, accessRules, combineAccessRestrictions, extraAttributes,
                        isExported);
            } else {
                // an invalid source folder
                entry = JavaCore.newSourceEntry(path, inclusionPatterns, exclusionPatterns, outputLocation,
                        extraAttributes);
            }
        }
        break;
    case IClasspathEntry.CPE_VARIABLE:
        entry = JavaCore.newVariableEntry(path, sourceAttachmentPath, sourceAttachmentRootPath, accessRules,
                extraAttributes, isExported);
        break;
    case IClasspathEntry.CPE_CONTAINER:
        entry = JavaCore.newContainerEntry(path, accessRules, extraAttributes, isExported);
        break;
    case ClasspathEntry.K_OUTPUT:
        if (!path.isAbsolute()) {
            return null;
        }
        /*
         * ClasspathEntry.EXCLUDE_NONE, null, // source attachment null, // source attachment root null, // custom output location false, null, //
         * no access rules false, // no accessible files to combine
         */
        entry = new ClasspathEntry(ClasspathEntry.K_OUTPUT, IClasspathEntry.CPE_LIBRARY, path,
                ClasspathEntry.INCLUDE_ALL, ClasspathEntry.EXCLUDE_NONE, null, null, null, false, null, false,
                ClasspathEntry.NO_EXTRA_ATTRIBUTES);
        break;
    default:
        throw new AssertionFailedException(Messages.bind(Messages.classpath_unknownKind, kindAttr));
    }

    if (unknownAttributes != null || unknownChildren != null) {
        final UnknownXmlElements unknownXmlElements = new UnknownXmlElements();
        unknownXmlElements.attributes = unknownAttributes;
        unknownXmlElements.children = unknownChildren;
        if (unknownElements != null) {
            unknownElements.put(path, unknownXmlElements);
        }
    }

    return entry;
}

From source file:io.sarl.eclipse.util.JavaClasspathParser.java

License:Apache License

/**
 * Returns the kind of a <code>PackageFragmentRoot</code> from its <code>String</code> form.
 *
 * @param kindStr/*from  www.j a  va2s  .c o  m*/
 *            - string to test
 * @return the integer identifier of the type of the specified string: CPE_PROJECT, CPE_VARIABLE, CPE_CONTAINER, etc.
 */
@SuppressWarnings("checkstyle:equalsavoidnull")
private static int kindFromString(String kindStr) {

    if (kindStr.equalsIgnoreCase("prj")) { //$NON-NLS-1$
        return IClasspathEntry.CPE_PROJECT;
    }
    if (kindStr.equalsIgnoreCase("var")) { //$NON-NLS-1$
        return IClasspathEntry.CPE_VARIABLE;
    }
    if (kindStr.equalsIgnoreCase("con")) { //$NON-NLS-1$
        return IClasspathEntry.CPE_CONTAINER;
    }
    if (kindStr.equalsIgnoreCase("src")) { //$NON-NLS-1$
        return IClasspathEntry.CPE_SOURCE;
    }
    if (kindStr.equalsIgnoreCase("lib")) { //$NON-NLS-1$
        return IClasspathEntry.CPE_LIBRARY;
    }
    if (kindStr.equalsIgnoreCase("output")) { //$NON-NLS-1$
        return ClasspathEntry.K_OUTPUT;
    }
    return -1;
}

From source file:io.sarl.eclipse.util.Utilities.java

License:Apache License

/** Create the classpath output location.
 *
 * @param bundle the bundle to point to. Never <code>null</code>.
 * @param precomputedBundlePath the path to the bundle that is already available. If <code>null</code>,
 *      the path is computed from the bundle with {@link BundleUtil}.
 * @param javadocURLs the mappings from the bundle to the javadoc URL. It is used for linking the javadoc to the bundle if
 *      the bundle platform does not know the Javadoc file. If <code>null</code>, no mapping is defined.
 * @return the classpath entry./*  w ww. ja v a2 s. c o m*/
 */
public static IClasspathEntry newOutputClasspathEntry(Bundle bundle, IPath precomputedBundlePath,
        BundleURLMappings javadocURLs) {
    assert bundle != null;
    final IPath bundlePath;
    if (precomputedBundlePath == null) {
        bundlePath = BundleUtil.getBundlePath(bundle);
    } else {
        bundlePath = precomputedBundlePath;
    }
    final IPath sourceBundlePath = BundleUtil.getSourceBundlePath(bundle, bundlePath);
    final IPath javadocPath = BundleUtil.getJavadocBundlePath(bundle, bundlePath);

    final IClasspathAttribute[] extraAttributes;
    if (javadocPath == null) {
        if (javadocURLs != null) {
            final String url = javadocURLs.getURLForBundle(bundle);
            if (!Strings.isNullOrEmpty(url)) {
                final IClasspathAttribute attr = JavaCore
                        .newClasspathAttribute(IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME, url);
                extraAttributes = new IClasspathAttribute[] { attr };
            } else {
                extraAttributes = ClasspathEntry.NO_EXTRA_ATTRIBUTES;
            }
        } else {
            extraAttributes = ClasspathEntry.NO_EXTRA_ATTRIBUTES;
        }
    } else {
        final IClasspathAttribute attr = JavaCore.newClasspathAttribute(
                IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME, javadocPath.makeAbsolute().toOSString());
        extraAttributes = new IClasspathAttribute[] { attr };
    }

    return new ClasspathEntry(ClasspathEntry.K_OUTPUT, IClasspathEntry.CPE_LIBRARY, bundlePath,
            ClasspathEntry.INCLUDE_ALL, ClasspathEntry.EXCLUDE_NONE, sourceBundlePath, null, null, false, null,
            false, extraAttributes);
}

From source file:jasima_gui.EclipseProjectClassLoader.java

License:Open Source License

protected Resource findResource(final String name, IJavaProject proj, boolean onlyExported)
        throws CoreException {
    IClasspathEntry[] classpath = proj.getResolvedClasspath(true);

    byte[] content;

    content = readResource(proj.getOutputLocation().makeRelative(), name);
    if (content != null) {
        return new Resource(proj.getOutputLocation().makeRelative(), content);
    }//  w  ww.  ja va  2 s.c om

    for (IClasspathEntry entry : classpath) {
        if (onlyExported && !entry.isExported())
            continue;

        if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
            content = readResource(entry.getPath(), name);
            if (content != null) {
                return new Resource(entry.getPath(), content);
            }
        } else if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT) {
            IProject projEntry = (IProject) ResourcesPlugin.getWorkspace().getRoot()
                    .findMember(entry.getPath());
            Resource result = findResource(name, JavaCore.create(projEntry), true);
            if (result != null) {
                return result;
            }
        }
    }
    return null;
}

From source file:me.gladwell.eclipse.m2e.android.configuration.ObjectSerializationClasspathPersister.java

License:Open Source License

public void save(String project, List<IClasspathEntry> classpath) {
    ObjectOutputStream os = null;
    try {/*from  ww  w . ja  va  2s .  co  m*/
        File file = new File(stateLocation, project);
        os = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(file))) {
            {
                enableReplaceObject(true);
            }

            protected Object replaceObject(Object o) throws IOException {
                if (o instanceof IClasspathEntry) {
                    IClasspathEntry e = (IClasspathEntry) o;
                    if (e.getEntryKind() == IClasspathEntry.CPE_PROJECT) {
                        return new ProjectEntryReplace(e);
                    } else if (e.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
                        return new LibraryEntryReplace(e);
                    }
                } else if (o instanceof IClasspathAttribute) {
                    return new ClasspathAttributeReplace((IClasspathAttribute) o);
                } else if (o instanceof IAccessRule) {
                    return new AccessRuleReplace((IAccessRule) o);
                } else if (o instanceof IPath) {
                    return new PathReplace((IPath) o);
                }
                return super.replaceObject(o);
            }
        };
        os.writeObject(classpath);
        os.flush();
    } catch (IOException e) {
        throw new ProjectConfigurationException(e);
    } finally {
        if (os != null) {
            try {
                os.close();
            } catch (IOException e) {
                throw new ProjectConfigurationException(e);
            }
        }
    }
}

From source file:net.kbserve.pyjdt.properties.models.CPEAbstractContainer.java

License:Open Source License

/**
 * Update the list of children to include the ICPEType contains the giveb IClasspathEntry
 * //from w  w w. java2  s.  co m
 * @param child
 *            the child
 * @param project
 *            the project
 * @return the iCPE type
 */
public synchronized ICPEType updateChild(IClasspathEntry child, IProject project) {

    String stringPath = makeStringPath(child.getPath());
    ICPEType icp = getChild(stringPath);
    if (icp == null) {
        switch (child.getEntryKind()) {
        case (IClasspathEntry.CPE_CONTAINER):
            icp = new CPEContainer();
            break;
        case (IClasspathEntry.CPE_LIBRARY):
            icp = new CPELibrary();
            break;
        case (IClasspathEntry.CPE_PROJECT):
            icp = new CPEProject();
            break;
        case (IClasspathEntry.CPE_SOURCE):
            icp = new CPESource();
            break;
        case (IClasspathEntry.CPE_VARIABLE):
            icp = new CPEVariable();
            break;
        default:
            throw new UnsupportedOperationException(
                    "Unsupported IClasspathEntry.getEntryKind() = '" + child.getEntryKind() + "' on " + child);
        }
        children.add(icp);
        icp.setPath(stringPath);
        icp.setParent(this.getPath());
    }

    return icp;
}

From source file:net.rim.ejde.internal.packaging.PackagingManager.java

License:Open Source License

static private void getCompileImportsRecusively(IClasspathEntry[] entries, IJavaProject jProject,
        Vector<ImportedJar> imports, boolean isMainProject) throws CoreException {
    if (imports == null) {
        imports = new Vector<ImportedJar>();
    }//from  w  w  w.  j a  va  2 s  .com
    // Workspace imports; if there aren't any specified, default to
    // using the runtime libraries.
    IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
    // String jarPathString;
    try {
        BlackBerryProperties properties = null;
        boolean needAddBBJar = false;
        IPath jarPath = null;
        ImportedJar importedJar = null;
        for (IClasspathEntry entry : entries) {
            switch (entry.getEntryKind()) {
            case IClasspathEntry.CPE_CONTAINER: {
                // libraries
                IClasspathContainer container = JavaCore.getClasspathContainer(entry.getPath(),
                        jProject.getJavaProject());
                if (container == null) {
                    continue;
                }

                IVMInstall containerVM;
                if (!(container instanceof JREContainer)) {
                    // We need to verify the type of the container because the path of Maven container only has one
                    // segment and JavaRuntime.getVMInstall(IPath) return the default VM install if the entry path has one
                    // segment.
                    containerVM = null;
                } else {
                    containerVM = JavaRuntime.getVMInstall(entry.getPath());
                }

                try {
                    if (containerVM != null) {
                        if (containerVM.getVMInstallType().getId().equals(BlackBerryVMInstallType.VM_ID)) {
                            if (isMainProject) {
                                // Add jars to a list
                                IClasspathEntry[] classpathEntries = container.getClasspathEntries();
                                if (classpathEntries != null && classpathEntries.length > 0) {
                                    getCompileImportsRecusively(classpathEntries, jProject, imports, false);
                                }
                            }
                        } else {
                            if (!jProject.getProject().hasNature(BlackBerryProjectCoreNature.NATURE_ID)) {
                                needAddBBJar = true;
                                continue;
                            }
                        }
                    } else {
                        // Add jars to a list
                        IClasspathEntry[] classpathEntries = container.getClasspathEntries();
                        if (classpathEntries != null && classpathEntries.length > 0) {
                            getCompileImportsRecusively(classpathEntries, jProject, imports, false);
                        }
                    }
                } catch (CoreException e) {
                    _log.error(e.getMessage());
                    continue;
                }
                break;
            }
            case IClasspathEntry.CPE_LIBRARY: {
                // imported jars
                jarPath = PackageUtils.getAbsoluteEntryPath(entry);
                // the jar path can be null if the jar file does not exist
                if (jarPath == null) {
                    throw new CoreException(StatusFactory.createErrorStatus(
                            NLS.bind(Messages.PackagingManager_Entry_Not_Found_MSG, entry.getPath())));
                }
                if (jarPath.lastSegment().equals(IConstants.RIM_API_JAR) && needAddBBJar) {
                    needAddBBJar = false;
                }

                importedJar = null;
                if (PackagingUtils.getPackagExportedJar()) {
                    if (entry.isExported()) {
                        if (isMainProject) {
                            // if the exported jar is not in the main project but a dependent project, the classes it
                            // contains are packaged into the dependent project jar. We don't add it to classpath.
                            importedJar = new ImportedJar(jarPath.toOSString(), true,
                                    getJarFileType(jarPath.toFile()));
                        }
                    } else {
                        importedJar = new ImportedJar(jarPath.toOSString(), false,
                                getJarFileType(jarPath.toFile()));
                    }
                } else {
                    importedJar = new ImportedJar(jarPath.toOSString(), false,
                            getJarFileType(jarPath.toFile()));
                }
                if (importedJar != null && !existingJar(imports, importedJar)) {
                    imports.add(importedJar);
                }
                break;
            }
            case IClasspathEntry.CPE_PROJECT: {
                // dependency projects
                IProject project = workspaceRoot.getProject(entry.getPath().toString());
                IJavaProject javaProject = JavaCore.create(project);
                try {
                    if (project.hasNature(BlackBerryProjectCoreNature.NATURE_ID)) {
                        properties = ContextManager.PLUGIN.getBBProperties(javaProject.getProject().getName(),
                                false);
                        if (properties == null) {
                            _log.error("BlackBerry properties is null");
                            break;
                        }
                    } else {
                        properties = BlackBerryPropertiesFactory.createBlackBerryProperties(javaProject);
                    }
                } catch (CoreException e) {
                    _log.error(e.getMessage());
                    continue;
                }
                if (PackagingManager.getProjectTypeID(properties._application.getType()) == Project.LIBRARY) {
                    IPath absoluteJarPath = PackagingUtils
                            .getAbsoluteStandardOutputFilePath(new BlackBerryProject(javaProject, properties));
                    File jarFile = new File(
                            absoluteJarPath.toOSString() + IConstants.DOT_MARK + IConstants.JAR_EXTENSION);
                    importedJar = new ImportedJar(jarFile.getAbsolutePath(), false, getJarFileType(jarFile));
                    if (!existingJar(imports, importedJar)) {
                        imports.add(importedJar);
                    }
                    IClasspathEntry[] subEntries = javaProject.getRawClasspath();
                    if (subEntries != null && subEntries.length > 0) {
                        getCompileImportsRecusively(subEntries, javaProject, imports, false);
                    }
                }
                break;
            }
            case IClasspathEntry.CPE_VARIABLE: {
                // variables
                String e = entry.getPath().toString();
                int index = e.indexOf('/');
                if (index == -1) {
                    index = e.indexOf('\\');
                }
                String variable = e;
                IPath cpvar = JavaCore.getClasspathVariable(variable);
                if (cpvar == null) {
                    String msg = NLS.bind(Messages.PackagingManager_Variable_Not_Defined_MSG, variable);
                    throw new CoreException(StatusFactory.createErrorStatus(msg));
                }
                if (cpvar.lastSegment().equals(IConstants.RIM_API_JAR) && needAddBBJar) {
                    needAddBBJar = false;
                }
                // TODO RAPC does not support a class folder. We may support it later on
                if (cpvar.lastSegment().endsWith("." + IConstants.JAR_EXTENSION)) {
                    importedJar = new ImportedJar(cpvar.toOSString(), false, getJarFileType(cpvar.toFile()));
                    if (!existingJar(imports, importedJar)) {
                        imports.add(importedJar);
                    }
                }
                break;
            }
            }
        }
        if (needAddBBJar && isMainProject) {
            // insert the default BB jre lib if needed
            IVMInstall bbVM = VMUtils.getDefaultBBVM();
            if (bbVM != null) {
                LibraryLocation[] libLocations = bbVM.getLibraryLocations();
                if (libLocations != null) {
                    for (LibraryLocation location : libLocations) {
                        importedJar = new ImportedJar(location.getSystemLibraryPath().toOSString(), false,
                                getJarFileType(location.getSystemLibraryPath().toFile()));
                        if (!existingJar(imports, importedJar)) {
                            imports.add(importedJar);
                        }
                    }
                }
            }
        }
    } catch (JavaModelException e) {
        _log.error(e.getMessage());
    }
}

From source file:net.rim.ejde.internal.util.PackageUtils.java

License:Open Source License

/**
 * Return the absolute path of the given entry.
 *
 * @param currentEntry/*www .j  a v a2s .  c  o m*/
 * @return the absolute path of the give entry. Return <code>null<code> if the entry can not be found.
 */
public static IPath getAbsolutePath(IClasspathEntry currentEntry) {
    if (currentEntry == null) {
        return null;
    }
    if (currentEntry.getEntryKind() != IClasspathEntry.CPE_LIBRARY) {
        return currentEntry.getPath();
    }
    IPath absolutePath = null;
    IPath path = currentEntry.getPath();
    Object target = JavaModel.getTarget(path, true);
    if (target instanceof IResource) {
        // if the target was found inside workspace
        IResource resource = (IResource) target;
        absolutePath = resource.getLocation();
    } else if (target instanceof File) {
        // if the target was found outside of the workspace
        absolutePath = new Path(((File) target).getAbsolutePath());
    }
    return absolutePath;
}

From source file:net.sf.eclipse.tomcat.TomcatBootstrap.java

License:Open Source License

private void getClassPathEntries(IClasspathEntry[] entries, IJavaProject prj, ArrayList data,
        List selectedPaths, ArrayList visitedProjects, IPath outputPath) {
    for (IClasspathEntry entrie : entries) {
        IClasspathEntry entry = entrie;//from www .  j  ava2  s.c om
        IPath path = entry.getPath();
        if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
            path = entry.getOutputLocation();
            if (path == null) {
                continue;
            }
        }
        if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT) {
            String prjName = entry.getPath().lastSegment();
            if (!visitedProjects.contains(prjName)) {
                visitedProjects.add(prjName);
                getClassPathEntries(prj.getJavaModel().getJavaProject(prjName), data, selectedPaths,
                        visitedProjects);
            }
            continue;
        } else if (!selectedPaths.contains(path.toFile().toString().replace('\\', '/'))) {
            if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER
                    && !entry.getPath().toString().equals("org.eclipse.jdt.launching.JRE_CONTAINER")) {

                // entires in container are only processed individually
                // if container itself is not selected

                IClasspathContainer container;
                try {
                    container = JavaCore.getClasspathContainer(path, prj);
                } catch (JavaModelException e1) {
                    TomcatLauncherPlugin.log(e1);
                    container = null;
                }

                if (container != null) {
                    getClassPathEntries(container.getClasspathEntries(), prj, data, selectedPaths,
                            visitedProjects, outputPath);
                }
            }
            continue;
        }

        IClasspathEntry[] tmpEntry = null;
        if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
            try {
                tmpEntry = JavaCore.getClasspathContainer(path, prj).getClasspathEntries();
            } catch (JavaModelException e1) {
                TomcatLauncherPlugin.log(e1);
                continue;
            }
        } else {
            tmpEntry = new IClasspathEntry[1];
            tmpEntry[0] = JavaCore.getResolvedClasspathEntry(entry);
        }

        for (IClasspathEntry element : tmpEntry) {
            if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
                IResource res = prj.getProject().getWorkspace().getRoot().findMember(element.getPath());
                if (res != null) {
                    add(data, res);
                } else {
                    add(data, element.getPath());
                }
            } else if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                IPath srcPath = entry.getOutputLocation();
                if (srcPath != null && !srcPath.equals(outputPath)) {
                    add(data, prj.getProject().getWorkspace().getRoot().findMember(srcPath));
                }
            } else {
                TomcatLauncherPlugin.log(">>> " + element);
                if (element.getPath() != null) {
                    add(data, element.getPath());
                }
            }
        }
    }
}

From source file:net.sf.eclipse.tomcat.TomcatBootstrap.java

License:Open Source License

private void collectMavenDependencies(IClasspathEntry[] entries, IJavaProject prj, List data,
        List visitedProjects) {//from  ww  w. j ava2s . c o  m
    for (int i = 0; i < entries.length; i++) {
        IClasspathEntry entry = entries[i];
        IPath path = entry.getPath();
        if ((entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER)
                && entry.getPath().toString().endsWith("MAVEN2_CLASSPATH_CONTAINER")) {
            IClasspathEntry[] tmpEntry = null;
            try {
                tmpEntry = JavaCore.getClasspathContainer(path, prj).getClasspathEntries();
            } catch (JavaModelException e1) {
                TomcatLauncherPlugin.log(e1);
                continue;
            }
            for (int j = 0; j < tmpEntry.length; j++) {
                if (tmpEntry[j].getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
                    if (tmpEntry[j].getPath().lastSegment().matches(".*servlet-api[^\\/]{0,10}\\.jar$")) {
                        continue;
                    }
                    if (tmpEntry[j].getPath().lastSegment().matches(".*jasper[^\\/]{0,10}\\.jar$")) {
                        continue;
                    }
                    if (tmpEntry[j].getPath().lastSegment().matches(".*annotations-api[^\\/]{0,10}.\\.jar$")) {
                        continue;
                    }
                    if (tmpEntry[j].getPath().lastSegment().matches(".*el-api[^\\/]{0,10}\\.jar$")) {
                        continue;
                    }
                    if (tmpEntry[j].getPath().lastSegment().matches(".*jsp-api[^\\/]{0,10}\\.jar$")) {
                        continue;
                    }
                    IResource res = prj.getProject().getWorkspace().getRoot().findMember(tmpEntry[j].getPath());
                    if (res != null) {
                        add(data, res);
                    } else {
                        add(data, tmpEntry[j].getPath());
                    }
                } else if (tmpEntry[j].getEntryKind() == IClasspathEntry.CPE_PROJECT) {
                    String prjName = tmpEntry[j].getPath().lastSegment();
                    IJavaProject subPrj = prj.getJavaModel().getJavaProject(prjName);

                    try {
                        add(data, prj.getProject().getWorkspace().getRoot()
                                .findMember(subPrj.getOutputLocation()));
                    } catch (JavaModelException e1) {
                        TomcatLauncherPlugin.log(e1);
                        continue;
                    }
                    if (!visitedProjects.contains(prjName)) {
                        visitedProjects.add(prjName);
                        collectMavenDependencies(subPrj, data, visitedProjects);
                    }
                    continue;
                } else {
                    TomcatLauncherPlugin.log(">>> " + tmpEntry[j]);
                    if (tmpEntry[j].getPath() != null) {
                        add(data, tmpEntry[j].getPath());
                    }
                }
            }
        }
    }
}