### Eclipse Workspace Patch 1.0 #P org.eclipse.ajdt.core.tests Index: src/org/eclipse/ajdt/core/tests/ajde/CoreCompilerConfigurationTests2.java =================================================================== RCS file: /cvsroot/tools/org.eclipse.ajdt/AJDT_src/org.eclipse.ajdt.core.tests/src/org/eclipse/ajdt/core/tests/ajde/CoreCompilerConfigurationTests2.java,v retrieving revision 1.1 diff -u -r1.1 CoreCompilerConfigurationTests2.java --- src/org/eclipse/ajdt/core/tests/ajde/CoreCompilerConfigurationTests2.java 6 Sep 2008 15:25:00 -0000 1.1 +++ src/org/eclipse/ajdt/core/tests/ajde/CoreCompilerConfigurationTests2.java 8 Sep 2008 17:01:13 -0000 @@ -1,6 +1,7 @@ package org.eclipse.ajdt.core.tests.ajde; import java.io.StringReader; +import java.util.List; import org.eclipse.ajdt.core.AspectJCorePreferences; import org.eclipse.ajdt.core.AspectJPlugin; @@ -8,8 +9,11 @@ import org.eclipse.ajdt.core.tests.testutils.ReaderInputStream; import org.eclipse.ajdt.core.tests.testutils.TestLogger; import org.eclipse.ajdt.core.tests.testutils.Utils; +import org.eclipse.core.resources.IMarker; import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IncrementalProjectBuilder; +import org.eclipse.jdt.core.IJavaModelMarker; /** * this set of tests ensures that the CoreCompilerConfiguration.getClasspathElementsWithModifiedContents() method @@ -207,4 +211,35 @@ // ensure that this is the only time the list has been set assertEquals(2, testLog.numberOfEntriesForMessage("Setting list of classpath elements with modified contents:")); } + + /** + * Test that when a jar on the classpath resides in a closed project + * there is an error and the build is aborted. + */ + public void testInvalidClasspath() throws Exception { + // incremental build + getWorkspace().build(IncrementalProjectBuilder.AUTO_BUILD, null); + waitForAutoBuild(); + + testLog.clearLog(); + + ap3.close(null); + + // incremental build + getWorkspace().build(IncrementalProjectBuilder.AUTO_BUILD, null); + waitForAutoBuild(); + + IMarker[] markers = myProj.findMarkers(IJavaModelMarker.BUILDPATH_PROBLEM_MARKER, + false, IResource.DEPTH_ZERO); + + assertEquals("Should have a single marker on the project", 1, markers.length); + assertEquals("Marker on project should be an error", IMarker.SEVERITY_ERROR, markers[0].getAttribute(IMarker.SEVERITY, -1)); + + // now check the log for an aborted message + // the last 3 messages should be about aborting the build + List entries = testLog.getMostRecentEntries(3); + assertEquals("build: Abort due to missing inpath/aspectpath/classpath entries", entries.get(0)); + assertEquals("Removed problems and tasks for project AspectProjWeCareAbout", entries.get(2)); + } + } Index: workspace/JavaProj3-ClassFolder/src/Nothing3.java =================================================================== RCS file: workspace/JavaProj3-ClassFolder/src/Nothing3.java diff -N workspace/JavaProj3-ClassFolder/src/Nothing3.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ workspace/JavaProj3-ClassFolder/src/Nothing3.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,1 @@ +class Nothing3 { } Index: workspace/JavaProj2-On Inpath/src/Nothing2.java =================================================================== RCS file: workspace/JavaProj2-On Inpath/src/Nothing2.java diff -N workspace/JavaProj2-On Inpath/src/Nothing2.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ workspace/JavaProj2-On Inpath/src/Nothing2.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,1 @@ +class Nothing2 { } Index: workspace/AspectProj1/src/Nothing.java =================================================================== RCS file: workspace/AspectProj1/src/Nothing.java diff -N workspace/AspectProj1/src/Nothing.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ workspace/AspectProj1/src/Nothing.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,1 @@ +class Nothing { } #P org.eclipse.ajdt.core Index: src/org/eclipse/ajdt/core/builder/AJBuilder.java =================================================================== RCS file: /cvsroot/tools/org.eclipse.ajdt/AJDT_src/org.eclipse.ajdt.core/src/org/eclipse/ajdt/core/builder/AJBuilder.java,v retrieving revision 1.51 diff -u -r1.51 AJBuilder.java --- src/org/eclipse/ajdt/core/builder/AJBuilder.java 6 Sep 2008 15:24:53 -0000 1.51 +++ src/org/eclipse/ajdt/core/builder/AJBuilder.java 8 Sep 2008 17:01:14 -0000 @@ -69,10 +69,12 @@ import org.eclipse.jdt.core.IJavaProject; import org.eclipse.jdt.core.JavaCore; import org.eclipse.jdt.core.JavaModelException; +import org.eclipse.jdt.core.compiler.CategorizedProblem; import org.eclipse.jdt.internal.core.ClasspathEntry; import org.eclipse.jdt.internal.core.JavaModelManager; import org.eclipse.jdt.internal.core.JavaProject; import org.eclipse.jdt.internal.core.builder.State; +import org.eclipse.jdt.internal.core.util.Messages; import org.eclipse.jdt.internal.core.util.Util; import org.eclipse.osgi.util.NLS; import org.osgi.service.prefs.BackingStoreException; @@ -132,14 +134,10 @@ AJLog.log(AJLog.BUILDER,"Project=" //$NON-NLS-1$ + project.getName() + ", kind of build requested=" + mode); //$NON-NLS-1$ - // bug 159197: check inpath and aspectpath - if (!validateInpathAspectPath(project)) { - postCallListeners(true); - AJLog.log(AJLog.BUILDER, - "build: Abort due to missing inpath/aspectpath entries"); //$NON-NLS-1$ - AJLog.logEnd(AJLog.BUILDER, TimerLogEvent.TIME_IN_BUILD); - progressMonitor.done(); - return requiredProjects; + if (!isWorthBuilding(project, requiredProjects)) { + postCallListeners(true); + progressMonitor.done(); + return requiredProjects; } // workaround for bug 73435 @@ -257,6 +255,28 @@ return requiredProjects; } + /** + * Check to see if the class paths are valid + * @param progressMonitor + * @param project + * @param requiredProjects + * @return true if aspect, in, and class paths are valid. False if there is a problem + * @throws CoreException + */ + private boolean isWorthBuilding(IProject project, IProject[] requiredProjects) throws CoreException { + // bug 159197: check inpath and aspectpath + // and classpath + if (!validateInpathAspectPath(project) || + isClasspathBroken(JavaCore.create(project).getRawClasspath(), project)) { + AJLog.log(AJLog.BUILDER, + "build: Abort due to missing inpath/aspectpath/classpath entries"); //$NON-NLS-1$ + AJLog.logEnd(AJLog.BUILDER, TimerLogEvent.TIME_IN_BUILD); + removeProblemsAndTasksFor(project); // make this the only problem for this project + return false; + } + return true; + } + // check to see if the .classpath has changed. // we know exactly where it is located, so no need for a visitor private boolean classpathChanged(IResourceDelta dta, IProject project) { @@ -504,6 +524,21 @@ return success; } + + 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) { + markProject(p, Messages.bind(Messages.build_prereqProjectHasClasspathProblems, + p.getName())); + return true; + } + } + return false; + } + + private void markProject(IProject project, String errorMessage) { try { IMarker errorMarker = project.createMarker(IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER);