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

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

Introduction

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

Prototype

int CPE_CONTAINER

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

Click Source Link

Document

Entry kind constant describing a classpath entry representing a name classpath container.

Usage

From source file:net.sf.fjep.fatjar.wizards.export.JProjectConfiguration.java

License:Open Source License

/**
 * Add all jars and class-folders referenced by jproject to jarfiles /
 * classesDirs. If exportedOnly is true, then only jars/class-folders which
 * are marked as exported will be added.
 * /*from ww w.jav a 2 s .c om*/
 * JRE_LIB (.../jre/lib/rt.jar) is ignored and not added to jarfiles
 * 
 * @param jarfiles
 * @param classesDirs
 * @param exportedOnly
 */
public void getClassPathJars(Vector jarfiles, Vector classesDirs, boolean exportedOnly) {

    IClasspathEntry[] cpes = getRawClasspathEntries();
    if (cpes != null) {
        for (int i = 0; i < cpes.length; i++) {
            IClasspathEntry cpe = JavaCore.getResolvedClasspathEntry(cpes[i]);
            if ((cpe != null) && (!exportedOnly || cpe.isExported())) {
                int kind = cpe.getEntryKind();
                String dir = relPath(cpe.getPath());
                if (kind == IClasspathEntry.CPE_CONTAINER) {
                    try {
                        IClasspathContainer container = JavaCore.getClasspathContainer(cpe.getPath(), jproject);
                        if ((container.getKind() == IClasspathContainer.K_APPLICATION)
                                || (container.getKind() == IClasspathContainer.K_SYSTEM)) {
                            IClasspathEntry[] cpes2 = container.getClasspathEntries();
                            for (int j = 0; j < cpes2.length; j++) {
                                IClasspathEntry cpe2 = cpes2[j];
                                int kind2 = cpe2.getEntryKind();
                                String dir2 = relPath(cpe2.getPath());
                                String jar2 = getAbsOrProjectPath(dir2);
                                if (jar2 == null) {
                                    System.err.println("invalid classpath entry: " + cpe2.toString());
                                } else {
                                    File f2 = new File(jar2);
                                    if (f2.isDirectory()) {
                                        if (!classesDirs.contains(jar2)) {
                                            classesDirs.add(jar2);
                                        }
                                    } else { // assume jar file
                                        if (!jarfiles.contains(jar2)) {
                                            jarfiles.add(jar2);
                                        }
                                    }
                                }
                            }
                        }
                    } catch (JavaModelException e) {
                    }
                } else if (kind == IClasspathEntry.CPE_LIBRARY) {
                    String jar = getAbsOrProjectPath(dir);
                    if (jar == null) {
                        System.err.println("invalid classpath entry: " + cpe.toString());
                    } else {

                        // ignore JRE_LIB
                        if (!jar.replace(File.separatorChar, '/').toLowerCase().endsWith("/jre/lib/rt.jar")) {
                            File f = new File(jar);
                            if (f.isDirectory()) {
                                if (!classesDirs.contains(jar)) {
                                    classesDirs.add(jar);
                                }
                            } else { // assume jar file
                                if (!jarfiles.contains(jar)) {
                                    jarfiles.add(jar);
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}

From source file:net.sf.fjep.fatjar.wizards.export.JProjectConfiguration.java

License:Open Source License

public void getChildProjects(Vector projects, boolean exportedOnly) {

    IClasspathEntry[] cpes = this.getRawClasspathEntries();
    if (cpes != null) {
        for (int i = 0; i < cpes.length; i++) {
            IClasspathEntry cpe = JavaCore.getResolvedClasspathEntry(cpes[i]);
            if (cpe == null) {
                System.err.println("Error: cpes[" + i + "]=" + cpes[i] + " does not resolve");
                continue;
            }/* w  w  w.  j  av  a2s .c o  m*/
            int kind = cpe.getEntryKind();
            String name = relPath(cpe.getPath());
            if (kind == IClasspathEntry.CPE_CONTAINER) {
                try {
                    IClasspathContainer container = JavaCore.getClasspathContainer(cpe.getPath(), jproject);
                    if ((container.getKind() == IClasspathContainer.K_APPLICATION)
                            || (container.getKind() == IClasspathContainer.K_SYSTEM)) {
                        IClasspathEntry[] cpes2 = container.getClasspathEntries();
                        for (int j = 0; j < cpes2.length; j++) {
                            IClasspathEntry cpe2 = cpes2[j];
                            int kind2 = cpe2.getEntryKind();
                            String name2 = relPath(cpe2.getPath());
                            if (name2 == null) {
                                System.err.println("invalid classpath entry: " + cpe2.toString());
                            } else {
                                if (kind2 == IClasspathEntry.CPE_PROJECT) {
                                    if (!exportedOnly || cpe2.isExported()) {
                                        if (!projects.contains(name2)) {
                                            IJavaProject jChildProject2 = jproject.getJavaModel()
                                                    .getJavaProject(name2);
                                            JProjectConfiguration jpcChild2 = new JProjectConfiguration(
                                                    jChildProject2, null);
                                            projects.add(jpcChild2);
                                            jpcChild2.getChildProjects(projects, true);
                                        }
                                    }
                                }
                            }
                        }
                    }
                } catch (JavaModelException e) {
                }
            } else if (kind == IClasspathEntry.CPE_PROJECT) {
                if (name == null) {
                    System.err.println("invalid classpath entry: " + cpe.toString());
                } else {
                    if (!exportedOnly || cpe.isExported()) {
                        if (!projects.contains(name)) {
                            IJavaProject jChildProject = jproject.getJavaModel().getJavaProject(name);
                            JProjectConfiguration jpcChild = new JProjectConfiguration(jChildProject, null);
                            projects.add(jpcChild);
                            jpcChild.getChildProjects(projects, true);
                        }
                    }
                }
            }
        }
    }
}

From source file:net.sf.jasperreports.eclipse.classpath.container.JRClasspathContainerPage.java

License:Open Source License

@Override
public void initialize(IJavaProject project, IClasspathEntry[] currentEntries) {
    jrcc = new JRClasspathContainer(null, project);
    for (int i = 0; i < currentEntries.length; i++) {
        IClasspathEntry curr = currentEntries[i];
        if (curr.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
            fUsedPaths.add(curr.getPath());
        }//from  w w w . ja  v a 2  s .c o  m
    }
}

From source file:net.sf.jasperreports.eclipse.classpath.JavaProjectClassLoader.java

License:Open Source License

private void resolveClasspathEntries(Set<URL> urls, IWorkspaceRoot root, IClasspathEntry[] entries)
        throws JavaModelException {
    for (int i = 0; i < entries.length; i++) {
        IClasspathEntry entry = entries[i];
        if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
            IPath path = entry.getPath();
            if (path.segmentCount() >= 2) {
                IFolder sourceFolder = root.getFolder(path);
                try {
                    urls.add(new URL("file:///" + sourceFolder.getRawLocation().toOSString() + "/"));
                } catch (MalformedURLException e) {
                }/*from   w w w  . j a  v a  2s.c  o  m*/
            }
        } else if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
            IPath sourcePath = entry.getPath();
            covertPathToUrl(javaProject.getProject(), urls, sourcePath);
            IPath sourceOutputPath = entry.getOutputLocation();
            covertPathToUrl(javaProject.getProject(), urls, sourceOutputPath);
        } else if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
            if (entry.getPath().equals(JRClasspathContainer.ID))
                continue;
            IClasspathContainer cont = JavaCore.getClasspathContainer(entry.getPath(), javaProject);
            resolveClasspathEntries(urls, root, cont.getClasspathEntries());
        }
    }
}

From source file:org.apache.derby.ui.popup.actions.RemoveDerbyNature.java

License:Apache License

public void run(IAction action) {
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    try {//w w  w.  j  ava  2s  .c o m
        ((ApplicationWindow) window).setStatus(Messages.REMOVING_NATURE);

        if (currentJavaProject == null) {
            currentJavaProject = JavaCore.create(currentProject);
        }
        //Shutdown server if running for the current project
        if (DerbyServerUtils.getDefault().getRunning(currentJavaProject.getProject())) {
            DerbyServerUtils.getDefault().stopDerbyServer(currentJavaProject.getProject());
        }
        IClasspathEntry[] rawClasspath = currentJavaProject.getRawClasspath();

        List<IClasspathEntry> newEntries = new ArrayList<IClasspathEntry>();
        for (IClasspathEntry e : rawClasspath) {
            if (e.getEntryKind() != IClasspathEntry.CPE_CONTAINER) {
                newEntries.add(e);
            } else if (!e.getPath().equals(DerbyClasspathContainer.CONTAINER_ID)) {
                newEntries.add(e);
            }
        }

        IClasspathEntry[] newEntriesArray = new IClasspathEntry[newEntries.size()];
        newEntriesArray = (IClasspathEntry[]) newEntries.toArray(newEntriesArray);
        currentJavaProject.setRawClasspath(newEntriesArray, null);

        IProjectDescription description = currentJavaProject.getProject().getDescription();
        String[] natures = description.getNatureIds();

        description.setNatureIds(removeDerbyNature(natures));
        currentJavaProject.getProject().setDescription(description, null);
        // refresh project so user sees changes
        currentJavaProject.getProject().refreshLocal(IResource.DEPTH_INFINITE, null);
        ((ApplicationWindow) window).setStatus(Messages.DERBY_NATURE_REMOVED);
    } catch (Exception e) {
        Logger.log(
                Messages.ERROR_REMOVING_NATURE + " '" + currentJavaProject.getProject().getName() + "': " + e,
                IStatus.ERROR);

        Shell shell = new Shell();
        MessageDialog.openInformation(shell, CommonNames.PLUGIN_NAME,
                Messages.ERROR_REMOVING_NATURE + ":\n" + SelectionUtil.getStatusMessages(e));
    }

}

From source file:org.apache.easyant4e.natures.EasyAntNature.java

License:Apache License

private void removeIvyClasspathContainer() {
    IJavaProject javaProject = JavaCore.create(project);
    ArrayList<IClasspathEntry> newEntries = new ArrayList<IClasspathEntry>();
    //FIXME call IvyDE command
    try {/*from   w  w w  . j  a  v  a2  s. c  o m*/
        IClasspathEntry[] entries = javaProject.getRawClasspath();
        for (int i = 0; i < entries.length; i++) {
            IClasspathEntry entry = entries[i];
            if (entry != null && entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
                IPath path = entry.getPath();
                if (IvyClasspathContainerHelper.isIvyClasspathContainer(path)) {
                    continue;
                }
            }
            newEntries.add(entry);
        }
        // TODO add progress monitor
        IClasspathEntry[] newClasspathEntries = newEntries.toArray(new IClasspathEntry[newEntries.size()]);
        javaProject.setRawClasspath(newClasspathEntries, null);
    } catch (JavaModelException e) {
        Activator.getEasyAntPlugin().log(IStatus.ERROR, "Cannot remove Ivy ClassPath container", e);
    }
}

From source file:org.apache.felix.sigil.eclipse.SigilCore.java

License:Apache License

/**
 * @param cp/*from  ww  w.  ja  v a2  s  . com*/
 * @return
 */
private static boolean isSigilOnClasspath(IClasspathEntry[] cp) {
    for (IClasspathEntry e : cp) {
        if (e.getEntryKind() == IClasspathEntry.CPE_CONTAINER
                && e.getPath().segment(0).equals(SigilCore.CLASSPATH_CONTAINER_PATH)) {
            return true;
        }
    }
    return false;
}

From source file:org.apache.felix.sigil.eclipse.ui.internal.editors.project.ClasspathSection.java

License:Apache License

private static int index(IClasspathEntry o1) {
    switch (o1.getEntryKind()) {
    case IClasspathEntry.CPE_SOURCE:
        return 0;
    case IClasspathEntry.CPE_PROJECT:
        return 1;
    case IClasspathEntry.CPE_LIBRARY:
        return 2;
    case IClasspathEntry.CPE_VARIABLE:
        return 3;
    case IClasspathEntry.CPE_CONTAINER:
        return 4;
    default://  ww w.ja  v a2  s  .  c om
        throw new IllegalStateException("Unknown classpath entry type " + o1);
    }
}

From source file:org.apache.ivyde.eclipse.cp.IvyClasspathContainerHelper.java

License:Apache License

/**
 * Search the Ivy classpath containers within the specified Java project
 * //w  w w . j  a v a  2  s.co  m
 * @param javaProject
 *            the project to search into
 * @return the Ivy classpath container if found
 */
public static List<IvyClasspathContainer> getContainers(IJavaProject javaProject) {
    List<IvyClasspathContainer> containers = new ArrayList<IvyClasspathContainer>();
    if (javaProject == null || !javaProject.exists()) {
        return containers;
    }
    try {
        IClasspathEntry[] entries = javaProject.getRawClasspath();
        for (int i = 0; i < entries.length; i++) {
            IClasspathEntry entry = entries[i];
            if (entry != null && entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
                IPath path = entry.getPath();
                if (isIvyClasspathContainer(path)) {
                    IClasspathContainer cp = JavaCore.getClasspathContainer(path, javaProject);
                    if (cp instanceof IvyClasspathContainer) {
                        containers.add((IvyClasspathContainer) cp);
                    }
                }
            }
        }
    } catch (JavaModelException e) {
        // unless there are issues with the JDT, this should never happen
        IvyPlugin.log(e);
    }
    return containers;
}

From source file:org.apache.ivyde.eclipse.cp.IvyClasspathContainerHelper.java

License:Apache License

public static List<IvyClasspathContainer> getContainersFromIvyFile(IFile ivyfile) {
    IJavaProject javaProject = JavaCore.create(ivyfile.getProject());
    List<IvyClasspathContainer> containers = new ArrayList<IvyClasspathContainer>();
    if (javaProject == null || !javaProject.exists()) {
        return containers;
    }// w w w.  j  a  v  a 2  s.  co  m
    try {
        IClasspathEntry[] entries = javaProject.getRawClasspath();
        for (int i = 0; i < entries.length; i++) {
            IClasspathEntry entry = entries[i];
            if (entry != null && entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
                IPath path = entry.getPath();
                if (isIvyClasspathContainer(path)) {
                    IClasspathContainer cp = JavaCore.getClasspathContainer(path, javaProject);
                    if (cp instanceof IvyClasspathContainerImpl) {
                        IvyClasspathContainerImpl ivycp = (IvyClasspathContainerImpl) cp;
                        if (ivycp.getConf().getIvyXmlPath()
                                .equals(ivyfile.getProjectRelativePath().toString())) {
                            containers.add(ivycp);
                        }
                    }
                }
            }
        }
    } catch (JavaModelException e) {
        // unless there are issues with the JDT, this should never happen
        IvyPlugin.log(e);
    }
    return containers;
}