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

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

Introduction

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

Prototype

int CPE_LIBRARY

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

Click Source Link

Document

Entry kind constant describing a classpath entry identifying a library.

Usage

From source file:com.drgarbage.bytecode.jdi.dialogs.ProjectBuildPathViewer.java

License:Apache License

/**
 * Fills the list of existing class folders in the project.
 *///from www . jav a  2s .  co m
private void fillLibList() {
    libs = new HashSet<IFolder>();

    /* fill a set with classpath entries */
    IClasspathEntry[] classpathEntries = fJavaProject.readRawClasspath();
    for (IClasspathEntry ice : classpathEntries) {
        if (ice.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
            IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
            IResource resource = root.findMember(ice.getPath());
            if (resource instanceof IFolder) {
                IFolder f = (IFolder) resource;
                libs.add(f);
            }
        }
    }
}

From source file:com.ebmwebsourcing.petals.common.internal.provisional.utils.JavaUtils.java

License:Open Source License

/**
 * Get the class path from Java project.
 *
 * @param javaProject/*from   ww  w  .  java2 s.co  m*/
 * @param getReferencedProjectClasspath
 * @param binaryDirectory
 * @return the class path as a list of string locations.
 */
public static List<String> getClasspath(IJavaProject javaProject, boolean getReferencedProjectClasspath,
        boolean binaryDirectory) {

    List<String> paths = new ArrayList<String>();
    try {
        if (javaProject != null) {

            // Get the raw class path
            IClasspathEntry[] entries = javaProject.getRawClasspath();
            for (IClasspathEntry entry : entries) {
                switch (entry.getEntryKind()) {

                case IClasspathEntry.CPE_PROJECT:
                    if (!getReferencedProjectClasspath)
                        break;

                    String projectName = entry.getPath().toString();
                    IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
                    IJavaProject jProject = JavaCore.create(project);

                    List<String> subPaths = getClasspath(jProject, true, binaryDirectory);
                    paths.addAll(subPaths);
                    break;

                case IClasspathEntry.CPE_LIBRARY:
                    IPath path = entry.getPath();
                    paths.add(path.toString());
                    break;

                case IClasspathEntry.CPE_VARIABLE:
                    entry = JavaCore.getResolvedClasspathEntry(entry);
                    if (entry != null) {
                        path = entry.getPath();
                        paths.add(path.toString());
                    }
                    break;

                }
            }

            // Add the "bin" directory?
            if (binaryDirectory && javaProject.getOutputLocation() != null) {
                IPath path = ResourcesPlugin.getWorkspace().getRoot().getLocation();
                path = path.append(javaProject.getOutputLocation());
                paths.add(path.toString());
            }
        }

    } catch (JavaModelException e) {
        PetalsCommonPlugin.log(e, IStatus.ERROR);
    }

    return paths;
}

From source file:com.ebmwebsourcing.petals.common.internal.provisional.utils.JavaUtils.java

License:Open Source License

/**
 * Populates an {@link ExportableClassPath} instance from a class path entry.
 * @param result the {@link ExportableClassPath} instance to populate
 * @param entry a class path entry//from  w w  w .j  a v a 2 s  .  c o m
 * @param monitor the progress monitor
 */
private static void updateExportableResult(ExportableClassPath result, IClasspathEntry entry,
        IProgressMonitor monitor) {

    switch (entry.getEntryKind()) {

    case IClasspathEntry.CPE_PROJECT:
        String projectName = entry.getPath().toString();
        IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
        IJavaProject jProject = JavaCore.create(project);

        ExportableClassPath subResult = getExportableClasspath(jProject, monitor);
        result.implementationJars.addAll(subResult.implementationJars);
        result.libraryJars.addAll(subResult.libraryJars);
        monitor.worked(1);
        break;

    case IClasspathEntry.CPE_LIBRARY:
        IPath path = entry.getPath();
        if (path != null) {
            File f = path.toFile();
            if (f.exists()) {
                if (f.getName().endsWith(".zip") || f.getName().endsWith(".jar"))
                    result.libraryJars.add(f);
            }
        }
        break;

    case IClasspathEntry.CPE_VARIABLE:
        entry = JavaCore.getResolvedClasspathEntry(entry);
        if (entry != null)
            updateExportableResult(result, entry, monitor);

        break;
    }
}

From source file:com.ecfeed.ui.common.EclipseLoaderProvider.java

License:Open Source License

public ModelClassLoader getLoader(boolean create, ClassLoader parent) {
    if ((fLoader == null) || create) {
        List<URL> urls = new ArrayList<URL>();
        try {//from  w ww  .ja v a  2  s. com
            IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
            for (IProject project : projects) {
                if (project.isOpen() && project.hasNature(JavaCore.NATURE_ID)) {
                    IJavaProject javaProject = JavaCore.create(project);
                    IPath path = project.getLocation()
                            .append(javaProject.getOutputLocation().removeFirstSegments(1));
                    urls.add(new URL("file", null, path.toOSString() + "/"));
                    IClasspathEntry table[] = javaProject.getResolvedClasspath(true);
                    for (int i = 0; i < table.length; ++i) {
                        if (table[i].getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
                            urls.add(new URL("file", null, table[i].getPath().toOSString()));
                            path = project.getLocation();
                            path = path.append(table[i].getPath().removeFirstSegments(1));
                            urls.add(new URL("file", null, path.toOSString()));
                        }
                    }
                }
            }
            if (fLoader != null) {
                fLoader.close();
            }
        } catch (Throwable e) {
        }
        fLoader = new ModelClassLoader(urls.toArray(new URL[] {}), parent);
    }
    return fLoader;
}

From source file:com.github.ko2ic.plugin.eclipse.taggen.core.service.WorkspaceClassLoader.java

License:Open Source License

private Set<URL> createUrls(IJavaProject javaProject) throws CoreException, MalformedURLException {
    Set<URL> urlList = new HashSet<>();
    IClasspathEntry[] classpathEntries = javaProject.getResolvedClasspath(true);
    for (IClasspathEntry entry : classpathEntries) {
        if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
            IPath path = entry.getOutputLocation();
            if (path != null) {
                IPath outputPath = javaProject.getOutputLocation().removeFirstSegments(1);
                IPath outputFullPath = javaProject.getProject().getFolder(outputPath).getLocation();
                outputFullPath.append(System.getProperty("line.separator"));
                URL url = outputFullPath.toFile().toURI().toURL();
                urlList.add(url);//w w w  .  j a  v a  2s  .  co  m
            }
        } else if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
            URL url = entry.getPath().toFile().toURI().toURL();
            urlList.add(url);
        }
    }
    return urlList;
}

From source file:com.google.cloud.tools.eclipse.appengine.libraries.persistence.LibraryClasspathContainerSerializerTest.java

License:Apache License

@Before
public void setUp() throws Exception {
    IClasspathEntry[] classpathEntries = new IClasspathEntry[] {
            getClasspathEntry(IClasspathEntry.CPE_LIBRARY, "/test/path/to/jar", "/test/path/to/src",
                    new IClasspathAttribute[] { getAttribute("attrName", "attrValue") },
                    new IAccessRule[] { getAccessRule("/com/example/accessible", true /* accessible */),
                            getAccessRule("/com/example/nonaccessible", false /* accessible */) },
                    true) };//from  ww  w  .j  a v a 2  s . co m
    when(artifactBaseLocationProvider.getBaseLocation()).thenReturn(new Path("/test"));
    container = new LibraryClasspathContainer(new Path(CONTAINER_PATH), CONTAINER_DESCRIPTION,
            classpathEntries);
}

From source file:com.google.gdt.eclipse.core.markers.quickfixes.CopyToServerClasspathMarkerResolution.java

License:Open Source License

public void run(IMarker marker) {
    String buildClasspathFileName = buildClasspathFilePath.lastSegment();
    IProject project = marker.getResource().getProject();
    IPath projRelativeWebInfLibFolderPath = null;

    try {//from w ww  . jav  a 2s .co m
        WebAppUtilities.verifyHasManagedWarOut(project);

        projRelativeWebInfLibFolderPath = WebAppUtilities.getWebInfLib(project).getProjectRelativePath();

        ResourceUtils.createFolderStructure(project, projRelativeWebInfLibFolderPath);
    } catch (CoreException e) {
        CorePluginLog.logError(e);
        MessageDialog.openError(CorePlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getShell(),
                "Error While Attempting to Copy " + buildClasspathFileName,
                "Unable to create <WAR>/WEB-INF/lib directory. See the Error Log for more details.");
        return;
    }

    IFolder webInfLibFolder = project.getFolder(projRelativeWebInfLibFolderPath);

    assert (webInfLibFolder.exists());

    IFile serverClasspathFile = webInfLibFolder.getFile(buildClasspathFileName);

    try {
        serverClasspathFile.create(new FileInputStream(buildClasspathFilePath.toFile()), false, null);
    } catch (FileNotFoundException e) {
        MessageDialog.openError(CorePlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getShell(),
                "Error While Attempting to Copy " + buildClasspathFileName,
                "The file " + buildClasspathFilePath.toOSString() + " does not exist.");
        return;
    } catch (CoreException e) {
        CorePluginLog.logError(e);
        MessageDialog.openError(CorePlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getShell(),
                "Error While Attempting to Copy " + buildClasspathFileName,
                "Unable to copy " + buildClasspathFilePath.toOSString() + " to "
                        + projRelativeWebInfLibFolderPath.toString() + ". See the Error Log for more details.");
        return;
    }

    // Update the project's classpath to use the file copied into
    // <WAR>/WEB-INF/lib
    IJavaProject javaProject = JavaCore.create(project);

    if (!JavaProjectUtilities.isJavaProjectNonNullAndExists(javaProject)) {
        MessageDialog.openError(CorePlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getShell(),
                "Error While Attempting to Update Project Classpath",
                "Unable to update project " + project.getName() + "'s classpath.");
        return;
    }

    try {

        List<IClasspathEntry> newRawClasspath = new ArrayList<IClasspathEntry>();

        for (IClasspathEntry entry : javaProject.getRawClasspath()) {
            IClasspathEntry resolvedEntry = JavaCore.getResolvedClasspathEntry(entry);
            IPath resolvedEntryPath = ResourceUtils.resolveToAbsoluteFileSystemPath(resolvedEntry.getPath());

            if (resolvedEntry.getEntryKind() == IClasspathEntry.CPE_LIBRARY
                    && resolvedEntryPath.equals(buildClasspathFilePath)) {
                newRawClasspath.add(JavaCore.newLibraryEntry(serverClasspathFile.getFullPath(), null, null));
            } else {
                newRawClasspath.add(entry);
            }
        }

        ClasspathUtilities.setRawClasspath(javaProject, newRawClasspath.toArray(new IClasspathEntry[0]));

    } catch (JavaModelException e) {
        CorePluginLog.logError(e);
        MessageDialog.openError(CorePlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getShell(),
                "Error While Attempting to Update Project Classpath", "Unable to update project "
                        + project.getName() + "'s classpath. See the Error Log for more details.");
    }
}

From source file:com.google.gdt.eclipse.core.properties.ui.BuildpathJarSelectionDialog.java

License:Open Source License

/**
 * Returns the absolute file system paths of all JAR files on the project's
 * build classpath, which are not part of a classpath container.
 *//*from w ww . j a  v a  2s .  c  o  m*/
private List<IPath> getJarsOnBuildPath() {
    List<IPath> jars = new ArrayList<IPath>();

    try {
        IClasspathEntry[] rawClasspaths = javaProject.getRawClasspath();

        for (IClasspathEntry rawClasspath : rawClasspaths) {
            rawClasspath = JavaCore.getResolvedClasspathEntry(rawClasspath);
            if (rawClasspath.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
                IPath jarPath = ResourceUtils.resolveToAbsoluteFileSystemPath(rawClasspath.getPath());
                jars.add(jarPath);
            }
        }
    } catch (JavaModelException e) {
        CorePluginLog.logError(e);
    }

    return jars;
}

From source file:com.google.gdt.eclipse.core.validators.WebAppProjectValidator.java

License:Open Source License

private boolean validateBuildClasspath(IJavaProject javaProject) throws CoreException {
    IPath webInfLibFolderLocation = null;

    IFolder webInfLibFolder = WebAppUtilities.getWebInfOut(getProject()).getFolder("lib");

    if (webInfLibFolder.exists()) {
        webInfLibFolderLocation = webInfLibFolder.getLocation();
    }/*from www  .j a va2  s .c o  m*/

    IClasspathEntry[] rawClasspaths = javaProject.getRawClasspath();
    boolean isOk = true;
    List<IPath> excludedJars = WebAppProjectProperties.getJarsExcludedFromWebInfLib(javaProject.getProject());

    for (IClasspathEntry rawClasspath : rawClasspaths) {
        rawClasspath = JavaCore.getResolvedClasspathEntry(rawClasspath);
        if (rawClasspath.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
            IPath entryPath = ResourceUtils.resolveToAbsoluteFileSystemPath(rawClasspath.getPath());
            if (excludedJars.contains(entryPath)) {
                continue;
            }

            if (webInfLibFolderLocation == null || !webInfLibFolderLocation.isPrefixOf(entryPath)) {
                MarkerUtilities.createQuickFixMarker(PROBLEM_MARKER_ID,
                        ProjectStructureOrSdkProblemType.JAR_OUTSIDE_WEBINF_LIB, entryPath.toPortableString(),
                        javaProject.getProject(), entryPath.toOSString());
                isOk = false;
            }
        }
    }

    return isOk;
}

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  w  w w.j av a2  s. com

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