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

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

Introduction

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

Prototype

int CPE_SOURCE

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

Click Source Link

Document

Entry kind constant describing a classpath entry identifying a folder containing package fragments with source code to be compiled.

Usage

From source file:org.grails.ide.eclipse.explorer.providers.GrailsNavigatorContentProvider.java

License:Open Source License

public Object[] getChildren(Object parentElement) {

    if (parentElement instanceof IProject && GrailsNature.isGrailsProject((IProject) parentElement)) {

        IProject project = (IProject) parentElement;

        Collection<GrailsProjectStructureTypes> types = GrailsProjectStructureManager.getInstance()
                .getAllTopLevelLogicalFolders().values();
        List<Object> topLevelFolders = new ArrayList<Object>();

        GrailsFolderElementFactory factory = getFolderElementFactory();
        for (GrailsProjectStructureTypes type : types) {
            ILogicalFolder element = factory.getElement(project,
                    project.getFolder(new Path(type.getFolderName())), type);
            if (element != null) {
                topLevelFolders.add(element);
            }//w  ww.j  a  v a  2  s .  c  o m
        }

        //Add a logical folder that contains the classpath containers
        topLevelFolders.add(new GrailsClasspathContainersFolder(project));

        // Now add the top level package fragment roots that are
        // non-dependency source folders
        IJavaProject javaProject = JavaCore.create(project);
        try {
            IPackageFragmentRoot[] roots = javaProject.getPackageFragmentRoots();
            if (roots != null) {
                for (IPackageFragmentRoot root : roots) {
                    if (root.getRawClasspathEntry().getEntryKind() == IClasspathEntry.CPE_SOURCE
                            && !GrailsResourceUtil.isGrailsDependencyPackageFragmentRoot(root)) {
                        topLevelFolders.add(root);
                    }
                }
            }
        } catch (JavaModelException e) {
            GrailsCoreActivator.log(e);
        }

        // Add the file folders that are reimaged
        Set<GrailsProjectStructureTypes> fileFolders = GrailsProjectStructureManager.getInstance()
                .getGrailsFileFolders();
        if (fileFolders != null) {
            for (GrailsProjectStructureTypes type : fileFolders) {
                IFolder folder = project.getFolder(new Path(type.getFolderName()));
                if (folder != null && folder.exists()) {
                    topLevelFolders.add(folder);
                }
            }
        }

        try {
            IResource[] children = project.members();
            if (children != null) {
                for (IResource resource : children) {
                    // Skip the linked folders that correspond to
                    // Grails dependency package fragment roots
                    if (!isLinkedDependencyPackageFragmentRoot(resource) && !isReimagedResource(resource)) {
                        topLevelFolders.add(resource);
                    }
                }
            }
        } catch (CoreException e) {
            GrailsCoreActivator.log(e);
        }

        return topLevelFolders.toArray();
    } else if (parentElement instanceof ILogicalFolder) {
        ILogicalFolder element = (ILogicalFolder) parentElement;
        List<?> children = element.getChildren();
        if (children != null) {
            return children.toArray();
        }
    } else if (parentElement instanceof IPackageFragmentRoot) {
        IPackageFragmentRoot root = (IPackageFragmentRoot) parentElement;
        GrailsProjectStructureTypes type = GrailsResourceUtil.getGrailsContainerType(root);
        if (type == GrailsProjectStructureTypes.CONF) {
            try {
                IJavaElement[] children = root.getChildren();
                if (children != null) {
                    List<IJavaElement> elements = new ArrayList<IJavaElement>();
                    for (IJavaElement child : children) {

                        IPackageFragment frag = (child instanceof IPackageFragment) ? (IPackageFragment) child
                                : null;

                        if (frag == null || !frag.isDefaultPackage()) {
                            elements.add(child);
                        } else {
                            IJavaElement[] defaultChildren = frag.getChildren();
                            for (IJavaElement defaultChild : defaultChildren) {
                                elements.add(defaultChild);
                            }
                        }
                    }
                    return elements.toArray();
                }
            } catch (JavaModelException e) {
                GrailsCoreActivator.log(e);
            }
        }
    }
    return null;
}

From source file:org.grails.ide.eclipse.groovy.debug.core.evaluation.GroovyJDIEvaluator.java

License:Open Source License

private void addClasspathEntries(JDIGroovyClassLoader groovyLoader, IJavaProject currentProject,
        boolean includeAll) throws JavaModelException, CoreException {
    IClasspathEntry[] entries = currentProject.getResolvedClasspath(true);
    IPath workspaceLocation = ResourcesPlugin.getWorkspace().getRoot().getLocation();
    for (int i = 0; i < entries.length; i++) {
        if (!includeAll && !entries[i].isExported()) {
            continue;
        }//from   ww  w .ja v a2s  . c  o  m
        switch (entries[i].getEntryKind()) {
        case IClasspathEntry.CPE_LIBRARY:
            try {
                groovyLoader.addURL(entries[i].getPath().toFile().toURL());
            } catch (MalformedURLException e) {
                throw new CoreException(new Status(IStatus.ERROR, GroovyDebugCoreActivator.PLUGIN_ID,
                        e.getLocalizedMessage(), e));
            }
            break;

        case IClasspathEntry.CPE_SOURCE:
            IPath outLocation = entries[i].getOutputLocation();
            if (outLocation != null) {
                // using non-default output location
                try {
                    groovyLoader.addURL(workspaceLocation.append(outLocation).toFile().toURL());
                } catch (MalformedURLException e) {
                    throw new CoreException(new Status(IStatus.ERROR, GroovyDebugCoreActivator.PLUGIN_ID,
                            e.getLocalizedMessage(), e));
                }
            }
            break;

        case IClasspathEntry.CPE_PROJECT:
            IProject otherProject = ResourcesPlugin.getWorkspace().getRoot()
                    .getProject(entries[i].getPath().lastSegment());
            if (otherProject.isAccessible()) {
                IJavaProject otherJavaProject = JavaCore.create(otherProject);
                addClasspathEntries(groovyLoader, otherJavaProject, false);
            }
            break;

        default:
            break;
        }
    }

    // now add default out location
    IPath outLocation = currentProject.getOutputLocation();
    if (outLocation != null) {
        try {
            groovyLoader.addURL(workspaceLocation.append(outLocation).toFile().toURL());
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
    }
}

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.
 * // ww  w. j a v a2  s  .c  o  m
 * @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./* www .  j av  a2 s  . co 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

protected void assertPluginSourceFolder(IProject proj, String plugin, String... pathElements)
        throws JavaModelException {
    IFolder folder = sourceFolderFor(proj, plugin, pathElements);
    assertClassPathEntry(IClasspathEntry.CPE_SOURCE, folder.getFullPath().toString(), getRawClassPath(proj));
    assertTrue("Source folder not found: " + folder, folder.exists());
}

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

License:Open Source License

protected void assertAbsentPluginSourceFolder(IProject proj, String plugin, String... pathElements)
        throws JavaModelException {
    IFolder folder = sourceFolderFor(proj, plugin, pathElements);
    assertFalse("Source folder exists but shouldn't: " + folder, folder.exists());
    assertAbsentClassPathEntry(IClasspathEntry.CPE_SOURCE, folder.getFullPath().toString(),
            getRawClassPath(proj));/*from   w  w w  .  j  av a  2  s  .  co m*/
}

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

License:Open Source License

/**
 * @param kind//from   w  w w.  j a  va  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.grails.ide.eclipse.ui.internal.filter.PackageExplorerFilter.java

License:Open Source License

@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
    if (element instanceof IPackageFragmentRoot) {
        try {//from  ww  w  .  j  a v  a2 s.c o  m
            IClasspathEntry entry = ((IPackageFragmentRoot) element).getRawClasspathEntry();
            if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                for (IClasspathAttribute attr : entry.getExtraAttributes()) {
                    if (attr.getName().equals(GrailsClasspathContainer.PLUGIN_SOURCEFOLDER_ATTRIBUTE_NAME)) {
                        return false;
                    }
                }
            }
        } catch (JavaModelException e) {
            e.printStackTrace();
        }
    }
    return true;
}

From source file:org.grails.ide.eclipse.ui.internal.utils.OpenNewResourcesCommandListener.java

License:Open Source License

public void newResource(final IResource resource) {
    if (resource instanceof IFile && resource.getName().endsWith(".groovy")
            && !resource.getName().endsWith("Tests.groovy")) {
        // Only open resource if is in any source folder
        IJavaProject jp = JdtUtils.getJavaProject(project);
        if (jp != null) {
            try {
                for (IClasspathEntry entry : jp.getRawClasspath()) {
                    if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                        if (entry.getPath() != null && entry.getPath().isPrefixOf(resource.getFullPath())) {
                            Display.getDefault().asyncExec(new Runnable() {

                                public void run() {
                                    SpringUIUtils.openInEditor((IFile) resource, -1);
                                }//  ww  w  .j a  v  a 2s. com
                            });
                            break;
                        }
                    }
                }
            } catch (JavaModelException e) {
            }
        }
    }
}