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

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

Introduction

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

Prototype

IPath getPath();

Source Link

Document

Returns the path of this classpath entry.

Usage

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

License:Open Source License

protected ManagedApi getManagedApiForPackageFragmentRoot(JarPackageFragmentRoot packageFragmentRoot) {
    ManagedApi managedApi = null;//  w  w  w . j  a  va  2s .  c o m
    try {
        IClasspathEntry icpe = ClasspathUtilities
                .getNullableRawClasspathEntryForPackageFragmentRoot(packageFragmentRoot);
        managedApi = ManagedApiProjectImpl.getManagedApiProject(packageFragmentRoot.getJavaProject())
                .findManagedApi(icpe.getPath().removeFirstSegments(1).toString());
    } catch (CoreException e) {
        ManagedApiLogger.warn(e, "Caught core exception while trying to access ManagedApi");
    }
    return managedApi;
}

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  ww . j a  va  2s  .co m
 * 
 * @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.gdt.eclipse.managedapis.ui.ManagedApiContainerPage.java

License:Open Source License

public void setSelection(IClasspathEntry containerEntry) {
    if (containerEntry != null) {
        initPath = containerEntry.getPath();
    }
}

From source file:com.google.gdt.eclipse.maven.sdk.GWTMavenRuntime.java

License:Open Source License

@Override
public URLClassLoader createClassLoader() throws SdkException, MalformedURLException {
    if (!validate().isOK()) {
        return new URLClassLoader(new URL[0]);
    }// www.  j  a  v a2s. c o m

    try {
        ArrayList<URL> classloaderURLs = new ArrayList<URL>();

        // getDevJar would throw an exception instead of returning null
        // gwt-dev.jar
        classloaderURLs.add(getDevJar().toURI().toURL());

        // findGwtUserClasspathEntry won't be null, because validate passed gwt-user.jar
        classloaderURLs.add(findGwtUserClasspathEntry().getPath().toFile().toURI().toURL());

        // validation jars
        IClasspathEntry javaxValidationJar = findJavaXValidationClasspathEntry();
        // could be null on older GWT projects
        if (javaxValidationJar != null) {
            classloaderURLs.add(javaxValidationJar.getPath().toFile().toURI().toURL());
        }

        return new URLClassLoader(classloaderURLs.toArray(new URL[classloaderURLs.size()]), null);
    } catch (JavaModelException jme) {
        return new URLClassLoader(new URL[0]);
    }
}

From source file:com.google.gdt.eclipse.maven.sdk.GWTMavenRuntime.java

License:Open Source License

@Override
public File getDevJar() throws SdkException, JavaModelException {
    IClasspathEntry classpathEntry = findGwtUserClasspathEntry();

    if (classpathEntry == null) {
        throw new SdkException("Unable to locate gwt-user.jar");
    }//from w w  w .java  2 s . c  om

    IPath path = MavenUtils.getArtifactPathForPeerMavenArtifact(classpathEntry.getPath(), MAVEN_GWT_GROUP_ID,
            MAVEN_GWT_DEV_JAR_ARTIFACT_ID);
    if (path == null) {
        throw new SdkException("Unable to locate gwt-dev.jar");
    }

    if (!path.toFile().exists()) {
        throw new SdkException(path.toOSString() + " does not exist.");
    }

    return path.toFile();
}

From source file:com.google.gdt.eclipse.maven.sdk.GWTMavenRuntime.java

License:Open Source License

/**
 * Maven-based GWT SDKs do not have a clear installation path. So, we say that the installation
 * path corresponds to: <code><repository path>/<group path></code>.
 *//*from w  w w . java 2 s. c  o  m*/
@Override
public IPath getInstallationPath() {

    try {
        IClasspathEntry classpathEntry = findGwtUserClasspathEntry();
        if (classpathEntry == null) {
            return null;
        }

        IPath p = classpathEntry.getPath();
        if (p.segmentCount() < 4) {
            return null;
        }
        return p.removeLastSegments(3);
    } catch (JavaModelException e) {
        Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID,
                "Unable to determine installation path for the maven-based GWT runtime.", e));
    }

    return null;
}

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. ja  v a 2  s .c o  m*/
 *
 * @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  va2 s  .  c om
 * @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;
                }/*  ww  w  .j  av a 2  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   w  w w .ja  va  2 s  .c  om
        }

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