### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core Index: model/org/eclipse/jdt/core/JavaCore.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/core/JavaCore.java,v retrieving revision 1.573 diff -u -r1.573 JavaCore.java --- model/org/eclipse/jdt/core/JavaCore.java 18 Apr 2007 14:22:46 -0000 1.573 +++ model/org/eclipse/jdt/core/JavaCore.java 25 Apr 2007 13:47:19 -0000 @@ -3242,6 +3242,26 @@ monitor.subTask(Messages.javamodel_configuring_classpath_containers); manager.batchContainerInitializationsProgress.set(new SubProgressMonitor(monitor, 50)); // 50% of the time is spent in initializing containers and variables } + + // all classpaths in the workspace are going to be resolved, ensure that containers are initialized in one batch + manager.batchContainerInitializations = true; + + // avoid leaking source attachment properties (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=183413) + IJavaProject[] projects = manager.getJavaModel().getJavaProjects(); + for (int i = 0, length = projects.length; i < length; i++) { + IClasspathEntry[] classpath = ((JavaProject) projects[i]).getResolvedClasspath(); + if (classpath != null) { + for (int j = 0, length2 = classpath.length; j < length2; j++) { + IClasspathEntry entry = classpath[j]; + if (entry.getSourceAttachmentPath() != null) + Util.setSourceAttachmentProperty(entry.getPath(), null); + // else source might have been attached by IPackageFragmentRoot#attachSource(...), we keep it + } + } + } + + // initialize delta state + manager.deltaState.rootsAreStale = true; // in case it was already initialized before we cleaned up the source attachment proprties manager.deltaState.initializeRoots(); } finally { manager.batchContainerInitializationsProgress.set(null); @@ -3348,6 +3368,7 @@ } catch (JavaModelException e) { // refreshing failed: ignore } + } finally { if (monitor != null) monitor.done(); } #P org.eclipse.jdt.core.tests.model Index: src/org/eclipse/jdt/core/tests/model/AttachSourceTests.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AttachSourceTests.java,v retrieving revision 1.46 diff -u -r1.46 AttachSourceTests.java --- src/org/eclipse/jdt/core/tests/model/AttachSourceTests.java 29 Sep 2006 17:13:29 -0000 1.46 +++ src/org/eclipse/jdt/core/tests/model/AttachSourceTests.java 25 Apr 2007 13:47:24 -0000 @@ -708,6 +708,31 @@ } } +/* + * Ensures that a source attached during a session is not taken into account on restart + * if the entry has a source attachment. + * (regression test for bug 183413 PDE can't find the source for plug-ins in the target) + */ +public void testRestart() throws Exception { + try { + this.pkgFragmentRoot.attachSource(new Path("/AttachSourceTests/attachsrc.new.zip"), new Path("")/*source root*/, null/*no progress*/); + + simulateExitRestart(); + JavaCore.initializeAfterLoad(null); + + // ensure source is correct + IClassFile cf = this.pkgFragmentRoot.getPackageFragment("x.y").getClassFile("A.class"); + IMethod method = cf.getType().getMethod("foo", new String[] {}); + assertSourceEquals( + "unexpected source for foo()", + "public void foo() {\n" + + " }", + method.getSource()); + } finally { + this.pkgFragmentRoot.attachSource(null/*no source attachment*/, null/*no source root*/, null/*no progress*/); + } +} + /** * Attaches a source zip to a jar. The source zip has * a nested root structure and exists as a resource. Tests that