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.grails.ide.eclipse.commands.test.GrailsCommandUtilTest.java

License:Open Source License

private void checkProjectBasics() throws CoreException, JavaModelException {
    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());
    }//from w w  w .ja  va 2 s .c  o m

    //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
    assertDefaultPluginSourceFolders(project);

    assertCharset(project);
}

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

License:Open Source License

/**
 * This test isn't actually testing stuff from {@link GrailsCommandUtils}, but it is in here because
 * it uses some similar checks that a project is properly setup after doing a "raw" import of project
 * created outside eclipse using grails commands.
 * <p>/*  w w w.  j a va2  s .  co m*/
 * A "raw" import means simply pulling in a project from files from somewhere outside eclipse and doing 
 * nothing more than adding them as a new project to the workspace. As of Grails 1.3.5 this should produce
 * a correctly configured grails project (grails 1.3.5 produces correct .project etc. files). So there
 * should be no need to call 'eclipsify' on such projects.
 */
public void testImportExistingProject() throws Throwable {
    GrailsProjectVersionFixer.globalAskToConvertToGrailsProjectAnswer = true;
    System.out.println(">>>>>>>>>>>>>>>>>>>testImportExistingProject");
    GroovyCompilerVersionCheck.testMode();
    ensureDefaultGrailsVersion(GrailsVersion.V_1_3_5); // GrailsVersion of test project!
    StsTestUtil.setAutoBuilding(true);
    System.out.println("Waiting for autobuild...");
    StsTestUtil.waitForAutoBuild();
    System.out.println("Done autobuild");

    URL bareBonesURL = this.getClass().getClassLoader().getResource("external-project.zip");

    String projectName = "External";
    // Create bare bones project from zip file
    IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();

    IPath unzipLoc = workspaceRoot.getLocation();
    ZipFileUtil.unzip(bareBonesURL, unzipLoc.toFile(), new NullProgressMonitor());

    project = workspaceRoot.getProject(projectName);
    project.create(null);

    if (!project.isOpen()) {
        project.open(null);
    }

    assertTrue(project.isAccessible());
    assertTrue(project.getFolder("grails-app").exists());

    /////////////////////////////////////////////////////////////////////////////////////////////////
    //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

    final IJavaProject javaProject = JavaCore.create(project);

    //Next we check the classpath related stuff. 
    // The classpath may not be right initially... but should eventually become correct as a background
    // refresh dependency job should get scheduled. 
    // ACondition
    new ACondition() {
        @Override
        public boolean test() throws Exception {
            System.out.println("Checking project config...");
            assertEquals("/" + project.getName() + "/target-eclipse/classes",
                    javaProject.getOutputLocation().toString());

            ///////////////////////////////////
            // Check resolved classpath stuff
            IClasspathEntry[] classPath = javaProject.getResolvedClasspath(false);

            // A whole bunch of libraries should be there, check for just a few of those

            // this one will fail on macs
            //            assertClassPathEntry(IClasspathEntry.CPE_LIBRARY, "jre/lib/rt.jar", classPath);
            assertClassPathEntry(IClasspathEntry.CPE_LIBRARY, "grails-core", classPath);
            assertClassPathEntry(IClasspathEntry.CPE_LIBRARY, "grails-bootstrap", classPath);
            assertClassPathEntry(IClasspathEntry.CPE_LIBRARY, "groovy-all", classPath);
            //assertClassPathEntry(IClasspathEntry.CPE_LIBRARY, "servlet-api", classPath);

            //            System.out.println(">>>Resolved classpath");
            //            for (IClasspathEntry entry : classPath) {
            //               System.out.println(kindString(entry.getEntryKind())+": "+entry.getPath());
            //            }
            //            System.out.println("<<<Resolved classpath");

            ///////////////////////////////////
            // Check raw classpath stuff
            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
            assertDefaultPluginSourceFolders(project);

            assertCharset(project);

            System.out.println("Checking project config => OK!");
            return true;
        }
    }.waitFor(60000);

    System.out.println("<<<<<<<<<<<<<<<<<<<<<<<<testImportExistingProject");
}

From source file:org.grails.ide.eclipse.core.internal.classpath.GrailsClasspathContainer.java

License:Open Source License

public static boolean isGrailsClasspathContainer(IClasspathEntry entry) {
    if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
        return entry.getPath().equals(CLASSPATH_CONTAINER_PATH);
    }//from   ww  w .  j  a  va  2  s  . com
    return false;
}

From source file:org.grails.ide.eclipse.explorer.elements.GrailsClasspathContainersFolder.java

License:Open Source License

public List<Object> getChildren() {
    //TODO: cache?
    IJavaProject javaProject = JavaCore.create(parent);
    try {/* ww w .  j a  va  2s  . c om*/
        IClasspathEntry[] classpath = javaProject.getRawClasspath();
        List<Object> children = new ArrayList<Object>();
        for (IClasspathEntry e : classpath) {
            if (e.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
                children.add(new ClassPathContainer(javaProject, e));
            }
        }
        return children;
    } catch (JavaModelException e) {
        GrailsCoreActivator.log(e);
    }
    return null;
}

From source file:org.grails.ide.eclipse.refactoring.test.GrailsRefactoringTest.java

License:Open Source License

/**
 * Checks a bunch of stuff about the imported test project.
 * //from   w ww  .j  a  va2  s . c  om
 * @throws Throwable
 */
protected void checkImportedProject() throws Exception {

    //Check project config, like classpath related stuff. 
    // The config may not be right initially... but should eventually become correct as a background
    // refresh dependency job should get scheduled. 
    // ACondition
    new ACondition() {
        @Override
        public boolean test() throws Exception {
            assertJobManagerIdle(); //Wait for jobs... like Refresh dependencies to all complete.
            System.out.println("Checking project config...");
            IJavaProject javaProject = JavaCore.create(project);

            assertDefaultOutputFolder(javaProject);
            assertTrue(project.hasNature(JavaCore.NATURE_ID)); // Should have Java Nature at this point
            assertTrue(GroovyNature.hasGroovyNature(project)); // Should also have Groovy nature
            assertTrue(GrailsNature.isGrailsAppProject(project)); // Should look like a Grails app to grails tooling

            ///////////////////////////////////
            // Check resolved classpath stuff
            IClasspathEntry[] classPath = javaProject.getResolvedClasspath(false);

            // A whole bunch of libraries should be there, check for just a few of those

            assertClassPathEntry(IClasspathEntry.CPE_LIBRARY, "/jsse.jar", classPath);
            assertClassPathEntry(IClasspathEntry.CPE_LIBRARY, "grails-core", classPath);
            assertClassPathEntry(IClasspathEntry.CPE_LIBRARY, "grails-bootstrap", classPath);
            assertClassPathEntry(IClasspathEntry.CPE_LIBRARY, "groovy-all", classPath);
            //               assertClassPathEntry(IClasspathEntry.CPE_LIBRARY, "servlet-api", classPath);

            //            System.out.println(">>>Resolved classpath");
            //            for (IClasspathEntry entry : classPath) {
            //               System.out.println(kindString(entry.getEntryKind())+": "+entry.getPath());
            //            }
            //            System.out.println("<<<Resolved classpath");

            ///////////////////////////////////
            // Check raw classpath stuff
            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
            assertDefaultPluginSourceFolders(project);

            System.out.println("Checking project config => OK!");
            return true;
        }

    }.waitFor(4 * 60000);
}

From source file:org.grails.ide.eclipse.test.GrailsProjectVersionFixerTest.java

License:Open Source License

/**
 * Checks a bunch of stuff about the "very old test project" once it has
 * been imported in the workspace.//from  w w  w.  jav a 2s. c  o m
 * 
 * @throws Throwable
 */
private void checkImportedProject() throws Exception {

    // Check project config, like classpath related stuff.
    // The config may not be right initially... but should eventually become
    // correct as a background
    // refresh dependency job should get scheduled.
    // ACondition
    new ACondition("check importe project: " + project.getName()) {
        @Override
        public boolean test() throws Exception {
            System.out.println("Checking project config...");
            IJavaProject javaProject = JavaCore.create(project);

            assertDefaultOutputFolder(javaProject);
            assertTrue(project.hasNature(JavaCore.NATURE_ID)); // Should
            // have Java
            // Nature at
            // this
            // point
            assertTrue(GroovyNature.hasGroovyNature(project)); // Should
            // also have
            // Groovy
            // nature
            assertTrue(GrailsNature.isGrailsAppProject(project)); // Should
            // look
            // like
            // a
            // Grails
            // app
            // to
            // grails
            // tooling

            // /////////////////////////////////
            // Check resolved classpath stuff
            IClasspathEntry[] classPath = javaProject.getResolvedClasspath(false);

            // A whole bunch of libraries should be there, check for just a
            // few of those

            assertClassPathEntry(IClasspathEntry.CPE_LIBRARY, "/jsse.jar", classPath);
            assertClassPathEntry(IClasspathEntry.CPE_LIBRARY, "grails-core", classPath);
            assertClassPathEntry(IClasspathEntry.CPE_LIBRARY, "grails-bootstrap", classPath);
            assertClassPathEntry(IClasspathEntry.CPE_LIBRARY, "groovy-all", classPath);
            // assertClassPathEntry(IClasspathEntry.CPE_LIBRARY,
            // "servlet-api", classPath);

            // System.out.println(">>>Resolved classpath");
            // for (IClasspathEntry entry : classPath) {
            // System.out.println(kindString(entry.getEntryKind())+": "+entry.getPath());
            // }
            // System.out.println("<<<Resolved classpath");

            // /////////////////////////////////
            // Check raw classpath stuff
            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
            assertDefaultPluginSourceFolders(project);

            System.out.println("Checking project config => OK!");
            return true;
        }

    }.waitFor(10 * 60000);
}

From source file:org.grails.ide.eclipse.test.util.GrailsTest.java

License:Open Source License

/**
 * Verify that an expected classPath entry with given kind and path exists in the classpath.
 *//*from w w  w .j a  va  2 s  .c om*/
protected void assertClassPathEntry(int kind, String path, IClasspathEntry[] classPath) {
    StringBuffer found = new StringBuffer();
    for (IClasspathEntry entry : classPath) {
        found.append(kindString(entry.getEntryKind()) + ": " + entry.getPath() + "\n");
        if (entry.getEntryKind() == kind) {
            if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
                if (entry.getPath().equals(Path.EMPTY.append(path))) {
                    return; //OK
                }
            } else if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
                // Library paths will vary a lot in location and version numbers, so use an 'approximate' 
                // check to see if it contains some key string.
                if (entry.getPath().toString().contains(path)) {
                    return; //OK
                }
            } else {
                if (entry.getPath().toString().endsWith(path)) {
                    return; //OK
                }
            }
        }
    }
    fail("No classpath entry found for: " + kindString(kind) + ": " + path + "\n" + "found entries are: \n"
            + found.toString());
}

From source file:org.grails.ide.eclipse.test.util.GrailsTest.java

License:Open Source License

/**
 * Verify that an expected classPath entry with given kind and path exists in the classpath.
 *///from www.  j  a  va 2s  .c o  m
protected void assertAbsentClassPathEntry(int kind, String path, IClasspathEntry[] classPath) {
    for (IClasspathEntry entry : classPath) {
        if (entry.getEntryKind() == kind) {
            if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
                if (entry.getPath().equals(Path.EMPTY.append(path))) {
                    fail("Class path entry should not be there: " + entry);
                }
            } else if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
                // Library paths will vary a lot in location and version numbers, so use an 'approximate' 
                // check to see if it contains some key string.
                if (entry.getPath().toString().contains(path)) {
                    fail("Class path entry should not be there: " + entry);
                }
            } else {
                if (entry.getPath().toString().endsWith(path)) {
                    fail("Class path entry should not be there: " + entry);
                }
            }
        }
    }
    // OK
}

From source file:org.grails.ide.eclipse.test.util.GrailsTest.java

License:Open Source License

/**
 * @param kind/*from  ww  w  .j a  v a 2  s.  co m*/
 * @return
 */
protected String kindString(int kind) {
    switch (kind) {
    case IClasspathEntry.CPE_SOURCE:
        return "src";
    case IClasspathEntry.CPE_CONTAINER:
        return "con";
    case IClasspathEntry.CPE_LIBRARY:
        return "lib";
    default:
        return "" + kind;
    }
}

From source file:org.granite.builder.util.ProjectUtil.java

License:Open Source License

public static List<CpEntry> getFullClasspath(IJavaProject project, IClasspathEntry[] classpathEntries)
        throws CoreException {
    List<CpEntry> classpath = new ArrayList<CpEntry>();

    IWorkspaceRoot workspace = project.getProject().getWorkspace().getRoot();
    IPath path = null;//ww w .jav a2s  . co m
    try {

        // Output locations.
        if (project.getOutputLocation() != null) {
            path = project.getOutputLocation();
            File file = workspace.findMember(path).getLocation().toFile();
            classpath.add(new CpEntry(path.makeRelative().toString(), path, file,
                    CpEntry.CpeKind.PROJECT_OUTPUT_DIR));
        }
        for (IClasspathEntry cpe : classpathEntries) {
            if (cpe.getEntryKind() == IClasspathEntry.CPE_SOURCE && cpe.getOutputLocation() != null) {
                path = cpe.getOutputLocation();
                File file = workspace.findMember(path).getLocation().toFile();
                classpath.add(new CpEntry(path.makeRelative().toString(), path, file,
                        CpEntry.CpeKind.SOURCE_OUTPUT_DIR));
            }
        }

        // Project jars.
        for (IClasspathEntry cpe : classpathEntries) {
            if (cpe.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
                path = cpe.getPath();
                if (path != null) {
                    IResource member = workspace.findMember(path);
                    String description = path.lastSegment();
                    if (path.segmentCount() > 1)
                        description += " - " + path.removeLastSegments(1).makeRelative();
                    if (member != null)
                        classpath.add(new CpEntry(description, path, member.getLocation().toFile(),
                                CpEntry.CpeKind.LIB_JAR));
                    else
                        classpath.add(new CpEntry(description, path, path.toFile(), CpEntry.CpeKind.LIB_JAR));
                }
            }
        }

        // Containers jars/directories.
        for (IClasspathEntry cpe : classpathEntries) {
            if (cpe.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
                path = cpe.getPath();
                IClasspathContainer container = JavaCore.getClasspathContainer(path, project);
                String description = container.getDescription();
                CpEntry entry = new CpEntry(description, path, (path != null ? path.toFile() : null),
                        CpEntry.CpeKind.CONTAINER_JAR);

                for (IClasspathEntry ccpe : container.getClasspathEntries()) {
                    path = ccpe.getPath();
                    String label = path.lastSegment();
                    if (path.segmentCount() > 1)
                        label += " - " + path.removeLastSegments(1).makeRelative();

                    File file = path.toFile();
                    IResource resource = workspace.findMember(path);
                    if (resource != null)
                        file = resource.getLocation().toFile();

                    entry.getChildren().add(new CpEntry(label, path, file, CpEntry.CpeKind.LIB_JAR));
                }

                classpath.add(entry);
            }
        }

    } catch (Exception e) {
        String msg = "Problem with classpath location: " + path;
        throw new CoreException(createErrorStatus(msg, e));
    }

    return classpath;
}