Search in sources :

Example 86 with IProject

use of org.eclipse.core.resources.IProject in project che by eclipse.

the class JavaSearchScope method packageFragmentRoot.

/**
     * @see AbstractJavaSearchScope#packageFragmentRoot(String, int, String)
     */
public IPackageFragmentRoot packageFragmentRoot(String resourcePathString, int jarSeparatorIndex, String jarPath) {
    int index = -1;
    boolean isJarFile = jarSeparatorIndex != -1;
    if (isJarFile) {
        // internal or external jar (case 3, 4, or 5)
        String relativePath = resourcePathString.substring(jarSeparatorIndex + 1);
        index = indexOf(jarPath, relativePath);
    } else {
        // resource in workspace (case 1 or 2)
        index = indexOf(resourcePathString);
    }
    if (index >= 0) {
        int idx = this.projectIndexes[index];
        String projectPath = idx == -1 ? null : (String) this.projectPaths.get(idx);
        if (projectPath != null) {
            IJavaProject project = JavaCore.create(ResourcesPlugin.getWorkspace().getRoot().getProject(projectPath));
            if (isJarFile) {
                IResource resource = JavaModel.getWorkspaceTarget(new Path(jarPath));
                if (resource != null)
                    return project.getPackageFragmentRoot(resource);
                return project.getPackageFragmentRoot(jarPath);
            }
            Object target = JavaModel.getWorkspaceTarget(new Path(this.containerPaths[index] + '/' + this.relativePaths[index]));
            if (target != null) {
                if (target instanceof IProject) {
                    return project.getPackageFragmentRoot((IProject) target);
                }
                IJavaElement element = JavaModelManager.create((IResource) target, project);
                return (IPackageFragmentRoot) element.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);
            }
        }
    }
    return null;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IJavaElement(org.eclipse.jdt.core.IJavaElement) IJavaProject(org.eclipse.jdt.core.IJavaProject) IResource(org.eclipse.core.resources.IResource) IProject(org.eclipse.core.resources.IProject) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot)

Example 87 with IProject

use of org.eclipse.core.resources.IProject in project che by eclipse.

the class JavaModelManager method removePerProjectInfo.

public void removePerProjectInfo(JavaProject javaProject, boolean removeExtJarInfo) {
    synchronized (this.perProjectInfos) {
        // use the perProjectInfo collection as its own lock
        IProject project = javaProject.getProject();
        PerProjectInfo info = (PerProjectInfo) this.perProjectInfos.get(project);
        if (info != null) {
            this.perProjectInfos.remove(project);
        //                if (removeExtJarInfo) {
        //                    info.forgetExternalTimestampsAndIndexes();
        //                }
        }
    }
    resetClasspathListCache();
}
Also used : IProject(org.eclipse.core.resources.IProject)

Example 88 with IProject

use of org.eclipse.core.resources.IProject in project che by eclipse.

the class JavaModelManager method resetProjectOptions.

/*
 * Reset project options stored in info cache.
 */
public void resetProjectOptions(JavaProject javaProject) {
    synchronized (this.perProjectInfos) {
        // use the perProjectInfo collection as its own lock
        IProject project = javaProject.getProject();
        PerProjectInfo info = (PerProjectInfo) this.perProjectInfos.get(project);
        if (info != null) {
            info.options = null;
        }
    }
}
Also used : IProject(org.eclipse.core.resources.IProject)

Example 89 with IProject

use of org.eclipse.core.resources.IProject in project che by eclipse.

the class JavaModel method getJavaProjects.

/**
 * @see org.eclipse.jdt.core.IJavaModel
 */
public IJavaProject[] getJavaProjects() throws JavaModelException {
    //    ArrayList list = getChildrenOfType(IJavaElement.JAVA_PROJECT);
    // determine my children
    IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
    int length = projects.length;
    IJavaProject[] children = new IJavaProject[length];
    int index = 0;
    for (int i = 0; i < length; i++) {
        IProject project = projects[i];
        if (org.eclipse.jdt.internal.core.JavaProject.hasJavaNature(project)) {
            children[index++] = getJavaProject(project);
        }
    }
    if (index < length)
        System.arraycopy(children, 0, children = new IJavaProject[index], 0, index);
    //    list.toArray(array);
    return children;
}
Also used : IJavaProject(org.eclipse.jdt.core.IJavaProject) IProject(org.eclipse.core.resources.IProject)

Example 90 with IProject

use of org.eclipse.core.resources.IProject in project che by eclipse.

the class JavaProject method computePackageFragmentRoots.

/**
     * Returns the package fragment roots identified by the given entry. In case it refers to
     * a project, it will follow its classpath so as to find exported roots as well.
     * Only works with resolved entry
     *
     * @param resolvedEntry
     *         IClasspathEntry
     * @param accumulatedRoots
     *         ObjectVector
     * @param rootIDs
     *         HashSet
     * @param referringEntry
     *         the CP entry (project) referring to this entry, or null if initial project
     * @param retrieveExportedRoots
     *         boolean
     * @throws JavaModelException
     */
public void computePackageFragmentRoots(IClasspathEntry resolvedEntry, ObjectVector accumulatedRoots, HashSet rootIDs, IClasspathEntry referringEntry, boolean retrieveExportedRoots, Map rootToResolvedEntries) throws JavaModelException {
    String rootID = ((ClasspathEntry) resolvedEntry).rootID();
    if (rootIDs.contains(rootID))
        return;
    IPath projectPath = this.project.getFullPath();
    IPath entryPath = resolvedEntry.getPath();
    IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
    IPackageFragmentRoot root = null;
    switch(resolvedEntry.getEntryKind()) {
        // source folder
        case IClasspathEntry.CPE_SOURCE:
            if (projectPath.isPrefixOf(entryPath)) {
                Object target = getTarget(entryPath, true);
                if (target == null)
                    return;
                if (target instanceof IFolder || target instanceof IProject) {
                    root = getPackageFragmentRoot((IResource) target);
                }
            }
            break;
        // internal/external JAR or folder
        case IClasspathEntry.CPE_LIBRARY:
            if (referringEntry != null && !resolvedEntry.isExported())
                return;
            Object target = getTarget(entryPath, true);
            if (target == null)
                return;
            if (target instanceof IResource) {
                //                    // internal target
                root = getPackageFragmentRoot((IResource) target, entryPath);
            } else if (target instanceof File) {
                // external target
                if (isFile(target)) {
                    root = new JarPackageFragmentRoot(entryPath, this);
                } else if (((File) target).isDirectory()) {
                    //                        root = new ExternalPackageFragmentRoot(entryPath, this);
                    throw new UnsupportedOperationException();
                }
            }
            break;
        // recurse into required project
        case IClasspathEntry.CPE_PROJECT:
            if (!retrieveExportedRoots)
                return;
            if (referringEntry != null && !resolvedEntry.isExported())
                return;
            IResource member = workspaceRoot.findMember(entryPath);
            if (member != null && member.getType() == IResource.PROJECT) {
                // double check if bound to project (23977)
                IProject requiredProjectRsc = (IProject) member;
                if (org.eclipse.jdt.internal.core.JavaProject.hasJavaNature(requiredProjectRsc)) {
                    // special builder binary output
                    rootIDs.add(rootID);
                    org.eclipse.jdt.internal.core.JavaProject requiredProject = (org.eclipse.jdt.internal.core.JavaProject) JavaCore.create(requiredProjectRsc);
                    requiredProject.computePackageFragmentRoots(requiredProject.getResolvedClasspath(), accumulatedRoots, rootIDs, rootToResolvedEntries == null ? resolvedEntry : ((ClasspathEntry) resolvedEntry).combineWith((ClasspathEntry) referringEntry), // only combine if need to build the reverse map
                    retrieveExportedRoots, rootToResolvedEntries);
                }
                break;
            }
    }
    if (root != null) {
        accumulatedRoots.add(root);
        rootIDs.add(rootID);
        if (rootToResolvedEntries != null)
            rootToResolvedEntries.put(root, ((ClasspathEntry) resolvedEntry).combineWith((ClasspathEntry) referringEntry));
    }
}
Also used : IJavaProject(org.eclipse.jdt.core.IJavaProject) IPath(org.eclipse.core.runtime.IPath) IProject(org.eclipse.core.resources.IProject) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) JavaModelManager.isFile(org.eclipse.jdt.internal.core.JavaModelManager.isFile) IFile(org.eclipse.core.resources.IFile) File(java.io.File) IResource(org.eclipse.core.resources.IResource) IFolder(org.eclipse.core.resources.IFolder)

Aggregations

IProject (org.eclipse.core.resources.IProject)665 CoreException (org.eclipse.core.runtime.CoreException)157 IFile (org.eclipse.core.resources.IFile)142 Test (org.junit.Test)130 IResource (org.eclipse.core.resources.IResource)112 IPath (org.eclipse.core.runtime.IPath)98 IFolder (org.eclipse.core.resources.IFolder)77 File (java.io.File)73 IOException (java.io.IOException)70 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)70 Path (org.eclipse.core.runtime.Path)70 IJavaProject (org.eclipse.jdt.core.IJavaProject)68 ArrayList (java.util.ArrayList)67 IWorkspace (org.eclipse.core.resources.IWorkspace)55 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)48 ByteArrayInputStream (java.io.ByteArrayInputStream)45 ProjectAdapter (org.apache.sling.ide.test.impl.helpers.ProjectAdapter)45 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)41 IProjectDescription (org.eclipse.core.resources.IProjectDescription)38 IStatus (org.eclipse.core.runtime.IStatus)35