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:org.jboss.tools.seam.internal.core.project.facet.SeamProjectCreator.java

License:Open Source License

public static int getJreContainerIndex(final IProject proj) throws CoreException {
    final IJavaProject jproj = JavaCore.create(proj);
    final IClasspathEntry[] cp = jproj.getRawClasspath();
    for (int i = 0; i < cp.length; i++) {
        final IClasspathEntry cpe = cp[i];
        if (cpe.getEntryKind() == IClasspathEntry.CPE_CONTAINER
                && cpe.getPath().segment(0).equals(JavaRuntime.JRE_CONTAINER)) {
            return i;
        }//from w  w w .j a  v a 2  s  . c  o m
    }
    return -1;
}

From source file:org.jboss.tools.seam.internal.core.project.facet.SeamProjectCreator.java

License:Open Source License

public static IClasspathEntry getJreContainer(final IProject proj) throws CoreException {
    final IJavaProject jproj = JavaCore.create(proj);
    final IClasspathEntry[] cp = jproj.getRawClasspath();
    for (int i = 0; i < cp.length; i++) {
        final IClasspathEntry cpe = cp[i];
        if (cpe.getEntryKind() == IClasspathEntry.CPE_CONTAINER
                && cpe.getPath().segment(0).equals(JavaRuntime.JRE_CONTAINER)) {
            return cpe;
        }// ww w.  jav a  2  s .  c  o  m
    }
    return null;
}

From source file:org.jboss.tools.seam.internal.core.project.facet.WtpUtils.java

License:Open Source License

static private void insertClasspathEntry(IClasspathEntry entry, List<IClasspathEntry> entries) {
    int length = entries.size();
    IClasspathEntry[] elements = entries.toArray(new IClasspathEntry[length]);
    int i = 0;//from ww w  .  j  a  v a2s.  c om
    while (i < length && elements[i].getEntryKind() != entry.getEntryKind()) {
        i++;
    }
    if (i < length) {
        i++;
        while (i < length && elements[i].getEntryKind() == entry.getEntryKind()) {
            i++;
        }
        entries.add(i, entry);
        return;
    }

    switch (entry.getEntryKind()) {
    case IClasspathEntry.CPE_SOURCE:
        entries.add(0, entry);
        break;
    case IClasspathEntry.CPE_CONTAINER:
    case IClasspathEntry.CPE_LIBRARY:
    case IClasspathEntry.CPE_PROJECT:
    case IClasspathEntry.CPE_VARIABLE:
    default:
        entries.add(entry);
        break;
    }
}

From source file:org.jboss.tools.seam.internal.core.project.facet.WtpUtils.java

License:Open Source License

/**
 * @param project// ww  w. ja v a  2  s.c o  m
 * @param monitor
 * @throws JavaModelException
 */
public static void setClasspathEntryAsExported(final IProject project, IPath path, IProgressMonitor monitor)
        throws JavaModelException {
    IJavaProject jProject = JavaCore.create(project);
    IClasspathEntry[] cps = jProject.getRawClasspath();
    for (int i = 0; i < cps.length; i++) {
        if (cps[i].getEntryKind() == IClasspathEntry.CPE_CONTAINER && cps[i].getPath().equals(path)) {
            cps[i] = JavaCore.newContainerEntry(cps[i].getPath(), true);
        }
    }
    jProject.setRawClasspath(cps, monitor);
}

From source file:org.jboss.tools.seam.ui.wizard.SeamProjectWizard.java

License:Open Source License

public static boolean checkClassPath(IProject project) throws CoreException {
    if (project == null || !project.isAccessible() || !project.hasNature(JavaCore.NATURE_ID))
        return false;
    IJavaProject javaProject = JavaCore.create(project);
    IClasspathEntry[] es = javaProject.getRawClasspath();
    for (int i = 0; i < es.length; i++) {
        if (es[i].getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
            IPath p = es[i].getPath();/*from   w w w  . j ava2  s  .  c  o m*/
            //"org.eclipse.jst.j2ee.internal.module.container"
            if (p.toString().startsWith("org.eclipse.jst.j2ee")) {
                IClasspathContainer c = JavaCore.getClasspathContainer(p, javaProject);
                if (c == null)
                    return false;
                IClasspathEntry[] cs = c.getClasspathEntries();
                return cs != null && cs.length > 0;
            }
        }
    }
    return true;
}

From source file:org.jboss.tools.ws.jaxws.ui.project.facet.JBossWSRuntimeConfigBlock.java

License:Open Source License

protected String getDuplicateJars(String jbwsName) throws JavaModelException {
    String prjName = model.getStringProperty(IFacetDataModelProperties.FACET_PROJECT_NAME);

    if (prjName == null || "".equals(prjName)) { //$NON-NLS-1$
        return ""; //$NON-NLS-1$
    }/* ww  w  . j av  a 2  s .c  o m*/
    IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(prjName);
    if (!project.exists()) {
        return ""; //$NON-NLS-1$
    }

    List<String> allExistingJars = new ArrayList<String>();
    List<String> runtimeJars = new ArrayList<String>();

    JBossWSRuntime jbws = JBossWSRuntimeManager.getInstance().findRuntimeByName(jbwsName);
    if (jbws.isUserConfigClasspath()) {
        runtimeJars.addAll(jbws.getLibraries());
    } else {
        runtimeJars.addAll(JBossWSRuntimeManager.getInstance().getAllRuntimeJars(jbws));
    }

    IJavaProject javaProject = JavaCore.create(project);
    IClasspathEntry[] entries = javaProject.getRawClasspath();
    for (IClasspathEntry entry : entries) {
        if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
            if (JBossJAXWSUIMessages.JBossWS_Runtime_Lib.equals(entry.getPath().segment(0))) {
                continue;
            }
            IClasspathContainer container = JavaCore.getClasspathContainer(entry.getPath(), javaProject);
            for (IClasspathEntry containedEntry : container.getClasspathEntries()) {
                allExistingJars.add(containedEntry.getPath().toOSString());
            }
        } else if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
            allExistingJars.add(entry.getPath().toOSString());
        }
    }

    for (String jarName : runtimeJars) {
        if (allExistingJars.contains(jarName)) {
            return jarName;
        }
    }

    return ""; //$NON-NLS-1$

}

From source file:org.jboss.tools.ws.ui.project.facet.JBossWSRuntimeConfigBlock.java

License:Open Source License

protected String getDuplicateJars(String jbwsName) throws JavaModelException {
    String prjName = model.getStringProperty(IFacetDataModelProperties.FACET_PROJECT_NAME);

    if (prjName == null || "".equals(prjName)) { //$NON-NLS-1$
        return ""; //$NON-NLS-1$
    }//from   w  w  w .  j  av  a2  s .  c  om
    IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(prjName);
    if (!project.exists()) {
        return ""; //$NON-NLS-1$
    }

    List<String> allExistingJars = new ArrayList<String>();
    List<String> runtimeJars = new ArrayList<String>();

    JBossWSRuntime jbws = JBossWSRuntimeManager.getInstance().findRuntimeByName(jbwsName);
    if (jbws.isUserConfigClasspath()) {
        runtimeJars.addAll(jbws.getLibraries());
    } else {
        runtimeJars.addAll(JBossWSRuntimeManager.getInstance().getAllRuntimeJars(jbws));
    }

    IJavaProject javaProject = JavaCore.create(project);
    IClasspathEntry[] entries = javaProject.getRawClasspath();
    for (IClasspathEntry entry : entries) {
        if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
            if (JBossWSCoreMessages.JBossWS_Runtime_Lib.equals(entry.getPath().segment(0))) {
                continue;
            }
            IClasspathContainer container = JavaCore.getClasspathContainer(entry.getPath(), javaProject);
            for (IClasspathEntry containedEntry : container.getClasspathEntries()) {
                allExistingJars.add(containedEntry.getPath().toOSString());
            }
        } else if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
            allExistingJars.add(entry.getPath().toOSString());
        }
    }

    for (String jarName : runtimeJars) {
        if (allExistingJars.contains(jarName)) {
            return jarName;
        }
    }

    return ""; //$NON-NLS-1$

}

From source file:org.jnario.ui.buildpath.JnarioLibClasspathAdder.java

License:Open Source License

protected boolean addToClasspath(IJavaProject javaProject, IProgressMonitor monitor) throws JavaModelException {
    IClasspathEntry xtendContainerEntry = JavaCore
            .newContainerEntry(JnarioContainerInitializer.JNARIO_LIBRARY_PATH);
    IClasspathEntry[] rawClasspath = javaProject.getRawClasspath();
    IClasspathEntry[] newRawClasspath = new IClasspathEntry[rawClasspath.length + 1];
    for (int i = 0; i < rawClasspath.length; ++i) {
        IClasspathEntry entry = rawClasspath[i];
        if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER
                && entry.getPath().equals(xtendContainerEntry.getPath())) {
            return false;
        }/*from  w w w  .  j  a  v  a  2 s  . c om*/
        newRawClasspath[i + 1] = entry;
    }
    newRawClasspath[0] = xtendContainerEntry;
    javaProject.setRawClasspath(newRawClasspath, monitor);
    return true;
}

From source file:org.key_project.util.jdt.JDTUtil.java

License:Open Source License

/**
 * Returns the {@link IResource}s of the given {@link IClasspathEntry}.
 * @param javaProject The actual {@link IJavaProject} that provides the {@link IClasspathEntry}.
 * @param entry The given {@link IClasspathEntry}.
 * @param alreadyHandledProjects The already handled {@link IProject} that don't need to be analysed again.
 * @return The found {@link IResource}s.
 * @throws JavaModelException // w  ww  .j  a  v  a2s. c  om
 */
private static List<IResource> getResourceFor(IJavaProject javaProject, IClasspathEntry entry, int expectedKind,
        Set<IProject> alreadyHandledProjects) throws JavaModelException {
    if (entry != null) {
        if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER
                || entry.getEntryKind() == IClasspathEntry.CPE_SOURCE
                || entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY
                || entry.getEntryKind() == IClasspathEntry.CPE_VARIABLE) {
            List<IResource> result = new LinkedList<IResource>();
            IPackageFragmentRoot[] roots = javaProject.findPackageFragmentRoots(entry);
            for (IPackageFragmentRoot root : roots) {
                if (root.getKind() == expectedKind) {
                    if (root.getResource() != null) {
                        if (root.getResource().getLocationURI() != null) {
                            result.add(root.getResource());
                        }
                    } else if (root.getPath() != null) {
                        IResource resource = ResourcesPlugin.getWorkspace().getRoot()
                                .findMember(root.getPath());
                        if (resource != null && resource.exists()) {
                            result.add(resource);
                        }
                    }
                }
            }
            return result; // Ignore containers
        } else if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT) {
            Assert.isNotNull(entry.getPath());
            IResource project = ResourcesPlugin.getWorkspace().getRoot().findMember(entry.getPath());
            Assert.isTrue(project instanceof IProject);
            if (!alreadyHandledProjects.contains(project)) {
                return getSourceResources((IProject) project, alreadyHandledProjects);
            } else {
                return null; // Project was already analyzed, no need to do it again.
            }
        } else {
            Assert.isTrue(false, "Unknown content kind \"" + entry.getContentKind()
                    + "\" of class path entry \"" + entry + "\".");
            return null;
        }
    } else {
        return null;
    }
}

From source file:org.key_project.util.jdt.JDTUtil.java

License:Open Source License

/**
 * Returns the locations of the given {@link IClasspathEntry}.
 * @param javaProject The actual {@link IJavaProject} that provides the {@link IClasspathEntry}.
 * @param entry The given {@link IClasspathEntry}.
 * @param alreadyHandledProjects The already handled {@link IProject} that don't need to be analysed again.
 * @return The found locations./*from   www.  j av a  2  s.c o m*/
 * @throws JavaModelException 
 */
private static List<File> getLocationFor(IJavaProject javaProject, IClasspathEntry entry, int expectedKind,
        Set<IProject> alreadyHandledProjects) throws JavaModelException {
    if (entry != null) {
        if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER
                || entry.getEntryKind() == IClasspathEntry.CPE_SOURCE
                || entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY
                || entry.getEntryKind() == IClasspathEntry.CPE_VARIABLE) {
            List<File> result = new LinkedList<File>();
            IPackageFragmentRoot[] roots = javaProject.findPackageFragmentRoots(entry);
            for (IPackageFragmentRoot root : roots) {
                if (root.getKind() == expectedKind) {
                    if (root.getResource() != null) {
                        if (root.getResource().getLocationURI() != null) {
                            result.add(ResourceUtil.getLocation(root.getResource()));
                        }
                    } else if (root.getPath() != null) {
                        File location = new File(root.getPath().toString());
                        if (location.exists()) {
                            result.add(location);
                        }
                    }
                }
            }
            return result; // Ignore containers
        } else if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT) {
            Assert.isNotNull(entry.getPath());
            IResource project = ResourcesPlugin.getWorkspace().getRoot().findMember(entry.getPath());
            Assert.isTrue(project instanceof IProject);
            if (!alreadyHandledProjects.contains(project)) {
                return getSourceLocations((IProject) project, alreadyHandledProjects);
            } else {
                return null; // Project was already analyzed, no need to do it again.
            }
        } else {
            Assert.isTrue(false, "Unknown content kind \"" + entry.getContentKind()
                    + "\" of class path entry \"" + entry + "\".");
            return null;
        }
    } else {
        return null;
    }
}