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

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

Introduction

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

Prototype

int getContentKind();

Source Link

Document

Returns the kind of files found in the package fragments identified by this classpath entry.

Usage

From source file:org.eclipse.ant.internal.ui.datatransfer.ExportUtil.java

License:Open Source License

private static void addClasspathProjects(List<IJavaProject> projects, IClasspathEntry[] entries) {
    for (int i = 0; i < entries.length; i++) {
        IClasspathEntry classpathEntry = entries[i];
        if (classpathEntry.getContentKind() == IPackageFragmentRoot.K_SOURCE
                && classpathEntry.getEntryKind() == IClasspathEntry.CPE_PROJECT) {
            // found required project on build path
            String subProjectRoot = classpathEntry.getPath().toString();
            IJavaProject subProject = getJavaProject(subProjectRoot);
            // is project available in workspace
            if (subProject != null) {
                projects.add(subProject);
            }/*from  w  ww  .ja v a 2 s . com*/
        }
    }
}

From source file:org.eclipse.buckminster.pde.cspecgen.bundle.CSpecFromSource.java

License:Open Source License

private IPath getDefaultOutputLocation(IClasspathEntry[] classPath, IPath[] projectRootReplacement) {
    for (IClasspathEntry cpe : classPath) {
        if (cpe.getContentKind() == ClasspathEntry.K_OUTPUT)
            return asProjectRelativeFolder(cpe.getPath(), projectRootReplacement);
    }/*  w w  w  .  j av  a2 s  .  co m*/
    return null;
}

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

License:Open Source License

/**
 * Returns the root's kind - K_SOURCE or K_BINARY, defaults
 * to K_SOURCE if it is not on the classpath.
 *
 * @throws JavaModelException/*from  w  w w  .  j av  a  2  s  . c o m*/
 *         if the project and root do
 *         not exist.
 */
protected int determineKind(File underlyingResource) throws JavaModelException {
    IClasspathEntry entry = ((JavaProject) getJavaProject())
            .getClasspathEntryFor(new Path(underlyingResource.getAbsolutePath()));
    if (entry != null) {
        return entry.getContentKind();
    }
    return IPackageFragmentRoot.K_SOURCE;
}

From source file:org.eclipse.emf.codegen.ecore.gwt.GWTBuilder.java

License:Open Source License

@SuppressWarnings("rawtypes")
@Override//from w ww.j  a  v  a  2 s  .  c  o  m
protected IProject[] build(int kind, Map args, IProgressMonitor monitor) throws CoreException {
    Set<IProject> result = new HashSet<IProject>();
    final IProject project = getProject();
    if (project.exists()) {
        IWorkspaceRoot root = project.getWorkspace().getRoot();
        IJavaProject javaProject = JavaCore.create(project);
        IClasspathContainer gaeClasspathContainer = JavaCore.getClasspathContainer(
                new Path("com.google.appengine.eclipse.core.GAE_CONTAINER"), javaProject);
        if (gaeClasspathContainer != null) {
            for (IClasspathEntry classpathEntry : gaeClasspathContainer.getClasspathEntries()) {
                if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_LIBRARY
                        && classpathEntry.getContentKind() == IPackageFragmentRoot.K_BINARY) {
                    IPath path = classpathEntry.getPath();
                    int segmentCount = path.segmentCount();
                    if (segmentCount >= 4) {
                        if (path.segment(segmentCount - 2).equals("user")
                                || path.segment(segmentCount - 3).equals("user")) {
                            copy(URI.createFileURI(path.toOSString()), URI.createPlatformResourceURI(
                                    project.getName() + "/war/WEB-INF/lib/" + path.lastSegment(), true));
                        }
                    }
                }
            }
        }

        IClasspathContainer gwtClasspathContainer = JavaCore
                .getClasspathContainer(new Path("com.google.gwt.eclipse.core.GWT_CONTAINER"), javaProject);
        if (gwtClasspathContainer != null) {
            for (IClasspathEntry classpathEntry : gwtClasspathContainer.getClasspathEntries()) {
                if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_LIBRARY
                        && classpathEntry.getContentKind() == IPackageFragmentRoot.K_BINARY) {
                    IPath path = classpathEntry.getPath();
                    int segmentCount = path.segmentCount();
                    if (segmentCount >= 2) {
                        path = path.removeLastSegments(1).append("gwt-servlet.jar");
                        URI fileURI = URI.createFileURI(path.toOSString());
                        if (URIConverter.INSTANCE.exists(fileURI, null)) {
                            copy(fileURI, URI.createPlatformResourceURI(
                                    project.getName() + "/war/WEB-INF/lib/" + path.lastSegment(), true));
                        }
                    }
                }
            }
        }
        IClasspathContainer pdeClasspathContainer = JavaCore
                .getClasspathContainer(new Path("org.eclipse.pde.core.requiredPlugins"), javaProject);
        if (pdeClasspathContainer != null) {
            for (IClasspathEntry classpathEntry : pdeClasspathContainer.getClasspathEntries()) {
                if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_PROJECT) {
                    IProject requiredProject = root.getProject(classpathEntry.getPath().segment(0));
                    IJavaProject requiredJavaProject = JavaCore.create(requiredProject);
                    IPath outputLocation = requiredJavaProject.getOutputLocation();
                    final int depth = outputLocation.segmentCount();
                    IFolder folder = root.getFolder(outputLocation);
                    folder.accept(new IResourceVisitor() {
                        public boolean visit(IResource resource) throws CoreException {
                            if (resource.getType() == IResource.FILE) {
                                IPath fullPath = resource.getFullPath();
                                copy(URI.createPlatformResourceURI(fullPath.toString(), true),
                                        URI.createPlatformResourceURI(project.getName()
                                                + "/war/WEB-INF/classes/" + fullPath.removeFirstSegments(depth),
                                                true));
                            }
                            return true;
                        }
                    }, IResource.DEPTH_INFINITE, 0);
                    result.add(requiredProject);
                } else if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_LIBRARY
                        && classpathEntry.getContentKind() == IPackageFragmentRoot.K_BINARY) {
                    IPath path = classpathEntry.getPath();
                    copy(URI.createFileURI(path.toOSString()), URI.createPlatformResourceURI(
                            project.getName() + "/war/WEB-INF/lib/" + path.lastSegment(), true));
                }
            }
        }
    }
    return result.toArray(new IProject[result.size()]);
}

From source file:org.eclipse.gmt.mod.infra.common.core.internal.utils.FileUtils.java

License:Open Source License

/**
 * Whether the given workspace file is in its project's output location
 * (e.g. "bin" directory)//www  .ja  va  2 s  .co m
 */
public static boolean isInOutputLocation(final IFile file) {
    try {
        IJavaProject javaProject = JavaCore.create(file.getProject());
        if (javaProject != null) {
            if (javaProject.getOutputLocation().isPrefixOf(file.getFullPath())) {
                return true;
            }
            IClasspathEntry[] rawClasspath = javaProject.getRawClasspath();
            for (IClasspathEntry classpathEntry : rawClasspath) {
                if (classpathEntry.getContentKind() == IPackageFragmentRoot.K_SOURCE) {
                    IPath outputLocation = classpathEntry.getOutputLocation();
                    if (outputLocation != null && outputLocation.isPrefixOf(file.getFullPath())) {
                        return true;
                    }
                }
            }
        }
    } catch (JavaModelException e) {
        log.error(e.toString()); //FP
    }
    return false;
}

From source file:org.eclipse.jdt.internal.core.JavaProject.java

License:Open Source License

/**
 * Compare current classpath with given one to see if any different.
 * Note that the argument classpath contains its binary output.
 * @param newClasspath IClasspathEntry[]
 * @param newOutputLocation IPath/* www  . j  a  va 2 s  .  co m*/
 * @param otherClasspathWithOutput IClasspathEntry[]
 * @return boolean
 */
private static boolean areClasspathsEqual(IClasspathEntry[] newClasspath, IPath newOutputLocation,
        IClasspathEntry[] otherClasspathWithOutput) {

    if (otherClasspathWithOutput == null || otherClasspathWithOutput.length == 0)
        return false;

    int length = otherClasspathWithOutput.length;
    if (length != newClasspath.length + 1)
        // output is amongst file entries (last one)
        return false;

    // compare classpath entries
    for (int i = 0; i < length - 1; i++) {
        if (!otherClasspathWithOutput[i].equals(newClasspath[i]))
            return false;
    }
    // compare binary outputs
    IClasspathEntry output = otherClasspathWithOutput[length - 1];
    if (output.getContentKind() != ClasspathEntry.K_OUTPUT || !output.getPath().equals(newOutputLocation))
        return false;
    return true;
}

From source file:org.eclipse.jdt.internal.core.JavaProject.java

License:Open Source License

/**
 * Reads and decode an XML classpath string. Returns a two-dimensional array, where the number of elements in the row is fixed to 2.
 * The first element is an array of raw classpath entries and the second element is an array of referenced entries that may have been stored
 * by the client earlier. See {@link IJavaProject#getReferencedClasspathEntries()} for more details. 
 * //  ww  w. j a  v  a 2  s.c  om
 */
public IClasspathEntry[][] decodeClasspath(String xmlClasspath, Map unknownElements)
        throws IOException, ClasspathEntry.AssertionFailedException {

    ArrayList paths = new ArrayList();
    IClasspathEntry defaultOutput = null;
    StringReader reader = new StringReader(xmlClasspath);
    Element cpElement;
    try {
        DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
        cpElement = parser.parse(new InputSource(reader)).getDocumentElement();
    } catch (SAXException e) {
        throw new IOException(Messages.file_badFormat);
    } catch (ParserConfigurationException e) {
        throw new IOException(Messages.file_badFormat);
    } finally {
        reader.close();
    }

    if (!cpElement.getNodeName().equalsIgnoreCase("classpath")) { //$NON-NLS-1$
        throw new IOException(Messages.file_badFormat);
    }
    NodeList list = cpElement.getElementsByTagName(ClasspathEntry.TAG_CLASSPATHENTRY);
    int length = list.getLength();

    for (int i = 0; i < length; ++i) {
        Node node = list.item(i);
        if (node.getNodeType() == Node.ELEMENT_NODE) {
            IClasspathEntry entry = ClasspathEntry.elementDecode((Element) node, this, unknownElements);
            if (entry != null) {
                if (entry.getContentKind() == ClasspathEntry.K_OUTPUT) {
                    defaultOutput = entry; // separate output
                } else {
                    paths.add(entry);
                }
            }
        }
    }
    int pathSize = paths.size();
    IClasspathEntry[][] entries = new IClasspathEntry[2][];
    entries[0] = new IClasspathEntry[pathSize + (defaultOutput == null ? 0 : 1)];
    paths.toArray(entries[0]);
    if (defaultOutput != null)
        entries[0][pathSize] = defaultOutput; // ensure output is last item

    paths.clear();
    list = cpElement.getElementsByTagName(ClasspathEntry.TAG_REFERENCED_ENTRY);
    length = list.getLength();

    for (int i = 0; i < length; ++i) {
        Node node = list.item(i);
        if (node.getNodeType() == Node.ELEMENT_NODE) {
            IClasspathEntry entry = ClasspathEntry.elementDecode((Element) node, this, unknownElements);
            if (entry != null) {
                paths.add(entry);
            }
        }
    }
    entries[1] = new IClasspathEntry[paths.size()];
    paths.toArray(entries[1]);

    return entries;
}

From source file:org.eclipse.jdt.internal.core.JavaProject.java

License:Open Source License

/**
 * @see IJavaProject/*ww w  . j  av a 2s.  c o  m*/
 */
public IPath readOutputLocation() {
    // Read classpath file without creating markers nor logging problems
    IClasspathEntry[][] classpath = readFileEntries(null/*not interested in unknown elements*/);
    if (classpath[0] == JavaProject.INVALID_CLASSPATH)
        return defaultOutputLocation();

    // extract the output location
    IPath outputLocation = null;
    if (classpath[0].length > 0) {
        IClasspathEntry entry = classpath[0][classpath[0].length - 1];
        if (entry.getContentKind() == ClasspathEntry.K_OUTPUT) {
            outputLocation = entry.getPath();
        }
    }
    return outputLocation;
}

From source file:org.eclipse.jdt.internal.core.JavaProject.java

License:Open Source License

/**
 * @see IJavaProject//from ww w.ja v  a 2  s  .  co m
 */
public IClasspathEntry[] readRawClasspath() {
    // Read classpath file without creating markers nor logging problems
    IClasspathEntry[][] classpath = readFileEntries(null/*not interested in unknown elements*/);
    if (classpath[0] == JavaProject.INVALID_CLASSPATH)
        return defaultClasspath();

    // discard the output location
    if (classpath[0].length > 0) {
        IClasspathEntry entry = classpath[0][classpath[0].length - 1];
        if (entry.getContentKind() == ClasspathEntry.K_OUTPUT) {
            IClasspathEntry[] copy = new IClasspathEntry[classpath[0].length - 1];
            System.arraycopy(classpath[0], 0, copy, 0, copy.length);
            classpath[0] = copy;
        }
    }
    return classpath[0];
}

From source file:org.eclipse.jst.common.project.facet.core.internal.ClasspathUtil.java

License:Open Source License

private static IClasspathEntry setOwners(final IClasspathEntry cpe, final String owners) {
    final List<IClasspathAttribute> attrs = new ArrayList<IClasspathAttribute>();

    for (IClasspathAttribute attr : cpe.getExtraAttributes()) {
        if (!attr.getName().equals(OWNER_PROJECT_FACETS_ATTR)) {
            attrs.add(attr);/*from www  .j a v a2 s .  c o m*/
        }
    }

    if (owners != null) {
        attrs.add(JavaCore.newClasspathAttribute(OWNER_PROJECT_FACETS_ATTR, owners));
    }

    return new ClasspathEntry(cpe.getContentKind(), cpe.getEntryKind(), cpe.getPath(),
            cpe.getInclusionPatterns(), cpe.getExclusionPatterns(), cpe.getSourceAttachmentPath(),
            cpe.getSourceAttachmentRootPath(), cpe.getOutputLocation(), cpe.isExported(), cpe.getAccessRules(),
            cpe.combineAccessRules(), attrs.toArray(new IClasspathAttribute[attrs.size()]));
}