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:org.jboss.tools.arquillian.core.internal.builder.ArquillianBuilder.java

License:Open Source License

private IProject[] getRequiredProjects(boolean includeBinaryPrerequisites) {
    JavaProject javaProject = (JavaProject) JavaCore.create(this.currentProject);
    IWorkspaceRoot workspaceRoot = this.currentProject.getWorkspace().getRoot();
    if (javaProject == null || workspaceRoot == null)
        return NO_PROJECTS;

    ArrayList projects = new ArrayList();
    ExternalFoldersManager externalFoldersManager = JavaModelManager.getExternalManager();
    try {/*from www. j  a va 2 s  .  c o m*/
        IClasspathEntry[] entries = javaProject.getExpandedClasspath();
        for (int i = 0, l = entries.length; i < l; i++) {
            IClasspathEntry entry = entries[i];
            IPath path = entry.getPath();
            IProject p = null;
            switch (entry.getEntryKind()) {
            case IClasspathEntry.CPE_PROJECT:
                p = workspaceRoot.getProject(path.lastSegment()); // missing projects are considered too
                if (((ClasspathEntry) entry).isOptional() && !JavaProject.hasJavaNature(p)) // except if entry is optional
                    p = null;
                break;
            case IClasspathEntry.CPE_LIBRARY:
                if (includeBinaryPrerequisites && path.segmentCount() > 0) {
                    // some binary resources on the class path can come from projects that are not included in the project references
                    IResource resource = workspaceRoot.findMember(path.segment(0));
                    if (resource instanceof IProject) {
                        p = (IProject) resource;
                    } else {
                        resource = externalFoldersManager.getFolder(path);
                        if (resource != null)
                            p = resource.getProject();
                    }
                }
            }
            if (p != null && !projects.contains(p))
                projects.add(p);
        }
    } catch (JavaModelException e) {
        return NO_PROJECTS;
    }
    IProject[] result = new IProject[projects.size()];
    projects.toArray(result);
    return result;
}

From source file:org.jboss.tools.arquillian.core.internal.classpath.ArquillianClassLoader.java

License:Open Source License

private static Set<URL> getURLSet(IJavaProject jProject) {
    Set<URL> urls = new HashSet<URL>();
    Set<IJavaProject> dependentProjects = new HashSet<IJavaProject>();
    if (jProject == null) {
        return urls;
    }// ww w . j a v  a  2 s .  c  om
    try {
        IClasspathEntry[] entries = jProject.getRawClasspath();

        for (int i = 0; i < entries.length; i++) {
            IClasspathEntry entry = entries[i];
            if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                addSource(jProject, urls, entry);
            } else if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
                IClasspathEntry resLib = JavaCore.getResolvedClasspathEntry(entry);
                addLibrary(urls, resLib);
            } else if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT) {
                addProject(urls, entry, dependentProjects);
            } else if (entry.getEntryKind() == IClasspathEntry.CPE_VARIABLE) {
                IClasspathEntry resLib = JavaCore.getResolvedClasspathEntry(entry);
                addLibrary(urls, resLib);
            } else if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
                if (!entry.getPath().segment(0).toString().endsWith("JRE_CONTAINER")) { //$NON-NLS-1$
                    addContainer(jProject, urls, entry, dependentProjects);
                }
            }
        }

    } catch (Exception e) {
        ArquillianCoreActivator.log(e);
    }

    return urls;
}

From source file:org.jboss.tools.arquillian.core.internal.classpath.ArquillianClassLoader.java

License:Open Source License

private static void addContainer(IJavaProject jProject, Set<URL> urls, IClasspathEntry entry,
        Set<IJavaProject> dependentProjects) throws JavaModelException, MalformedURLException {
    IClasspathEntry[] resLibs = JavaCore.getClasspathContainer(entry.getPath(), jProject).getClasspathEntries();
    for (int i = 0; i < resLibs.length; i++) {
        if (resLibs[i] == null) {
            continue;
        }//from  w  w  w.j ava 2s .c  o  m
        if (resLibs[i].getEntryKind() == IClasspathEntry.CPE_PROJECT) {
            addProject(urls, resLibs[i], dependentProjects);
        } else if (resLibs[i].getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
            addContainer(jProject, urls, resLibs[i], dependentProjects);
        } else if (resLibs[i].getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
            addLibrary(urls, resLibs[i]);
        } else if (resLibs[i].getEntryKind() == IClasspathEntry.CPE_SOURCE) {
            addSource(jProject, urls, resLibs[i]);
        }
    }
}

From source file:org.jboss.tools.arquillian.core.internal.compiler.ArquillianNameEnvironment.java

License:Open Source License

private void computeClasspathLocations(IWorkspaceRoot root, JavaProject javaProject,
        SimpleLookupTable binaryLocationsPerProject) throws CoreException {

    /* Update cycle marker */
    IMarker cycleMarker = javaProject.getCycleMarker();
    if (cycleMarker != null) {
        int severity = JavaCore.ERROR.equals(javaProject.getOption(JavaCore.CORE_CIRCULAR_CLASSPATH, true))
                ? IMarker.SEVERITY_ERROR
                : IMarker.SEVERITY_WARNING;
        if (severity != cycleMarker.getAttribute(IMarker.SEVERITY, severity))
            cycleMarker.setAttribute(IMarker.SEVERITY, severity);
    }/*from w w  w  .  j  a v a  2  s  . c om*/

    IClasspathEntry[] classpathEntries = javaProject.getExpandedClasspath();
    ArrayList sLocations = new ArrayList(classpathEntries.length);
    ArrayList bLocations = new ArrayList(classpathEntries.length);
    nextEntry: for (int i = 0, l = classpathEntries.length; i < l; i++) {
        ClasspathEntry entry = (ClasspathEntry) classpathEntries[i];
        IPath path = entry.getPath();
        Object target = JavaModel.getTarget(path, true);
        if (target == null)
            continue nextEntry;

        switch (entry.getEntryKind()) {
        case IClasspathEntry.CPE_SOURCE:
            if (!(target instanceof IContainer))
                continue nextEntry;
            IPath outputPath = entry.getOutputLocation() != null ? entry.getOutputLocation()
                    : javaProject.getOutputLocation();
            IContainer outputFolder;
            if (outputPath.segmentCount() == 1) {
                outputFolder = javaProject.getProject();
            } else {
                outputFolder = root.getFolder(outputPath);
                if (!outputFolder.exists())
                    createOutputFolder(outputFolder);
            }
            sLocations.add(ClasspathLocation.forSourceFolder((IContainer) target, outputFolder,
                    entry.fullInclusionPatternChars(), entry.fullExclusionPatternChars()));
            continue nextEntry;

        case IClasspathEntry.CPE_PROJECT:
            if (!(target instanceof IProject))
                continue nextEntry;
            IProject prereqProject = (IProject) target;
            if (!JavaProject.hasJavaNature(prereqProject))
                continue nextEntry; // if project doesn't have java nature or is not accessible

            JavaProject prereqJavaProject = (JavaProject) JavaCore.create(prereqProject);
            IClasspathEntry[] prereqClasspathEntries = prereqJavaProject.getRawClasspath();
            ArrayList seen = new ArrayList();
            nextPrereqEntry: for (int j = 0, m = prereqClasspathEntries.length; j < m; j++) {
                IClasspathEntry prereqEntry = prereqClasspathEntries[j];
                if (prereqEntry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                    Object prereqTarget = JavaModel.getTarget(prereqEntry.getPath(), true);
                    if (!(prereqTarget instanceof IContainer))
                        continue nextPrereqEntry;
                    IPath prereqOutputPath = prereqEntry.getOutputLocation() != null
                            ? prereqEntry.getOutputLocation()
                            : prereqJavaProject.getOutputLocation();
                    IContainer binaryFolder = prereqOutputPath.segmentCount() == 1 ? (IContainer) prereqProject
                            : (IContainer) root.getFolder(prereqOutputPath);
                    if (binaryFolder.exists() && !seen.contains(binaryFolder)) {
                        seen.add(binaryFolder);
                        ClasspathLocation bLocation = ClasspathLocation.forBinaryFolder(binaryFolder, true,
                                entry.getAccessRuleSet());
                        bLocations.add(bLocation);
                        if (binaryLocationsPerProject != null) { // normal builder mode
                            ClasspathLocation[] existingLocations = (ClasspathLocation[]) binaryLocationsPerProject
                                    .get(prereqProject);
                            if (existingLocations == null) {
                                existingLocations = new ClasspathLocation[] { bLocation };
                            } else {
                                int size = existingLocations.length;
                                System.arraycopy(existingLocations, 0,
                                        existingLocations = new ClasspathLocation[size + 1], 0, size);
                                existingLocations[size] = bLocation;
                            }
                            binaryLocationsPerProject.put(prereqProject, existingLocations);
                        }
                    }
                }
            }
            continue nextEntry;

        case IClasspathEntry.CPE_LIBRARY:
            if (target instanceof IResource) {
                IResource resource = (IResource) target;
                ClasspathLocation bLocation = null;
                if (resource instanceof IFile) {
                    AccessRuleSet accessRuleSet = (JavaCore.IGNORE
                            .equals(javaProject.getOption(JavaCore.COMPILER_PB_FORBIDDEN_REFERENCE, true))
                            && JavaCore.IGNORE.equals(
                                    javaProject.getOption(JavaCore.COMPILER_PB_DISCOURAGED_REFERENCE, true)))
                                            ? null
                                            : entry.getAccessRuleSet();
                    bLocation = ClasspathLocation.forLibrary((IFile) resource, accessRuleSet);
                } else if (resource instanceof IContainer) {
                    AccessRuleSet accessRuleSet = (JavaCore.IGNORE
                            .equals(javaProject.getOption(JavaCore.COMPILER_PB_FORBIDDEN_REFERENCE, true))
                            && JavaCore.IGNORE.equals(
                                    javaProject.getOption(JavaCore.COMPILER_PB_DISCOURAGED_REFERENCE, true)))
                                            ? null
                                            : entry.getAccessRuleSet();
                    bLocation = ClasspathLocation.forBinaryFolder((IContainer) target, false, accessRuleSet); // is library folder not output folder
                }
                bLocations.add(bLocation);
                if (binaryLocationsPerProject != null) { // normal builder mode
                    IProject p = resource.getProject(); // can be the project being built
                    ClasspathLocation[] existingLocations = (ClasspathLocation[]) binaryLocationsPerProject
                            .get(p);
                    if (existingLocations == null) {
                        existingLocations = new ClasspathLocation[] { bLocation };
                    } else {
                        int size = existingLocations.length;
                        System.arraycopy(existingLocations, 0,
                                existingLocations = new ClasspathLocation[size + 1], 0, size);
                        existingLocations[size] = bLocation;
                    }
                    binaryLocationsPerProject.put(p, existingLocations);
                }
            } else if (target instanceof File) {

                AccessRuleSet accessRuleSet = (JavaCore.IGNORE
                        .equals(javaProject.getOption(JavaCore.COMPILER_PB_FORBIDDEN_REFERENCE, true))
                        && JavaCore.IGNORE.equals(
                                javaProject.getOption(JavaCore.COMPILER_PB_DISCOURAGED_REFERENCE, true))) ? null
                                        : entry.getAccessRuleSet();
                bLocations.add(ClasspathLocation.forLibrary(path.toString(), accessRuleSet));
            }
            continue nextEntry;
        }
    }

    // now split the classpath locations... place the output folders ahead of the other .class file folders & jars
    ArrayList outputFolders = new ArrayList(1);
    this.sourceLocations = new ClasspathMultiDirectory[sLocations.size()];
    if (!sLocations.isEmpty()) {
        sLocations.toArray(this.sourceLocations);

        // collect the output folders, skipping duplicates
        next: for (int i = 0, l = this.sourceLocations.length; i < l; i++) {
            ClasspathMultiDirectory md = this.sourceLocations[i];
            IPath outputPath = md.binaryFolder.getFullPath();
            for (int j = 0; j < i; j++) { // compare against previously walked source folders
                if (outputPath.equals(this.sourceLocations[j].binaryFolder.getFullPath())) {
                    md.hasIndependentOutputFolder = this.sourceLocations[j].hasIndependentOutputFolder;
                    continue next;
                }
            }
            outputFolders.add(md);

            // also tag each source folder whose output folder is an independent folder & is not also a source folder
            for (int j = 0, m = this.sourceLocations.length; j < m; j++)
                if (outputPath.equals(this.sourceLocations[j].sourceFolder.getFullPath()))
                    continue next;
            md.hasIndependentOutputFolder = true;
        }
    }

    // combine the output folders with the binary folders & jars... place the output folders before other .class file folders & jars
    //        this.binaryLocations = new ClasspathLocation[outputFolders.size() + bLocations.size()];
    //        int index = 0;
    //        for (int i = 0, l = outputFolders.size(); i < l; i++)
    //            this.binaryLocations[index++] = (ClasspathLocation) outputFolders.get(i);
    //        for (int i = 0, l = bLocations.size(); i < l; i++)
    //            this.binaryLocations[index++] = (ClasspathLocation) bLocations.get(i);

    this.binaryLocations = new ClasspathLocation[bLocations.size()];
    int index = 0;
    //        for (int i = 0, l = outputFolders.size(); i < l; i++)
    //            this.binaryLocations[index++] = (ClasspathLocation) outputFolders.get(i);
    for (int i = 0, l = bLocations.size(); i < l; i++)
        this.binaryLocations[index++] = (ClasspathLocation) bLocations.get(i);

    this.baseBinaryLocations = new ClasspathLocation[binaryLocations.length];
    System.arraycopy(binaryLocations, 0, baseBinaryLocations, 0, binaryLocations.length);
    this.baseSourceLocations = new ClasspathMultiDirectory[sourceLocations.length];
    System.arraycopy(sourceLocations, 0, baseSourceLocations, 0, sourceLocations.length);

}

From source file:org.jboss.tools.batch.internal.core.scanner.lib.ClassPathMonitor.java

License:Open Source License

public static List<IBatchProject> getProjects(IProject project) throws CoreException {
    List<IBatchProject> list = new ArrayList<IBatchProject>();
    IJavaProject javaProject = EclipseUtil.getJavaProject(project);
    if (javaProject != null) {
        IClasspathEntry[] es = javaProject.getResolvedClasspath(true);
        for (int i = 0; i < es.length; i++) {
            if (es[i].getEntryKind() == IClasspathEntry.CPE_PROJECT) {
                IProject p = ResourcesPlugin.getWorkspace().getRoot().getProject(es[i].getPath().lastSegment());
                if (p == null || !p.isAccessible())
                    continue;
                IBatchProject sp = BatchProjectFactory.getBatchProject(p, false);
                if (sp != null)
                    list.add(sp);/* w w  w .  j a  v  a 2 s.c  o  m*/
            }
        }
    }
    return list;
}

From source file:org.jboss.tools.batch.internal.core.scanner.lib.Libs.java

License:Open Source License

private void updateProjects() throws JavaModelException {
    Set<String> result = new HashSet<String>();
    IJavaProject javaProject = EclipseUtil.getJavaProject(getProjectResource());
    if (javaProject != null) {
        result.add(getProjectResource().getName());
        IClasspathEntry[] es = javaProject.getResolvedClasspath(true);
        for (int i = 0; i < es.length; i++) {
            if (es[i].getEntryKind() == IClasspathEntry.CPE_PROJECT) {
                IProject p = ResourcesPlugin.getWorkspace().getRoot().getProject(es[i].getPath().lastSegment());
                if (p == null || !p.isAccessible())
                    continue;
                result.add(p.getName());
            }/*w  w w  .  j a va 2  s.com*/
        }
    }
    projects = result;
}

From source file:org.jboss.tools.cdi.internal.core.scanner.lib.ClassPathMonitor.java

License:Open Source License

public static List<CDICoreNature> getProjects(IProject project) throws CoreException {
    List<CDICoreNature> list = new ArrayList<CDICoreNature>();
    IJavaProject javaProject = EclipseResourceUtil.getJavaProject(project);
    if (javaProject != null) {
        IClasspathEntry[] es = javaProject.getResolvedClasspath(true);
        for (int i = 0; i < es.length; i++) {
            if (es[i].getEntryKind() == IClasspathEntry.CPE_PROJECT) {
                IProject p = ResourcesPlugin.getWorkspace().getRoot().getProject(es[i].getPath().lastSegment());
                if (p == null || !p.isAccessible())
                    continue;
                CDICoreNature sp = CDICorePlugin.getCDI(p, false);
                if (sp != null)
                    list.add(sp);//from   www. j  a  v  a  2  s .c o  m
            }
        }
    }
    return list;
}

From source file:org.jboss.tools.common.jdt.core.buildpath.MaterializeLibraryJob.java

License:Open Source License

private LinkedHashSet<IClasspathEntry> copyClasspathEntries(IProgressMonitor monitor, final IPath rootPath)
        throws CoreException, JavaModelException {

    int jarSize = jars.size();

    monitor.beginTask(Messages.Materialize_Library, jarSize);

    if (libFolder instanceof IFolder) {
        mkdirs((IFolder) libFolder, monitor);
    }/*from   w  ww  .j  a  v  a 2  s  . c o m*/

    IPath destination = libFolder.getLocation();

    LinkedHashSet<IClasspathEntry> newCpes = new LinkedHashSet<IClasspathEntry>(jarSize);

    IClasspathEntry[] cpEntries = containerToRemove.getClasspathEntries();

    for (IClasspathEntry entry : cpEntries) {
        if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {

            IPath sourceFilePath = entry.getPath();
            String fileName = jars.get(sourceFilePath);
            if (fileName == null) {
                // Jar was not selected
                continue;
            }

            monitor.subTask(fileName);
            IPath destinationFilePath = destination.append(fileName);
            try {
                if ((javaProject.findPackageFragmentRoot(destinationFilePath) == null)// Not already defined
                        && copy(sourceFilePath, destinationFilePath)) {
                    // TODO handle duplicate files -> rename?
                    // FIXME use absolute / relative paths depending on the
                    // location of the destination folder (in project /
                    // elsewhere in the workspace)
                    // FIXME need a more elegant way to get a relative path
                    // with a leading /
                    IPath relativePath = new Path("/").append(libFolder.getFullPath()).append(fileName); //$NON-NLS-1$
                    IClasspathEntry newEntry = getNewClasspathEntry(entry, relativePath);
                    newCpes.add(newEntry);
                }
            } catch (IOException e) {
                IStatus status = new Status(IStatus.ERROR, JDTExtActivator.PLUGIN_ID,
                        NLS.bind(Messages.MaterializeLibraryJob_error_copying_file, fileName), e);
                throw new CoreException(status);
            }
        } else if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT) {
            newCpes.add(entry);
        }
    }
    return newCpes;
}

From source file:org.jboss.tools.common.jdt.ui.buildpath.dialog.MaterializeLibraryDialog.java

License:Open Source License

private void initClasspathEntryPaths() {
    IClasspathEntry[] cpEntries = containerToMaterialize.getClasspathEntries();
    classpathEntryPaths = new LinkedHashMap<IClasspathEntry, String>(cpEntries.length);
    for (IClasspathEntry entry : cpEntries) {
        if ((entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY && entry.getPath() != null)
                || (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT)) {
            IPath sourceFilePath = entry.getPath();
            String fileName = sourceFilePath.lastSegment();
            classpathEntryPaths.put(entry, fileName);
        }/*from  w  w  w .ja  v a 2  s.  c o m*/
    }
}

From source file:org.jboss.tools.common.model.filesystems.impl.Libs.java

License:Open Source License

private void updateProjects() throws JavaModelException {
    Set<String> result = new HashSet<String>();
    IJavaProject javaProject = EclipseResourceUtil.getJavaProject(getProjectResource());
    if (javaProject != null) {
        result.add(getProjectResource().getName());
        IClasspathEntry[] es = javaProject.getResolvedClasspath(true);
        for (int i = 0; i < es.length; i++) {
            if (es[i].getEntryKind() == IClasspathEntry.CPE_PROJECT) {
                IProject p = ResourcesPlugin.getWorkspace().getRoot().getProject(es[i].getPath().lastSegment());
                if (p == null || !p.isAccessible())
                    continue;
                result.add(p.getName());
            }//  ww  w. j  av  a 2s .c o m
        }
    }
    projects = result;
}