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:com.iw.plugins.spindle.core.builder.TapestryBuilder.java

License:Mozilla Public License

public static IProject[] getBuildInterestingProjects(IJavaProject jproject, IWorkspaceRoot root) {
    if (jproject == null || root == null)
        return new IProject[0];

    ArrayList projects = new ArrayList();
    try {//w  ww  . j  a  v a  2 s .c o  m
        IClasspathEntry[] entries = ((JavaProject) jproject).getExpandedClasspath();
        for (int i = 0, length = entries.length; i < length; i++) {
            IClasspathEntry entry = JavaCore.getResolvedClasspathEntry(entries[i]);
            if (entry != null) {
                IPath path = entry.getPath();
                IProject p = null;
                if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT) {
                    IProject workspaceProject = root.getProject(path.lastSegment());
                    if (workspaceProject.hasNature(JavaCore.NATURE_ID))
                        p = workspaceProject;

                }
                if (p != null && !projects.contains(p))
                    projects.add(p);

            }
        }
    } catch (CoreException e) {
        return new IProject[0];
    }
    IProject[] result = new IProject[projects.size()];
    projects.toArray(result);
    return result;
}

From source file:com.jaspersoft.studio.backward.ConsoleExecuter.java

License:Open Source License

/**
 * Get all the resolved classpath entries for a specific project. The entries 
 * with ID JRClasspathContainer.ID and JavaRuntime.JRE_CONTAINER are not resolved
 * or included in the result. At also add the source and output folder provided with the 
 * project//from   w  w  w. j a  va2  s .co m
 * 
 * @param project the project where the file to compile is contained, must be not null
 * @return a not null list of string that contains the classpath to include in the compilation project
 */
private List<String> getClasspaths(IProject project) {
    IJavaProject jprj = JavaCore.create(project);
    List<String> classpath = new ArrayList<String>();
    IWorkspaceRoot wsRoot = project.getWorkspace().getRoot();
    if (jprj != null) {
        try {
            IClasspathEntry[] entries = jprj.getRawClasspath();

            //Add the default output folder if any
            IPath defaultLocationPath = jprj.getOutputLocation();
            if (defaultLocationPath != null) {
                IFolder entryOutputFolder = wsRoot.getFolder(defaultLocationPath);
                classpath.add(entryOutputFolder.getLocation().toOSString() + File.separator);
            }

            for (IClasspathEntry en : entries) {
                if (en.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
                    String containerPath = en.getPath().toString();
                    //Don't add the eclipse runtime and the classpath extension defined in the exclusion list
                    if (!containerPath.startsWith(JavaRuntime.JRE_CONTAINER)
                            && !classpathExclusionSet.contains(containerPath)) {
                        addEntries(JavaCore.getClasspathContainer(en.getPath(), jprj).getClasspathEntries(),
                                classpath, jprj);
                    }
                } else if (en.getEntryKind() == IClasspathEntry.CPE_PROJECT) {
                    classpath.add(wsRoot.findMember(en.getPath()).getLocation().toOSString() + File.separator);
                } else if (en.getEntryKind() == IClasspathEntry.CPE_SOURCE
                        && en.getContentKind() == IPackageFragmentRoot.K_SOURCE) {
                    //check if is a source folder and if it has a custom output folder to add them also to the classpath
                    IPath entryOutputLocation = en.getOutputLocation();
                    if (entryOutputLocation != null) {
                        IFolder entryOutputFolder = wsRoot.getFolder(entryOutputLocation);
                        classpath.add(entryOutputFolder.getLocation().toOSString() + File.separator);
                    }
                } else {
                    //It is a jar check if it is internal to the workspace of external
                    IPath location = wsRoot.getFile(en.getPath()).getLocation();
                    if (location == null) {
                        //The location could not be resolved from the root of the workspace, it is external
                        classpath.add(en.getPath().toOSString());
                    } else {
                        //The location has been resolved from the root of the workspace, it is internal
                        classpath.add(location.toOSString());
                    }
                }
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
    return classpath;
}

From source file:com.jaspersoft.studio.backward.ConsoleExecuter.java

License:Open Source License

/**
 * Add an array of classpath entry to the result set. If an entry is a classpath container 
 * then it is resolved and the resulting entries are added recursively
 * //w ww  .  ja v  a 2 s.c o m
 * @param entries the entries to add
 * @param classpath the current result
 * @param jprj the current java project
 */
private void addEntries(IClasspathEntry[] entries, List<String> classpath, IJavaProject jprj) {
    IWorkspace workspace = ResourcesPlugin.getWorkspace();
    for (IClasspathEntry en : entries) {
        if (en.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
            try {
                addEntries(JavaCore.getClasspathContainer(en.getPath(), jprj).getClasspathEntries(), classpath,
                        jprj);
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        } else if (en.getEntryKind() == IClasspathEntry.CPE_PROJECT
                || en.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
            classpath.add(workspace.getRoot().findMember(en.getPath()).getLocation().toOSString()
                    + File.separator + "*"); //$NON-NLS-1$
        } else {
            classpath.add(en.getPath().toOSString());
        }
    }
}

From source file:com.javadude.dependencies.actions.DOTReportAction.java

License:Open Source License

public void run(IAction action) {
    // create DOT definition
    String NL = System.getProperty("line.separator");
    String dot = "digraph dependencies {" + NL;
    try {//from w w  w .j  a  v  a 2  s .com
        for (IProject project : ResourcesPlugin.getWorkspace().getRoot().getProjects()) {
            if (project.isOpen() && project.hasNature(JavaCore.NATURE_ID)) {
                IJavaProject javaProject = JavaCore.create(project);
                for (IClasspathEntry entry : javaProject.getRawClasspath()) {
                    if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT) {
                        dot += '\t' + fixName(project.getName()) + " -> "
                                + fixName(entry.getPath().lastSegment()) + ';' + NL;
                    }
                }
            }
        }
        dot += "}";
        try {
            FileWriter fileWriter = new FileWriter("/dependencies.dot");
            fileWriter.write(dot);
            fileWriter.close();
        } catch (IOException e) {
            DependenciesPlugin.error(111, "Error writing dot file /dependencies.dot", e);
        }
    } catch (CoreException e) {
        DependenciesPlugin.error(222, "Error determining dependencies", e);
    }
}

From source file:com.javadude.dependencies.commands.DeleteCommand.java

License:Open Source License

@Override
public void execute() {
    // delete the target dep from the project
    try {/*w  ww  . j  a  v a  2s .c  o m*/
        IClasspathEntry[] rawClasspath = getDependency().getSource().getRawClasspath();
        List<IClasspathEntry> newClasspath = new ArrayList<IClasspathEntry>();
        for (IClasspathEntry entry : rawClasspath) {
            if (entry.getEntryKind() != IClasspathEntry.CPE_PROJECT
                    || !entry.getPath().equals(getDependency().getTarget().getPath())) {
                newClasspath.add(entry);
            } else {
                setDeletedPosition(newClasspath.size());
                setDeletedEntry(entry);
            }
        }
        rawClasspath = newClasspath.toArray(new IClasspathEntry[rawClasspath.length - 1]);
        getDependency().getSource().setRawClasspath(rawClasspath, null);
    } catch (JavaModelException e) {
        throw new RuntimeException("Trouble deleting!", e);
    }
}

From source file:com.javadude.dependencies.editparts.WorkspaceRootEditPart.java

License:Open Source License

@SuppressWarnings("rawtypes")
@Override//from  www .  ja va  2  s  . c o  m
protected List getModelChildren() {
    List<String> geronimoLibs = new ArrayList<String>();

    // return the java projects
    IWorkspaceRoot root = (IWorkspaceRoot) getModel();
    List<IJavaProject> javaProjects = new ArrayList<IJavaProject>();
    Map<IPath, IJavaProject> projectFinder = new HashMap<IPath, IJavaProject>();
    for (int i = 0; i < root.getProjects().length; i++) {
        IProject project = root.getProjects()[i];
        try {
            if (project.isOpen() && project.hasNature(JavaCore.NATURE_ID)) {
                IJavaProject javaProject = JavaCore.create(project);
                javaProjects.add(javaProject);
                projectFinder.put(javaProject.getPath(), javaProject);
            }
        } catch (CoreException e) {
            DependenciesPlugin.error(142, "Could not check project nature", e);
        }
    }

    // need to make this more efficient -- should only process deltas
    // set up dependencies
    DependencyManager.clear();

    for (Iterator iter = javaProjects.iterator(); iter.hasNext();) {
        IJavaProject project = (IJavaProject) iter.next();
        try {
            IClasspathEntry[] rawClasspath = project.getRawClasspath();
            for (int i = 0; i < rawClasspath.length; i++) {
                IClasspathEntry entry = rawClasspath[i];
                if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT) {
                    IPath path = entry.getPath();
                    IJavaProject targetProject = projectFinder.get(path);
                    Dependency dependency = new Dependency(project, targetProject, entry.isExported());
                    DependencyManager.add(dependency);
                }
            }
        } catch (JavaModelException e) {
            DependenciesPlugin.error(342, "Could not get classpath", e);
        }
    }

    List<Object> results = new ArrayList<Object>(javaProjects);
    results.addAll(geronimoLibs);
    return results;
}

From source file:com.laex.j2objc.preferences.ClasspathPropertyPage.java

License:Open Source License

/**
 * Load project referenced classpaths./*from w  ww . j a v  a 2 s  .co  m*/
 */
private void loadProjectReferencedClasspaths() {
    try {
        IClasspathEntry[] refClasspath = ProjectUtil.getJavaProject(getElement()).getResolvedClasspath(true);
        for (IClasspathEntry o : refClasspath) {

            IClasspathEntry entry = JavaCore.getResolvedClasspathEntry((IClasspathEntry) o);
            String path = null;

            // We need to figure out the path for different types of
            // classpath entries.
            // the types of entries are: CPE_LIBRARY, CPE_PROJECT,
            // CPE_SOURCE, CPE_VARIABLE, CPE_CONTAINER
            switch (entry.getEntryKind()) {
            case IClasspathEntry.CPE_LIBRARY:

                // With CPE Library: some jar files could reside in system,
                // like JDK jar files
                // some jar files may reside in workspace, within other
                // project.
                // Check if the library resides in workspace project
                IResource file = ResourcesPlugin.getWorkspace().getRoot().findMember(entry.getPath());
                // null means, this library does not reside in workspace but
                // instead in the system
                if (file == null) {
                    // get the apropriate path
                    path = entry.getPath().makeAbsolute().toOSString();
                } else {
                    // if resdies in workspace, get the appropriate path
                    if (file.exists()) {
                        path = file.getLocation().makeAbsolute().toOSString();
                    }
                }

                break;

            case IClasspathEntry.CPE_PROJECT:
            case IClasspathEntry.CPE_SOURCE:
                // project and source
                IResource res = ResourcesPlugin.getWorkspace().getRoot().findMember(entry.getPath());
                if (res.exists()) {
                    path = res.getFullPath().makeAbsolute().toOSString();
                }
                break;
            }

            // some path may be folders. In that case, we have to make sure
            // we store the full absolute path to the folders
            boolean isArchive = path.endsWith("jar") || path.endsWith("zip");
            if (!isArchive) {
                IPath ipath = new Path(path);
                // We can only get a folder if the segment count is greater
                // 2 i.e. if the path has at least two segments
                if (ipath.segmentCount() >= 2) {
                    IFolder folder = ResourcesPlugin.getWorkspace().getRoot().getFolder(ipath);
                    if (folder.exists()) {
                        classpathRef.add(folder.getLocation().makeAbsolute().toOSString());
                    }
                }

                // If the segment count is 1, then it is probably a project
                if (ipath.segmentCount() == 1) {
                    IProject refPrj = ResourcesPlugin.getWorkspace().getRoot().getProject(path);
                    // if this is a project, then we assume it has a SRC
                    // folder; and therefore append SRC at the end
                    // this is required because j2objc compiler needs the
                    // path till the src folder to compile properly

                    classpathRef.add(refPrj.getLocation().append("src").makeAbsolute().toOSString());
                }

            } else {
                // add whatever archive path we get from the results
                classpathRef.add(path);
            }

        }

        checkboxTableViewer.setInput(classpathRef);
        checkboxTableViewer.refresh();

    } catch (JavaModelException e) {
        LogUtil.logException(e);
    } catch (CoreException e) {
        LogUtil.logException(e);
    }
}

From source file:com.liferay.ide.server.remote.ModuleTraverser.java

License:Open Source License

private static boolean isValid(final IClasspathEntry entry, final IClasspathAttribute attrib, boolean isWebApp,
        final IProject project) {
    int kind = entry.getEntryKind();
    boolean isClassFolder = isClassFolderEntry(entry);

    if (kind == IClasspathEntry.CPE_PROJECT || kind == IClasspathEntry.CPE_SOURCE) {
        return false;
    }/*  ww w  .j  a va 2 s .c  om*/

    String runtimePath = getRuntimePath(attrib, isWebApp, isClassFolder);
    if (!isWebApp) {
        if (!runtimePath.equals("../") && !runtimePath.equals("/")) { //$NON-NLS-1$//$NON-NLS-2$
            return false;
        }
        if (isClassFolder && !runtimePath.equals("/")) { //$NON-NLS-1$
            return false;
        }
    } else {
        if (runtimePath != null && !runtimePath.equals("/WEB-INF/lib") //$NON-NLS-1$
                && !runtimePath.equals("/WEB-INF/classes") //$NON-NLS-1$
                && !runtimePath.equals("../")) { //$NON-NLS-1$
            return false;
        }
        if (isClassFolder && !runtimePath.equals("/WEB-INF/classes")) { //$NON-NLS-1$
            return false;
        }
    }
    return true;
}

From source file:com.microsoft.javapkgbuild.Tasks.java

License:MIT License

private static String getClassPathType(IClasspathEntry cp) {
    switch (cp.getEntryKind()) {
    case IClasspathEntry.CPE_CONTAINER:
        return "con";
    case IClasspathEntry.CPE_LIBRARY:
        return "lib";
    case IClasspathEntry.CPE_PROJECT:
        return "proj";
    case IClasspathEntry.CPE_SOURCE:
        return "src";
    case IClasspathEntry.CPE_VARIABLE:
        return "var";
    default:/*from  w ww .  ja  v  a  2 s  .c o m*/
        return "unexpected";
    }
}

From source file:com.redhat.ceylon.eclipse.code.preferences.CeylonBuildPathsBlock.java

License:Open Source License

private int getPageIndex(int entryKind) {
    switch (entryKind) {
    case IClasspathEntry.CPE_CONTAINER:
    case IClasspathEntry.CPE_LIBRARY:
    case IClasspathEntry.CPE_VARIABLE:
        return 2;
    case IClasspathEntry.CPE_PROJECT:
        return 1;
    case IClasspathEntry.CPE_SOURCE:
        return 0;
    }/*from   w  ww .  ja va  2  s .c o m*/
    return 0;
}