Search in sources :

Example 41 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 42 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 43 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 44 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)

Example 45 with IProject

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

the class DeltaProcessor method traverseDelta.

/*
     * Converts an <code>IResourceDelta</code> and its children into
     * the corresponding <code>IJavaElementDelta</code>s.
     */
private void traverseDelta(IResourceDelta delta, int elementType, RootInfo rootInfo, OutputsInfo outputsInfo) {
    IResource res = delta.getResource();
    // set stack of elements
    if (this.currentElement == null && rootInfo != null) {
        this.currentElement = rootInfo.project;
    }
    // process current delta
    boolean processChildren = true;
    if (res instanceof IProject) {
        // reset source element parser cache
        this.sourceElementParserCache = null;
        processChildren = updateCurrentDeltaAndIndex(delta, elementType == IJavaElement.PACKAGE_FRAGMENT_ROOT ? // case of prj=src
        IJavaElement.JAVA_PROJECT : elementType, rootInfo);
    } else if (rootInfo != null) {
        processChildren = updateCurrentDeltaAndIndex(delta, elementType, rootInfo);
    } else {
        // not yet inside a package fragment root
        processChildren = true;
    }
    // process children if needed
    if (processChildren) {
        IResourceDelta[] children = (IResourceDelta[]) delta.getAffectedChildren();
        boolean oneChildOnClasspath = false;
        int length = children.length;
        IResourceDelta[] orphanChildren = null;
        Openable parent = null;
        boolean isValidParent = true;
        for (int i = 0; i < length; i++) {
            IResourceDelta child = children[i];
            IResource childRes = child.getResource();
            // check source attachment change
            checkSourceAttachmentChange(child, childRes);
            // find out whether the child is a package fragment root of the current project
            IPath childPath = externalPath(childRes);
            int childKind = child.getKind();
            RootInfo childRootInfo = rootInfo(childPath, childKind);
            RootInfo originalChildRootInfo = childRootInfo;
            if (childRootInfo != null && !childRootInfo.isRootOfProject(childPath)) {
                // package fragment root of another project (dealt with later)
                childRootInfo = null;
            }
            // compute child type
            int childType = elementType(childRes, childKind, elementType, rootInfo == null ? childRootInfo : rootInfo);
            // is childRes in the output folder and is it filtered out ?
            boolean isResFilteredFromOutput = isResFilteredFromOutput(rootInfo, outputsInfo, childRes, childType);
            boolean isNestedRoot = rootInfo != null && childRootInfo != null;
            if (!isResFilteredFromOutput && !isNestedRoot) {
                // do not treat as non-java rsc if nested root
                traverseDelta(child, childType, rootInfo == null ? childRootInfo : rootInfo, // traverse delta for child in the same project
                outputsInfo);
                if (childType == NON_JAVA_RESOURCE) {
                    if (rootInfo != null) {
                        // if inside a package fragment root
                        if (!isValidParent)
                            continue;
                        if (parent == null) {
                            // find the parent of the non-java resource to attach to
                            if (this.currentElement == null || !rootInfo.project.equals(this.currentElement.getJavaProject())) {
                                // note if currentElement is the
                                // IJavaModel, getJavaProject() is null
                                // force the currentProject to be used
                                this.currentElement = rootInfo.project;
                            }
                            if (elementType == IJavaElement.JAVA_PROJECT || (elementType == IJavaElement.PACKAGE_FRAGMENT_ROOT && res instanceof IProject)) {
                                // NB: attach non-java resource to project (not to its package fragment root)
                                parent = rootInfo.project;
                            } else {
                                parent = createElement(res, elementType, rootInfo);
                            }
                            if (parent == null) {
                                isValidParent = false;
                                continue;
                            }
                        }
                        // add child as non java resource
                        try {
                            nonJavaResourcesChanged(parent, child);
                        } catch (JavaModelException e) {
                        // ignore
                        }
                    } else {
                        // the non-java resource (or its parent folder) will be attached to the java project
                        if (orphanChildren == null)
                            orphanChildren = new IResourceDelta[length];
                        orphanChildren[i] = child;
                    }
                } else {
                    if (rootInfo == null && childRootInfo == null) {
                        // the non-java resource (or its parent folder) will be attached to the java project
                        if (orphanChildren == null)
                            orphanChildren = new IResourceDelta[length];
                        orphanChildren[i] = child;
                    }
                }
            } else {
                // to avoid reporting child delta as non-java resource delta
                oneChildOnClasspath = true;
            }
            // but it is a package fragment root of another project, traverse delta too
            if (isNestedRoot || (childRootInfo == null && originalChildRootInfo != null)) {
                traverseDelta(child, IJavaElement.PACKAGE_FRAGMENT_ROOT, originalChildRootInfo, // binary output of childRootInfo.project cannot be this root
                null);
            }
            // if the child is a package fragment root of one or several other projects
            ArrayList rootList;
            if ((rootList = otherRootsInfo(childPath, childKind)) != null) {
                Iterator iterator = rootList.iterator();
                while (iterator.hasNext()) {
                    originalChildRootInfo = (RootInfo) iterator.next();
                    this.currentElement = // ensure that 2 roots refering to the same resource don't share the current element (see
                    null;
                    // https://bugs.eclipse.org/bugs/show_bug.cgi?id=210746 )
                    traverseDelta(child, IJavaElement.PACKAGE_FRAGMENT_ROOT, originalChildRootInfo, // binary output of childRootInfo.project cannot be this root
                    null);
                }
            }
        }
        if (orphanChildren != null && (// orphan children are siblings of a package fragment root
        oneChildOnClasspath || res instanceof IProject)) {
        // non-java resource directly under a project
        //				// attach orphan children
        //				IProject rscProject = res.getProject();
        //				JavaProject adoptiveProject = (JavaProject)JavaCore.create(rscProject);
        //				if (adoptiveProject != null
        //						&& JavaProject.hasJavaNature(rscProject)) { // delta iff Java project (18698)
        //					for (int i = 0; i < length; i++) {
        //						if (orphanChildren[i] != null) {
        //							try {
        //								nonJavaResourcesChanged(adoptiveProject, orphanChildren[i]);
        //							} catch (JavaModelException e) {
        //								// ignore
        //							}
        //						}
        //					}
        //				}
        }
    // else resource delta will be added by parent
    }
// else resource delta will be added by parent
}
Also used : JavaModelException(org.eclipse.jdt.core.JavaModelException) IPath(org.eclipse.core.runtime.IPath) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) IResource(org.eclipse.core.resources.IResource) IProject(org.eclipse.core.resources.IProject) IResourceDelta(org.eclipse.core.resources.IResourceDelta)

Aggregations

IProject (org.eclipse.core.resources.IProject)2658 IFile (org.eclipse.core.resources.IFile)642 CoreException (org.eclipse.core.runtime.CoreException)598 Test (org.junit.Test)483 IPath (org.eclipse.core.runtime.IPath)408 IFolder (org.eclipse.core.resources.IFolder)339 IResource (org.eclipse.core.resources.IResource)305 File (java.io.File)279 ArrayList (java.util.ArrayList)270 Path (org.eclipse.core.runtime.Path)268 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)259 IOException (java.io.IOException)201 IJavaProject (org.eclipse.jdt.core.IJavaProject)193 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)186 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)175 IProjectDescription (org.eclipse.core.resources.IProjectDescription)161 IWorkspace (org.eclipse.core.resources.IWorkspace)138 IStatus (org.eclipse.core.runtime.IStatus)124 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)116 List (java.util.List)109