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:org.jboss.tools.servers.wildfly.swarm.core.internal.WildlfySwarmDetectionJob.java

License:Open Source License

private boolean isSwarmEntry(IClasspathEntry cpe) {
    //this is a quick n' very dirty detection
    if (cpe.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
        IPath path = cpe.getPath();//from   w w w .  j a  v  a2 s.c o  m
        String name = path.lastSegment();
        return name.startsWith("container-") && containsSwarm(path.toFile());
    }
    return false;
}

From source file:org.jboss.tools.ws.creation.core.utils.ClasspathParser.java

License:Open Source License

private String[] classpathEntryToString(IClasspathEntry entry, IProject project) {
    switch (entry.getEntryKind()) {
    case IClasspathEntry.CPE_LIBRARY: {
        return new String[] { pathToString(entry.getPath()) };
    }/*from  w  w  w  .  j a v a  2  s. c o  m*/
    case IClasspathEntry.CPE_PROJECT: {
        return getClasspath(ResourcesPlugin.getWorkspace().getRoot().getProject(entry.getPath().lastSegment()),
                true);
    }
    case IClasspathEntry.CPE_SOURCE: {
        IPath path = entry.getPath();
        if (path.segment(0).equals(project.getName()))
            path = path.removeFirstSegments(1);
        return new String[] { pathToString(project.getLocation().addTrailingSeparator().append(path)) };
    }
    case IClasspathEntry.CPE_VARIABLE: {
        return classpathEntryToString(JavaCore.getResolvedClasspathEntry(entry), project);
    }
    default: {
        return new String[] { pathToString(entry.getPath()) };
    }
    }
}

From source file:org.jboss.tools.ws.jaxws.ui.project.facet.JBossWSRuntimeConfigBlock.java

License:Open Source License

protected String getDuplicateJars(String jbwsName) throws JavaModelException {
    String prjName = model.getStringProperty(IFacetDataModelProperties.FACET_PROJECT_NAME);

    if (prjName == null || "".equals(prjName)) { //$NON-NLS-1$
        return ""; //$NON-NLS-1$
    }/*from   w w  w  .j  a va 2  s.  c o m*/
    IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(prjName);
    if (!project.exists()) {
        return ""; //$NON-NLS-1$
    }

    List<String> allExistingJars = new ArrayList<String>();
    List<String> runtimeJars = new ArrayList<String>();

    JBossWSRuntime jbws = JBossWSRuntimeManager.getInstance().findRuntimeByName(jbwsName);
    if (jbws.isUserConfigClasspath()) {
        runtimeJars.addAll(jbws.getLibraries());
    } else {
        runtimeJars.addAll(JBossWSRuntimeManager.getInstance().getAllRuntimeJars(jbws));
    }

    IJavaProject javaProject = JavaCore.create(project);
    IClasspathEntry[] entries = javaProject.getRawClasspath();
    for (IClasspathEntry entry : entries) {
        if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
            if (JBossJAXWSUIMessages.JBossWS_Runtime_Lib.equals(entry.getPath().segment(0))) {
                continue;
            }
            IClasspathContainer container = JavaCore.getClasspathContainer(entry.getPath(), javaProject);
            for (IClasspathEntry containedEntry : container.getClasspathEntries()) {
                allExistingJars.add(containedEntry.getPath().toOSString());
            }
        } else if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
            allExistingJars.add(entry.getPath().toOSString());
        }
    }

    for (String jarName : runtimeJars) {
        if (allExistingJars.contains(jarName)) {
            return jarName;
        }
    }

    return ""; //$NON-NLS-1$

}

From source file:org.jboss.tools.ws.ui.project.facet.JBossWSRuntimeConfigBlock.java

License:Open Source License

protected String getDuplicateJars(String jbwsName) throws JavaModelException {
    String prjName = model.getStringProperty(IFacetDataModelProperties.FACET_PROJECT_NAME);

    if (prjName == null || "".equals(prjName)) { //$NON-NLS-1$
        return ""; //$NON-NLS-1$
    }/*from  w  w  w . ja v  a2  s  .  co m*/
    IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(prjName);
    if (!project.exists()) {
        return ""; //$NON-NLS-1$
    }

    List<String> allExistingJars = new ArrayList<String>();
    List<String> runtimeJars = new ArrayList<String>();

    JBossWSRuntime jbws = JBossWSRuntimeManager.getInstance().findRuntimeByName(jbwsName);
    if (jbws.isUserConfigClasspath()) {
        runtimeJars.addAll(jbws.getLibraries());
    } else {
        runtimeJars.addAll(JBossWSRuntimeManager.getInstance().getAllRuntimeJars(jbws));
    }

    IJavaProject javaProject = JavaCore.create(project);
    IClasspathEntry[] entries = javaProject.getRawClasspath();
    for (IClasspathEntry entry : entries) {
        if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
            if (JBossWSCoreMessages.JBossWS_Runtime_Lib.equals(entry.getPath().segment(0))) {
                continue;
            }
            IClasspathContainer container = JavaCore.getClasspathContainer(entry.getPath(), javaProject);
            for (IClasspathEntry containedEntry : container.getClasspathEntries()) {
                allExistingJars.add(containedEntry.getPath().toOSString());
            }
        } else if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
            allExistingJars.add(entry.getPath().toOSString());
        }
    }

    for (String jarName : runtimeJars) {
        if (allExistingJars.contains(jarName)) {
            return jarName;
        }
    }

    return ""; //$NON-NLS-1$

}

From source file:org.jbpm.eclipse.util.ProjectClassLoader.java

License:Apache License

public static List<URL> getProjectClassPathURLs(IJavaProject project, List<String> alreadyLoadedProjects) {
    List<URL> pathElements = new ArrayList<URL>();
    try {/*w w w . jav  a 2s .co m*/
        IClasspathEntry[] paths = project.getResolvedClasspath(true);
        Set<IPath> outputPaths = new HashSet<IPath>();
        if (paths != null) {
            for (int i = 0; i < paths.length; i++) {
                IClasspathEntry path = paths[i];
                if (path.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
                    URL url = getRawLocationURL(path.getPath());
                    pathElements.add(url);
                } else if (path.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                    IPath output = path.getOutputLocation();
                    if (path.getOutputLocation() != null) {
                        outputPaths.add(output);
                    }
                }
            }
        }
        IPath location = getProjectLocation(project.getProject());
        IPath outputPath = location.append(project.getOutputLocation().removeFirstSegments(1));
        pathElements.add(0, outputPath.toFile().toURI().toURL());
        for (IPath path : outputPaths) {
            outputPath = location.append(path.removeFirstSegments(1));
            pathElements.add(0, outputPath.toFile().toURI().toURL());
        }

        // also add classpath of required projects
        for (String projectName : project.getRequiredProjectNames()) {
            if (!alreadyLoadedProjects.contains(projectName)) {
                alreadyLoadedProjects.add(projectName);
                IProject reqProject = project.getProject().getWorkspace().getRoot().getProject(projectName);
                if (reqProject != null) {
                    IJavaProject reqJavaProject = JavaCore.create(reqProject);
                    pathElements.addAll(getProjectClassPathURLs(reqJavaProject, alreadyLoadedProjects));
                }
            }
        }
    } catch (JavaModelException e) {
        JBPMEclipsePlugin.log(e);
    } catch (MalformedURLException e) {
        JBPMEclipsePlugin.log(e);
    } catch (Throwable t) {
        JBPMEclipsePlugin.log(t);
    }
    return pathElements;
}

From source file:org.jetbrains.kotlin.core.utils.ProjectUtils.java

License:Apache License

public static List<File> collectClasspathWithDependenciesForLaunch(@NotNull IJavaProject javaProject)
        throws JavaModelException {
    return expandClasspath(javaProject, true, true, new Predicate<IClasspathEntry>() {
        @Override// w  w  w. ja  v  a 2 s.  com
        public boolean apply(IClasspathEntry entry) {
            return entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY;
        }
    });
}

From source file:org.jsweet.plugin.builder.JSweetBuilder.java

License:Apache License

private void fullBuild(BuildingContext context, final IProgressMonitor monitor) throws CoreException {
    Log.info("JSweet: full build...");
    context.project.deleteMarkers(JSWEET_PROBLEM_MARKER_TYPE, true, IResource.DEPTH_INFINITE);
    List<IPath> sourceDirs = new ArrayList<>();
    if (!StringUtils.isEmpty(Preferences.getSourceFolders(context.project, context.profile))) {
        String[] names = Preferences.getSourceFolders(context.project, context.profile).split("[,;]");
        try {/* w w w .  j  a  va2s. co  m*/
            for (String name : names) {
                sourceDirs.add(context.project.getFolder(name).getFullPath());
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    String jdkHome = null;
    boolean lookupSourceFolder = sourceDirs.isEmpty();
    if (context.project.isNatureEnabled("org.eclipse.jdt.core.javanature")) {
        IJavaProject javaProject = JavaCore.create(context.project);
        IClasspathEntry[] classPathEntries = javaProject.getResolvedClasspath(true);
        for (IClasspathEntry e : classPathEntries) {
            if (lookupSourceFolder && e.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                sourceDirs.add(e.getPath());
            } else if (e.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
                if (e.getPath().toString().endsWith("/lib/rt.jar")) {
                    jdkHome = e.getPath().removeLastSegments(2).toString();
                }
            }
        }
    }
    Log.info("source dirs: " + sourceDirs);
    GrabJavaFilesVisitor v = new GrabJavaFilesVisitor(context, sourceDirs);

    context.project.accept(v);
    context.sourceFiles.clear();
    Log.info("init classpath, jdkHome: " + jdkHome);
    JSweetConfig.initClassPath(jdkHome);
    createJSweetTranspiler(context);
    transpileFiles(context, v.javaFiles.toArray(new File[0]));
}

From source file:org.key_project.util.jdt.JDTUtil.java

License:Open Source License

/**
 * Returns the {@link IResource}s of the given {@link IClasspathEntry}.
 * @param javaProject The actual {@link IJavaProject} that provides the {@link IClasspathEntry}.
 * @param entry The given {@link IClasspathEntry}.
 * @param alreadyHandledProjects The already handled {@link IProject} that don't need to be analysed again.
 * @return The found {@link IResource}s.
 * @throws JavaModelException //from   w  ww.j  a  v a 2  s . co m
 */
private static List<IResource> getResourceFor(IJavaProject javaProject, IClasspathEntry entry, int expectedKind,
        Set<IProject> alreadyHandledProjects) throws JavaModelException {
    if (entry != null) {
        if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER
                || entry.getEntryKind() == IClasspathEntry.CPE_SOURCE
                || entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY
                || entry.getEntryKind() == IClasspathEntry.CPE_VARIABLE) {
            List<IResource> result = new LinkedList<IResource>();
            IPackageFragmentRoot[] roots = javaProject.findPackageFragmentRoots(entry);
            for (IPackageFragmentRoot root : roots) {
                if (root.getKind() == expectedKind) {
                    if (root.getResource() != null) {
                        if (root.getResource().getLocationURI() != null) {
                            result.add(root.getResource());
                        }
                    } else if (root.getPath() != null) {
                        IResource resource = ResourcesPlugin.getWorkspace().getRoot()
                                .findMember(root.getPath());
                        if (resource != null && resource.exists()) {
                            result.add(resource);
                        }
                    }
                }
            }
            return result; // Ignore containers
        } else if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT) {
            Assert.isNotNull(entry.getPath());
            IResource project = ResourcesPlugin.getWorkspace().getRoot().findMember(entry.getPath());
            Assert.isTrue(project instanceof IProject);
            if (!alreadyHandledProjects.contains(project)) {
                return getSourceResources((IProject) project, alreadyHandledProjects);
            } else {
                return null; // Project was already analyzed, no need to do it again.
            }
        } else {
            Assert.isTrue(false, "Unknown content kind \"" + entry.getContentKind()
                    + "\" of class path entry \"" + entry + "\".");
            return null;
        }
    } else {
        return null;
    }
}

From source file:org.key_project.util.jdt.JDTUtil.java

License:Open Source License

/**
 * Returns the locations of the given {@link IClasspathEntry}.
 * @param javaProject The actual {@link IJavaProject} that provides the {@link IClasspathEntry}.
 * @param entry The given {@link IClasspathEntry}.
 * @param alreadyHandledProjects The already handled {@link IProject} that don't need to be analysed again.
 * @return The found locations./*ww w .j a v a 2  s  .  c o m*/
 * @throws JavaModelException 
 */
private static List<File> getLocationFor(IJavaProject javaProject, IClasspathEntry entry, int expectedKind,
        Set<IProject> alreadyHandledProjects) throws JavaModelException {
    if (entry != null) {
        if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER
                || entry.getEntryKind() == IClasspathEntry.CPE_SOURCE
                || entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY
                || entry.getEntryKind() == IClasspathEntry.CPE_VARIABLE) {
            List<File> result = new LinkedList<File>();
            IPackageFragmentRoot[] roots = javaProject.findPackageFragmentRoots(entry);
            for (IPackageFragmentRoot root : roots) {
                if (root.getKind() == expectedKind) {
                    if (root.getResource() != null) {
                        if (root.getResource().getLocationURI() != null) {
                            result.add(ResourceUtil.getLocation(root.getResource()));
                        }
                    } else if (root.getPath() != null) {
                        File location = new File(root.getPath().toString());
                        if (location.exists()) {
                            result.add(location);
                        }
                    }
                }
            }
            return result; // Ignore containers
        } else if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT) {
            Assert.isNotNull(entry.getPath());
            IResource project = ResourcesPlugin.getWorkspace().getRoot().findMember(entry.getPath());
            Assert.isTrue(project instanceof IProject);
            if (!alreadyHandledProjects.contains(project)) {
                return getSourceLocations((IProject) project, alreadyHandledProjects);
            } else {
                return null; // Project was already analyzed, no need to do it again.
            }
        } else {
            Assert.isTrue(false, "Unknown content kind \"" + entry.getContentKind()
                    + "\" of class path entry \"" + entry + "\".");
            return null;
        }
    } else {
        return null;
    }
}

From source file:org.libreoffice.ide.eclipse.java.JavaBuilder.java

License:LGPL

/**
 * Get the libraries in the classpath that are located in the project
 * directory or one of its subfolder.//from w w w .jav  a  2  s .  c  o m
 *
 * @param pJavaPrj the project from which to extract the libraries
 * @return a list of all the File pointing to the libraries.
 */
private ArrayList<IFile> getLibs(IJavaProject pJavaPrj) {
    ArrayList<IFile> libs = new ArrayList<IFile>();
    try {
        IClasspathEntry[] entries = pJavaPrj.getResolvedClasspath(true);
        for (IClasspathEntry entry : entries) {
            if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
                /*
                 * At first, add only the libraries located in the project
                 * or one of its children. All others libraries have to be
                 * managed by the user.
                 */
                IPath path = entry.getPath();
                if (!new File(path.toOSString()).exists() && path.isAbsolute()
                        && path.toString().startsWith("/" + pJavaPrj.getProject().getName())) { //$NON-NLS-1$
                    // Relative to the project
                    IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
                    if (file != null && file.exists()) {
                        libs.add(file);
                    }
                }
            }
        }

    } catch (JavaModelException e) {
        // Enable to add some missing library
    }

    return libs;
}