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

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

Introduction

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

Prototype

int getEntryKind();

Source Link

Document

Returns the kind of this classpath entry.

Usage

From source file:com.google.gdt.eclipse.managedapis.impl.ManagedApiProjectImpl.java

License:Open Source License

public static String getAndroidSdk(IProject androidProject) throws JavaModelException {
    if (androidProject == null) {
        return null;
    }// www.  j  ava2  s  . co  m
    IJavaProject androidJavaProject = JavaCore.create(androidProject);
    List<IClasspathEntry> rawClasspathList = new ArrayList<IClasspathEntry>();
    rawClasspathList.addAll(Arrays.asList(androidJavaProject.getRawClasspath()));
    for (IClasspathEntry e : rawClasspathList) {
        if (e.getEntryKind() != IClasspathEntry.CPE_CONTAINER) {
            continue;
        }
        IClasspathContainer c = JavaCore.getClasspathContainer(e.getPath(), androidJavaProject);
        if (c.getDescription().contains(ANDROID_2_CLASSPATH_CONTAINER)) {
            return ANDROID2_ENVIRONMENT;
        } else if (c.getDescription().contains(ANDROID_3_CLASSPATH_CONTAINER)
                || c.getDescription().contains(ANDROID_4_CLASSPATH_CONTAINER)) {
            return ANDROID3_ENVIRONMENT;
        }
    }
    return null;
}

From source file:com.google.gdt.eclipse.managedapis.impl.ManagedApiProjectImpl.java

License:Open Source License

public ManagedApi[] getManagedApis() {
    List<ManagedApi> installedApis = new ArrayList<ManagedApi>();
    if (eProject != null) {
        IJavaProject project = eProject.getJavaProject();
        if (project != null) {
            try {
                IClasspathEntry[] rawClasspath = project.getRawClasspath();
                for (IClasspathEntry entry : rawClasspath) {
                    if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
                        if (ManagedApiPlugin.API_CONTAINER_PATH.isPrefixOf(entry.getPath())) {
                            IClasspathContainer container = JavaCore.getClasspathContainer(entry.getPath(),
                                    project);
                            if (container instanceof ManagedApiContainer) {
                                ManagedApiContainer managedApiContainer = (ManagedApiContainer) container;
                                installedApis.add(managedApiContainer.getManagedApi());
                            }/*from  www . jav a 2s .  co  m*/
                        }
                    }
                }
            } catch (JavaModelException e) {
                ManagedApiLogger.warn(e, "Error reading classpath");
            }
        }
    }
    return installedApis.toArray(new ManagedApi[installedApis.size()]);
}

From source file:com.google.gdt.eclipse.managedapis.ui.ManagedApiContainerFilter.java

License:Open Source License

/**
 * @return false if the Java element is a file that is contained in a
 *         SimpleDirContainer that is in the classpath of the owning Java
 *         project (non-Javadoc)/*w  w w.  j a  v  a2s  .c om*/
 * 
 * @see org.eclipse.jface.viewers.ViewerFilter#select(org.eclipse.jface.viewers.Viewer,
 *      java.lang.Object, java.lang.Object)
 */
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
    if (element instanceof IResource) {
        IResource resource = (IResource) element;
        if (resource.getType() == IResource.FILE || resource.getType() == IResource.FOLDER) {
            IProject project = resource.getProject();
            try {
                if (project != null && project.exists() && NatureUtils.hasNature(project, JavaCore.NATURE_ID)) {
                    IJavaProject jp = JavaCore.create(resource.getProject());
                    // lets see if this file is included within a ManagedApiRoot
                    IClasspathEntry[] entries = jp.getRawClasspath();
                    for (IClasspathEntry entry : entries) {
                        if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
                            if (ManagedApiPlugin.API_CONTAINER_PATH.isPrefixOf(entry.getPath())) {
                                // this is likely a ManagedApiContainer, but the container
                                // could be a ghost, and thus unmapped to a
                                // ManagedApiContainer - check below
                                IClasspathContainer container = JavaCore.getClasspathContainer(entry.getPath(),
                                        jp);
                                if (container instanceof ManagedApiContainer) {
                                    ManagedApiContainer managedApiContainer = (ManagedApiContainer) container;
                                    if (managedApiContainer.contains(resource)) {
                                        // this file will is included in the container, so hide it
                                        return false;
                                    }
                                }
                            }
                        }
                    }
                }
            } catch (JavaModelException e) {
                ManagedApiLogger.warn(e, "Error reading the classpath");
            } catch (CoreException e) {
                ManagedApiLogger.warn(e, "Error accessing Java Project");
            }
        }
    }
    return true;
}

From source file:com.google.gwt.eclipse.core.GWTProjectUtilities.java

License:Open Source License

/**
 * Returns the GWT-applicable source folder paths from a project (note: this
 * will not traverse into the project's dependencies, for this behavior, see
 * {@link #getGWTSourceFolderPathsFromProjectAndDependencies(IJavaProject, boolean)}
 * )./*from  w  w w. jav a2  s. com*/
 *
 * @param javaProject Reference to the project
 * @param sourceEntries The list to be filled with the entries corresponding
 *          to the source folder paths
 * @param includeTestSourceEntries Whether to include the entries for test
 *          source
 * @throws SdkException
 */
private static void fillGWTSourceFolderPathsFromProject(IJavaProject javaProject,
        Collection<? super IRuntimeClasspathEntry> sourceEntries, boolean includeTestSourceEntries)
        throws SdkException {

    assert (javaProject != null);

    if (GWTProjectsRuntime.isGWTRuntimeProject(javaProject)) {
        // TODO: Do we still need to handle this here since Sdk's report their
        // own runtime classpath entries?
        sourceEntries.addAll(
                GWTProjectsRuntime.getGWTRuntimeProjectSourceEntries(javaProject, includeTestSourceEntries));
    } else {
        try {
            for (IClasspathEntry curClasspathEntry : javaProject.getRawClasspath()) {
                if (curClasspathEntry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                    IPath sourcePath = curClasspathEntry.getPath();
                    // If including tests, include all source, or if not including tests, ensure
                    // it is not a test path
                    if (includeTestSourceEntries || !GWTProjectUtilities.isTestPath(sourcePath)) {
                        if (!isOptional(curClasspathEntry) || exists(sourcePath)) {
                            sourceEntries.add(JavaRuntime.newArchiveRuntimeClasspathEntry(sourcePath));
                        }
                    }
                }
            }
            IFolder folder = javaProject.getProject().getFolder("super");
            if (folder.exists()) {
                sourceEntries.add(JavaRuntime.newArchiveRuntimeClasspathEntry(folder.getFullPath()));
            }
        } catch (JavaModelException jme) {
            GWTPluginLog.logError(jme,
                    "Unable to retrieve raw classpath for project " + javaProject.getProject().getName());
        }
    }
}

From source file:com.google.gwt.eclipse.core.launch.processors.codeserver.SuperDevModeSrcArgumentProcessor.java

License:Open Source License

/**
 * Get the class path entries that are the source.
 *
 * @param javaProject the java project.//from  ww w. j  a  va 2  s . c  o m
 * @param entry classpath entry value.
 * @return the path.
 */
private String getPathIfDir(IJavaProject javaProject, IClasspathEntry entry) {
    IPath p = entry.getPath();

    String projectName = javaProject.getProject().getName();

    String path = null;
    // src directories don't have an output
    // cpe source are src,test directories
    if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE
            && (entry.getOutputLocation() == null || (entry.getOutputLocation() != null
                    && !entry.getOutputLocation().lastSegment().toString().equals("test-classes")))) {
        String dir = p.toString();
        // if the base segment has the project name,
        // lets remove that so its relative to project
        if (dir.contains(projectName)) {
            IPath relative = p.removeFirstSegments(1);
            path = relative.toString();
        }
    }

    return path;
}

From source file:com.google.gwt.eclipse.core.runtime.AbstractGWTRuntimeTest.java

License:Open Source License

protected boolean assertGWTRuntimeEntry(IPath runtimePath, IClasspathEntry[] entries) {
    boolean hasGWTRuntime = false;

    for (IClasspathEntry entry : entries) {
        IPath entryPath = entry.getPath();

        if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
            if (GWTRuntimeContainer.isPathForGWTRuntimeContainer(entryPath)) {
                // Make sure we have only one GWT runtime
                if (hasGWTRuntime) {
                    return false;
                }/*from   www  .  j  a  v a2  s. c o  m*/

                // We found at a GWT runtime
                hasGWTRuntime = true;

                // Make sure it's the one we're looking for
                if (!entryPath.equals(runtimePath)) {
                    return false;
                }
            }
        }

        // Make sure we don't have any gwt-user.jar dependencies
        if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
            String jarName = entryPath.lastSegment();
            if (jarName.equals(GWTRuntime.GWT_USER_JAR)) {
                return false;
            }
        }
    }

    return hasGWTRuntime;
}

From source file:com.google.gwt.eclipse.core.runtime.AbstractGWTRuntimeTest.java

License:Open Source License

protected void removeGWTRuntimeFromTestProject() throws Exception {
    IJavaProject project = getTestProject();

    // Replace GWT runtime classpath entry with gwt-user.jar and
    // gwt-dev-PLAT.jar
    List<IClasspathEntry> newEntries = new ArrayList<IClasspathEntry>();
    for (IClasspathEntry entry : project.getRawClasspath()) {
        if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
            if (GWTRuntimeContainer.isPathForGWTRuntimeContainer(entry.getPath())) {
                GWTJarsRuntime defaultSdk = GwtRuntimeTestUtilities.getDefaultRuntime();
                IPath gwtUserJar = defaultSdk.getInstallationPath().append(GWTRuntime.GWT_USER_JAR);
                newEntries.add(JavaCore.newLibraryEntry(gwtUserJar, null, null));

                IPath gwtDevJar = defaultSdk.getInstallationPath()
                        .append(Util.getDevJarName(defaultSdk.getInstallationPath()));
                newEntries.add(JavaCore.newLibraryEntry(gwtDevJar, null, null));
                continue;
            }//from   ww w. j av  a 2 s  . c o m
        }

        // Leave non-GWT runtime entries on the classpath as is
        newEntries.add(entry);
    }
    ClasspathUtilities.setRawClasspath(project, newEntries);
    JobsUtilities.waitForIdle();
}

From source file:com.google.gwt.eclipse.core.runtime.GWTJarsRuntimeTest.java

License:Open Source License

public void testGetClasspathEntries() throws Exception {
    IClasspathEntry[] cpEntries = runtime.getClasspathEntries();

    // Look for the gwt-specific classpath entries
    List<IClasspathEntry> gwtCpEntries = new ArrayList<IClasspathEntry>();
    for (IClasspathEntry cpEntry : cpEntries) {
        if (isGWTJar(runtime, cpEntry.getPath().lastSegment())) {
            gwtCpEntries.add(cpEntry);//  w ww  .ja  va2 s .  c  o  m
        }
    }

    // Make sure that there are two of them
    assertEquals(3, gwtCpEntries.size());

    for (int i = 0; i < gwtCpEntries.size(); i++) {
        IClasspathEntry gwtClasspathEntry = gwtCpEntries.get(i);
        assertEquals(IClasspathEntry.CPE_LIBRARY, gwtClasspathEntry.getEntryKind());
        assertEquals(IPackageFragmentRoot.K_BINARY, gwtClasspathEntry.getContentKind());

        // Verify that our classpath entries point at the GWT javadoc.
        IClasspathAttribute[] extraAttributes = gwtClasspathEntry.getExtraAttributes();
        assertTrue("No extra attributes seen for classpath entry: " + gwtClasspathEntry,
                extraAttributes.length > 0);
        assertEquals(IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME, extraAttributes[0].getName());

        /*
         * Entries should have their javadoc location point at a directory with "index.html".
         * Strangely, the values of these classpath attributes are specified as "file://" urls.
         */
        File jdLocation = new File(new URL(extraAttributes[0].getValue()).getFile());
        assertTrue("Javadoc file does not exist", jdLocation.exists());
        List<String> files1 = Arrays.asList(jdLocation.list());
        assertTrue("Javadoc file is not an index.html file.", files1.contains("index.html"));
    }
}

From source file:com.google.gwt.eclipse.core.runtime.GWTJarsRuntimeTest.java

License:Open Source License

public void testGetValidationClasspathEntries() throws Exception {
    IClasspathEntry[] cpEntries = runtime.getClasspathEntries();

    // Look for the validation-specific classpath entries
    List<IClasspathEntry> validationCpEntries = new ArrayList<IClasspathEntry>();
    for (IClasspathEntry cpEntry : cpEntries) {
        if (cpEntry.getPath().lastSegment().startsWith(GWTRuntime.VALIDATION_API_JAR_PREFIX)) {
            validationCpEntries.add(cpEntry);
        }//from  w  w w .  j  a  va  2s. co m
    }

    if (validationCpEntries.size() == 0) {
        String sdkVersion = runtime.getVersion();

        // Can't be an internal version, because it would have the
        // validation jars
        assertFalse(SdkUtils.isInternal(sdkVersion));

        // Sdk version must be pre-GWT 2.3.0
        assertTrue(SdkUtils.compareVersionStrings(sdkVersion, "2.3.0") < 0);

        return;
    }

    // Make sure that there are at least two of them
    assertEquals(2, validationCpEntries.size());

    IClasspathEntry sourcesEntry = null;
    IClasspathEntry binaryEntry = null;

    for (IClasspathEntry validationClasspathEntry : validationCpEntries) {
        // Verify the entry types
        assertEquals(IClasspathEntry.CPE_LIBRARY, validationClasspathEntry.getEntryKind());
        assertEquals(IPackageFragmentRoot.K_BINARY, validationClasspathEntry.getContentKind());

        if (validationClasspathEntry.getPath().lastSegment().contains("sources")) {
            sourcesEntry = validationClasspathEntry;
        } else {
            binaryEntry = validationClasspathEntry;
        }
    }

    // Verify that the sources and binary entries correspond to each other
    assertTrue(Util.findSourcesJarForClassesJar(binaryEntry.getPath()).equals(sourcesEntry.getPath()));

    // Verify that the source attachment path has been set for the binary
    // entry
    assertTrue(binaryEntry.getSourceAttachmentPath().equals(sourcesEntry.getPath()));
}

From source file:com.google.gwt.eclipse.core.runtime.GWTProjectsRuntime.java

License:Open Source License

/**
 * FIXME - Were it not for the super source stuff, we would need this method. Can't we provide a
 * way for users to state which folders are super-source, etc?
 *///from   w  w w . j a va  2s  .  c o  m
public static List<IRuntimeClasspathEntry> getGWTRuntimeProjectSourceEntries(IJavaProject project,
        boolean includeTestSourceEntries) throws SdkException {

    assert (isGWTRuntimeProject(project) && project.exists());

    String projectName = project.getProject().getName();
    List<IRuntimeClasspathEntry> sourceEntries = new ArrayList<IRuntimeClasspathEntry>();

    IClasspathEntry[] gwtUserJavaProjClasspathEntries = null;

    try {
        gwtUserJavaProjClasspathEntries = project.getRawClasspath();
    } catch (JavaModelException e) {
        throw new SdkException("Cannot extract raw classpath from " + projectName + " project.");
    }

    Set<IPath> absoluteSuperSourcePaths = new HashSet<IPath>();

    for (IClasspathEntry curClasspathEntry : gwtUserJavaProjClasspathEntries) {
        if (curClasspathEntry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
            IPath sourcePath = curClasspathEntry.getPath();

            if (isJavadocPath(sourcePath)) {
                // Ignore javadoc paths.
                continue;
            }

            if (GWTProjectUtilities.isTestPath(sourcePath) && !includeTestSourceEntries) {
                // Ignore test paths, unless it is specified explicitly that we should
                // include them.
                continue;
            }

            sourceEntries.add(JavaRuntime.newArchiveRuntimeClasspathEntry(sourcePath));

            // Figure out the location of the super source path.

            IPath absoluteSuperSourcePath = sourcePath.removeLastSegments(1).append(SUPER_SOURCE_FOLDER_NAME);
            IPath relativeSuperSourcePath = absoluteSuperSourcePath.removeFirstSegments(1);

            if (absoluteSuperSourcePaths.contains(absoluteSuperSourcePath)) {
                // I've already included this path.
                continue;
            }

            if (project.getProject().getFolder(relativeSuperSourcePath).exists()) {
                /*
                 * We've found the super source path, and we've not added it already. The existence test
                 * uses a relative path, but the creation of a runtime classpath entry requires an
                 * absolute path.
                 */
                sourceEntries.add(JavaRuntime.newArchiveRuntimeClasspathEntry(absoluteSuperSourcePath));
                absoluteSuperSourcePaths.add(absoluteSuperSourcePath);
            }

            IPath absoluteTestSuperSourcePath = sourcePath.removeLastSegments(1)
                    .append(TEST_SUPER_SOURCE_FOLDER_NAME);
            IPath relativeTestSuperSourcePath = absoluteTestSuperSourcePath.removeFirstSegments(1);
            if (absoluteSuperSourcePaths.contains(absoluteTestSuperSourcePath)) {
                // I've already included this path.
                continue;
            }

            if (includeTestSourceEntries
                    && project.getProject().getFolder(relativeTestSuperSourcePath).exists()) {
                /*
                 * We've found the super source path, and we've not added it already. The existence test
                 * uses a relative path, but the creation of a runtime classpath entry requires an
                 * absolute path.
                 */
                sourceEntries.add(JavaRuntime.newArchiveRuntimeClasspathEntry(absoluteTestSuperSourcePath));
                absoluteSuperSourcePaths.add(absoluteTestSuperSourcePath);
            }
        }
    }

    if (absoluteSuperSourcePaths.isEmpty()) {
        GWTPluginLog.logError("There were no super source folders found for the project '{0}'",
                project.getProject().getName());
    }

    return sourceEntries;
}