diff options
author | Stephan Herrmann | 2015-12-08 00:22:14 +0000 |
---|---|---|
committer | Stephan Herrmann | 2015-12-08 00:22:14 +0000 |
commit | cdb3e8d99e2ddf40df3afd879c65627abb3809dc (patch) | |
tree | 7c36a1c66e80ddeb2c667415aeca1a951b66b0d3 | |
parent | 380f51fb07b01d50fdf783879a49310c31bf8dde (diff) | |
download | eclipse.jdt.core-cdb3e8d99e2ddf40df3afd879c65627abb3809dc.tar.gz eclipse.jdt.core-cdb3e8d99e2ddf40df3afd879c65627abb3809dc.tar.xz eclipse.jdt.core-cdb3e8d99e2ddf40df3afd879c65627abb3809dc.zip |
Bug 466291: IAE on renaming the location for external annotationI20151208-0800
attachment
- validation
Change-Id: I88ee02d8125962b4eb9b4bafff2d6235b7cae9f4
5 files changed, 85 insertions, 23 deletions
diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/core/IJavaModelStatusConstants.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/core/IJavaModelStatusConstants.java index a88db5e105..d3d643b199 100644 --- a/org.eclipse.jdt.core/model/org/eclipse/jdt/core/IJavaModelStatusConstants.java +++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/core/IJavaModelStatusConstants.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2011 IBM Corporation and others. + * Copyright (c) 2000, 2015 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,9 +7,6 @@ * * Contributors: * IBM Corporation - initial API and implementation - * - * TODO missing 2.1 and subsequent contributions - * COMPILER_FAILURE *******************************************************************************/ package org.eclipse.jdt.core; @@ -352,4 +349,11 @@ public interface IJavaModelStatusConstants { * @since 3.6.4 */ public static final int OUTPUT_LOCATION_OVERLAPPING_ANOTHER_SOURCE = 1013; + + /** + * <p>Status constant indicating that an external annotation path is invalid.</p> + * @since 3.12 + * @see org.eclipse.jdt.core.IClasspathAttribute#EXTERNAL_ANNOTATION_PATH + */ + public static final int CP_INVALID_EXTERNAL_ANNOTATION_PATH = 1014; } diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ClasspathEntry.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ClasspathEntry.java index a003b2bf51..08acbd600e 100644 --- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ClasspathEntry.java +++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ClasspathEntry.java @@ -35,6 +35,7 @@ import java.util.zip.ZipFile; import org.eclipse.core.resources.IContainer; import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IMarker; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IWorkspaceRoot; @@ -47,6 +48,7 @@ import org.eclipse.jdt.core.IAccessRule; import org.eclipse.jdt.core.IClasspathAttribute; import org.eclipse.jdt.core.IClasspathContainer; import org.eclipse.jdt.core.IClasspathEntry; +import org.eclipse.jdt.core.IJavaModelMarker; import org.eclipse.jdt.core.IJavaModelStatus; import org.eclipse.jdt.core.IJavaModelStatusConstants; import org.eclipse.jdt.core.IJavaProject; @@ -1285,15 +1287,13 @@ public class ClasspathEntry implements IClasspathEntry { return annotationPath; // try Workspace-absolute: - IProject targetProject = project.getWorkspace().getRoot().getProject(annotationPath.segment(0)); - if (targetProject.exists()) { - if (annotationPath.segmentCount() > 1) - return targetProject.getLocation().append(annotationPath.removeFirstSegments(1)); - else - return targetProject.getLocation(); + IResource resource = project.getWorkspace().getRoot().findMember(annotationPath); + if (resource != null) { + return resource.getLocation(); + } else if (new File(annotationPath.toOSString()).exists()) { // absolute, not in workspace, must be Filesystem-absolute + return annotationPath; } - // absolute, not in workspace, must be Filesystem-absolute: - return annotationPath; + invalidExternalAnnotationPath(project); } else { // try Variable (always resolved): IPath resolved = JavaCore.getResolvedVariablePath(annotationPath); @@ -1302,10 +1302,14 @@ public class ClasspathEntry implements IClasspathEntry { // Project-relative: if (project != null) { - if (resolve) - return project.getLocation().append(annotationPath); - else + if (resolve) { + IResource member = project.findMember(annotationPath); + if (member != null) + return member.getLocation(); + invalidExternalAnnotationPath(project); + } else { return new Path(project.getName()).append(annotationPath).makeAbsolute(); + } } } } @@ -1327,7 +1331,42 @@ public class ClasspathEntry implements IClasspathEntry { } return null; } - + + private static void invalidExternalAnnotationPath(IProject project) { + try { + IMarker[] markers = project.findMarkers(IJavaModelMarker.BUILDPATH_PROBLEM_MARKER, false, IResource.DEPTH_ZERO); + for (int i = 0, l = markers.length; i < l; i++) { + if (markers[i].getAttribute(IMarker.SEVERITY, -1) == IMarker.SEVERITY_ERROR) + return; // one marker is enough + } + } catch (CoreException ce) { + return; + } + // no buildpath marker yet, trigger validation to create one: + new ClasspathValidation((JavaProject) JavaCore.create(project)).validate(); + } + + private IJavaModelStatus validateExternalAnnotationPath(IJavaProject javaProject, IPath annotationPath) { + IProject project = javaProject.getProject(); + if (annotationPath.isAbsolute()) { + if (project.getWorkspace().getRoot().exists(annotationPath) // workspace absolute + || new File(annotationPath.toOSString()).exists()) // file system abolute + { + return null; + } + } else { + if (JavaCore.getResolvedVariablePath(annotationPath) != null // variable (relative) + || project.exists(annotationPath)) // project relative + { + return null; + } + } + return new JavaModelStatus(IJavaModelStatusConstants.CP_INVALID_EXTERNAL_ANNOTATION_PATH, + javaProject, + Messages.bind(Messages.classpath_invalidExternalAnnotationPath, + new String[] { annotationPath.toString(), project.getName(), this.path.toString()})); + } + public IClasspathEntry getReferencingEntry() { return this.referencingEntry; } @@ -2029,6 +2068,14 @@ public class ClasspathEntry implements IClasspathEntry { break; } } + if (status == null) { + String annotationPath = getRawExternalAnnotationPath(entry); + if (annotationPath != null) { + status = ((ClasspathEntry) entry).validateExternalAnnotationPath(project, new Path(annotationPath)); + if (status != null) + return status; + } + } } IClasspathContainer container = JavaModelManager.getJavaModelManager().getClasspathContainer(path, project); // container retrieval is performing validation check on container entry kinds. diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/JavaBuilder.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/JavaBuilder.java index 3975387797..c919e79ea9 100644 --- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/JavaBuilder.java +++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/JavaBuilder.java @@ -633,11 +633,20 @@ private int initializeBuilder(int kind, boolean forBuild) throws CoreException { return kind; } -private boolean isClasspathBroken(IClasspathEntry[] classpath, IProject p) throws CoreException { - IMarker[] markers = p.findMarkers(IJavaModelMarker.BUILDPATH_PROBLEM_MARKER, false, IResource.DEPTH_ZERO); - for (int i = 0, l = markers.length; i < l; i++) - if (markers[i].getAttribute(IMarker.SEVERITY, -1) == IMarker.SEVERITY_ERROR) +private boolean isClasspathBroken(JavaProject jProj, boolean tryRepair) throws CoreException { + IMarker[] markers = jProj.getProject().findMarkers(IJavaModelMarker.BUILDPATH_PROBLEM_MARKER, false, IResource.DEPTH_ZERO); + for (int i = 0, l = markers.length; i < l; i++) { + if (markers[i].getAttribute(IMarker.SEVERITY, -1) == IMarker.SEVERITY_ERROR) { + if (tryRepair) { + Object code = markers[i].getAttribute(IJavaModelMarker.ID); + if (code instanceof Integer && ((Integer)code) == IJavaModelStatusConstants.CP_INVALID_EXTERNAL_ANNOTATION_PATH) { + new ClasspathValidation(jProj).validate(); + return isClasspathBroken(jProj, false); + } + } return true; + } + } return false; } @@ -651,7 +660,7 @@ private boolean isWorthBuilding() throws CoreException { } // Abort build only if there are classpath errors - if (isClasspathBroken(this.javaProject.getRawClasspath(), this.currentProject)) { + if (isClasspathBroken(this.javaProject, true)) { if (DEBUG) System.out.println("JavaBuilder: Aborted build because project has classpath errors (incomplete or involved in cycle)"); //$NON-NLS-1$ @@ -702,7 +711,7 @@ private boolean isWorthBuilding() throws CoreException { marker.setAttributes( new String[] {IMarker.MESSAGE, IMarker.SEVERITY, IJavaModelMarker.CATEGORY_ID, IMarker.SOURCE_ID}, new Object[] { - isClasspathBroken(prereq.getRawClasspath(), p) + isClasspathBroken(prereq, true) ? Messages.bind(Messages.build_prereqProjectHasClasspathProblems, p.getName()) : Messages.bind(Messages.build_prereqProjectMustBeRebuilt, p.getName()), new Integer(IMarker.SEVERITY_ERROR), diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/util/Messages.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/util/Messages.java index ceb402f1c6..0303e70fe0 100644 --- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/util/Messages.java +++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/util/Messages.java @@ -185,6 +185,7 @@ public final class Messages extends NLS { public static String classpath_incompatibleLibraryJDKLevelInContainer; public static String classpath_duplicateEntryExtraAttribute; public static String classpath_deprecated_variable; + public static String classpath_invalidExternalAnnotationPath; public static String file_notFound; public static String file_badFormat; public static String path_nullPath; diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/util/messages.properties b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/util/messages.properties index bf3c646063..724696c150 100644 --- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/util/messages.properties +++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/util/messages.properties @@ -1,5 +1,5 @@ ############################################################################### -# Copyright (c) 2000, 2014 IBM Corporation and others. +# Copyright (c) 2000, 2015 IBM Corporation and others. # All rights reserved. This program and the accompanying materials # are made available under the terms of the Eclipse Public License v1.0 # which accompanies this distribution, and is available at @@ -181,6 +181,7 @@ classpath_incompatibleLibraryJDKLevel = Incompatible .class files version in req classpath_incompatibleLibraryJDKLevelInContainer = Incompatible .class files version in required binaries. Project ''{0}'' is targeting a {1} runtime, but is compiled against ''{2}'' (from the {3}) which requires a {4} runtime classpath_duplicateEntryExtraAttribute = Duplicate extra attribute: ''{0}'' in classpath entry ''{1}'' for project ''{2}'' classpath_deprecated_variable = Classpath variable ''{0}'' in project ''{1}'' is deprecated: {2} +classpath_invalidExternalAnnotationPath = Invalid external annotation path: ''{0}'' in project ''{1}'', for classpath entry ''{2}'' ### miscellaneous buffer_closed=Buffer is closed |