Example usage for org.eclipse.jdt.internal.core JavaProject getResolvedClasspath

List of usage examples for org.eclipse.jdt.internal.core JavaProject getResolvedClasspath

Introduction

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

Prototype

public IClasspathEntry[] getResolvedClasspath() throws JavaModelException 

Source Link

Usage

From source file:com.cisco.yangide.core.indexing.DeltaProcessor.java

License:Open Source License

private OutputsInfo outputsInfo(IResource res) {
    try {//  w ww . j  a v  a2  s .c  om
        JavaProject proj = (JavaProject) JavaCore.create(res.getProject());
        if (proj != null) {
            IPath projectOutput = proj.getOutputLocation();
            int traverseMode = IGNORE;
            if (proj.getProject().getFullPath().equals(projectOutput)) { // case of
                // proj==bin==src
                return new OutputsInfo(new IPath[] { projectOutput }, new int[] { SOURCE }, 1);
            }
            IClasspathEntry[] classpath = proj.getResolvedClasspath();
            IPath[] outputs = new IPath[classpath.length + 1];
            int[] traverseModes = new int[classpath.length + 1];
            int outputCount = 1;
            outputs[0] = projectOutput;
            traverseModes[0] = traverseMode;
            for (int i = 0, length = classpath.length; i < length; i++) {
                IClasspathEntry entry = classpath[i];
                IPath entryPath = entry.getPath();
                IPath output = entry.getOutputLocation();
                if (output != null) {
                    outputs[outputCount] = output;
                    // check case of src==bin
                    if (entryPath.equals(output)) {
                        traverseModes[outputCount++] = (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE)
                                ? SOURCE
                                : BINARY;
                    } else {
                        traverseModes[outputCount++] = IGNORE;
                    }
                }

                // check case of src==bin
                if (entryPath.equals(projectOutput)) {
                    traverseModes[0] = (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) ? SOURCE : BINARY;
                }
            }
            return new OutputsInfo(outputs, traverseModes, outputCount);
        }
    } catch (JavaModelException e) {
        // java project doesn't exist: ignore
    }
    return null;
}

From source file:com.cisco.yangide.core.indexing.IndexAllProject.java

License:Open Source License

@Override
public boolean execute(IProgressMonitor progressMonitor) {
    System.err.println("[I] Project: " + project.getName());

    if (this.isCancelled || progressMonitor != null && progressMonitor.isCanceled()) {
        return true;
    }//w  ww.ja va  2s  . c  o  m

    if (!this.project.isAccessible()) {
        return true;
    }
    final HashSet<IPath> ignoredPath = new HashSet<IPath>();
    final HashSet<IPath> externalJarsPath = new HashSet<IPath>();
    try {
        JavaProject proj = (JavaProject) JavaCore.create(project);
        final HashSet<String> projectScope = new HashSet<>();
        projectScope.add(project.getName());

        if (proj != null) {
            IClasspathEntry[] classpath = proj.getResolvedClasspath();
            for (int i = 0, length = classpath.length; i < length; i++) {
                IClasspathEntry entry = classpath[i];
                IPath entryPath = entry.getPath();
                IPath output = entry.getOutputLocation();
                if (output != null && !entryPath.equals(output)) {
                    ignoredPath.add(output);
                }

                // index dependencies projects
                if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT) {
                    IProject prj = ResourcesPlugin.getWorkspace().getRoot()
                            .getProject(entry.getPath().lastSegment());
                    if (prj != null && prj.exists()) {
                        this.manager.indexAll(prj);
                        projectScope.add(prj.getName());
                    }
                }
            }
            IPackageFragmentRoot[] roots = proj.getAllPackageFragmentRoots();
            for (int i = 0, length = roots.length; i < length; i++) {
                IPath entryPath = roots[i].getPath();
                if (entryPath != null && entryPath.toFile().exists()
                        && entryPath.lastSegment().toLowerCase().endsWith(".jar")) {
                    externalJarsPath.add(entryPath);
                }
            }
            // Update project information with set of project dependencies
            YangProjectInfo yangProjectInfo = (YangProjectInfo) YangCorePlugin.create(project)
                    .getElementInfo(null);
            yangProjectInfo.setProjectScope(projectScope);
            // fill indirect scope
            HashSet<String> indirectScope = new HashSet<String>();
            indirectScope.add(project.getName());
            for (IJavaProject jproj : JavaCore.create(ResourcesPlugin.getWorkspace().getRoot())
                    .getJavaProjects()) {
                if (jproj != proj) {
                    for (String name : jproj.getRequiredProjectNames()) {
                        if (name.equals(project.getName())) {
                            indirectScope.add(jproj.getProject().getName());
                        }
                    }
                }
            }
            yangProjectInfo.setIndirectScope(indirectScope);
        }
    } catch (JavaModelException | YangModelException e) {
        // java project doesn't exist: ignore
    }

    for (IPath iPath : externalJarsPath) {
        try (JarFile jarFile = new JarFile(iPath.toFile())) {
            ZipEntry entry = jarFile.getEntry("META-INF/yang/");
            if (entry != null) {
                this.manager.addJarFile(project, iPath);
            }
        } catch (IOException e) {
            YangCorePlugin.log(e);
        }
    }
    try {
        final HashSet<IFile> indexedFiles = new HashSet<IFile>();
        project.accept(new IResourceProxyVisitor() {
            @Override
            public boolean visit(IResourceProxy proxy) {
                if (IndexAllProject.this.isCancelled) {
                    return false;
                }
                if (!ignoredPath.isEmpty() && ignoredPath.contains(proxy.requestFullPath())) {
                    return false;
                }
                if (proxy.getType() == IResource.FILE) {
                    if (CoreUtil.isYangLikeFileName(proxy.getName())) {
                        IFile file = (IFile) proxy.requestResource();
                        indexedFiles.add(file);
                    }
                    return false;
                }
                return true;
            }
        }, IResource.NONE);

        for (IFile iFile : indexedFiles) {
            this.manager.addSource(iFile);
        }
    } catch (CoreException e) {
        this.manager.removeIndexFamily(project);
        return false;
    }
    return true;
}

From source file:com.codenvy.ide.ext.java.server.internal.core.JavaProjectElementInfo.java

License:Open Source License

/**
 * Compute the non-java resources contained in this java project.
 *//* w  ww .  j  a v  a  2  s .  c  o m*/
private Object[] computeNonJavaResources(JavaProject project) {

    // determine if src == project and/or if bin == project
    IPath projectPath = project.getProject().getFullPath();
    boolean srcIsProject = false;
    boolean binIsProject = false;
    char[][] inclusionPatterns = null;
    char[][] exclusionPatterns = null;
    IPath projectOutput = null;
    boolean isClasspathResolved = true;
    try {
        IClasspathEntry entry = project.getClasspathEntryFor(projectPath);
        if (entry != null) {
            srcIsProject = true;
            inclusionPatterns = ((ClasspathEntry) entry).fullInclusionPatternChars();
            exclusionPatterns = ((ClasspathEntry) entry).fullExclusionPatternChars();
        }
        projectOutput = project.getOutputLocation();
        binIsProject = projectPath.equals(projectOutput);
    } catch (JavaModelException e) {
        isClasspathResolved = false;
    }

    Object[] resources = new IResource[5];
    int resourcesCounter = 0;
    try {
        IResource[] members = ((IContainer) project.getResource()).members();
        int length = members.length;
        if (length > 0) {
            String sourceLevel = project.getOption(JavaCore.COMPILER_SOURCE, true);
            String complianceLevel = project.getOption(JavaCore.COMPILER_COMPLIANCE, true);
            IClasspathEntry[] classpath = project.getResolvedClasspath();
            for (int i = 0; i < length; i++) {
                IResource res = members[i];
                switch (res.getType()) {
                case IResource.FILE:
                    IPath resFullPath = res.getFullPath();
                    String resName = res.getName();

                    // ignore a jar file on the classpath
                    if (isClasspathResolved && isClasspathEntryOrOutputLocation(resFullPath,
                            res.getLocation()/* see https://bugs.eclipse
                                             .org/bugs/show_bug.cgi?id=244406 */, classpath, projectOutput)) {
                        break;
                    }
                    // ignore .java file if src == project
                    if (srcIsProject && Util.isValidCompilationUnitName(resName, sourceLevel, complianceLevel)
                            && !Util.isExcluded(res, inclusionPatterns, exclusionPatterns)) {
                        break;
                    }
                    // ignore .class file if bin == project
                    if (binIsProject && Util.isValidClassFileName(resName, sourceLevel, complianceLevel)) {
                        break;
                    }
                    // else add non java resource
                    if (resources.length == resourcesCounter) {
                        // resize
                        System.arraycopy(resources, 0, (resources = new IResource[resourcesCounter * 2]), 0,
                                resourcesCounter);
                    }
                    resources[resourcesCounter++] = res;
                    break;
                case IResource.FOLDER:
                    resFullPath = res.getFullPath();

                    // ignore non-excluded folders on the classpath or that correspond to an output location
                    if ((srcIsProject && !Util.isExcluded(res, inclusionPatterns, exclusionPatterns)
                            && Util.isValidFolderNameForPackage(res.getName(), sourceLevel, complianceLevel))
                            || (isClasspathResolved && isClasspathEntryOrOutputLocation(resFullPath,
                                    res.getLocation(), classpath, projectOutput))) {
                        break;
                    }
                    // else add non java resource
                    if (resources.length == resourcesCounter) {
                        // resize
                        System.arraycopy(resources, 0, (resources = new IResource[resourcesCounter * 2]), 0,
                                resourcesCounter);
                    }
                    resources[resourcesCounter++] = res;
                }
            }
        }
        if (resources.length != resourcesCounter) {
            System.arraycopy(resources, 0, (resources = new IResource[resourcesCounter]), 0, resourcesCounter);
        }
    } catch (CoreException e) {
        resources = NO_NON_JAVA_RESOURCES;
        resourcesCounter = 0;
    }
    return resources;
}

From source file:com.codenvy.ide.ext.java.server.internal.core.search.IndexSelector.java

License:Open Source License

private void initializeIndexLocations() {
    IPath[] projectsAndJars = this.searchScope.enclosingProjectsAndJars();
    // use a linked set to preserve the order during search: see bug 348507
    LinkedHashSet locations = new LinkedHashSet();
    IJavaElement focus = MatchLocator.projectOrJarFocus(this.pattern);
    if (focus == null) {
        for (int i = 0; i < projectsAndJars.length; i++) {
            IPath path = projectsAndJars[i];
            Object target = new File(path.toOSString());//JavaModel.getTarget(path, false/*don't check existence*/);
            if (target instanceof IFolder) // case of an external folder
                path = ((IFolder) target).getFullPath();
            locations.add(indexManager.computeIndexLocation(path));
        }/*from w  w w .j a v  a 2s .  com*/
    } else {
        try {
            // See whether the state builder might be used to reduce the number of index locations

            // find the projects from projectsAndJars that see the focus then walk those projects looking for the jars from projectsAndJars
            int length = projectsAndJars.length;
            JavaProject[] projectsCanSeeFocus = new JavaProject[length];
            SimpleSet visitedProjects = new SimpleSet(length);
            int projectIndex = 0;
            SimpleSet externalLibsToCheck = new SimpleSet(length);
            ObjectVector superTypes = new ObjectVector();
            IJavaElement[] focuses = getFocusedElementsAndTypes(this.pattern, focus, superTypes);
            char[][][] focusQualifiedNames = null;
            boolean isAutoBuilding = ResourcesPlugin.getWorkspace().getDescription().isAutoBuilding();
            if (isAutoBuilding && focus instanceof IJavaProject) {
                focusQualifiedNames = getQualifiedNames(superTypes);
            }
            IJavaModel model = JavaModelManager.getJavaModelManager().getJavaModel();
            for (int i = 0; i < length; i++) {
                IPath path = projectsAndJars[i];
                JavaProject project = (JavaProject) getJavaProject(path, model);
                if (project != null) {
                    visitedProjects.add(project);
                    if (canSeeFocus(focuses, project, focusQualifiedNames)) {
                        locations.add(indexManager.computeIndexLocation(path));
                        projectsCanSeeFocus[projectIndex++] = project;
                    }
                } else {
                    externalLibsToCheck.add(path);
                }
            }
            for (int i = 0; i < projectIndex && externalLibsToCheck.elementSize > 0; i++) {
                IClasspathEntry[] entries = projectsCanSeeFocus[i].getResolvedClasspath();
                for (int j = entries.length; --j >= 0;) {
                    IClasspathEntry entry = entries[j];
                    if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
                        IPath path = entry.getPath();
                        if (externalLibsToCheck.remove(path) != null) {
                            Object target = JavaModel.getTarget(path, false/*don't check existence*/);
                            if (target instanceof IFolder) // case of an external folder
                                path = ((IFolder) target).getFullPath();
                            locations.add(indexManager.computeIndexLocation(path));
                        }
                    }
                }
            }
            // jar files can be included in the search scope without including one of the projects that references them, so scan all projects that have not been visited
            if (externalLibsToCheck.elementSize > 0) {
                IJavaProject[] allProjects = model.getJavaProjects();
                for (int i = 0, l = allProjects.length; i < l && externalLibsToCheck.elementSize > 0; i++) {
                    JavaProject project = (JavaProject) allProjects[i];
                    if (!visitedProjects.includes(project)) {
                        IClasspathEntry[] entries = project.getResolvedClasspath();
                        for (int j = entries.length; --j >= 0;) {
                            IClasspathEntry entry = entries[j];
                            if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
                                IPath path = entry.getPath();
                                if (externalLibsToCheck.remove(path) != null) {
                                    Object target = JavaModel.getTarget(path, false/*don't check existence*/);
                                    if (target instanceof IFolder) // case of an external folder
                                        path = ((IFolder) target).getFullPath();
                                    locations.add(indexManager.computeIndexLocation(path));
                                }
                            }
                        }
                    }
                }
            }
        } catch (JavaModelException e) {
            // ignored
        }
    }

    locations.remove(null); // Ensure no nulls
    this.indexLocations = (IndexLocation[]) locations.toArray(new IndexLocation[locations.size()]);
}

From source file:com.codenvy.ide.ext.java.server.internal.core.search.JavaWorkspaceScope.java

License:Open Source License

public IPath[] enclosingProjectsAndJars() {
    IPath[] result = this.enclosingPaths;
    if (result != null) {
        return result;
    }/* w w  w.  ja v a 2s.c o  m*/
    long start = BasicSearchEngine.VERBOSE ? System.currentTimeMillis() : -1;
    try {
        IJavaProject[] projects = JavaModelManager.getJavaModelManager().getJavaModel().getJavaProjects();
        // use a linked set to preserve the order during search: see bug 348507
        Set paths = new LinkedHashSet(projects.length * 2);
        for (int i = 0, length = projects.length; i < length; i++) {
            JavaProject javaProject = (JavaProject) projects[i];

            // Add project full path
            IPath projectPath = javaProject.getProject().getFullPath();
            paths.add(projectPath);
        }

        // add the project source paths first in a separate loop above
        // to ensure source files always get higher precedence during search.
        // see bug 348507

        for (int i = 0, length = projects.length; i < length; i++) {
            JavaProject javaProject = (JavaProject) projects[i];

            // Add project libraries paths
            IClasspathEntry[] entries = javaProject.getResolvedClasspath();
            for (int j = 0, eLength = entries.length; j < eLength; j++) {
                IClasspathEntry entry = entries[j];
                if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
                    IPath path = entry.getPath();
                    Object target = JavaModel.getTarget(path, false/*don't check existence*/);
                    if (target instanceof IFolder) // case of an external folder
                        path = ((IFolder) target).getFullPath();
                    paths.add(entry.getPath());
                }
            }
        }
        result = new IPath[paths.size()];
        paths.toArray(result);
        return this.enclosingPaths = result;
    } catch (JavaModelException e) {
        Util.log(e, "Exception while computing workspace scope's enclosing projects and jars"); //$NON-NLS-1$
        return new IPath[0];
    } finally {
        if (BasicSearchEngine.VERBOSE) {
            long time = System.currentTimeMillis() - start;
            int length = result == null ? 0 : result.length;
            Util.verbose("JavaWorkspaceScope.enclosingProjectsAndJars: " + length + " paths computed in " + time //$NON-NLS-1$//$NON-NLS-2$
                    + "ms."); //$NON-NLS-1$
        }
    }
}

From source file:org.eclipse.che.jdt.internal.core.PackageFragmentRoot.java

License:Open Source License

@Override
public IClasspathEntry getRawClasspathEntry() throws JavaModelException {
    IClasspathEntry rawEntry = null;//from   w w  w. j av a 2  s.  c om
    JavaProject project = (JavaProject) getJavaProject();
    project.getResolvedClasspath(); // force the reverse rawEntry cache to be populated
    Map rootPathToRawEntries = project.resolvedClasspath().rawReverseMap;
    if (rootPathToRawEntries != null) {
        rawEntry = (IClasspathEntry) rootPathToRawEntries.get(getPath());
    }
    if (rawEntry == null) {
        throw new JavaModelException(
                new JavaModelStatus(IJavaModelStatusConstants.ELEMENT_NOT_ON_CLASSPATH, this));
    }
    return rawEntry;
}

From source file:org.eclipse.che.jdt.internal.core.PackageFragmentRoot.java

License:Open Source License

@Override
public IClasspathEntry getResolvedClasspathEntry() throws JavaModelException {
    IClasspathEntry rawEntry = null;// ww  w  . j  av a2  s .c  o m
    JavaProject project = (JavaProject) getJavaProject();
    project.getResolvedClasspath(); // force the reverse rawEntry cache to be populated
    Map rootPathToRawEntries = project.resolvedClasspath().rootPathToResolvedEntries;
    if (rootPathToRawEntries != null) {
        rawEntry = (IClasspathEntry) rootPathToRawEntries.get(getPath());
    }
    if (rawEntry == null) {
        throw new JavaModelException(
                new JavaModelStatus(IJavaModelStatusConstants.ELEMENT_NOT_ON_CLASSPATH, this));
    }
    return rawEntry;
}

From source file:org.eclipse.che.jdt.internal.core.search.IndexSelector.java

License:Open Source License

private void initializeIndexLocations() {
    IPath[] projectsAndJars = this.searchScope.enclosingProjectsAndJars();
    // use a linked set to preserve the order during search: see bug 348507
    LinkedHashSet locations = new LinkedHashSet();
    IJavaElement focus = MatchLocator.projectOrJarFocus(this.pattern);
    if (focus == null) {
        for (int i = 0; i < projectsAndJars.length; i++) {
            IPath path = projectsAndJars[i];
            Object target = new File(path.toOSString());//JavaModel.getTarget(path, false/*don't check existence*/);
            if (target instanceof IFolder) // case of an external folder
                path = ((IFolder) target).getFullPath();
            locations.add(indexManager.computeIndexLocation(path));
        }/*from  www  .j  a v  a  2s  . c  o m*/
    } else {
        try {
            // See whether the state builder might be used to reduce the number of index locations

            // find the projects from projectsAndJars that see the focus then walk those projects looking for the jars from projectsAndJars
            int length = projectsAndJars.length;
            JavaProject[] projectsCanSeeFocus = new JavaProject[length];
            SimpleSet visitedProjects = new SimpleSet(length);
            int projectIndex = 0;
            SimpleSet externalLibsToCheck = new SimpleSet(length);
            ObjectVector superTypes = new ObjectVector();
            IJavaElement[] focuses = getFocusedElementsAndTypes(this.pattern, focus, superTypes);
            char[][][] focusQualifiedNames = null;
            boolean isAutoBuilding = ResourcesPlugin.getWorkspace().getDescription().isAutoBuilding();
            if (isAutoBuilding && focus instanceof IJavaProject) {
                focusQualifiedNames = getQualifiedNames(superTypes);
            }
            IJavaModel model = JavaModelManager.getJavaModelManager().getJavaModel();
            for (int i = 0; i < length; i++) {
                IPath path = projectsAndJars[i];
                JavaProject project = (JavaProject) getJavaProject(path, model);
                if (project != null) {
                    visitedProjects.add(project);
                    int canSeeFocus = canSeeFocus(focuses, project, focusQualifiedNames);
                    if (canSeeFocus == PROJECT_CAN_SEE_FOCUS) {
                        locations.add(indexManager.computeIndexLocation(path));
                    }
                    if (canSeeFocus != PROJECT_CAN_NOT_SEE_FOCUS) {
                        projectsCanSeeFocus[projectIndex++] = project;
                    }
                } else {
                    externalLibsToCheck.add(path);
                }
            }
            for (int i = 0; i < projectIndex && externalLibsToCheck.elementSize > 0; i++) {
                IClasspathEntry[] entries = projectsCanSeeFocus[i].getResolvedClasspath();
                for (int j = entries.length; --j >= 0;) {
                    IClasspathEntry entry = entries[j];
                    if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
                        IPath path = entry.getPath();
                        if (externalLibsToCheck.remove(path) != null) {
                            Object target = JavaModel.getTarget(path, false/*don't check existence*/);
                            if (target instanceof IFolder) // case of an external folder
                                path = ((IFolder) target).getFullPath();
                            locations.add(indexManager.computeIndexLocation(path));
                        }
                    }
                }
            }
            // jar files can be included in the search scope without including one of the projects that references them, so scan all projects that have not been visited
            if (externalLibsToCheck.elementSize > 0) {
                IJavaProject[] allProjects = model.getJavaProjects();
                for (int i = 0, l = allProjects.length; i < l && externalLibsToCheck.elementSize > 0; i++) {
                    JavaProject project = (JavaProject) allProjects[i];
                    if (!visitedProjects.includes(project)) {
                        IClasspathEntry[] entries = project.getResolvedClasspath();
                        for (int j = entries.length; --j >= 0;) {
                            IClasspathEntry entry = entries[j];
                            if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
                                IPath path = entry.getPath();
                                if (externalLibsToCheck.remove(path) != null) {
                                    Object target = JavaModel.getTarget(path, false/*don't check existence*/);
                                    if (target instanceof IFolder) // case of an external folder
                                        path = ((IFolder) target).getFullPath();
                                    locations.add(indexManager.computeIndexLocation(path));
                                }
                            }
                        }
                    }
                }
            }
        } catch (JavaModelException e) {
            // ignored
        }
    }

    locations.remove(null); // Ensure no nulls
    this.indexLocations = (IndexLocation[]) locations.toArray(new IndexLocation[locations.size()]);
}

From source file:org.eclipse.che.jdt.internal.core.search.JavaWorkspaceScope.java

License:Open Source License

public IPath[] enclosingProjectsAndJars() {
    IPath[] result = this.enclosingPaths;
    if (result != null) {
        return result;
    }/*from w w w  . ja va 2  s.co m*/
    long start = org.eclipse.jdt.internal.core.search.BasicSearchEngine.VERBOSE ? System.currentTimeMillis()
            : -1;
    try {
        IJavaProject[] projects = JavaModelManager.getJavaModelManager().getJavaModel().getJavaProjects();
        // use a linked set to preserve the order during search: see bug 348507
        Set paths = new LinkedHashSet(projects.length * 2);
        for (int i = 0, length = projects.length; i < length; i++) {
            JavaProject javaProject = (JavaProject) projects[i];

            // Add project full path
            IPath projectPath = javaProject.getProject().getFullPath();
            paths.add(projectPath);
        }

        // add the project source paths first in a separate loop above
        // to ensure source files always get higher precedence during search.
        // see bug 348507

        for (int i = 0, length = projects.length; i < length; i++) {
            JavaProject javaProject = (JavaProject) projects[i];

            // Add project libraries paths
            IClasspathEntry[] entries = javaProject.getResolvedClasspath();
            for (int j = 0, eLength = entries.length; j < eLength; j++) {
                IClasspathEntry entry = entries[j];
                if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
                    IPath path = entry.getPath();
                    Object target = JavaModel.getTarget(path, false/*don't check existence*/);
                    if (target instanceof IFolder) // case of an external folder
                        path = ((IFolder) target).getFullPath();
                    paths.add(entry.getPath());
                }
            }
        }
        result = new IPath[paths.size()];
        paths.toArray(result);
        return this.enclosingPaths = result;
    } catch (JavaModelException e) {
        Util.log(e, "Exception while computing workspace scope's enclosing projects and jars"); //$NON-NLS-1$
        return new IPath[0];
    } finally {
        if (BasicSearchEngine.VERBOSE) {
            long time = System.currentTimeMillis() - start;
            int length = result == null ? 0 : result.length;
            Util.verbose("JavaWorkspaceScope.enclosingProjectsAndJars: " + length + " paths computed in " + time //$NON-NLS-1$//$NON-NLS-2$
                    + "ms."); //$NON-NLS-1$
        }
    }
}

From source file:org.eclipse.che.plugin.maven.server.classpath.OutputPathTest.java

License:Open Source License

@Test
public void testSourceClasspathEntryShouldHaveOutputLocationPath() throws Exception {
    String pom = "<groupId>test</groupId>" + "<artifactId>testOutputLocation</artifactId>"
            + "<version>42</version>" + "<dependencies>" + "    <dependency>"
            + "        <groupId>junit</groupId>" + "        <artifactId>junit</artifactId>"
            + "        <version>4.12</version>" + "    </dependency>" + "</dependencies>";
    createTestProject("test", pom);

    IProject test = ResourcesPlugin.getWorkspace().getRoot().getProject("test");
    mavenWorkspace.update(Collections.singletonList(test));
    mavenWorkspace.waitForUpdate();/*from   w ww  .j  a va  2s .c o m*/

    JavaProject javaProject = (JavaProject) JavaCore.create(test);
    IClasspathEntry[] classpath = javaProject.getResolvedClasspath();
    IClasspathEntry srcMainJava = null;
    for (IClasspathEntry entry : classpath) {
        if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE
                && entry.getPath().toOSString().endsWith("src/main/java")) {
            srcMainJava = entry;
            break;
        }
    }

    assertThat(srcMainJava).isNotNull();
    assertThat(srcMainJava.getOutputLocation()).isNotNull();
    assertThat(srcMainJava.getOutputLocation().toOSString()).endsWith("target/classes");
}