Search in sources :

Example 16 with IFolder

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

the class JavaModelOperation method deleteEmptyPackageFragment.

/**
	 * Convenience method to delete an empty package fragment
	 */
protected void deleteEmptyPackageFragment(IPackageFragment fragment, boolean forceFlag, IResource rootResource) throws JavaModelException {
    IContainer resource = (IContainer) ((JavaElement) fragment).resource();
    try {
        resource.delete(forceFlag ? IResource.FORCE | IResource.KEEP_HISTORY : IResource.KEEP_HISTORY, getSubProgressMonitor(1));
        setAttribute(HAS_MODIFIED_RESOURCE_ATTR, TRUE);
        while (resource instanceof IFolder) {
            // deleting a package: delete the parent if it is empty (e.g. deleting x.y where folder x doesn't have resources but y)
            // without deleting the package fragment root
            resource = resource.getParent();
            if (!resource.equals(rootResource) && resource.members().length == 0) {
                resource.delete(forceFlag ? IResource.FORCE | IResource.KEEP_HISTORY : IResource.KEEP_HISTORY, getSubProgressMonitor(1));
                setAttribute(HAS_MODIFIED_RESOURCE_ATTR, TRUE);
            }
        }
    } catch (CoreException e) {
        throw new JavaModelException(e);
    }
}
Also used : JavaModelException(org.eclipse.jdt.core.JavaModelException) CoreException(org.eclipse.core.runtime.CoreException) IContainer(org.eclipse.core.resources.IContainer) IFolder(org.eclipse.core.resources.IFolder)

Example 17 with IFolder

use of org.eclipse.core.resources.IFolder 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 18 with IFolder

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

the class DeltaProcessor method updateRootIndex.

/*
     * Updates the index of the given root (assuming it's an addition or a removal).
     * This is done recusively, pkg being the current package.
     */
private void updateRootIndex(PackageFragmentRoot root, String[] pkgName, IResourceDelta delta) {
    Openable pkg = root.getPackageFragment(pkgName);
    updateIndex(pkg, delta);
    IResourceDelta[] children = (IResourceDelta[]) delta.getAffectedChildren();
    for (int i = 0, length = children.length; i < length; i++) {
        IResourceDelta child = children[i];
        IResource resource = child.getResource();
        if (resource instanceof IFolder) {
            String[] subpkgName = Util.arrayConcat(pkgName, resource.getName());
            updateRootIndex(root, subpkgName, child);
        }
    }
}
Also used : IResource(org.eclipse.core.resources.IResource) IResourceDelta(org.eclipse.core.resources.IResourceDelta) IFolder(org.eclipse.core.resources.IFolder)

Example 19 with IFolder

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

the class JavaElementResourceMapping method getPackageFragmentTraversals.

private static ResourceTraversal[] getPackageFragmentTraversals(IPackageFragment pack) throws CoreException {
    ArrayList<ResourceTraversal> res = new ArrayList<ResourceTraversal>();
    IContainer container = (IContainer) pack.getResource();
    if (container != null) {
        res.add(new ResourceTraversal(new IResource[] { container }, IResource.DEPTH_ONE, 0));
        if (pack.exists()) {
            // folder may not exist any more, see https://bugs.eclipse.org/bugs/show_bug.cgi?id=269167
            Object[] nonJavaResources = pack.getNonJavaResources();
            for (int i = 0; i < nonJavaResources.length; i++) {
                Object resource = nonJavaResources[i];
                if (resource instanceof IFolder) {
                    res.add(new ResourceTraversal(new IResource[] { (IResource) resource }, IResource.DEPTH_INFINITE, 0));
                }
            }
        }
    }
    return res.toArray(new ResourceTraversal[res.size()]);
}
Also used : ResourceTraversal(org.eclipse.core.resources.mapping.ResourceTraversal) ArrayList(java.util.ArrayList) IContainer(org.eclipse.core.resources.IContainer) IResource(org.eclipse.core.resources.IResource) IFolder(org.eclipse.core.resources.IFolder)

Example 20 with IFolder

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

the class JavaElementResourceMapping method getRemotePackageFragmentTraversals.

private static ResourceTraversal[] getRemotePackageFragmentTraversals(IPackageFragment pack, RemoteResourceMappingContext context, IProgressMonitor monitor) throws CoreException {
    ArrayList<ResourceTraversal> res = new ArrayList<ResourceTraversal>();
    IContainer container = (IContainer) pack.getResource();
    if (container != null) {
        res.add(new ResourceTraversal(new IResource[] { container }, IResource.DEPTH_ONE, 0));
        IResource[] remoteMembers = context.fetchRemoteMembers(container, monitor);
        if (remoteMembers == null) {
            remoteMembers = context.fetchMembers(container, monitor);
        }
        if (remoteMembers != null) {
            for (int i = 0; i < remoteMembers.length; i++) {
                IResource member = remoteMembers[i];
                if (member instanceof IFolder && JavaConventionsUtil.validatePackageName(member.getName(), pack).getSeverity() == IStatus.ERROR) {
                    res.add(new ResourceTraversal(new IResource[] { member }, IResource.DEPTH_INFINITE, 0));
                }
            }
        }
    }
    return res.toArray(new ResourceTraversal[res.size()]);
}
Also used : ResourceTraversal(org.eclipse.core.resources.mapping.ResourceTraversal) ArrayList(java.util.ArrayList) IContainer(org.eclipse.core.resources.IContainer) IResource(org.eclipse.core.resources.IResource) IFolder(org.eclipse.core.resources.IFolder)

Aggregations

IFolder (org.eclipse.core.resources.IFolder)237 IFile (org.eclipse.core.resources.IFile)95 IPath (org.eclipse.core.runtime.IPath)70 CoreException (org.eclipse.core.runtime.CoreException)65 IProject (org.eclipse.core.resources.IProject)64 IResource (org.eclipse.core.resources.IResource)56 File (java.io.File)35 IContainer (org.eclipse.core.resources.IContainer)33 ArrayList (java.util.ArrayList)31 Path (org.eclipse.core.runtime.Path)31 IOException (java.io.IOException)26 ITalendProcessJavaProject (org.talend.core.runtime.process.ITalendProcessJavaProject)26 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)18 Test (org.junit.Test)18 IRunProcessService (org.talend.designer.runprocess.IRunProcessService)17 PersistenceException (org.talend.commons.exception.PersistenceException)16 InputStream (java.io.InputStream)15 IClasspathEntry (org.eclipse.jdt.core.IClasspathEntry)13 IJavaProject (org.eclipse.jdt.core.IJavaProject)13 URL (java.net.URL)12