Search in sources :

Example 1 with IFolder

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

the class Util method getJdkLevel.

/**
     * Get the jdk level of this root.
     * The value can be:
     * <ul>
     * <li>major<<16 + minor : see predefined constants on ClassFileConstants </li>
     * <li><code>0</null> if the root is a source package fragment root or if a Java model exception occured</li>
     * </ul>
     * Returns the jdk level
     */
public static long getJdkLevel(Object targetLibrary) {
    try {
        ClassFileReader reader = null;
        if (targetLibrary instanceof IFolder) {
            // only internal classfolders are allowed
            IFile classFile = findFirstClassFile((IFolder) targetLibrary);
            if (classFile != null)
                reader = Util.newClassFileReader(classFile);
        } else {
            // root is a jar file or a zip file
            ZipFile jar = null;
            try {
                IPath path = null;
                if (targetLibrary instanceof IResource) {
                    path = ((IResource) targetLibrary).getFullPath();
                } else if (targetLibrary instanceof File) {
                    File f = (File) targetLibrary;
                    if (!f.isDirectory()) {
                        path = new Path(((File) targetLibrary).getPath());
                    }
                }
                if (path != null) {
                    jar = JavaModelManager.getJavaModelManager().getZipFile(path);
                    for (Enumeration e = jar.entries(); e.hasMoreElements(); ) {
                        ZipEntry member = (ZipEntry) e.nextElement();
                        String entryName = member.getName();
                        if (org.eclipse.jdt.internal.compiler.util.Util.isClassFileName(entryName)) {
                            reader = ClassFileReader.read(jar, entryName);
                            break;
                        }
                    }
                }
            } catch (CoreException e) {
            // ignore
            } finally {
                JavaModelManager.getJavaModelManager().closeZipFile(jar);
            }
        }
        if (reader != null) {
            return reader.getVersion();
        }
    } catch (CoreException e) {
    // ignore
    } catch (ClassFormatException e) {
    // ignore
    } catch (IOException e) {
    // ignore
    }
    return 0;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IFile(org.eclipse.core.resources.IFile) Enumeration(java.util.Enumeration) IPath(org.eclipse.core.runtime.IPath) IClassFileReader(org.eclipse.jdt.core.util.IClassFileReader) ClassFileReader(org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader) ZipEntry(java.util.zip.ZipEntry) IOException(java.io.IOException) ClassFormatException(org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException) ZipFile(java.util.zip.ZipFile) CoreException(org.eclipse.core.runtime.CoreException) IClassFile(org.eclipse.jdt.core.IClassFile) ClassFile(org.eclipse.jdt.internal.core.ClassFile) ZipFile(java.util.zip.ZipFile) IFile(org.eclipse.core.resources.IFile) File(java.io.File) IResource(org.eclipse.core.resources.IResource) IFolder(org.eclipse.core.resources.IFolder)

Example 2 with IFolder

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

the class RenamePackageProcessor method getRefactoredResource.

//---- IResourceMapper  ----------------------------------
public IResource getRefactoredResource(IResource element) {
    IFolder packageFolder = (IFolder) fPackage.getResource();
    if (packageFolder == null)
        return element;
    IContainer newPackageFolder = (IContainer) getNewPackage().getResource();
    if (packageFolder.equals(element))
        return newPackageFolder;
    IPath packagePath = packageFolder.getProjectRelativePath();
    IPath elementPath = element.getProjectRelativePath();
    if (packagePath.isPrefixOf(elementPath)) {
        if (fRenameSubpackages || (element instanceof IFile && packageFolder.equals(element.getParent()))) {
            IPath pathInPackage = elementPath.removeFirstSegments(packagePath.segmentCount());
            if (element instanceof IFile)
                return newPackageFolder.getFile(pathInPackage);
            else
                return newPackageFolder.getFolder(pathInPackage);
        }
    }
    return element;
}
Also used : IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) IContainer(org.eclipse.core.resources.IContainer) IFolder(org.eclipse.core.resources.IFolder)

Example 3 with IFolder

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

the class RenameModifications method addAllResourceModifications.

private void addAllResourceModifications(IPackageFragment rootPackage, RenameArguments args, boolean renameSubPackages, IPackageFragment[] allSubPackages) throws CoreException {
    IFolder target = addResourceModifications(rootPackage, args, rootPackage, renameSubPackages);
    if (renameSubPackages) {
        IContainer container = (IContainer) rootPackage.getResource();
        if (container == null)
            return;
        boolean removeContainer = !container.contains(target);
        for (int i = 0; i < allSubPackages.length; i++) {
            IPackageFragment pack = allSubPackages[i];
            IFolder subTarget = addResourceModifications(rootPackage, args, pack, renameSubPackages);
            if (container.contains(subTarget))
                removeContainer = false;
        }
        if (removeContainer) {
            getResourceModifications().addDelete(container);
        }
    }
}
Also used : IPackageFragment(org.eclipse.jdt.core.IPackageFragment) IContainer(org.eclipse.core.resources.IContainer) IFolder(org.eclipse.core.resources.IFolder)

Example 4 with IFolder

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

the class ImportOperation method collectExistingReadonlyFiles.

/**
     * Prompts if existing resources should be overwritten. Recursively collects
     * existing read-only files to overwrite and resources that should not be
     * overwritten.
     *
     * @param sourceStart destination path to check for existing files
     * @param sources file system objects that may exist in the destination
     * @param noOverwrite files that were selected to be skipped (don't overwrite).
     * 	object type IPath
     * @param overwriteReadonly the collected existing read-only files to overwrite.
     * 	object type IPath
     * @param policy on of the POLICY constants defined in the
     * class.
     */
void collectExistingReadonlyFiles(IPath sourceStart, List sources, ArrayList noOverwrite, ArrayList overwriteReadonly, int policy) {
    IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
    Iterator sourceIter = sources.iterator();
    IPath sourceRootPath = null;
    if (this.source != null) {
        sourceRootPath = new Path(provider.getFullPath(this.source));
    }
    while (sourceIter.hasNext()) {
        Object nextSource = sourceIter.next();
        IPath sourcePath = new Path(provider.getFullPath(nextSource));
        IPath newDestinationPath;
        IResource newDestination;
        if (sourceRootPath == null) {
            newDestinationPath = sourceStart.append(provider.getLabel(nextSource));
        } else {
            int prefixLength = sourcePath.matchingFirstSegments(sourceRootPath);
            IPath relativeSourcePath = sourcePath.removeFirstSegments(prefixLength);
            newDestinationPath = this.destinationPath.append(relativeSourcePath);
        }
        newDestination = workspaceRoot.findMember(newDestinationPath);
        if (newDestination == null) {
            continue;
        }
        IFolder folder = getFolder(newDestination);
        if (folder != null) {
            if (policy != POLICY_FORCE_OVERWRITE) {
                if (this.overwriteState == OVERWRITE_NONE || !queryOverwrite(newDestinationPath)) {
                    noOverwrite.add(folder);
                    continue;
                }
            }
            if (provider.isFolder(nextSource)) {
                collectExistingReadonlyFiles(newDestinationPath, provider.getChildren(nextSource), noOverwrite, overwriteReadonly, POLICY_FORCE_OVERWRITE);
            }
        } else {
            IFile file = getFile(newDestination);
            if (file != null) {
                if (!queryOverwriteFile(file, policy)) {
                    noOverwrite.add(file.getFullPath());
                } else if (file.isReadOnly()) {
                    overwriteReadonly.add(file);
                }
            }
        }
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IFile(org.eclipse.core.resources.IFile) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) IPath(org.eclipse.core.runtime.IPath) Iterator(java.util.Iterator) IResource(org.eclipse.core.resources.IResource) IFolder(org.eclipse.core.resources.IFolder)

Example 5 with IFolder

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

the class ImportOperation method createFromRoot.

/**
     * Creates the folders that appear in the specified resource path
     * assuming that the destinationContainer begins at the root. Do not create projects.
     *
     * @param path the relative path of the resource
     * @return the container resource coresponding to the given path
     * @exception CoreException if this method failed
     */
private IContainer createFromRoot(IPath path) throws CoreException {
    int segmentCount = path.segmentCount();
    //Assume the project exists 
    IContainer currentFolder = ((IWorkspaceRoot) destinationContainer).getProject(path.segment(0));
    for (int i = 1; i < segmentCount; i++) {
        currentFolder = currentFolder.getFolder(new Path(path.segment(i)));
        if (!currentFolder.exists()) {
            ((IFolder) currentFolder).create(false, true, null);
        }
    }
    return currentFolder;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) IContainer(org.eclipse.core.resources.IContainer) IFolder(org.eclipse.core.resources.IFolder)

Aggregations

IFolder (org.eclipse.core.resources.IFolder)1114 IFile (org.eclipse.core.resources.IFile)516 IProject (org.eclipse.core.resources.IProject)342 IPath (org.eclipse.core.runtime.IPath)287 CoreException (org.eclipse.core.runtime.CoreException)267 IResource (org.eclipse.core.resources.IResource)197 Test (org.junit.Test)176 Path (org.eclipse.core.runtime.Path)169 File (java.io.File)151 ArrayList (java.util.ArrayList)124 IContainer (org.eclipse.core.resources.IContainer)119 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)91 IOException (java.io.IOException)83 IJavaProject (org.eclipse.jdt.core.IJavaProject)83 ByteArrayInputStream (java.io.ByteArrayInputStream)62 IClasspathEntry (org.eclipse.jdt.core.IClasspathEntry)55 StringInputStream (org.eclipse.xtext.util.StringInputStream)53 IWebProject (com.liferay.ide.core.IWebProject)50 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)46 IStatus (org.eclipse.core.runtime.IStatus)43