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.jst.web.kb.internal.scanner.ClassPathMonitor.java

License:Open Source License

List<KbProject> getKbProjects(IProject project) throws CoreException {
    List<KbProject> list = new ArrayList<KbProject>();
    if (project.isAccessible() && project.hasNature(JavaCore.NATURE_ID)) {
        IJavaProject javaProject = JavaCore.create(project);
        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;
                KbProject.checkKBBuilderInstalled(p);
                IKbProject sp = KbProjectFactory.getKbProject(p, false);
                if (sp != null)
                    list.add((KbProject) sp);
            }/* ww  w. j av  a2  s.  c  o m*/
        }

    }
    return list;
}

From source file:org.jboss.tools.jst.web.ui.internal.editor.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  v  a  2 s. c  o 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) {
        WebUiPlugin.getPluginLog().logError(e);
        return null;
    }
    return null;
}

From source file:org.jboss.tools.jst.web.ui.operation.RemoveJavaSource.java

License:Open Source License

public void execute(IProject project) {
    IJavaProject javaProject = JavaCore.create(project);
    try {//from  w  ww .  j ava  2s.  c o m
        IClasspathEntry[] oldEntries = javaProject.getResolvedClasspath(true);
        ArrayList list = new ArrayList();
        ArrayList src = new ArrayList();
        for (int i = 0; i < oldEntries.length; i++) {
            if (oldEntries[i].getEntryKind() != IClasspathEntry.CPE_SOURCE) {
                list.add(oldEntries[i]);
            } else {
                IResource r = project.findMember(oldEntries[i].getPath().removeFirstSegments(1));
                src.add(r);
            }
        }
        IClasspathEntry[] classpathEntries = (IClasspathEntry[]) list.toArray(new IClasspathEntry[0]);
        javaProject.setRawClasspath(classpathEntries, null);
        IResource[] rs = (IResource[]) src.toArray(new IResource[0]);
        for (int i = 0; i < rs.length; i++) {
            try {
                if (rs[i] != null)
                    rs[i].delete(true, null);
            } catch (CoreException ce) {
                WebUiPlugin.getPluginLog().logError(ce);
            }
        }
    } catch (JavaModelException e) {
        WebUiPlugin.getPluginLog().logError(e);
    }
}

From source file:org.jboss.tools.openshift.core.server.behavior.springboot.OpenShiftSpringBootProfileDetector.java

License:Open Source License

private boolean hasSpringBootDependency(IProject eclipseProject) {
    boolean hasSpringBootDependency = false;
    try {//from  w  w w .ja va2s .com
        if (eclipseProject.hasNature(JavaCore.NATURE_ID)) {
            IJavaProject javaProject = JavaCore.create(eclipseProject);
            IClasspathEntry[] classpath = javaProject.getResolvedClasspath(true);
            hasSpringBootDependency = Stream.of(classpath).anyMatch(classpathEntry -> classpathEntry.getPath()
                    .lastSegment().contains(COMPONENT_OF_SPRINGBOOT_APP));
        }
    } catch (CoreException e) {
        OpenShiftCoreActivator
                .logError(NLS.bind("Cannot determine if the project {0} is a SpringBoot starter one.",
                        eclipseProject.getName()), e);
    }
    return hasSpringBootDependency;
}

From source file:org.jboss.tools.portlet.ui.internal.wizard.xpl.NewJavaClassWizardPageEx.java

License:Open Source License

/**
 * /*from w ww .  j  a va2s  .com*/
 **/
private IFolder getDefaultJavaSourceFolder(IProject project) {

    if (project == null)
        return null;
    IPackageFragmentRoot[] sources = J2EEProjectUtilities.getSourceContainers(project);
    // Try and return the first source folder
    if (sources.length > 0) {
        try {
            return (IFolder) sources[0].getCorrespondingResource();
        } catch (Exception e) {
            return null;
        }
    }
    IJavaProject javaProject = JavaCore.create(project);
    if (javaProject == null) {
        return null;
    }
    try {
        IClasspathEntry[] entries = javaProject.getResolvedClasspath(false);
        for (int i = 0; i < entries.length; i++) {
            IClasspathEntry entry = entries[i];
            if (entry.getContentKind() == IPackageFragmentRoot.K_SOURCE) {
                IPath path = entry.getPath();
                IResource resource = ResourcesPlugin.getWorkspace().getRoot().findMember(path);
                if (resource instanceof IFolder) {
                    return (IFolder) resource;
                }
            }
        }
    } catch (JavaModelException e) {
        // ignore
    }
    return null;
}

From source file:org.jboss.tools.seam.internal.core.scanner.lib.ClassPath.java

License:Open Source License

List<SeamProject> getSeamProjects(IProject project) throws CoreException {
    List<SeamProject> list = new ArrayList<SeamProject>();
    if (project.isAccessible() && project.hasNature(JavaCore.NATURE_ID)) {
        IJavaProject javaProject = JavaCore.create(project);
        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;
                ISeamProject sp = SeamCorePlugin.getSeamProject(p, false);
                if (sp != null)
                    list.add((SeamProject) sp);
            }//from  w w w  .  j av  a  2 s .  c om
        }
    }
    return list;
}

From source file:org.jboss.tools.seam.internal.core.SeamResourceVisitor.java

License:Open Source License

void getJavaSourceRoots(IProject project) {
    IJavaProject javaProject = EclipseResourceUtil.getJavaProject(project);
    if (javaProject == null)
        return;/*w ww.java  2s .  co  m*/
    List<IPath> ps = new ArrayList<IPath>();
    List<IPath> os = new ArrayList<IPath>();
    try {
        IPath output = javaProject.getOutputLocation();
        if (output != null)
            os.add(output);
        IClasspathEntry[] es = javaProject.getResolvedClasspath(true);
        for (int i = 0; i < es.length; i++) {
            if (es[i].getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                IResource findMember = ResourcesPlugin.getWorkspace().getRoot().findMember(es[i].getPath());
                if (findMember != null && findMember.exists()) {
                    ps.add(findMember.getFullPath());
                }
                IPath out = es[i].getOutputLocation();
                if (out != null && !os.contains(out)) {
                    os.add(out);
                }
            }
        }
        srcs = ps.toArray(new IPath[ps.size()]);
        outs = os.toArray(new IPath[os.size()]);
    } catch (CoreException ce) {
        ModelPlugin.getPluginLog().logError("Error while locating java source roots for " + project, ce);
    }
}

From source file:org.jboss.tools.seam.ui.preferences.SeamSettingsPreferencePage.java

License:Open Source License

private String getJBossSeamJarLocation() {
    IJavaProject jp = EclipseResourceUtil.getJavaProject(project);
    if (jp == null)
        return null;
    IClasspathEntry[] es = null;/*from  w  w w . j  a va2 s .c  o  m*/
    try {
        es = jp.getResolvedClasspath(true);
    } catch (JavaModelException e) {
        //ignore
        return null;
    }
    if (es == null)
        return null;
    for (int i = 0; i < es.length; i++) {
        IPath p = es[i].getPath();
        if (p != null && p.lastSegment().equalsIgnoreCase("jboss-seam.jar")) {
            IFile f = ResourcesPlugin.getWorkspace().getRoot().getFile(p);
            if (f != null && f.exists())
                return f.getLocation().toString();
        }
    }
    return null;
}

From source file:org.jboss.tools.servers.wildfly.swarm.core.internal.WildlfySwarmDetectionJob.java

License:Open Source License

private boolean isWildflySwarmProject(IJavaProject p) {
    if (!p.getProject().isAccessible()) {
        return false;
    }//from  w w  w  . ja  v a 2s . co m
    try {
        IClasspathEntry[] resolvedClasspath = p.getResolvedClasspath(true);
        Stream<IClasspathEntry> classpath = Stream.of(resolvedClasspath);//.parallel();
        return classpath.filter(cpe -> isSwarmEntry(cpe)).findFirst().isPresent();
    } catch (JavaModelException e) {
        e.printStackTrace();
    }
    return false;
}

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

License:Open Source License

private String[] getClasspathForJavaProject(IJavaProject javaProject) {
    ArrayList<String> projectClasspath = new ArrayList<String>();
    try {/*from www  .  ja v  a 2 s  . c om*/
        IClasspathEntry[] buildPath = javaProject.getResolvedClasspath(true);
        for (int i = 0; i < buildPath.length; i++) {
            String[] buildPathString = classpathEntryToString(buildPath[i], javaProject.getProject());
            for (int j = 0; j < buildPathString.length; j++) {
                projectClasspath.add(buildPathString[j]);
            }
        }
    } catch (JavaModelException jme) {
    }

    String[] utilityJarsClasspath;
    IProject project = javaProject.getProject();
    IProject[] referencingProjects = project.getReferencingProjects();
    for (int i = 0; i < referencingProjects.length; i++) {
        utilityJarsClasspath = getUtilityJarClasspath(referencingProjects[i]);
        for (int j = 0; j < utilityJarsClasspath.length; j++) {
            projectClasspath.add(utilityJarsClasspath[j]);
        }
    }

    return (String[]) projectClasspath.toArray(new String[projectClasspath.size()]);
}