### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core Index: model/org/eclipse/jdt/internal/core/JavaModelManager.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaModelManager.java,v retrieving revision 1.311 diff -u -r1.311 JavaModelManager.java --- model/org/eclipse/jdt/internal/core/JavaModelManager.java 8 Dec 2005 14:48:52 -0000 1.311 +++ model/org/eclipse/jdt/internal/core/JavaModelManager.java 15 Dec 2005 15:07:18 -0000 @@ -1721,7 +1721,7 @@ } // collect all container paths - HashMap allContainerPaths = new HashMap(); + final HashMap allContainerPaths = new HashMap(); IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects(); for (int i = 0, length = projects.length; i < length; i++) { IProject project = projects[i]; @@ -1768,23 +1768,42 @@ // initialize all containers boolean ok = false; try { - Set keys = allContainerPaths.keySet(); - int length = keys.size(); - IJavaProject[] javaProjects = new IJavaProject[length]; // clone as the following will have a side effect - keys.toArray(javaProjects); - for (int i = 0; i < length; i++) { - IJavaProject javaProject = javaProjects[i]; - HashSet pathSet = (HashSet) allContainerPaths.get(javaProject); - if (pathSet == null) continue; - int length2 = pathSet.size(); - IPath[] paths = new IPath[length2]; - pathSet.toArray(paths); // clone as the following will have a side effect - for (int j = 0; j < length2; j++) { - IPath path = paths[j]; - initializeContainer(javaProject, path); - } - } + // if possible run iniside an IWokspaceRunnable with AVOID_UPATE to avoid unwanted builds + // (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=118507) + IWorkspaceRunnable runnable = + new IWorkspaceRunnable() { + public void run(IProgressMonitor monitor) throws CoreException { + Set keys = allContainerPaths.keySet(); + int length = keys.size(); + IJavaProject[] javaProjects = new IJavaProject[length]; // clone as the following will have a side effect + keys.toArray(javaProjects); + for (int i = 0; i < length; i++) { + IJavaProject javaProject = javaProjects[i]; + HashSet pathSet = (HashSet) allContainerPaths.get(javaProject); + if (pathSet == null) continue; + int length2 = pathSet.size(); + IPath[] paths = new IPath[length2]; + pathSet.toArray(paths); // clone as the following will have a side effect + for (int j = 0; j < length2; j++) { + IPath path = paths[j]; + initializeContainer(javaProject, path); + } + } + } + }; + IWorkspace workspace = ResourcesPlugin.getWorkspace(); + if (workspace.isTreeLocked()) + runnable.run(null/*no progress available*/); + else + workspace.run( + runnable, + null/*don't take any lock*/, + IWorkspace.AVOID_UPDATE, + null/*no progress available here*/); ok = true; + } catch (CoreException e) { + // ignore + Util.log(e, "Exception while initializing all containers"); //$NON-NLS-1$ } finally { if (!ok) { // if we're being traversed by an exception, ensure that that containers are @@ -1797,7 +1816,7 @@ return containerGet(javaProjectToInit, containerToInit); } - private IClasspathContainer initializeContainer(IJavaProject project, IPath containerPath) throws JavaModelException { + IClasspathContainer initializeContainer(IJavaProject project, IPath containerPath) throws JavaModelException { IClasspathContainer container = null; final ClasspathContainerInitializer initializer = JavaCore.getClasspathContainerInitializer(containerPath.segment(0));