Example usage for org.eclipse.jdt.internal.core ExternalFoldersManager getFolder

List of usage examples for org.eclipse.jdt.internal.core ExternalFoldersManager getFolder

Introduction

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

Prototype

public IFolder getFolder(IPath externalFolderPath) 

Source Link

Usage

From source file:in.software.analytics.parichayana.core.internal.builder.ParichayanaBuilder.java

License:Open Source License

private IProject[] getRequiredProjects(boolean includeBinaryPrerequisites) {
    JavaProject javaProject = (JavaProject) JavaCore.create(this.project);
    IWorkspaceRoot workspaceRoot = this.project.getWorkspace().getRoot();
    if (javaProject == null || workspaceRoot == null) {
        return ZERO_PROJECT;
    }//from   w  ww.j a  v a2 s. co  m

    List<IProject> projects = new ArrayList<IProject>();
    ExternalFoldersManager externalFoldersManager = JavaModelManager.getExternalManager();
    try {
        IClasspathEntry[] entries = javaProject.getExpandedClasspath();
        for (int i = 0, l = entries.length; i < l; i++) {
            IClasspathEntry entry = entries[i];
            IPath path = entry.getPath();
            IProject p = null;
            switch (entry.getEntryKind()) {
            case IClasspathEntry.CPE_PROJECT:
                p = workspaceRoot.getProject(path.lastSegment()); // missing projects are considered too
                if (((ClasspathEntry) entry).isOptional() && !JavaProject.hasJavaNature(p)) // except if entry is optional
                    p = null;
                break;
            case IClasspathEntry.CPE_LIBRARY:
                if (includeBinaryPrerequisites && path.segmentCount() > 0) {
                    // some binary resources on the class path can come from projects that are not included in the project references
                    IResource resource = workspaceRoot.findMember(path.segment(0));
                    if (resource instanceof IProject) {
                        p = (IProject) resource;
                    } else {
                        resource = externalFoldersManager.getFolder(path);
                        if (resource != null)
                            p = resource.getProject();
                    }
                }
            }
            if (p != null && !projects.contains(p))
                projects.add(p);
        }
    } catch (JavaModelException e) {
        return ZERO_PROJECT;
    }
    IProject[] result = new IProject[projects.size()];
    projects.toArray(result);
    return result;
}

From source file:net.sf.j2s.core.builder.JavaBuilder.java

License:Open Source License

private IProject[] getRequiredProjects(boolean includeBinaryPrerequisites) {
    if (this.javaProject == null || this.workspaceRoot == null)
        return new IProject[0];

    ArrayList projects = new ArrayList();
    ExternalFoldersManager externalFoldersManager = JavaModelManager.getExternalManager();
    try {/*  ww w. jav a 2 s.c o  m*/
        IClasspathEntry[] entries = this.javaProject.getExpandedClasspath();
        for (int i = 0, l = entries.length; i < l; i++) {
            IClasspathEntry entry = entries[i];
            IPath path = entry.getPath();
            IProject p = null;
            switch (entry.getEntryKind()) {
            case IClasspathEntry.CPE_PROJECT:
                p = this.workspaceRoot.getProject(path.lastSegment()); // missing projects are considered too
                if (((ClasspathEntry) entry).isOptional() && !JavaProject.hasJavaNature(p)) // except if entry is optional
                    p = null;
                break;
            case IClasspathEntry.CPE_LIBRARY:
                if (includeBinaryPrerequisites && path.segmentCount() > 0) {
                    // some binary resources on the class path can come from projects that are not included in the project references
                    IResource resource = this.workspaceRoot.findMember(path.segment(0));
                    if (resource instanceof IProject) {
                        p = (IProject) resource;
                    } else {
                        resource = externalFoldersManager.getFolder(path);
                        if (resource != null)
                            p = resource.getProject();
                    }
                }
            }
            if (p != null && !projects.contains(p))
                projects.add(p);
        }
    } catch (JavaModelException e) {
        return new IProject[0];
    }
    IProject[] result = new IProject[projects.size()];
    projects.toArray(result);
    return result;
}

From source file:org.eclipse.jdt.internal.core.JavaProject.java

License:Open Source License

public boolean contains(IResource resource) {

    IClasspathEntry[] classpath;//from  ww w .j  av a 2 s.  c om
    IPath output;
    try {
        classpath = getResolvedClasspath();
        output = getOutputLocation();
    } catch (JavaModelException e) {
        return false;
    }

    IPath fullPath = resource.getFullPath();
    IPath innerMostOutput = output.isPrefixOf(fullPath) ? output : null;
    IClasspathEntry innerMostEntry = null;
    ExternalFoldersManager foldersManager = JavaModelManager.getExternalManager();
    for (int j = 0, cpLength = classpath.length; j < cpLength; j++) {
        IClasspathEntry entry = classpath[j];

        IPath entryPath = entry.getPath();
        if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
            IResource linkedFolder = foldersManager.getFolder(entryPath);
            if (linkedFolder != null)
                entryPath = linkedFolder.getFullPath();
        }
        if ((innerMostEntry == null || innerMostEntry.getPath().isPrefixOf(entryPath))
                && entryPath.isPrefixOf(fullPath)) {
            innerMostEntry = entry;
        }
        IPath entryOutput = classpath[j].getOutputLocation();
        if (entryOutput != null && entryOutput.isPrefixOf(fullPath)) {
            innerMostOutput = entryOutput;
        }
    }
    if (innerMostEntry != null) {
        // special case prj==src and nested output location
        if (innerMostOutput != null && innerMostOutput.segmentCount() > 1 // output isn't project
                && innerMostEntry.getPath().segmentCount() == 1) { // 1 segment must be project name
            return false;
        }
        if (resource instanceof IFolder) {
            // folders are always included in src/lib entries
            return true;
        }
        switch (innerMostEntry.getEntryKind()) {
        case IClasspathEntry.CPE_SOURCE:
            // .class files are not visible in source folders
            return !org.eclipse.jdt.internal.compiler.util.Util.isClassFileName(fullPath.lastSegment());
        case IClasspathEntry.CPE_LIBRARY:
            // .java files are not visible in library folders
            return !org.eclipse.jdt.internal.core.util.Util.isJavaLikeFileName(fullPath.lastSegment());
        }
    }
    if (innerMostOutput != null) {
        return false;
    }
    return true;
}

From source file:org.jboss.tools.arquillian.core.internal.builder.ArquillianBuilder.java

License:Open Source License

private IProject[] getRequiredProjects(boolean includeBinaryPrerequisites) {
    JavaProject javaProject = (JavaProject) JavaCore.create(this.currentProject);
    IWorkspaceRoot workspaceRoot = this.currentProject.getWorkspace().getRoot();
    if (javaProject == null || workspaceRoot == null)
        return NO_PROJECTS;

    ArrayList projects = new ArrayList();
    ExternalFoldersManager externalFoldersManager = JavaModelManager.getExternalManager();
    try {/* w ww  .  ja v a  2  s .c  o  m*/
        IClasspathEntry[] entries = javaProject.getExpandedClasspath();
        for (int i = 0, l = entries.length; i < l; i++) {
            IClasspathEntry entry = entries[i];
            IPath path = entry.getPath();
            IProject p = null;
            switch (entry.getEntryKind()) {
            case IClasspathEntry.CPE_PROJECT:
                p = workspaceRoot.getProject(path.lastSegment()); // missing projects are considered too
                if (((ClasspathEntry) entry).isOptional() && !JavaProject.hasJavaNature(p)) // except if entry is optional
                    p = null;
                break;
            case IClasspathEntry.CPE_LIBRARY:
                if (includeBinaryPrerequisites && path.segmentCount() > 0) {
                    // some binary resources on the class path can come from projects that are not included in the project references
                    IResource resource = workspaceRoot.findMember(path.segment(0));
                    if (resource instanceof IProject) {
                        p = (IProject) resource;
                    } else {
                        resource = externalFoldersManager.getFolder(path);
                        if (resource != null)
                            p = resource.getProject();
                    }
                }
            }
            if (p != null && !projects.contains(p))
                projects.add(p);
        }
    } catch (JavaModelException e) {
        return NO_PROJECTS;
    }
    IProject[] result = new IProject[projects.size()];
    projects.toArray(result);
    return result;
}