Search in sources :

Example 51 with IPath

use of org.eclipse.core.runtime.IPath in project che by eclipse.

the class ClasspathEntry method equals.

/**
     * Returns true if the given object is a classpath entry
     * with equivalent attributes.
     */
public boolean equals(Object object) {
    if (this == object)
        return true;
    if (object instanceof org.eclipse.jdt.internal.core.ClasspathEntry) {
        org.eclipse.jdt.internal.core.ClasspathEntry otherEntry = (org.eclipse.jdt.internal.core.ClasspathEntry) object;
        if (this.contentKind != otherEntry.getContentKind())
            return false;
        if (this.entryKind != otherEntry.getEntryKind())
            return false;
        if (this.isExported != otherEntry.isExported())
            return false;
        if (!this.path.equals(otherEntry.getPath()))
            return false;
        IPath otherPath = otherEntry.getSourceAttachmentPath();
        if (this.sourceAttachmentPath == null) {
            if (otherPath != null)
                return false;
        } else {
            if (!this.sourceAttachmentPath.equals(otherPath))
                return false;
        }
        otherPath = otherEntry.getSourceAttachmentRootPath();
        if (this.sourceAttachmentRootPath == null) {
            if (otherPath != null)
                return false;
        } else {
            if (!this.sourceAttachmentRootPath.equals(otherPath))
                return false;
        }
        if (!equalPatterns(this.inclusionPatterns, otherEntry.getInclusionPatterns()))
            return false;
        if (!equalPatterns(this.exclusionPatterns, otherEntry.getExclusionPatterns()))
            return false;
        AccessRuleSet otherRuleSet = otherEntry.getAccessRuleSet();
        if (getAccessRuleSet() != null) {
            if (!getAccessRuleSet().equals(otherRuleSet))
                return false;
        } else if (otherRuleSet != null)
            return false;
        if (this.combineAccessRules != otherEntry.combineAccessRules())
            return false;
        otherPath = otherEntry.getOutputLocation();
        if (this.specificOutputLocation == null) {
            if (otherPath != null)
                return false;
        } else {
            if (!this.specificOutputLocation.equals(otherPath))
                return false;
        }
        if (!equalAttributes(this.extraAttributes, otherEntry.getExtraAttributes()))
            return false;
        return true;
    } else {
        return false;
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) AccessRuleSet(org.eclipse.jdt.internal.compiler.env.AccessRuleSet)

Example 52 with IPath

use of org.eclipse.core.runtime.IPath 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 53 with IPath

use of org.eclipse.core.runtime.IPath in project che by eclipse.

the class ClasspathEntry method elementEncode.

/**
	 * Returns the XML encoding of the class path.
	 */
public void elementEncode(XMLWriter writer, IPath projectPath, boolean indent, boolean newLine, Map unknownElements, boolean isReferencedEntry) {
    HashMap parameters = new HashMap();
    parameters.put(TAG_KIND, ClasspathEntry.kindToString(this.entryKind));
    IPath xmlPath = this.path;
    if (this.entryKind != IClasspathEntry.CPE_VARIABLE && this.entryKind != IClasspathEntry.CPE_CONTAINER) {
        // translate to project relative from absolute (unless a device path)
        if (xmlPath.isAbsolute()) {
            if (projectPath != null && projectPath.isPrefixOf(xmlPath)) {
                if (xmlPath.segment(0).equals(projectPath.segment(0))) {
                    xmlPath = xmlPath.removeFirstSegments(projectPath.segmentCount());
                    xmlPath = xmlPath.makeRelative();
                } else {
                    xmlPath = xmlPath.makeAbsolute();
                }
            }
        }
    }
    parameters.put(TAG_PATH, String.valueOf(xmlPath));
    if (this.sourceAttachmentPath != null) {
        xmlPath = this.sourceAttachmentPath;
        // translate to project relative from absolute
        if (this.entryKind != IClasspathEntry.CPE_VARIABLE && projectPath != null && projectPath.isPrefixOf(xmlPath)) {
            if (xmlPath.segment(0).equals(projectPath.segment(0))) {
                xmlPath = xmlPath.removeFirstSegments(1);
                xmlPath = xmlPath.makeRelative();
            }
        }
        parameters.put(TAG_SOURCEPATH, String.valueOf(xmlPath));
    }
    if (this.sourceAttachmentRootPath != null) {
        parameters.put(TAG_ROOTPATH, String.valueOf(this.sourceAttachmentRootPath));
    }
    if (this.isExported) {
        //$NON-NLS-1$
        parameters.put(TAG_EXPORTED, "true");
    }
    encodePatterns(this.inclusionPatterns, TAG_INCLUDING, parameters);
    encodePatterns(this.exclusionPatterns, TAG_EXCLUDING, parameters);
    if (this.entryKind == IClasspathEntry.CPE_PROJECT && !this.combineAccessRules)
        //$NON-NLS-1$
        parameters.put(TAG_COMBINE_ACCESS_RULES, "false");
    // unknown attributes
    UnknownXmlElements unknownXmlElements = unknownElements == null ? null : (UnknownXmlElements) unknownElements.get(this.path);
    String[] unknownAttributes;
    if (unknownXmlElements != null && (unknownAttributes = unknownXmlElements.attributes) != null)
        for (int i = 0, length = unknownAttributes.length; i < length; i += 2) {
            String tagName = unknownAttributes[i];
            String tagValue = unknownAttributes[i + 1];
            parameters.put(tagName, tagValue);
        }
    if (this.specificOutputLocation != null) {
        IPath outputLocation = this.specificOutputLocation.removeFirstSegments(1);
        outputLocation = outputLocation.makeRelative();
        parameters.put(TAG_OUTPUT, String.valueOf(outputLocation));
    }
    boolean hasExtraAttributes = this.extraAttributes.length != 0;
    // access rule set is null if no access rules
    boolean hasRestrictions = getAccessRuleSet() != null;
    ArrayList unknownChildren = unknownXmlElements != null ? unknownXmlElements.children : null;
    boolean hasUnknownChildren = unknownChildren != null;
    /* close tag if no extra attributes, no restriction and no unknown children */
    String tagName = isReferencedEntry ? TAG_REFERENCED_ENTRY : TAG_CLASSPATHENTRY;
    writer.printTag(tagName, parameters, indent, newLine, !hasExtraAttributes && !hasRestrictions && !hasUnknownChildren);
    if (hasExtraAttributes)
        encodeExtraAttributes(writer, indent, newLine);
    if (hasRestrictions)
        encodeAccessRules(writer, indent, newLine);
    if (hasUnknownChildren)
        encodeUnknownChildren(writer, indent, newLine, unknownChildren);
    if (hasExtraAttributes || hasRestrictions || hasUnknownChildren)
        writer.endTag(tagName, indent, true);
}
Also used : IPath(org.eclipse.core.runtime.IPath) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList)

Example 54 with IPath

use of org.eclipse.core.runtime.IPath in project che by eclipse.

the class ClasspathEntry method resolveDotDot.

/*
	 * Resolves the ".." in the given path. Returns the given path if it contains no ".." segment.
	 */
public static IPath resolveDotDot(IPath reference, IPath path) {
    IPath newPath = null;
    IPath workspaceLocation = workspaceRoot.getLocation();
    if (reference == null || workspaceLocation.isPrefixOf(reference)) {
        for (int i = 0, length = path.segmentCount(); i < length; i++) {
            String segment = path.segment(i);
            if (DOT_DOT.equals(segment)) {
                if (newPath == null) {
                    if (i == 0) {
                        newPath = workspaceLocation;
                    } else {
                        newPath = path.removeFirstSegments(i);
                    }
                } else {
                    if (newPath.segmentCount() > 0) {
                        newPath = newPath.removeLastSegments(1);
                    } else {
                        newPath = workspaceLocation;
                    }
                }
            } else if (newPath != null) {
                if (newPath.equals(workspaceLocation) && workspaceRoot.getProject(segment).isAccessible()) {
                    newPath = new Path(segment).makeAbsolute();
                } else {
                    newPath = newPath.append(segment);
                }
            }
        }
    } else {
        for (int i = 0, length = path.segmentCount(); i < length; i++) {
            String segment = path.segment(i);
            if (DOT_DOT.equals(segment)) {
                if (newPath == null) {
                    newPath = reference;
                }
                if (newPath.segmentCount() > 0) {
                    newPath = newPath.removeLastSegments(1);
                }
            } else if (newPath != null) {
                newPath = newPath.append(segment);
            }
        }
    }
    if (newPath == null)
        return path;
    return newPath;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IPath(org.eclipse.core.runtime.IPath)

Example 55 with IPath

use of org.eclipse.core.runtime.IPath in project che by eclipse.

the class DeltaProcessingState method saveExternalLibTimeStamps.

public void saveExternalLibTimeStamps() throws CoreException {
    if (this.externalTimeStamps == null)
        return;
    // cleanup to avoid any leak ( https://bugs.eclipse.org/bugs/show_bug.cgi?id=244849 )
    HashSet toRemove = new HashSet();
    if (this.roots != null) {
        Enumeration keys = this.externalTimeStamps.keys();
        while (keys.hasMoreElements()) {
            Object key = keys.nextElement();
            if (this.roots.get(key) == null) {
                toRemove.add(key);
            }
        }
    }
    File timestamps = getTimeStampsFile();
    DataOutputStream out = null;
    try {
        out = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(timestamps)));
        out.writeInt(this.externalTimeStamps.size() - toRemove.size());
        Iterator entries = this.externalTimeStamps.entrySet().iterator();
        while (entries.hasNext()) {
            Map.Entry entry = (Map.Entry) entries.next();
            IPath key = (IPath) entry.getKey();
            if (!toRemove.contains(key)) {
                out.writeUTF(key.toPortableString());
                Long timestamp = (Long) entry.getValue();
                out.writeLong(timestamp.longValue());
            }
        }
    } catch (IOException e) {
        //$NON-NLS-1$
        IStatus status = new Status(IStatus.ERROR, JavaCore.PLUGIN_ID, IStatus.ERROR, "Problems while saving timestamps", e);
        throw new CoreException(status);
    } finally {
        if (out != null) {
            try {
                out.close();
            } catch (IOException e) {
            // nothing we can do: ignore
            }
        }
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) Enumeration(java.util.Enumeration) IPath(org.eclipse.core.runtime.IPath) DataOutputStream(java.io.DataOutputStream) IOException(java.io.IOException) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) CoreException(org.eclipse.core.runtime.CoreException) FileOutputStream(java.io.FileOutputStream) Iterator(java.util.Iterator) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Aggregations

IPath (org.eclipse.core.runtime.IPath)800 Path (org.eclipse.core.runtime.Path)219 File (java.io.File)161 IFile (org.eclipse.core.resources.IFile)150 CoreException (org.eclipse.core.runtime.CoreException)135 IResource (org.eclipse.core.resources.IResource)112 IOException (java.io.IOException)100 ArrayList (java.util.ArrayList)92 IProject (org.eclipse.core.resources.IProject)85 IFolder (org.eclipse.core.resources.IFolder)80 Test (org.junit.Test)72 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)58 IClasspathEntry (org.eclipse.jdt.core.IClasspathEntry)55 IStatus (org.eclipse.core.runtime.IStatus)48 InputStream (java.io.InputStream)44 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)42 Status (org.eclipse.core.runtime.Status)36 IJavaProject (org.eclipse.jdt.core.IJavaProject)36 URL (java.net.URL)33 IContainer (org.eclipse.core.resources.IContainer)33