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.eclipse.xtext.ui.util.JREContainerProvider.java

License:Open Source License

public static IClasspathEntry getJREContainerEntry(IJavaProject javaProject) throws JavaModelException {
    IClasspathEntry defaultJREContainerEntry = getDefaultJREContainerEntry();

    IClasspathEntry[] rawClasspath = javaProject.getRawClasspath();
    for (IClasspathEntry classpathEntry : rawClasspath) {
        int entryKind = classpathEntry.getEntryKind();
        if (entryKind == IClasspathEntry.CPE_CONTAINER
                && defaultJREContainerEntry.getPath().isPrefixOf(classpathEntry.getPath())) {
            return classpathEntry;
        }// www . ja  v  a2s  .  c  o m
    }
    return null;
}

From source file:org.eclipseguru.gwt.core.classpath.GwtClasspathUtil.java

License:Open Source License

private static boolean isContainerEntry(final IClasspathEntry entry, final String containerId) {
    return (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) && (entry.getPath().segmentCount() > 0)
            && containerId.equals(entry.getPath().segment(0));
}

From source file:org.eclipseguru.gwt.core.runtimes.GwtRuntimeManager.java

License:Open Source License

private static void rebindClasspathEntries() throws CoreException {
    final IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
    final IJavaProject[] projects = JavaCore.create(root).getJavaProjects();
    final IPath containerPath = new Path(GwtCore.GWT_CONTAINER);

    final List<IJavaProject> affectedProjects = new ArrayList<IJavaProject>();
    final List<IClasspathContainer> newContainers = new ArrayList<IClasspathContainer>();

    for (final IJavaProject project : projects) {
        final IClasspathEntry[] entries = project.getRawClasspath();
        for (final IClasspathEntry curr : entries) {
            if (curr.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
                final IPath currPath = curr.getPath();
                if (containerPath.isPrefixOf(currPath)) {
                    affectedProjects.add(project);
                    GwtContainer container = null;
                    if (currPath.segmentCount() > 1) {
                        final GwtRuntime runtime = findInstalledRuntime(currPath.segment(1));
                        if ((null != runtime) && !runtime.getLocation().isEmpty()) {
                            container = new GwtContainer(runtime, containerPath);
                        }/*from w  ww. ja  v  a 2s . c  o m*/
                    }
                    newContainers.add(container);
                    break;
                }
            }
        }
    }
    if (!affectedProjects.isEmpty()) {
        final IJavaProject[] affected = affectedProjects.toArray(new IJavaProject[affectedProjects.size()]);
        final IClasspathContainer[] containers = newContainers
                .toArray(new IClasspathContainer[newContainers.size()]);
        JavaCore.setClasspathContainer(containerPath, affected, containers, null);

    }
}

From source file:org.eclipselabs.spray.xtext.ui.wizard.SprayPluginProjectFactory.java

License:Open Source License

@Override
protected void addMoreClasspathEntriesTo(List<IClasspathEntry> classpathEntries) {
    super.addMoreClasspathEntriesTo(classpathEntries);
    int index = -1;
    for (IClasspathEntry entry : classpathEntries) {
        if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER && entry.getPath() != null
                && entry.getPath().toString().contains("JRE_CONTAINER")) {
            index = classpathEntries.indexOf(entry);
        }/* w w w  .ja  v a  2 s.  c  om*/
    }
    if (index >= 0) {
        classpathEntries.remove(index);
        classpathEntries.add(index, JavaCore.newContainerEntry(new Path(
                "org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"))); //$NON-NLS-1$
    }
}

From source file:org.entirej.ide.core.project.EJPluginEntireJClassLoader.java

License:Apache License

private static void processEntry(IJavaProject javaProject, List<URL> urlList, IClasspathEntry entry,
        boolean ignoreSource) throws MalformedURLException {
    // This source output ... always included & exported
    if (!ignoreSource && entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
        IPath outputLocation = entry.getOutputLocation();

        if (outputLocation != null) {
            URL url = new URL("file", null, outputLocation.toString() + "/");
            urlList.add(url);/*from   w  w w . jav a2s.  c  o  m*/
        }
    }

    // Referenced project classpath. If this project is exported,
    // Then all *exported* entries are exported with respect to this
    // project,
    else if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT) {
        IProject ijproject = ResourcesPlugin.getWorkspace().getRoot().getProject(entry.getPath().segment(0));
        IJavaProject ref = JavaCore.create(ijproject);
        Collection<URL> cpEntries = getClasspathEntries(ref, false);
        urlList.addAll(cpEntries);
    }

    // This is the Directories classpath
    else if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
        IPath entryPath = entry.getPath();
        URL url = new URL("file", null, entryPath.toString());
        IResource res = ResourcesPlugin.getWorkspace().getRoot().findMember(entryPath);

        if (res != null && res.exists()) {
            url = new URL("file", null, res.getLocation().toString());
        }
        urlList.add(url);
    }
    // This is Library classpath
    else if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
        IPath entryPath = entry.getPath();
        URL url = new URL("file", null, entryPath.toString());

        IResource res = ResourcesPlugin.getWorkspace().getRoot().findMember(entryPath);
        if (res != null && res.exists()) {
            url = new URL("file", null, res.getLocation().toString());
        }
        urlList.add(url);
    }
    // This is Variables classpath
    else if (entry.getEntryKind() == IClasspathEntry.CPE_VARIABLE) {
        String variableName = entry.getPath().segment(0);
        IPath variablePath = JavaCore.getClasspathVariable(variableName);
        if (variablePath != null) {
            URL url = new URL("file", null, variablePath.toString());
            urlList.add(url);
        }
    }
}

From source file:org.evosuite.eclipse.popup.actions.TestGenerationAction.java

License:Open Source License

/**
 * If we generate JUnit tests, we need to make sure that JUnit is on the
 * classpath of the project, otherwise we will see compile errors
 * // w w w.  ja  v a 2s.co  m
 * @param project
 */
public void fixJUnitClassPath(IJavaProject project) {
    IPath junitPath = JUnitCore.JUNIT4_CONTAINER_PATH;

    boolean hasJUnit = false;
    boolean hasEvoSuite = false;
    boolean hasOldEvoSuite = false;

    try {
        Path containerPath = new Path("org.evosuite.eclipse.classpathContainerInitializer");
        IClasspathContainer container = JavaCore.getClasspathContainer(containerPath, project);
        System.out.println("EvoSuite JAR at: " + container.getPath().toOSString());

        IClasspathEntry[] oldEntries = project.getRawClasspath();
        ArrayList<IClasspathEntry> newEntries = new ArrayList<IClasspathEntry>(oldEntries.length + 1);

        IClasspathEntry cpentry = JavaCore.newContainerEntry(junitPath);

        for (int i = 0; i < oldEntries.length; i++) {
            IClasspathEntry curr = oldEntries[i];

            // Check if JUnit is already in the build path
            if (curr.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
                IPath path = curr.getPath();
                if (path.equals(cpentry.getPath())) {
                    hasJUnit = true;
                }
                if (path.equals(container.getPath())) {
                    hasEvoSuite = true;
                }
            } else if (curr.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
                // Check for older EvoSuite entries
                IPath path = curr.getPath();
                if (path.toFile().getName().equals(Activator.EVOSUITE_JAR)) {
                    if (path.equals(container.getPath())) {
                        System.out.println("Is current evosuite!");
                        hasEvoSuite = true;
                    } else {
                        System.out.println("Is NOT current evosuite!");
                        hasOldEvoSuite = true;
                        continue;
                    }
                }
                if (path.equals(cpentry.getPath())) {
                    hasJUnit = true;
                }
                if (path.equals(container.getPath())) {
                    hasEvoSuite = true;
                }
            }

            if (curr != null) {
                newEntries.add(curr);
            }
        }

        if (hasJUnit && hasEvoSuite && !hasOldEvoSuite) {
            return;
        }

        // add the entry
        if (!hasJUnit) {
            newEntries.add(cpentry);
        }

        if (!hasEvoSuite && container != null) {
            for (IClasspathEntry entry : container.getClasspathEntries()) {
                newEntries.add(entry);
            }
        }

        System.out.println("New classpath: " + newEntries);

        // newEntries.add(JavaCore.newContainerEntry(EvoSuiteClasspathContainer.ID));

        // Convert newEntries to an array
        IClasspathEntry[] newCPEntries = newEntries.toArray(new IClasspathEntry[newEntries.size()]);
        project.setRawClasspath(newCPEntries, null);
    } catch (JavaModelException e) {
        e.printStackTrace();
    }

}

From source file:org.evosuite.eclipse.popup.actions.TestGenerationJob.java

License:Open Source License

private String buildProjectCP() throws JavaModelException {
    IJavaProject jProject = JavaCore.create(target.getProject());
    IClasspathEntry[] oldEntries = jProject.getRawClasspath();
    String classPath = "";
    boolean first = true;

    for (int i = 0; i < oldEntries.length; i++) {
        IClasspathEntry curr = oldEntries[i];
        System.out.println("Current entry: " + curr.getPath());

        if (curr.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
            IPath path = curr.getPath();
            if (path.toFile().getName().startsWith("evosuite")) {
                System.out.println("Skipping evosuite.jar");
                continue;
            }//from  w  w w.j av a 2 s .c  o m
            if (!first)
                classPath += File.pathSeparator;
            else
                first = false;

            if (path.toFile().exists()) {
                classPath += path.toOSString();
                System.out.println("Adding CPE_LIBRARY to classpath: " + path.toOSString());
            } else {
                classPath += target.getWorkspace().getRoot().getLocation().toOSString() + path.toOSString();
                System.out.println("Adding CPE_LIBRARY to classpath: "
                        + target.getWorkspace().getRoot().getLocation().toOSString() + path.toOSString());
            }
        } else if (curr.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
            if (curr.isExported()) {
                if (curr.toString().equals("org.eclipse.jdt.launching.JRE_CONTAINER")) {
                    System.out.println("Found JRE container");
                } else if (curr.toString().startsWith("org.eclipse.jdt.junit.JUNIT_CONTAINER")) {
                    System.out.println("Found JUnit container");
                } else {
                    System.out.println("Found unknown container: " + curr);
                }
            } else {
                System.out.println("Container not exported: " + curr);
            }
        } else if (curr.getEntryKind() == IClasspathEntry.CPE_PROJECT) {
            // Add binary dirs of this project to classpath
            System.out.println("Don't handle CPE_PROJECT yet");
        } else if (curr.getEntryKind() == IClasspathEntry.CPE_VARIABLE) {
            System.out.println("Path: " + curr.getPath());
            System.out.println("Resolved Path: " + JavaCore.getResolvedVariablePath(curr.getPath()));
            if (!first)
                classPath += File.pathSeparator;
            else
                first = false;

            classPath += JavaCore.getResolvedVariablePath(curr.getPath());
        } else if (curr.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
            System.out.println("Don't handle CPE_SOURCE yet");
        } else {
            System.out.println("CP type: " + curr.getEntryKind());
        }
    }
    ResourceList.resetAllCaches();
    if (!first)
        classPath += File.pathSeparator;

    classPath += target.getWorkspace().getRoot().findMember(jProject.getOutputLocation()).getLocation()
            .toOSString();
    return classPath;
}

From source file:org.fusesource.tools.core.Classpath.java

License:Open Source License

public Collection<IPath> getContainers() {
    Collection<IPath> names = new ArrayList<IPath>();
    Collection<IClasspathEntry> entries = getEntries(IClasspathEntry.CPE_CONTAINER);
    for (IClasspathEntry entry : entries) {
        try {//w  w  w. ja  v a 2 s .  com
            IClasspathContainer c = JavaCore.getClasspathContainer(entry.getPath(), jp);
            if (c.getKind() != IClasspathContainer.K_DEFAULT_SYSTEM) {
                names.add(entry.getPath());
            }
        } catch (JavaModelException e) {
            System.out.println(e.getMessage());
        }
    }
    return names;
}

From source file:org.fusesource.tools.core.Classpath.java

License:Open Source License

protected IClasspathContainer getContainer(IPath containerPath) {
    Collection<IClasspathEntry> entries = getEntries(IClasspathEntry.CPE_CONTAINER);
    for (IClasspathEntry entry : entries) {
        try {//from  w  w w. j  a  v  a 2 s  . c  o m
            if (containerPath.equals(entry.getPath())) {
                IClasspathContainer c = JavaCore.getClasspathContainer(entry.getPath(), jp);
                return c;
            }
        } catch (JavaModelException e) {
            System.out.println(e.getMessage());
        }
    }
    return null;

}

From source file:org.grails.ide.eclipse.commands.test.GrailsCommandUtilTest.java

License:Open Source License

/**
 * Test to see if we can use the "eclipsifyProject" method to "eclipsify" a very bare-bones
 * imported grails project that is missing just about *everything* in the way of configuration files.
 * <p>/*from   w w  w .j  a  v  a 2  s  .c om*/
 * This bare bones project is created by deleting all Eclipse related stuff and the target directory
 * from a grails project and then importing this into eclipse as a "general" project. Thus it has the
 * minimum, of configuration to make it a valid Eclipse project but nothing more.
 */
public void testEclipsifyBareBonesProject() throws Exception {
    GrailsVersion version = GrailsVersion.MOST_RECENT;
    if (GrailsVersion.MOST_RECENT.isSnapshot()) {
        //Don't run this for snapshot builds. Too much work to create test projects for moving target.
        return;
    }
    ensureDefaultGrailsVersion(version); // The version of the BareBones project
    URL bareBonesURL = getProjectZip("bareBonesProject", version);

    // Create bare bones project from zip file
    IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
    project = workspaceRoot.getProject("testProject");
    IPath unzipLoc = workspaceRoot.getLocation();
    ZipFileUtil.unzip(bareBonesURL, unzipLoc.toFile(), new NullProgressMonitor());
    project.create(new NullProgressMonitor());
    assertTrue(project.exists());
    project.open(new NullProgressMonitor());
    project.refreshLocal(IResource.DEPTH_INFINITE, null);
    assertTrue(project.isAccessible());
    assertTrue(project.isAccessible());
    assertTrue(project.getFolder("grails-app").exists());

    GrailsCommandUtils.eclipsifyProject(project);

    /////////////////////////////////////////////////////////////////////////////////////////////////
    //Check a few things about this test project

    assertTrue(project.hasNature(JavaCore.NATURE_ID)); // Should have Java Nature at this point
    assertTrue(GroovyNature.hasGroovyNature(project)); // Should also have Groovy nature

    IJavaProject javaProject = JavaCore.create(project);

    assertDefaultOutputFolder(javaProject);

    IClasspathEntry[] classPath = javaProject.getRawClasspath();
    for (IClasspathEntry classpathEntry : classPath) {
        System.out.println(kindString(classpathEntry.getEntryKind()) + ": " + classpathEntry.getPath());
    }

    //The usual source folders:
    assertClassPathEntry(IClasspathEntry.CPE_SOURCE, "src/java", classPath);
    assertClassPathEntry(IClasspathEntry.CPE_SOURCE, "src/groovy", classPath);
    assertClassPathEntry(IClasspathEntry.CPE_SOURCE, "grails-app/conf", classPath);
    assertClassPathEntry(IClasspathEntry.CPE_SOURCE, "grails-app/controllers", classPath);
    assertClassPathEntry(IClasspathEntry.CPE_SOURCE, "grails-app/domain", classPath);
    assertClassPathEntry(IClasspathEntry.CPE_SOURCE, "grails-app/services", classPath);
    assertClassPathEntry(IClasspathEntry.CPE_SOURCE, "grails-app/taglib", classPath);
    assertClassPathEntry(IClasspathEntry.CPE_SOURCE, "test/integration", classPath);
    assertClassPathEntry(IClasspathEntry.CPE_SOURCE, "test/unit", classPath);

    //The classpath containers for Java and Grails
    assertClassPathEntry(IClasspathEntry.CPE_CONTAINER, "org.eclipse.jdt.launching.JRE_CONTAINER", classPath);
    assertClassPathEntry(IClasspathEntry.CPE_CONTAINER, "org.grails.ide.eclipse.core.CLASSPATH_CONTAINER",
            classPath);

    //Installed plugins source folders
    assertBareBonesProjectUserPluginSourceFolders(version);
    assertDefaultPluginSourceFolders(project);

    assertCharset(project);
}