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

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

Introduction

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

Prototype

int CPE_PROJECT

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

Click Source Link

Document

Entry kind constant describing a classpath entry identifying a required project.

Usage

From source file:bz.davide.dmeclipsesavehookplugin.builder.DMEclipseSaveHookPluginBuilder.java

License:Open Source License

static void findTransitiveDepProjects(IJavaProject current, ArrayList<IProject> projects,
        ArrayList<String> fullClasspath) throws CoreException {
    if (!projects.contains(current.getProject())) {
        projects.add(current.getProject());
    }/*from  w w  w  .j a v  a 2 s .  com*/

    fullClasspath.add(ResourcesPlugin.getWorkspace().getRoot().findMember(current.getOutputLocation())
            .getLocation().toOSString() + "/");
    ArrayList<IClasspathEntry> classPaths = new ArrayList<IClasspathEntry>();
    classPaths.addAll(Arrays.asList(current.getRawClasspath()));

    for (int x = 0; x < classPaths.size(); x++) {
        IClasspathEntry cp = classPaths.get(x);
        if (cp.getEntryKind() == IClasspathEntry.CPE_PROJECT) {
            String prjName = cp.getPath().lastSegment();
            IProject prj = ResourcesPlugin.getWorkspace().getRoot().getProject(prjName);
            if (prj.hasNature(JavaCore.NATURE_ID)) {
                IJavaProject javaProject = JavaCore.create(prj);
                findTransitiveDepProjects(javaProject, projects, fullClasspath);
            }
            continue;
        }
        if (cp.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
            String fullContainerName = cp.getPath().toString();
            if (!fullContainerName.startsWith("org.eclipse.jdt.launching.JRE_CONTAINER/")) {
                System.out.println("CP C: " + fullContainerName);
                IClasspathContainer container = JavaCore.getClasspathContainer(cp.getPath(), current);
                classPaths.addAll(Arrays.asList(container.getClasspathEntries()));

            }
        }
        if (cp.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
            IPath path = cp.getPath();
            // Check first if this path is relative to workspace
            IResource workspaceMember = ResourcesPlugin.getWorkspace().getRoot().findMember(path);
            if (workspaceMember != null) {
                String fullPath = workspaceMember.getLocation().toOSString();
                fullClasspath.add(fullPath);
            } else {
                fullClasspath.add(path.toOSString());
            }
        }
    }
}

From source file:ccw.builder.ClojureBuilder.java

License:Open Source License

private static Map<IFolder, IFolder> getSrcFolders(IProject project) throws CoreException {
    Map<IFolder, IFolder> srcFolders = new HashMap<IFolder, IFolder>();

    IJavaProject jProject = JavaCore.create(project);
    IClasspathEntry[] entries = jProject.getResolvedClasspath(true);
    IPath defaultOutputFolder = jProject.getOutputLocation();
    for (IClasspathEntry entry : entries) {
        switch (entry.getEntryKind()) {
        case IClasspathEntry.CPE_SOURCE:
            IFolder folder = project.getWorkspace().getRoot().getFolder(entry.getPath());
            IFolder outputFolder = project.getWorkspace().getRoot().getFolder(
                    (entry.getOutputLocation() == null) ? defaultOutputFolder : entry.getOutputLocation());
            if (folder.exists())
                srcFolders.put(folder, outputFolder);
            break;
        case IClasspathEntry.CPE_LIBRARY:
            break;
        case IClasspathEntry.CPE_PROJECT:
            // TODO should compile here ?
            break;
        case IClasspathEntry.CPE_CONTAINER:
        case IClasspathEntry.CPE_VARIABLE:
            // Impossible cases, since entries are resolved
        default:/*from   w  w w.j a v  a2  s .c o  m*/
            break;
        }
    }
    return srcFolders;
}

From source file:com.android.ide.eclipse.adt.internal.build.BuildHelper.java

License:Open Source License

private void handleCPE(IClasspathEntry entry, IJavaProject javaProject, IWorkspaceRoot wsRoot,
        ResourceMarker resMarker) {/*  w w w.  j a va 2 s.  c o m*/

    // if this is a classpath variable reference, we resolve it.
    if (entry.getEntryKind() == IClasspathEntry.CPE_VARIABLE) {
        entry = JavaCore.getResolvedClasspathEntry(entry);
    }

    if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT) {
        IProject refProject = wsRoot.getProject(entry.getPath().lastSegment());
        try {
            // ignore if it's an Android project, or if it's not a Java Project
            if (refProject.hasNature(JavaCore.NATURE_ID)
                    && refProject.hasNature(AdtConstants.NATURE_DEFAULT) == false) {
                IJavaProject refJavaProject = JavaCore.create(refProject);

                // get the output folder
                IPath path = refJavaProject.getOutputLocation();
                IResource outputResource = wsRoot.findMember(path);
                if (outputResource != null && outputResource.getType() == IResource.FOLDER) {
                    mCompiledCodePaths.add(outputResource.getLocation().toOSString());
                }
            }
        } catch (CoreException exception) {
            // can't query the project nature? ignore
        }

    } else if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
        handleClasspathLibrary(entry, wsRoot, resMarker);
    } else if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
        // get the container
        try {
            IClasspathContainer container = JavaCore.getClasspathContainer(entry.getPath(), javaProject);
            // ignore the system and default_system types as they represent
            // libraries that are part of the runtime.
            if (container != null && container.getKind() == IClasspathContainer.K_APPLICATION) {
                IClasspathEntry[] entries = container.getClasspathEntries();
                for (IClasspathEntry cpe : entries) {
                    handleCPE(cpe, javaProject, wsRoot, resMarker);
                }
            }
        } catch (JavaModelException jme) {
            // can't resolve the container? ignore it.
            AdtPlugin.log(jme, "Failed to resolve ClasspathContainer: %s", entry.getPath());
        }
    }
}

From source file:com.android.ide.eclipse.adt.internal.project.LibraryClasspathContainerInitializer.java

License:Open Source License

/**
 * Processes a {@link IClasspathEntry} and add it to one of the list if applicable.
 * @param entry the entry to process/*from  ww w  . j a v  a  2  s .c  om*/
 * @param javaProject the {@link IJavaProject} from which this entry came.
 * @param wsRoot the {@link IWorkspaceRoot}
 * @param projects the project list to add to
 * @param jarFiles the jar list to add to
 * @param includeJarFiles whether to include jar files or just projects. This is useful when
 *           calling on an Android project (value should be <code>false</code>)
 */
private static void processCPE(IClasspathEntry entry, IJavaProject javaProject, IWorkspaceRoot wsRoot,
        Set<IProject> projects, Set<File> jarFiles, boolean includeJarFiles) {

    // if this is a classpath variable reference, we resolve it.
    if (entry.getEntryKind() == IClasspathEntry.CPE_VARIABLE) {
        entry = JavaCore.getResolvedClasspathEntry(entry);
    }

    if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT) {
        IProject refProject = wsRoot.getProject(entry.getPath().lastSegment());
        try {
            // ignore if it's an Android project, or if it's not a Java Project
            if (refProject.hasNature(JavaCore.NATURE_ID)
                    && refProject.hasNature(AdtConstants.NATURE_DEFAULT) == false) {
                // add this project to the list
                projects.add(refProject);

                // also get the dependency from this project.
                getDependencyListFromClasspath(refProject, projects, jarFiles, true /*includeJarFiles*/);
            }
        } catch (CoreException exception) {
            // can't query the project nature? ignore
        }
    } else if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
        if (includeJarFiles) {
            handleClasspathLibrary(entry, wsRoot, jarFiles);
        }
    } else if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
        // get the container and its content
        try {
            IClasspathContainer container = JavaCore.getClasspathContainer(entry.getPath(), javaProject);
            // ignore the system and default_system types as they represent
            // libraries that are part of the runtime.
            if (container != null && container.getKind() == IClasspathContainer.K_APPLICATION) {
                IClasspathEntry[] entries = container.getClasspathEntries();
                for (IClasspathEntry cpe : entries) {
                    processCPE(cpe, javaProject, wsRoot, projects, jarFiles, includeJarFiles);
                }
            }
        } catch (JavaModelException jme) {
            // can't resolve the container? ignore it.
            AdtPlugin.log(jme, "Failed to resolve ClasspathContainer: %s", entry.getPath());
        }
    }
}

From source file:com.android.ide.eclipse.adt.internal.wizards.exportgradle.ProjectSetupBuilder.java

License:Open Source License

@NonNull
private static List<IJavaProject> getReferencedProjects(IJavaProject javaProject)
        throws JavaModelException, InternalException {

    List<IJavaProject> projects = Lists.newArrayList();

    IClasspathEntry entries[] = javaProject.getRawClasspath();
    for (IClasspathEntry classpathEntry : entries) {
        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);
            } else {
                throw new InternalException(String.format(
                        "Project '%s' is missing project dependency '%s' in Eclipse workspace.\n"
                                + "Make sure all dependencies are opened.",
                        javaProject.getProject().getName(), classpathEntry.getPath().toString()));
            }/*from  w ww  .  j  a v  a2 s .  c  om*/
        }
    }

    return projects;
}

From source file:com.android.ide.eclipse.auidt.internal.build.BuildHelper.java

License:Open Source License

private void handleCPE(IClasspathEntry entry, IJavaProject javaProject, IWorkspaceRoot wsRoot,
        ResourceMarker resMarker) {/*from  w  w w  .  j a v a  2s.  c  om*/

    // if this is a classpath variable reference, we resolve it.
    if (entry.getEntryKind() == IClasspathEntry.CPE_VARIABLE) {
        entry = JavaCore.getResolvedClasspathEntry(entry);
    }

    if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT) {
        IProject refProject = wsRoot.getProject(entry.getPath().lastSegment());
        try {
            // ignore if it's an Android project, or if it's not a Java Project
            if (refProject.hasNature(JavaCore.NATURE_ID)
                    && refProject.hasNature(AdtConstants.NATURE_DEFAULT) == false) {
                IJavaProject refJavaProject = JavaCore.create(refProject);

                // get the output folder
                IPath path = refJavaProject.getOutputLocation();
                IResource outputResource = wsRoot.findMember(path);
                if (outputResource != null && outputResource.getType() == IResource.FOLDER) {
                    mCompiledCodePaths.add(outputResource.getLocation().toOSString());
                }
            }
        } catch (CoreException exception) {
            // can't query the project nature? ignore
        }

    } else if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
        handleClasspathLibrary(entry, wsRoot, resMarker);
    } else if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
        // get the container
        try {
            IClasspathContainer container = JavaCore.getClasspathContainer(entry.getPath(), javaProject);
            // ignore the system and default_system types as they represent
            // libraries that are part of the runtime.
            if (container.getKind() == IClasspathContainer.K_APPLICATION) {
                IClasspathEntry[] entries = container.getClasspathEntries();
                for (IClasspathEntry cpe : entries) {
                    handleCPE(cpe, javaProject, wsRoot, resMarker);
                }
            }
        } catch (JavaModelException jme) {
            // can't resolve the container? ignore it.
            AdtPlugin.log(jme, "Failed to resolve ClasspathContainer: %s", entry.getPath());
        }
    }
}

From source file:com.cisco.yangide.core.indexing.IndexAllProject.java

License:Open Source License

@Override
public boolean execute(IProgressMonitor progressMonitor) {
    System.err.println("[I] Project: " + project.getName());

    if (this.isCancelled || progressMonitor != null && progressMonitor.isCanceled()) {
        return true;
    }// w  w w .ja  v  a2s  .c o m

    if (!this.project.isAccessible()) {
        return true;
    }
    final HashSet<IPath> ignoredPath = new HashSet<IPath>();
    final HashSet<IPath> externalJarsPath = new HashSet<IPath>();
    try {
        JavaProject proj = (JavaProject) JavaCore.create(project);
        final HashSet<String> projectScope = new HashSet<>();
        projectScope.add(project.getName());

        if (proj != null) {
            IClasspathEntry[] classpath = proj.getResolvedClasspath();
            for (int i = 0, length = classpath.length; i < length; i++) {
                IClasspathEntry entry = classpath[i];
                IPath entryPath = entry.getPath();
                IPath output = entry.getOutputLocation();
                if (output != null && !entryPath.equals(output)) {
                    ignoredPath.add(output);
                }

                // index dependencies projects
                if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT) {
                    IProject prj = ResourcesPlugin.getWorkspace().getRoot()
                            .getProject(entry.getPath().lastSegment());
                    if (prj != null && prj.exists()) {
                        this.manager.indexAll(prj);
                        projectScope.add(prj.getName());
                    }
                }
            }
            IPackageFragmentRoot[] roots = proj.getAllPackageFragmentRoots();
            for (int i = 0, length = roots.length; i < length; i++) {
                IPath entryPath = roots[i].getPath();
                if (entryPath != null && entryPath.toFile().exists()
                        && entryPath.lastSegment().toLowerCase().endsWith(".jar")) {
                    externalJarsPath.add(entryPath);
                }
            }
            // Update project information with set of project dependencies
            YangProjectInfo yangProjectInfo = (YangProjectInfo) YangCorePlugin.create(project)
                    .getElementInfo(null);
            yangProjectInfo.setProjectScope(projectScope);
            // fill indirect scope
            HashSet<String> indirectScope = new HashSet<String>();
            indirectScope.add(project.getName());
            for (IJavaProject jproj : JavaCore.create(ResourcesPlugin.getWorkspace().getRoot())
                    .getJavaProjects()) {
                if (jproj != proj) {
                    for (String name : jproj.getRequiredProjectNames()) {
                        if (name.equals(project.getName())) {
                            indirectScope.add(jproj.getProject().getName());
                        }
                    }
                }
            }
            yangProjectInfo.setIndirectScope(indirectScope);
        }
    } catch (JavaModelException | YangModelException e) {
        // java project doesn't exist: ignore
    }

    for (IPath iPath : externalJarsPath) {
        try (JarFile jarFile = new JarFile(iPath.toFile())) {
            ZipEntry entry = jarFile.getEntry("META-INF/yang/");
            if (entry != null) {
                this.manager.addJarFile(project, iPath);
            }
        } catch (IOException e) {
            YangCorePlugin.log(e);
        }
    }
    try {
        final HashSet<IFile> indexedFiles = new HashSet<IFile>();
        project.accept(new IResourceProxyVisitor() {
            @Override
            public boolean visit(IResourceProxy proxy) {
                if (IndexAllProject.this.isCancelled) {
                    return false;
                }
                if (!ignoredPath.isEmpty() && ignoredPath.contains(proxy.requestFullPath())) {
                    return false;
                }
                if (proxy.getType() == IResource.FILE) {
                    if (CoreUtil.isYangLikeFileName(proxy.getName())) {
                        IFile file = (IFile) proxy.requestResource();
                        indexedFiles.add(file);
                    }
                    return false;
                }
                return true;
            }
        }, IResource.NONE);

        for (IFile iFile : indexedFiles) {
            this.manager.addSource(iFile);
        }
    } catch (CoreException e) {
        this.manager.removeIndexFamily(project);
        return false;
    }
    return true;
}

From source file:com.codenvy.ide.ext.java.server.internal.core.ClasspathEntry.java

License:Open Source License

/**
 * Returns the kind of a <code>PackageFragmentRoot</code> from its <code>String</code> form.
 *//*  www  . j a v  a  2s .c om*/
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:com.codenvy.ide.ext.java.server.internal.core.ClasspathEntry.java

License:Open Source License

/**
 * Returns a <code>String</code> for the kind of a class path entry.
 */// w ww  . j av a2s  . c  o  m
static String kindToString(int kind) {

    switch (kind) {
    case IClasspathEntry.CPE_PROJECT:
        return "src"; // backward compatibility //$NON-NLS-1$
    case IClasspathEntry.CPE_SOURCE:
        return "src"; //$NON-NLS-1$
    case IClasspathEntry.CPE_LIBRARY:
        return "lib"; //$NON-NLS-1$
    case IClasspathEntry.CPE_VARIABLE:
        return "var"; //$NON-NLS-1$
    case IClasspathEntry.CPE_CONTAINER:
        return "con"; //$NON-NLS-1$
    case ClasspathEntry.K_OUTPUT:
        return "output"; //$NON-NLS-1$
    default:
        return "unknown"; //$NON-NLS-1$
    }
}

From source file:com.codenvy.ide.ext.java.server.internal.core.ClasspathEntry.java

License:Open Source License

/**
 * Returns a printable representation of this classpath entry.
 *//*from   w  w  w . jav  a 2 s.  com*/
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();
}