Example usage for org.eclipse.jdt.core IJavaProject getResolvedClasspath

List of usage examples for org.eclipse.jdt.core IJavaProject getResolvedClasspath

Introduction

In this page you can find the example usage for org.eclipse.jdt.core IJavaProject getResolvedClasspath.

Prototype

IClasspathEntry[] getResolvedClasspath(boolean ignoreUnresolvedEntry) throws JavaModelException;

Source Link

Document

This is a helper method returning the resolved classpath for the project as a list of simple (non-variable, non-container) classpath entries.

Usage

From source file:org.jboss.tools.common.java.generation.JavaBeanGenerator.java

License:Open Source License

public static IPackageFragmentRoot getJavaProjectSrcRoot(IJavaProject javaProject) throws CoreException {
    IClasspathEntry[] es = javaProject.getResolvedClasspath(true);
    for (int i = 0; i < es.length; i++) {
        if (es[i].getEntryKind() != IClasspathEntry.CPE_SOURCE)
            continue;
        return javaProject
                .getPackageFragmentRoot(ModelPlugin.getWorkspace().getRoot().getFolder(es[i].getPath()));
    }/*w w  w . j  a v a 2s. c  o m*/
    return null;
}

From source file:org.jboss.tools.common.model.filesystems.impl.Libs.java

License:Open Source License

private void updateProjects() throws JavaModelException {
    Set<String> result = new HashSet<String>();
    IJavaProject javaProject = EclipseResourceUtil.getJavaProject(getProjectResource());
    if (javaProject != null) {
        result.add(getProjectResource().getName());
        IClasspathEntry[] es = javaProject.getResolvedClasspath(true);
        for (int i = 0; i < es.length; i++) {
            if (es[i].getEntryKind() == IClasspathEntry.CPE_PROJECT) {
                IProject p = ResourcesPlugin.getWorkspace().getRoot().getProject(es[i].getPath().lastSegment());
                if (p == null || !p.isAccessible())
                    continue;
                result.add(p.getName());
            }/*from  w  w w.j  a va  2s . co m*/
        }
    }
    projects = result;
}

From source file:org.jboss.tools.common.model.filesystems.impl.Libs.java

License:Open Source License

private int computeExcludedState() throws JavaModelException {
    int result = 0;
    IJavaProject javaProject = EclipseResourceUtil.getJavaProject(getProjectResource());
    if (javaProject != null) {
        IClasspathEntry[] es = javaProject.getResolvedClasspath(true);
        for (int i = 0; i < es.length; i++) {
            IPath p = es[i].getPath();//from   www .j  av a  2s . c o  m
            IPath[] ps = es[i].getExclusionPatterns();
            if (ps != null && ps.length > 0) {
                for (int j = 0; j < ps.length; j++) {
                    String key = p.toString() + "/" + ps[j].toString(); //$NON-NLS-1$
                    result += key.hashCode();
                }
            }
        }
    }
    return result;
}

From source file:org.jboss.tools.common.model.util.EclipseResourceUtil.java

License:Open Source License

/**
 * Returns list of canonical paths to resources of libraries (jars and class folders) included in class path.
 * @throws IOException //from  ww w  . ja  v a  2 s. c  o  m
 */
public static List<String> getClassPath(IProject project) throws CoreException, IOException {
    IJavaProject javaProject = getJavaProject(project);
    if (javaProject == null) {
        return null;
    }

    ArrayList<String> l = new ArrayList<String>();
    IClasspathEntry[] es = javaProject.getResolvedClasspath(true);
    for (int i = 0; i < es.length; i++) {
        if (es[i].getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
            String s = expandPath(es[i].getPath(), project);
            if (s != null) {
                l.add(s);
            }
        }
    }
    return l;
}

From source file:org.jboss.tools.common.model.util.EclipseResourceUtil.java

License:Open Source License

public static boolean hasSources(IJavaProject javaProject) throws JavaModelException {
    IClasspathEntry[] es = javaProject.getResolvedClasspath(true);
    for (int i = 0; i < es.length; i++) {
        if (es[i].getEntryKind() == IClasspathEntry.CPE_SOURCE)
            return true;
    }/*from w  w  w  .  j  a  v a2s.  c  o  m*/
    return false;
}

From source file:org.jboss.tools.common.model.util.EclipseResourceUtil.java

License:Open Source License

public static IResource getJavaSourceRoot(IProject project) {
    IJavaProject javaProject = getJavaProject(project);
    if (javaProject == null)
        return null;
    try {//w w w.  j a  v  a2 s  .co m
        IClasspathEntry[] es = javaProject.getResolvedClasspath(true);
        for (int i = 0; i < es.length; i++) {
            if (es[i].getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                IResource findMember = ModelPlugin.getWorkspace().getRoot().findMember(es[i].getPath());
                if (findMember != null && findMember.exists()) {
                    return findMember;
                }
            }
        }
    } catch (JavaModelException ex) {
        ModelPlugin.getPluginLog().logError(ex);
    }
    return null;
}

From source file:org.jboss.tools.common.model.util.EclipseResourceUtil.java

License:Open Source License

public static IResource[] getClasspathResources(IProject project) {
    IJavaProject javaProject = getJavaProject(project);
    if (javaProject == null)
        return new IProject[0];

    ArrayList<IResource> l = new ArrayList<IResource>();

    IClasspathEntry[] es = null;/*  w  w  w  .  jav a 2  s. c om*/

    try {
        es = javaProject.getResolvedClasspath(true);
    } catch (JavaModelException e) {
        //ignore - if project cannot respond, it may not have resources of interest.
        return new IProject[0];
    }

    if (es != null)
        for (int i = 0; i < es.length; i++) {
            if (es[i].getEntryKind() == IClasspathEntry.CPE_PROJECT) {
                IPath path = es[i].getPath();
                IProject p = (IProject) project.getWorkspace().getRoot().findMember(path);
                l.add(p);
            } else if (es[i].getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
                IPath path = es[i].getPath();
                IResource r = project.getWorkspace().getRoot().findMember(path);
                if (r instanceof IContainer) {
                    l.add(r);
                } else if (r != null && !project.getFullPath().isPrefixOf(r.getFullPath())) {
                    l.add(r); //probably it is jar 
                }
            }
        }

    return l.toArray(new IResource[0]);
}

From source file:org.jboss.tools.fuse.transformation.editor.internal.util.JavaUtil.java

License:Open Source License

/**
 * Creates a ClassLoader using the project's build path.
 *
 * @param javaProject the Java project./*www .  ja v a 2s . co m*/
 * @param parentClassLoader the parent class loader, may be null.
 *
 * @return a new ClassLoader based on the project's build path.
 *
 * @throws Exception if something goes wrong.
 */
public static ClassLoader getProjectClassLoader(IJavaProject javaProject, ClassLoader parentClassLoader)
        throws Exception {
    IProject project = javaProject.getProject();
    IWorkspaceRoot root = project.getWorkspace().getRoot();
    List<URL> urls = new ArrayList<>();
    urls.add(new File(project.getLocation() + "/" + javaProject.getOutputLocation().removeFirstSegments(1) //$NON-NLS-1$
            + "/") //$NON-NLS-1$
                    .toURI().toURL());
    for (IClasspathEntry classpathEntry : javaProject.getResolvedClasspath(true)) {
        if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_PROJECT) {
            IPath projectPath = classpathEntry.getPath();
            IProject otherProject = root.getProject(projectPath.segment(0));
            IJavaProject otherJavaProject = JavaCore.create(otherProject);
            urls.add(new File(otherProject.getLocation() + "/" //$NON-NLS-1$
                    + otherJavaProject.getOutputLocation().removeFirstSegments(1) + "/").toURI().toURL()); //$NON-NLS-1$
        } else if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
            urls.add(new File(classpathEntry.getPath().toOSString()).toURI().toURL());
        }
    }
    if (parentClassLoader == null) {
        return new URLClassLoader(urls.toArray(new URL[urls.size()]));
    }
    return new URLClassLoader(urls.toArray(new URL[urls.size()]), parentClassLoader);
}

From source file:org.jboss.tools.jsf.jsf2.bean.scanner.lib.ClassPathMonitor.java

License:Open Source License

public static List<IJSF2Project> getProjects(IProject project) throws CoreException {
    List<IJSF2Project> list = new ArrayList<IJSF2Project>();
    IJavaProject javaProject = EclipseResourceUtil.getJavaProject(project);
    if (javaProject != null) {
        IClasspathEntry[] es = javaProject.getResolvedClasspath(true);
        for (int i = 0; i < es.length; i++) {
            if (es[i].getEntryKind() == IClasspathEntry.CPE_PROJECT) {
                IProject p = ResourcesPlugin.getWorkspace().getRoot().getProject(es[i].getPath().lastSegment());
                if (p == null || !p.isAccessible())
                    continue;
                IJSF2Project sp = JSF2ProjectFactory.getJSF2Project(p, false);
                if (sp != null)
                    list.add(sp);/*from w w w. j  a  va 2 s.co  m*/
            }
        }
    }
    return list;
}

From source file:org.jboss.tools.jst.jsp.bundle.BundleMap.java

License:Open Source License

/**
 * Gets the bundle file based on the locale 
 * from the loaded resource bundle./*  w  w w  .  j  a  va 2s.co  m*/
 *
 * @param uri the uri
 * @return the bundle file
 */
public IFile getBundleFile(String uri) {
    if (project == null || !project.isOpen()) {
        return null;
    }
    try {
        if (!project.hasNature(JavaCore.NATURE_ID)) {
            return null;
        }
        IJavaProject javaProject = JavaCore.create(project);
        IClasspathEntry[] es = javaProject.getResolvedClasspath(true);
        for (int i = 0; i < es.length; i++) {
            if (es[i].getEntryKind() != IClasspathEntry.CPE_SOURCE) {
                continue;
            }
            IFile file = (IFile) project.getWorkspace().getRoot().getFolder(es[i].getPath())
                    .findMember("/" + getBundleFileName(uri)); //$NON-NLS-1$
            if (file != null && file.exists()) {
                return file;
            }
        }
    } catch (CoreException e) {
        JspEditorPlugin.getPluginLog().logError(e);
        return null;
    }
    return null;
}