Search in sources :

Example 46 with IResource

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

the class ClasspathEntry method validateLibraryEntry.

// https://bugs.eclipse.org/bugs/show_bug.cgi?id=232816, Now we have the facility to include a container
// name in diagnostics. If the parameter ``container'' is not null, it is used to point to the library
// more fully.
private static IJavaModelStatus validateLibraryEntry(IPath path, IJavaProject project, String container, IPath sourceAttachment, String entryPathMsg) {
    if (path.isAbsolute() && !path.isEmpty()) {
        Object target = JavaModel.getTarget(path, true);
        if (target == null) {
            // https://bugs.eclipse.org/bugs/show_bug.cgi?id=248661
            IPath workspaceLocation = workspaceRoot.getLocation();
            if (workspaceLocation.isPrefixOf(path)) {
                target = JavaModel.getTarget(path.makeRelativeTo(workspaceLocation).makeAbsolute(), true);
            }
        }
        if (target != null && !JavaCore.IGNORE.equals(project.getOption(JavaCore.CORE_INCOMPATIBLE_JDK_LEVEL, true))) {
            long projectTargetJDK = CompilerOptions.versionToJdkLevel(project.getOption(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, true));
            long libraryJDK = Util.getJdkLevel(target);
            if (libraryJDK != 0 && libraryJDK > projectTargetJDK) {
                if (container != null) {
                    return new JavaModelStatus(IJavaModelStatusConstants.INCOMPATIBLE_JDK_LEVEL, project, path, Messages.bind(Messages.classpath_incompatibleLibraryJDKLevelInContainer, new String[] { project.getElementName(), CompilerOptions.versionFromJdkLevel(projectTargetJDK), path.makeRelative().toString(), container, CompilerOptions.versionFromJdkLevel(libraryJDK) }));
                } else {
                    return new JavaModelStatus(IJavaModelStatusConstants.INCOMPATIBLE_JDK_LEVEL, project, path, Messages.bind(Messages.classpath_incompatibleLibraryJDKLevel, new String[] { project.getElementName(), CompilerOptions.versionFromJdkLevel(projectTargetJDK), path.makeRelative().toString(), CompilerOptions.versionFromJdkLevel(libraryJDK) }));
                }
            }
        }
        if (target instanceof IResource) {
            IResource resolvedResource = (IResource) target;
            switch(resolvedResource.getType()) {
                case IResource.FILE:
                    if (sourceAttachment != null && !sourceAttachment.isEmpty() && JavaModel.getTarget(sourceAttachment, true) == null) {
                        if (container != null) {
                            return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_unboundSourceAttachmentInContainedLibrary, new String[] { sourceAttachment.toString(), path.toString(), container }));
                        } else {
                            return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_unboundSourceAttachment, new String[] { sourceAttachment.toString(), path.toString(), project.getElementName() }));
                        }
                    }
                    // https://bugs.eclipse.org/bugs/show_bug.cgi?id=229042
                    // Validate the contents of the archive
                    IJavaModelStatus status = validateLibraryContents(path, project, entryPathMsg);
                    if (status != JavaModelStatus.VERIFIED_OK)
                        return status;
                    break;
                case // internal binary folder
                IResource.FOLDER:
                    if (sourceAttachment != null && !sourceAttachment.isEmpty() && JavaModel.getTarget(sourceAttachment, true) == null) {
                        if (container != null) {
                            return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_unboundSourceAttachmentInContainedLibrary, new String[] { sourceAttachment.toString(), path.toString(), container }));
                        } else {
                            return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_unboundSourceAttachment, new String[] { sourceAttachment.toString(), path.toString(), project.getElementName() }));
                        }
                    }
            }
        } else if (target instanceof File) {
            File file = JavaModel.getFile(target);
            if (file == null) {
                if (container != null) {
                    return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_illegalExternalFolderInContainer, new String[] { path.toOSString(), container }));
                } else {
                    return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_illegalExternalFolder, new String[] { path.toOSString(), project.getElementName() }));
                }
            } else {
                if (sourceAttachment != null && !sourceAttachment.isEmpty() && JavaModel.getTarget(sourceAttachment, true) == null) {
                    if (container != null) {
                        return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_unboundSourceAttachmentInContainedLibrary, new String[] { sourceAttachment.toString(), path.toOSString(), container }));
                    } else {
                        return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_unboundSourceAttachment, new String[] { sourceAttachment.toString(), path.toOSString(), project.getElementName() }));
                    }
                }
                // Validate the contents of the archive
                if (file.isFile()) {
                    IJavaModelStatus status = validateLibraryContents(path, project, entryPathMsg);
                    if (status != JavaModelStatus.VERIFIED_OK)
                        return status;
                }
            }
        } else {
            boolean isExternal = path.getDevice() != null || !ResourcesPlugin.getWorkspace().getRoot().getProject(path.segment(0)).exists();
            if (isExternal) {
                if (container != null) {
                    return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_unboundLibraryInContainer, new String[] { path.toOSString(), container }));
                } else {
                    return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_unboundLibrary, new String[] { path.toOSString(), project.getElementName() }));
                }
            } else {
                if (entryPathMsg == null)
                    entryPathMsg = project.getElementName().equals(path.segment(0)) ? path.removeFirstSegments(1).makeRelative().toString() : path.toString();
                if (container != null) {
                    return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_unboundLibraryInContainer, new String[] { entryPathMsg, container }));
                } else {
                    return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_unboundLibrary, new String[] { entryPathMsg, project.getElementName() }));
                }
            }
        }
    } else {
        if (entryPathMsg == null)
            entryPathMsg = project.getElementName().equals(path.segment(0)) ? path.removeFirstSegments(1).makeRelative().toString() : path.toString();
        if (container != null) {
            return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_illegalLibraryPathInContainer, new String[] { entryPathMsg, container }));
        } else {
            return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_illegalLibraryPath, new String[] { entryPathMsg, project.getElementName() }));
        }
    }
    return JavaModelStatus.VERIFIED_OK;
}
Also used : IPath(org.eclipse.core.runtime.IPath) IJavaModelStatus(org.eclipse.jdt.core.IJavaModelStatus) IJavaModelStatus(org.eclipse.jdt.core.IJavaModelStatus) ZipFile(java.util.zip.ZipFile) IFile(org.eclipse.core.resources.IFile) File(java.io.File) IResource(org.eclipse.core.resources.IResource)

Example 47 with IResource

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

the class JavaElementLabelComposer method isReferenced.

/**
	 * Returns <code>true</code> if the given package fragment root is
	 * referenced. This means it is a descendant of a different project but is referenced
	 * by the root's parent. Returns <code>false</code> if the given root
	 * doesn't have an underlying resource.
	 *
	 * @param root the package fragment root
	 * @return returns <code>true</code> if the given package fragment root is referenced
	 */
private boolean isReferenced(IPackageFragmentRoot root) {
    IResource resource = root.getResource();
    if (resource != null) {
        IProject jarProject = resource.getProject();
        IProject container = root.getJavaProject().getProject();
        return !container.equals(jarProject);
    }
    return false;
}
Also used : IResource(org.eclipse.core.resources.IResource) IProject(org.eclipse.core.resources.IProject)

Example 48 with IResource

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

the class RefactoringSession method prepareRenamePackageChange.

private void prepareRenamePackageChange(List<ChangeInfo> changesInfo, ChangeInfo changeInfo, Change ch) {
    changeInfo.setName(ChangeInfo.ChangeName.RENAME_PACKAGE);
    RenamePackageChange renameChange = (RenamePackageChange) ch;
    IPath oldPackageName = new Path(renameChange.getOldName().replace('.', IPath.SEPARATOR));
    IPath newPackageName = new Path(renameChange.getNewName().replace('.', IPath.SEPARATOR));
    changeInfo.setOldPath(renameChange.getResourcePath().removeLastSegments(oldPackageName.segmentCount()).append(newPackageName).toString());
    changeInfo.setPath(renameChange.getResourcePath().toString());
    Set<IResource> compilationUnits = renameChange.getFCompilationUnitStamps().keySet();
    for (IResource iResource : compilationUnits) {
        ChangeInfo change = DtoFactory.newDto(ChangeInfo.class);
        change.setName(ChangeInfo.ChangeName.UPDATE);
        IPath fullPathOldPath = iResource.getFullPath();
        IPath newPath = renameChange.getResourcePath().append(fullPathOldPath.toFile().getName());
        change.setOldPath(fullPathOldPath.toString());
        change.setPath(newPath.toString());
        changesInfo.add(change);
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IPath(org.eclipse.core.runtime.IPath) ChangeInfo(org.eclipse.che.ide.ext.java.shared.dto.refactoring.ChangeInfo) RenamePackageChange(org.eclipse.jdt.internal.corext.refactoring.changes.RenamePackageChange) IResource(org.eclipse.core.resources.IResource)

Example 49 with IResource

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

the class RefactoringTest method tryDeletingAllNonJavaChildResources.

private static void tryDeletingAllNonJavaChildResources(IPackageFragmentRoot root) throws CoreException {
    Object[] nonJavaKids = root.getNonJavaResources();
    for (int i = 0; i < nonJavaKids.length; i++) {
        if (nonJavaKids[i] instanceof IResource) {
            IResource resource = (IResource) nonJavaKids[i];
            JavaProjectHelper.delete(resource);
        }
    }
}
Also used : IResource(org.eclipse.core.resources.IResource)

Example 50 with IResource

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

the class Checks method isClasspathDelete.

public static boolean isClasspathDelete(IPackageFragmentRoot pkgRoot) {
    IResource res = pkgRoot.getResource();
    if (res == null)
        return true;
    IProject definingProject = res.getProject();
    if (res.getParent() != null && pkgRoot.isArchive() && !res.getParent().equals(definingProject))
        return true;
    IProject occurringProject = pkgRoot.getJavaProject().getProject();
    return !definingProject.equals(occurringProject);
}
Also used : IResource(org.eclipse.core.resources.IResource) IProject(org.eclipse.core.resources.IProject)

Aggregations

IResource (org.eclipse.core.resources.IResource)559 CoreException (org.eclipse.core.runtime.CoreException)141 IFile (org.eclipse.core.resources.IFile)140 IPath (org.eclipse.core.runtime.IPath)119 IProject (org.eclipse.core.resources.IProject)104 IContainer (org.eclipse.core.resources.IContainer)88 ArrayList (java.util.ArrayList)84 IFolder (org.eclipse.core.resources.IFolder)64 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)52 IStatus (org.eclipse.core.runtime.IStatus)47 IOException (java.io.IOException)46 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)44 Path (org.eclipse.core.runtime.Path)42 File (java.io.File)39 Status (org.eclipse.core.runtime.Status)38 IJavaProject (org.eclipse.jdt.core.IJavaProject)31 IJavaElement (org.eclipse.jdt.core.IJavaElement)30 ISelection (org.eclipse.jface.viewers.ISelection)26 List (java.util.List)25 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)22