### 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.423 diff -u -r1.423 JavaModelManager.java --- model/org/eclipse/jdt/internal/core/JavaModelManager.java 1 Dec 2008 17:56:27 -0000 1.423 +++ model/org/eclipse/jdt/internal/core/JavaModelManager.java 6 Jan 2009 16:51:37 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. + * Copyright (c) 2000, 2009 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 @@ -103,7 +103,8 @@ public HashMap containers = new HashMap(5); public HashMap previousSessionContainers = new HashMap(5); private ThreadLocal containerInitializationInProgress = new ThreadLocal(); - + ThreadLocal containersBeingInitiliazed = new ThreadLocal(); + public static final int NO_BATCH_INITIALIZATION = 0; public static final int NEED_BATCH_INITIALIZATION = 1; public static final int BATCH_INITIALIZATION_IN_PROGRESS = 2; @@ -495,6 +496,41 @@ initializations.put(project, projectInitializations = new HashSet()); projectInitializations.add(containerPath); } + + public void containerBeingInitializedPut(IJavaProject project, IPath containerPath, IClasspathContainer container) { + Map perProjectContainers = (Map)this.containersBeingInitiliazed.get(); + if (perProjectContainers == null) + this.containersBeingInitiliazed.set(perProjectContainers = new HashMap()); + HashMap perPathContainers = (HashMap) perProjectContainers.get(project); + if (perPathContainers == null) + perProjectContainers.put(project, perPathContainers = new HashMap()); + perPathContainers.put(containerPath, container); + } + + public IClasspathContainer containerBeingInitializedGet(IJavaProject project, IPath containerPath) { + Map perProjectContainers = (Map)this.containersBeingInitiliazed.get(); + if (perProjectContainers == null) + return null; + HashMap perPathContainers = (HashMap) perProjectContainers.get(project); + if (perPathContainers == null) + return null; + return (IClasspathContainer) perPathContainers.get(containerPath); + } + + public IClasspathContainer containerBeingInitializedRemove(IJavaProject project, IPath containerPath) { + Map perProjectContainers = (Map)this.containersBeingInitiliazed.get(); + if (perProjectContainers == null) + return null; + HashMap perPathContainers = (HashMap) perProjectContainers.get(project); + if (perPathContainers == null) + return null; + IClasspathContainer container = (IClasspathContainer) perPathContainers.remove(containerPath); + if (perPathContainers.size() == 0) + perPathContainers.remove(project); + if (perProjectContainers.size() == 0) + this.containersBeingInitiliazed.set(null); + return container; + } public synchronized void containerPut(IJavaProject project, IPath containerPath, IClasspathContainer container){ @@ -1719,6 +1755,9 @@ } } else { container = initializeContainer(project, containerPath); + containerBeingInitializedRemove(project, containerPath); + SetContainerOperation operation = new SetContainerOperation(containerPath, new IJavaProject[] {project}, new IClasspathContainer[] {container}); + operation.runOperation(null); } } return container; @@ -2434,6 +2473,7 @@ new IWorkspaceRunnable() { public void run(IProgressMonitor monitor) throws CoreException { try { + // Collect all containers Set entrySet = allContainerPaths.entrySet(); int length = entrySet.size(); if (monitor != null) @@ -2451,10 +2491,34 @@ for (int j = 0; j < length2; j++) { IPath path = paths[j]; initializeContainer(javaProject, path); + IClasspathContainer container = containerBeingInitializedGet(javaProject, path); + if (container != null) { + containerPut(javaProject, path, container); + } } if (monitor != null) monitor.worked(1); } + + // Set all containers + Map perProjectContainers = (Map) JavaModelManager.this.containersBeingInitiliazed.get(); + if (perProjectContainers != null) { + Iterator entriesIterator = perProjectContainers.entrySet().iterator(); + while (entriesIterator.hasNext()) { + Map.Entry entry = (Map.Entry) entriesIterator.next(); + IJavaProject project = (IJavaProject) entry.getKey(); + HashMap perPathContainers = (HashMap) entry.getValue(); + Iterator containersIterator = perPathContainers.entrySet().iterator(); + while (containersIterator.hasNext()) { + Map.Entry containerEntry = (Map.Entry) containersIterator.next(); + IPath containerPath = (IPath) containerEntry.getKey(); + IClasspathContainer container = (IClasspathContainer) containerEntry.getValue(); + SetContainerOperation operation = new SetContainerOperation(containerPath, new IJavaProject[] {project}, new IClasspathContainer[] {container}); + operation.runOperation(monitor); + } + } + JavaModelManager.this.containersBeingInitiliazed.set(null); + } } finally { if (monitor != null) monitor.done(); @@ -2526,8 +2590,8 @@ monitor.subTask(""); //$NON-NLS-1$ // retrieve value (if initialization was successful) - container = containerGet(project, containerPath); - if (container == CONTAINER_INITIALIZATION_IN_PROGRESS) { + container = containerBeingInitializedGet(project, containerPath); + if (container == null && containerGet(project, containerPath) == CONTAINER_INITIALIZATION_IN_PROGRESS) { // initializer failed to do its job: redirect to the failure container container = initializer.getFailureContainer(containerPath, project); if (container == null) { 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.633 diff -u -r1.633 JavaCore.java --- model/org/eclipse/jdt/core/JavaCore.java 29 Nov 2008 22:35:36 -0000 1.633 +++ model/org/eclipse/jdt/core/JavaCore.java 6 Jan 2009 16:51:36 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. + * Copyright (c) 2000, 2009 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 @@ -4711,6 +4711,18 @@ public static void setClasspathContainer(IPath containerPath, IJavaProject[] affectedProjects, IClasspathContainer[] respectiveContainers, IProgressMonitor monitor) throws JavaModelException { if (affectedProjects.length != respectiveContainers.length) throw new ClasspathEntry.AssertionFailedException("Projects and containers collections should have the same size"); //$NON-NLS-1$ + if (affectedProjects.length == 1) { + IClasspathContainer container = respectiveContainers[0]; + if (container != null) { + JavaModelManager manager = JavaModelManager.getJavaModelManager(); + IJavaProject project = affectedProjects[0]; + IClasspathContainer existingCointainer = manager.containerGet(project, containerPath); + if (existingCointainer == JavaModelManager.CONTAINER_INITIALIZATION_IN_PROGRESS) { + manager.containerBeingInitializedPut(project, containerPath, container); + return; + } + } + } SetContainerOperation operation = new SetContainerOperation(containerPath, affectedProjects, respectiveContainers); operation.runOperation(monitor); }