Search in sources :

Example 16 with IClasspathContainer

use of org.eclipse.jdt.core.IClasspathContainer in project che by eclipse.

the class JavaModelManager method containerGet.

public synchronized IClasspathContainer containerGet(IJavaProject project, IPath containerPath) {
    //        // check initialization in progress first
    if (containerIsInitializationInProgress(project, containerPath)) {
        return CONTAINER_INITIALIZATION_IN_PROGRESS;
    }
    Map projectContainers = (Map) this.containers.get(project);
    if (projectContainers == null) {
        return null;
    }
    IClasspathContainer container = (IClasspathContainer) projectContainers.get(containerPath);
    return container;
}
Also used : IClasspathContainer(org.eclipse.jdt.core.IClasspathContainer) Map(java.util.Map) HashMap(java.util.HashMap) WeakHashMap(java.util.WeakHashMap)

Example 17 with IClasspathContainer

use of org.eclipse.jdt.core.IClasspathContainer in project che by eclipse.

the class JavaModelManager method containerPutIfInitializingWithSameEntries.

public boolean containerPutIfInitializingWithSameEntries(IPath containerPath, IJavaProject[] projects, IClasspathContainer[] respectiveContainers) {
    int projectLength = projects.length;
    if (projectLength != 1)
        return false;
    final IClasspathContainer container = respectiveContainers[0];
    IJavaProject project = projects[0];
    //        // optimize only if initializing, otherwise we are in a regular setContainer(...) call
    if (!containerIsInitializationInProgress(project, containerPath))
        return false;
    IClasspathContainer previousContainer = containerGetDefaultToPreviousSession(project, containerPath);
    if (container == null) {
        if (previousContainer == null) {
            containerPut(project, containerPath, null);
            return true;
        }
        return false;
    }
    final IClasspathEntry[] newEntries = container.getClasspathEntries();
    if (previousContainer == null)
        if (newEntries.length == 0) {
            containerPut(project, containerPath, container);
            return true;
        } else {
            if (CP_RESOLVE_VERBOSE || CP_RESOLVE_VERBOSE_FAILURE)
                verbose_missbehaving_container(containerPath, projects, respectiveContainers, container, newEntries, null);
            return false;
        }
    final IClasspathEntry[] oldEntries = previousContainer.getClasspathEntries();
    if (oldEntries.length != newEntries.length) {
        if (CP_RESOLVE_VERBOSE || CP_RESOLVE_VERBOSE_FAILURE)
            verbose_missbehaving_container(containerPath, projects, respectiveContainers, container, newEntries, oldEntries);
        return false;
    }
    for (int i = 0, length = newEntries.length; i < length; i++) {
        if (newEntries[i] == null) {
            if (CP_RESOLVE_VERBOSE || CP_RESOLVE_VERBOSE_FAILURE)
                verbose_missbehaving_container(project, containerPath, newEntries);
            return false;
        }
        if (!newEntries[i].equals(oldEntries[i])) {
            if (CP_RESOLVE_VERBOSE || CP_RESOLVE_VERBOSE_FAILURE)
                verbose_missbehaving_container(containerPath, projects, respectiveContainers, container, newEntries, oldEntries);
            return false;
        }
    }
    containerPut(project, containerPath, container);
    return true;
}
Also used : IJavaProject(org.eclipse.jdt.core.IJavaProject) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) IClasspathContainer(org.eclipse.jdt.core.IClasspathContainer)

Example 18 with IClasspathContainer

use of org.eclipse.jdt.core.IClasspathContainer in project che by eclipse.

the class JavaModelManager method getClasspathContainer.

public IClasspathContainer getClasspathContainer(final IPath containerPath, final IJavaProject project) throws JavaModelException {
    IClasspathContainer container = containerGet(project, containerPath);
    if (container == null) {
        //            if (batchContainerInitializations()) {
        //                // avoid deep recursion while initializing container on workspace restart
        //                // (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=60437)
        //                try {
        //                    container = initializeAllContainers(project, containerPath);
        //                } finally {
        //                    batchInitializationFinished();
        //                }
        //            } else {
        container = initializeContainer(project, containerPath);
        //                containerBeingInitializedRemove(project, containerPath);
        SetContainerOperation operation = new SetContainerOperation(containerPath, new IJavaProject[] { project }, new IClasspathContainer[] { container });
        operation.runOperation(null);
    //            }
    }
    return container;
}
Also used : IClasspathContainer(org.eclipse.jdt.core.IClasspathContainer)

Example 19 with IClasspathContainer

use of org.eclipse.jdt.core.IClasspathContainer in project che by eclipse.

the class SetContainerOperation method executeOperation.

protected void executeOperation() throws JavaModelException {
    checkCanceled();
    try {
        //$NON-NLS-1$
        beginTask("", 1);
        if (JavaModelManager.CP_RESOLVE_VERBOSE)
            verbose_set_container();
        if (JavaModelManager.CP_RESOLVE_VERBOSE_ADVANCED)
            verbose_set_container_invocation_trace();
        JavaModelManager manager = JavaModelManager.getJavaModelManager();
        if (manager.containerPutIfInitializingWithSameEntries(this.containerPath, this.affectedProjects, this.respectiveContainers))
            return;
        final int projectLength = this.affectedProjects.length;
        final IJavaProject[] modifiedProjects;
        System.arraycopy(this.affectedProjects, 0, modifiedProjects = new IJavaProject[projectLength], 0, projectLength);
        // filter out unmodified project containers
        int remaining = 0;
        for (int i = 0; i < projectLength; i++) {
            if (isCanceled())
                return;
            JavaProject affectedProject = (JavaProject) this.affectedProjects[i];
            IClasspathContainer newContainer = this.respectiveContainers[i];
            // 30920 - prevent infinite loop
            if (newContainer == null)
                newContainer = JavaModelManager.CONTAINER_INITIALIZATION_IN_PROGRESS;
            boolean found = false;
            if (JavaProject.hasJavaNature(affectedProject.getProject())) {
                IClasspathEntry[] rawClasspath = affectedProject.getRawClasspath();
                for (int j = 0, cpLength = rawClasspath.length; j < cpLength; j++) {
                    IClasspathEntry entry = rawClasspath[j];
                    if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER && entry.getPath().equals(this.containerPath)) {
                        found = true;
                        break;
                    }
                }
            }
            if (!found) {
                // filter out this project - does not reference the container path, or isnt't yet Java project
                modifiedProjects[i] = null;
                manager.containerPut(affectedProject, this.containerPath, newContainer);
                continue;
            }
            IClasspathContainer oldContainer = manager.containerGet(affectedProject, this.containerPath);
            if (oldContainer == JavaModelManager.CONTAINER_INITIALIZATION_IN_PROGRESS) {
                oldContainer = null;
            }
            if ((oldContainer != null && oldContainer.equals(this.respectiveContainers[i])) || (oldContainer == this.respectiveContainers[i])) /*handle case where old and new containers are null (see bug 149043*/
            {
                // filter out this project - container did not change
                modifiedProjects[i] = null;
                continue;
            }
            remaining++;
            manager.containerPut(affectedProject, this.containerPath, newContainer);
        }
        if (remaining == 0)
            return;
        // trigger model refresh
        try {
            for (int i = 0; i < projectLength; i++) {
                if (isCanceled())
                    return;
                JavaProject affectedProject = (JavaProject) modifiedProjects[i];
                // was filtered out
                if (affectedProject == null)
                    continue;
                if (JavaModelManager.CP_RESOLVE_VERBOSE_ADVANCED)
                    verbose_update_project(affectedProject);
                // force resolved classpath to be recomputed
                ClasspathChange classpathChange = affectedProject.getPerProjectInfo().resetResolvedClasspath();
                // if needed, generate delta, update project ref, create markers, ...
                classpathChanged(classpathChange, i == 0);
                if (this.canChangeResources) {
                    // touch project to force a build if needed
                    try {
                        affectedProject.getProject().touch(this.progressMonitor);
                    } catch (CoreException e) {
                    // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=148970
                    //							if (!ExternalJavaProject.EXTERNAL_PROJECT_NAME.equals(affectedProject.getElementName()))
                    //								throw e;
                    }
                }
            }
        } catch (CoreException e) {
            if (JavaModelManager.CP_RESOLVE_VERBOSE || JavaModelManager.CP_RESOLVE_VERBOSE_FAILURE)
                verbose_failure(e);
            if (e instanceof JavaModelException) {
                throw (JavaModelException) e;
            } else {
                throw new JavaModelException(e);
            }
        } finally {
            for (int i = 0; i < projectLength; i++) {
                if (this.respectiveContainers[i] == null) {
                    // reset init in progress marker
                    manager.containerPut(this.affectedProjects[i], this.containerPath, null);
                }
            }
        }
    } finally {
        done();
    }
}
Also used : IJavaProject(org.eclipse.jdt.core.IJavaProject) JavaModelException(org.eclipse.jdt.core.JavaModelException) IJavaProject(org.eclipse.jdt.core.IJavaProject) CoreException(org.eclipse.core.runtime.CoreException) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) IClasspathContainer(org.eclipse.jdt.core.IClasspathContainer)

Example 20 with IClasspathContainer

use of org.eclipse.jdt.core.IClasspathContainer in project che by eclipse.

the class JavaSearchScope method add.

/**
     * Add a path to current java search scope or all project fragment roots if null.
     * Use project resolved classpath to retrieve and store access restriction on each classpath entry.
     * Recurse if dependent projects are found.
     * @param javaProject Project used to get resolved classpath entries
     * @param pathToAdd Path to add in case of single element or null if user want to add all project package fragment roots
     * @param includeMask Mask to apply on classpath entries
     * @param projectsToBeAdded Set to avoid infinite recursion
     * @param visitedProjects Set to avoid adding twice the same project
     * @param referringEntry Project raw entry in referring project classpath
     * @throws JavaModelException May happen while getting java model info
     */
void add(JavaProject javaProject, IPath pathToAdd, int includeMask, HashSet projectsToBeAdded, HashSet visitedProjects, IClasspathEntry referringEntry) throws JavaModelException {
    IProject project = javaProject.getProject();
    if (!project.isAccessible() || !visitedProjects.add(project))
        return;
    IPath projectPath = project.getFullPath();
    String projectPathString = projectPath.toString();
    addEnclosingProjectOrJar(projectPath);
    IClasspathEntry[] entries = javaProject.getResolvedClasspath();
    IJavaModel model = javaProject.getJavaModel();
    JavaModelManager.PerProjectInfo perProjectInfo = javaProject.getPerProjectInfo();
    for (int i = 0, length = entries.length; i < length; i++) {
        IClasspathEntry entry = entries[i];
        AccessRuleSet access = null;
        ClasspathEntry cpEntry = (ClasspathEntry) entry;
        if (referringEntry != null) {
            // Source folder are implicitly exported.
            if (!entry.isExported() && entry.getEntryKind() != IClasspathEntry.CPE_SOURCE) {
                continue;
            }
            cpEntry = cpEntry.combineWith((ClasspathEntry) referringEntry);
        //				cpEntry = ((ClasspathEntry)referringEntry).combineWith(cpEntry);
        }
        access = cpEntry.getAccessRuleSet();
        switch(entry.getEntryKind()) {
            case IClasspathEntry.CPE_LIBRARY:
                IClasspathEntry rawEntry = null;
                Map rootPathToRawEntries = perProjectInfo.rootPathToRawEntries;
                if (rootPathToRawEntries != null) {
                    rawEntry = (IClasspathEntry) rootPathToRawEntries.get(entry.getPath());
                }
                if (rawEntry == null)
                    break;
                rawKind: switch(rawEntry.getEntryKind()) {
                    case IClasspathEntry.CPE_LIBRARY:
                    case IClasspathEntry.CPE_VARIABLE:
                        if ((includeMask & APPLICATION_LIBRARIES) != 0) {
                            IPath path = entry.getPath();
                            if (pathToAdd == null || pathToAdd.equals(path)) {
                                Object target = JavaModel.getTarget(path, false);
                                if (// case of an external folder
                                target instanceof IFolder)
                                    path = ((IFolder) target).getFullPath();
                                String pathToString = path.getDevice() == null ? path.toString() : path.toOSString();
                                //$NON-NLS-1$
                                add(projectPath.toString(), "", pathToString, false, /*not a package*/
                                access);
                                addEnclosingProjectOrJar(entry.getPath());
                            }
                        }
                        break;
                    case IClasspathEntry.CPE_CONTAINER:
                        IClasspathContainer container = JavaCore.getClasspathContainer(rawEntry.getPath(), javaProject);
                        if (container == null)
                            break;
                        switch(container.getKind()) {
                            case IClasspathContainer.K_APPLICATION:
                                if ((includeMask & APPLICATION_LIBRARIES) == 0)
                                    break rawKind;
                                break;
                            case IClasspathContainer.K_SYSTEM:
                            case IClasspathContainer.K_DEFAULT_SYSTEM:
                                if ((includeMask & SYSTEM_LIBRARIES) == 0)
                                    break rawKind;
                                break;
                            default:
                                break rawKind;
                        }
                        IPath path = entry.getPath();
                        if (pathToAdd == null || pathToAdd.equals(path)) {
                            Object target = JavaModel.getTarget(path, false);
                            if (// case of an external folder
                            target instanceof IFolder)
                                path = ((IFolder) target).getFullPath();
                            String pathToString = path.getDevice() == null ? path.toString() : path.toOSString();
                            //$NON-NLS-1$
                            add(projectPath.toString(), "", pathToString, false, /*not a package*/
                            access);
                            addEnclosingProjectOrJar(entry.getPath());
                        }
                        break;
                }
                break;
            case IClasspathEntry.CPE_PROJECT:
                if ((includeMask & REFERENCED_PROJECTS) != 0) {
                    IPath path = entry.getPath();
                    if (pathToAdd == null || pathToAdd.equals(path)) {
                        JavaProject referencedProject = (JavaProject) model.getJavaProject(path.toOSString());
                        if (!projectsToBeAdded.contains(referencedProject)) {
                            // do not recurse if depending project was used to create the scope
                            add(referencedProject, null, includeMask, projectsToBeAdded, visitedProjects, cpEntry);
                        }
                    }
                }
                break;
            case IClasspathEntry.CPE_SOURCE:
                if ((includeMask & SOURCES) != 0) {
                    IPath path = entry.getPath();
                    if (pathToAdd == null || pathToAdd.equals(path)) {
                        add(projectPath.toString(), Util.relativePath(path, projectPath.segmentCount()), projectPathString, false, /*not a package*/
                        access);
                    }
                }
                break;
        }
    }
}
Also used : JavaProject(org.eclipse.jdt.internal.core.JavaProject) IJavaProject(org.eclipse.jdt.core.IJavaProject) IPath(org.eclipse.core.runtime.IPath) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) AccessRuleSet(org.eclipse.jdt.internal.compiler.env.AccessRuleSet) IProject(org.eclipse.core.resources.IProject) JavaModelManager(org.eclipse.jdt.internal.core.JavaModelManager) ClasspathEntry(org.eclipse.jdt.internal.core.ClasspathEntry) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) IClasspathContainer(org.eclipse.jdt.core.IClasspathContainer) Map(java.util.Map) IJavaModel(org.eclipse.jdt.core.IJavaModel) IFolder(org.eclipse.core.resources.IFolder)

Aggregations

IClasspathContainer (org.eclipse.jdt.core.IClasspathContainer)34 IClasspathEntry (org.eclipse.jdt.core.IClasspathEntry)16 IJavaProject (org.eclipse.jdt.core.IJavaProject)16 IPath (org.eclipse.core.runtime.IPath)13 CoreException (org.eclipse.core.runtime.CoreException)10 ClasspathContainerInitializer (org.eclipse.jdt.core.ClasspathContainerInitializer)8 ArrayList (java.util.ArrayList)6 JavaModelException (org.eclipse.jdt.core.JavaModelException)6 Map (java.util.Map)5 IProject (org.eclipse.core.resources.IProject)5 HashMap (java.util.HashMap)4 WeakHashMap (java.util.WeakHashMap)3 IClasspathAttribute (org.eclipse.jdt.core.IClasspathAttribute)3 ILiferayRuntime (com.liferay.ide.server.core.ILiferayRuntime)2 PortalBundle (com.liferay.ide.server.core.portal.PortalBundle)2 IResource (org.eclipse.core.resources.IResource)2 IStatus (org.eclipse.core.runtime.IStatus)2 Path (org.eclipse.core.runtime.Path)2 IJavaModelStatus (org.eclipse.jdt.core.IJavaModelStatus)2 ClasspathDecorations (org.eclipse.jst.common.jdt.internal.classpath.ClasspathDecorations)2