Search in sources :

Example 16 with IClasspathEntry

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

the class DeltaProcessor method createExternalArchiveDelta.

/*
     * Check if external archives have changed for the given elements and create the corresponding deltas.
     * Returns whether at least one delta was created.
     */
private boolean createExternalArchiveDelta(HashSet refreshedElements, IProgressMonitor monitor) {
    HashMap externalArchivesStatus = new HashMap();
    boolean hasDelta = false;
    // find JARs to refresh
    HashSet archivePathsToRefresh = new HashSet();
    Iterator iterator = refreshedElements.iterator();
    while (iterator.hasNext()) {
        IJavaElement element = (IJavaElement) iterator.next();
        switch(element.getElementType()) {
            case IJavaElement.PACKAGE_FRAGMENT_ROOT:
                archivePathsToRefresh.add(element.getPath());
                break;
            case IJavaElement.JAVA_PROJECT:
                JavaProject javaProject = (JavaProject) element;
                if (!JavaProject.hasJavaNature(javaProject.getProject())) {
                    // project is not accessible or has lost its Java nature
                    break;
                }
                IClasspathEntry[] classpath;
                try {
                    classpath = javaProject.getResolvedClasspath();
                    for (int j = 0, cpLength = classpath.length; j < cpLength; j++) {
                        if (classpath[j].getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
                            archivePathsToRefresh.add(classpath[j].getPath());
                        }
                    }
                } catch (JavaModelException e) {
                // project doesn't exist -> ignore
                }
                break;
            case IJavaElement.JAVA_MODEL:
                //					}
                throw new UnsupportedOperationException();
        }
    }
    //		}
    return hasDelta;
}
Also used : IJavaElement(org.eclipse.jdt.core.IJavaElement) IJavaProject(org.eclipse.jdt.core.IJavaProject) JavaModelException(org.eclipse.jdt.core.JavaModelException) HashMap(java.util.HashMap) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) Iterator(java.util.Iterator) HashSet(java.util.HashSet)

Example 17 with IClasspathEntry

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

the class JavaProject method getRawClasspath.

/**
     * Returns the raw classpath for the project, as a list of classpath
     * entries. This corresponds to the exact set of entries which were assigned
     * using <code>setRawClasspath</code>, in particular such a classpath may
     * contain classpath variable and classpath container entries. Classpath
     * variable and classpath container entries can be resolved using the
     * helper method <code>getResolvedClasspath</code>; classpath variable
     * entries also can be resolved individually using
     * <code>JavaCore#getClasspathVariable</code>).
     * <p>
     * Both classpath containers and classpath variables provides a level of
     * indirection that can make the <code>.classpath</code> file stable across
     * workspaces.
     * As an example, classpath variables allow a classpath to no longer refer
     * directly to external JARs located in some user specific location.
     * The classpath can simply refer to some variables defining the proper
     * locations of these external JARs. Similarly, classpath containers
     * allows classpath entries to be computed dynamically by the plug-in that
     * defines that kind of classpath container.
     * </p>
     * <p>
     * Note that in case the project isn't yet opened, the classpath will
     * be read directly from the associated <tt>.classpath</tt> file.
     * </p>
     *
     * @return the raw classpath for the project, as a list of classpath entries
     * @throws org.eclipse.jdt.core.JavaModelException
     *         if this element does not exist or if an
     *         exception occurs while accessing its corresponding resource
     * @see org.eclipse.jdt.core.IClasspathEntry
     */
public IClasspathEntry[] getRawClasspath() throws JavaModelException {
    PerProjectInfo perProjectInfo = getPerProjectInfo();
    IClasspathEntry[] classpath = perProjectInfo.rawClasspath;
    if (classpath != null)
        return classpath;
    classpath = perProjectInfo.readAndCacheClasspath(this)[0];
    if (classpath == JavaProject.INVALID_CLASSPATH)
        return defaultClasspath();
    return classpath;
}
Also used : PerProjectInfo(org.eclipse.jdt.internal.core.JavaModelManager.PerProjectInfo) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry)

Example 18 with IClasspathEntry

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

the class JavaModelOperation method getNestedFolders.

protected IPath[] getNestedFolders(IPackageFragmentRoot root) throws JavaModelException {
    IPath rootPath = root.getPath();
    IClasspathEntry[] classpath = root.getJavaProject().getRawClasspath();
    int length = classpath.length;
    IPath[] result = new IPath[length];
    int index = 0;
    for (int i = 0; i < length; i++) {
        IPath path = classpath[i].getPath();
        if (rootPath.isPrefixOf(path) && !rootPath.equals(path)) {
            result[index++] = path;
        }
    }
    if (index < length) {
        System.arraycopy(result, 0, result = new IPath[index], 0, index);
    }
    return result;
}
Also used : IPath(org.eclipse.core.runtime.IPath) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry)

Example 19 with IClasspathEntry

use of org.eclipse.jdt.core.IClasspathEntry 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 20 with IClasspathEntry

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

the class JavaProject method resolveClasspath.

/*
     * Resolve the given perProjectInfo's raw classpath and store the resolved classpath in the perProjectInfo.
     */
public void resolveClasspath(PerProjectInfo perProjectInfo, boolean usePreviousSession, boolean addClasspathChange) throws JavaModelException {
    JavaModelManager manager = getJavaModelManager();
    boolean isClasspathBeingResolved = manager.isClasspathBeingResolved(this);
    try {
        if (!isClasspathBeingResolved) {
            manager.setClasspathBeingResolved(this, true);
        }
        // get raw info inside a synchronized block to ensure that it is consistent
        IClasspathEntry[][] classpath = new IClasspathEntry[2][];
        int timeStamp;
        synchronized (perProjectInfo) {
            classpath[0] = perProjectInfo.rawClasspath;
            classpath[1] = perProjectInfo.referencedEntries;
            // Checking null only for rawClasspath enough
            if (classpath[0] == null)
                classpath = perProjectInfo.readAndCacheClasspath(this);
            timeStamp = perProjectInfo.rawTimeStamp;
        }
        ResolvedClasspath result = resolveClasspath(classpath[0], classpath[1], usePreviousSession, true);
        // store resolved info along with the raw info to ensure consistency
        perProjectInfo.setResolvedClasspath(result.resolvedClasspath, result.referencedEntries, result.rawReverseMap, result.rootPathToResolvedEntries, usePreviousSession ? PerProjectInfo.NEED_RESOLUTION : result.unresolvedEntryStatus, timeStamp, addClasspathChange);
    } finally {
        if (!isClasspathBeingResolved) {
            manager.setClasspathBeingResolved(this, false);
        }
    }
}
Also used : JavaModelManager.getJavaModelManager(org.eclipse.jdt.internal.core.JavaModelManager.getJavaModelManager) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry)

Aggregations

IClasspathEntry (org.eclipse.jdt.core.IClasspathEntry)115 IPath (org.eclipse.core.runtime.IPath)50 IJavaProject (org.eclipse.jdt.core.IJavaProject)40 ArrayList (java.util.ArrayList)34 Path (org.eclipse.core.runtime.Path)25 JavaModelException (org.eclipse.jdt.core.JavaModelException)20 IProject (org.eclipse.core.resources.IProject)17 IClasspathAttribute (org.eclipse.jdt.core.IClasspathAttribute)16 File (java.io.File)15 IFolder (org.eclipse.core.resources.IFolder)13 IPackageFragmentRoot (org.eclipse.jdt.core.IPackageFragmentRoot)13 IJavaElement (org.eclipse.jdt.core.IJavaElement)12 CoreException (org.eclipse.core.runtime.CoreException)11 JavaProject (org.eclipse.jdt.internal.core.JavaProject)11 HashMap (java.util.HashMap)9 IResource (org.eclipse.core.resources.IResource)9 IFile (org.eclipse.core.resources.IFile)8 Test (org.testng.annotations.Test)8 IOException (java.io.IOException)7 URL (java.net.URL)6