### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core Index: model/org/eclipse/jdt/internal/core/ChangeClasspathOperation.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ChangeClasspathOperation.java,v retrieving revision 1.4 diff -u -r1.4 ChangeClasspathOperation.java --- model/org/eclipse/jdt/internal/core/ChangeClasspathOperation.java 24 May 2007 13:15:25 -0000 1.4 +++ model/org/eclipse/jdt/internal/core/ChangeClasspathOperation.java 14 Dec 2007 16:30:26 -0000 @@ -40,6 +40,10 @@ * - create resolved classpath markers */ protected void classpathChanged(JavaProject project) throws JavaModelException { + // reset the project's caches early since some clients rely on the project's caches being up-to-date when run inside an IWorkspaceRunnable + // (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=212769#c5 ) + project.resetCaches(); + DeltaProcessingState state = JavaModelManager.getJavaModelManager().deltaState; DeltaProcessor deltaProcessor = state.getDeltaProcessor(); ClasspathChange change = (ClasspathChange) deltaProcessor.classpathChanges.get(project.getProject()); #P org.eclipse.jdt.core.tests.model Index: src/org/eclipse/jdt/core/tests/model/ExternalJarDeltaTests.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ExternalJarDeltaTests.java,v retrieving revision 1.28 diff -u -r1.28 ExternalJarDeltaTests.java --- src/org/eclipse/jdt/core/tests/model/ExternalJarDeltaTests.java 20 Oct 2006 01:45:46 -0000 1.28 +++ src/org/eclipse/jdt/core/tests/model/ExternalJarDeltaTests.java 14 Dec 2007 16:30:31 -0000 @@ -293,6 +293,42 @@ this.stopDeltas(); } } +/* + * Ensures that the correct delta is reported after a setRawClasspath and after a modification of an external jar. + * (regression test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=212769 ) + */ +public void testExternalJarChanged7() throws CoreException, IOException { + File f = null; + try { + IJavaProject project = this.createJavaProject("P", new String[] {""}, ""); + + String pPath = getExternalPath() + "p.jar"; + setClasspath(project, new IClasspathEntry[]{JavaCore.newLibraryEntry(new Path(pPath), null, null)}); + + f = new File(pPath); + f.createNewFile(); + getJavaModel().refreshExternalArchives(null,null); + waitUntilIndexesReady(); + startDeltas(); + + touch(f); + setClasspath(project, new IClasspathEntry[]{JavaCore.newLibraryEntry(new Path(pPath), null, null), JavaCore.newSourceEntry(new Path("/P"))}); + + assertDeltas( + "Unexpected delta", + "P[*]: {CHILDREN | CONTENT | CLASSPATH CHANGED}\n" + + " [*]: {ADDED TO CLASSPATH}\n" + + " "+f.getCanonicalPath()+"[*]: {CONTENT | ARCHIVE CONTENT CHANGED}\n" + + " ResourceDelta(/P/.classpath)[*]" + ); + } finally { + if(f != null) { + deleteFile(f); + } + this.deleteProject("P"); + this.stopDeltas(); + } +} /** * Refresh the JavaModel after an addition of an external jar. */ Index: src/org/eclipse/jdt/core/tests/model/JavaProjectTests.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaProjectTests.java,v retrieving revision 1.84.2.1 diff -u -r1.84.2.1 JavaProjectTests.java --- src/org/eclipse/jdt/core/tests/model/JavaProjectTests.java 24 Aug 2007 12:55:16 -0000 1.84.2.1 +++ src/org/eclipse/jdt/core/tests/model/JavaProjectTests.java 14 Dec 2007 16:30:31 -0000 @@ -391,6 +391,33 @@ assertEquals("Unexpected number of roots for non existing entry", 0, roots.length); } +/* + * Ensures that a type can be found if run after setting the classpath in a runnable + * (regression test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=212769 ) + */ +public void testFindTypeAfterSetClasspath() throws CoreException { + try { + final IJavaProject project = createJavaProject("P", new String[] {"src1"}, "bin"); + createFolder("/P/src2/p"); + createFile("/P/src2/p/X.java", "package p; public class X {}"); + project.findType("p.X"); // populate project's cache + final IType[] result = new IType[1]; + ResourcesPlugin.getWorkspace().run( + new IWorkspaceRunnable() { + public void run(IProgressMonitor monitor) throws CoreException { + addClasspathEntry(project, JavaCore.newSourceEntry(new Path("/P/src2"))); + result[0] = project.findType("p.X"); + } + }, + null); + assertElementsEqual( + "Unexpected type found", + "X [in X.java [in p [in src2 [in P]]]]", + result); + } finally { + deleteProject("P"); + } +} /** * Test that a folder with a dot name does not relate to a package fragment */ Index: src/org/eclipse/jdt/core/tests/model/AbstractJavaModelTests.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AbstractJavaModelTests.java,v retrieving revision 1.185 diff -u -r1.185 AbstractJavaModelTests.java --- src/org/eclipse/jdt/core/tests/model/AbstractJavaModelTests.java 27 Mar 2007 14:28:56 -0000 1.185 +++ src/org/eclipse/jdt/core/tests/model/AbstractJavaModelTests.java 14 Dec 2007 16:30:31 -0000 @@ -233,6 +233,13 @@ return suite; } + protected void addClasspathEntry(IJavaProject project, IClasspathEntry entry) throws JavaModelException{ + IClasspathEntry[] entries = project.getRawClasspath(); + int length = entries.length; + System.arraycopy(entries, 0, entries = new IClasspathEntry[length + 1], 0, length); + entries[length] = entry; + project.setRawClasspath(entries, null); + } protected void addJavaNature(String projectName) throws CoreException { IProject project = getWorkspaceRoot().getProject(projectName); IProjectDescription description = project.getDescription();