View | Details | Raw Unified | Return to bug 259607
Collapse All | Expand All

(-)model/org/eclipse/jdt/internal/core/JavaModelManager.java (-4 / +68 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2008 IBM Corporation and others.
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 103-109 Link Here
103
	public HashMap containers = new HashMap(5);
103
	public HashMap containers = new HashMap(5);
104
	public HashMap previousSessionContainers = new HashMap(5);
104
	public HashMap previousSessionContainers = new HashMap(5);
105
	private ThreadLocal containerInitializationInProgress = new ThreadLocal();
105
	private ThreadLocal containerInitializationInProgress = new ThreadLocal();
106
106
	ThreadLocal containersBeingInitiliazed = new ThreadLocal();
107
	
107
	public static final int NO_BATCH_INITIALIZATION = 0;
108
	public static final int NO_BATCH_INITIALIZATION = 0;
108
	public static final int NEED_BATCH_INITIALIZATION = 1;
109
	public static final int NEED_BATCH_INITIALIZATION = 1;
109
	public static final int BATCH_INITIALIZATION_IN_PROGRESS = 2;
110
	public static final int BATCH_INITIALIZATION_IN_PROGRESS = 2;
Lines 495-500 Link Here
495
			initializations.put(project, projectInitializations = new HashSet());
496
			initializations.put(project, projectInitializations = new HashSet());
496
		projectInitializations.add(containerPath);
497
		projectInitializations.add(containerPath);
497
	}
498
	}
499
	
500
	public void containerBeingInitializedPut(IJavaProject project, IPath containerPath, IClasspathContainer container) {
501
		Map perProjectContainers = (Map)this.containersBeingInitiliazed.get();
502
		if (perProjectContainers == null)
503
			this.containersBeingInitiliazed.set(perProjectContainers = new HashMap());
504
		HashMap perPathContainers = (HashMap) perProjectContainers.get(project);
505
		if (perPathContainers == null)
506
			perProjectContainers.put(project, perPathContainers = new HashMap());
507
		perPathContainers.put(containerPath, container);
508
	}
509
510
	public IClasspathContainer containerBeingInitializedGet(IJavaProject project, IPath containerPath) {
511
		Map perProjectContainers = (Map)this.containersBeingInitiliazed.get();
512
		if (perProjectContainers == null)
513
			return null;
514
		HashMap perPathContainers = (HashMap) perProjectContainers.get(project);
515
		if (perPathContainers == null)
516
			return null;
517
		return (IClasspathContainer) perPathContainers.get(containerPath);
518
	}
519
520
	public IClasspathContainer containerBeingInitializedRemove(IJavaProject project, IPath containerPath) {
521
		Map perProjectContainers = (Map)this.containersBeingInitiliazed.get();
522
		if (perProjectContainers == null)
523
			return null;
524
		HashMap perPathContainers = (HashMap) perProjectContainers.get(project);
525
		if (perPathContainers == null)
526
			return null;
527
		IClasspathContainer container = (IClasspathContainer) perPathContainers.remove(containerPath);
528
		if (perPathContainers.size() == 0)
529
			perPathContainers.remove(project);
530
		if (perProjectContainers.size() == 0)
531
			this.containersBeingInitiliazed.set(null);
532
		return container;
533
	}
498
534
499
	public synchronized void containerPut(IJavaProject project, IPath containerPath, IClasspathContainer container){
535
	public synchronized void containerPut(IJavaProject project, IPath containerPath, IClasspathContainer container){
500
536
Lines 1719-1724 Link Here
1719
				}
1755
				}
1720
			} else {
1756
			} else {
1721
				container = initializeContainer(project, containerPath);
1757
				container = initializeContainer(project, containerPath);
1758
				containerBeingInitializedRemove(project, containerPath);
1759
				SetContainerOperation operation = new SetContainerOperation(containerPath, new IJavaProject[] {project}, new IClasspathContainer[] {container});
1760
				operation.runOperation(null);
1722
			}
1761
			}
1723
		}
1762
		}
1724
		return container;
1763
		return container;
Lines 2434-2439 Link Here
2434
				new IWorkspaceRunnable() {
2473
				new IWorkspaceRunnable() {
2435
					public void run(IProgressMonitor monitor) throws CoreException {
2474
					public void run(IProgressMonitor monitor) throws CoreException {
2436
						try {
2475
						try {
2476
							// Collect all containers
2437
							Set entrySet = allContainerPaths.entrySet();
2477
							Set entrySet = allContainerPaths.entrySet();
2438
							int length = entrySet.size();
2478
							int length = entrySet.size();
2439
							if (monitor != null)
2479
							if (monitor != null)
Lines 2451-2460 Link Here
2451
								for (int j = 0; j < length2; j++) {
2491
								for (int j = 0; j < length2; j++) {
2452
									IPath path = paths[j];
2492
									IPath path = paths[j];
2453
									initializeContainer(javaProject, path);
2493
									initializeContainer(javaProject, path);
2494
									IClasspathContainer container = containerBeingInitializedGet(javaProject, path);
2495
									if (container != null) {
2496
										containerPut(javaProject, path, container);
2497
									}
2454
								}
2498
								}
2455
								if (monitor != null)
2499
								if (monitor != null)
2456
									monitor.worked(1);
2500
									monitor.worked(1);
2457
							}
2501
							}
2502
							
2503
							// Set all containers
2504
							Map perProjectContainers = (Map) JavaModelManager.this.containersBeingInitiliazed.get();
2505
							if (perProjectContainers != null) {
2506
								Iterator entriesIterator = perProjectContainers.entrySet().iterator();
2507
								while (entriesIterator.hasNext()) {
2508
									Map.Entry entry = (Map.Entry) entriesIterator.next();
2509
									IJavaProject project = (IJavaProject) entry.getKey();
2510
									HashMap perPathContainers = (HashMap) entry.getValue();
2511
									Iterator containersIterator = perPathContainers.entrySet().iterator();
2512
									while (containersIterator.hasNext()) {
2513
										Map.Entry containerEntry = (Map.Entry) containersIterator.next();
2514
										IPath containerPath = (IPath) containerEntry.getKey();
2515
										IClasspathContainer container = (IClasspathContainer) containerEntry.getValue();
2516
										SetContainerOperation operation = new SetContainerOperation(containerPath, new IJavaProject[] {project}, new IClasspathContainer[] {container});
2517
										operation.runOperation(monitor);
2518
									}
2519
								}
2520
								JavaModelManager.this.containersBeingInitiliazed.set(null);
2521
							}
2458
						} finally {
2522
						} finally {
2459
							if (monitor != null)
2523
							if (monitor != null)
2460
								monitor.done();
2524
								monitor.done();
Lines 2526-2533 Link Here
2526
					monitor.subTask(""); //$NON-NLS-1$
2590
					monitor.subTask(""); //$NON-NLS-1$
2527
2591
2528
				// retrieve value (if initialization was successful)
2592
				// retrieve value (if initialization was successful)
2529
				container = containerGet(project, containerPath);
2593
				container = containerBeingInitializedGet(project, containerPath);
2530
				if (container == CONTAINER_INITIALIZATION_IN_PROGRESS) {
2594
				if (container == null && containerGet(project, containerPath) == CONTAINER_INITIALIZATION_IN_PROGRESS) {
2531
					// initializer failed to do its job: redirect to the failure container
2595
					// initializer failed to do its job: redirect to the failure container
2532
					container = initializer.getFailureContainer(containerPath, project);
2596
					container = initializer.getFailureContainer(containerPath, project);
2533
					if (container == null) {
2597
					if (container == null) {
(-)model/org/eclipse/jdt/core/JavaCore.java (-1 / +13 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2008 IBM Corporation and others.
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 4711-4716 Link Here
4711
	public static void setClasspathContainer(IPath containerPath, IJavaProject[] affectedProjects, IClasspathContainer[] respectiveContainers, IProgressMonitor monitor) throws JavaModelException {
4711
	public static void setClasspathContainer(IPath containerPath, IJavaProject[] affectedProjects, IClasspathContainer[] respectiveContainers, IProgressMonitor monitor) throws JavaModelException {
4712
		if (affectedProjects.length != respectiveContainers.length)
4712
		if (affectedProjects.length != respectiveContainers.length)
4713
			throw new ClasspathEntry.AssertionFailedException("Projects and containers collections should have the same size"); //$NON-NLS-1$
4713
			throw new ClasspathEntry.AssertionFailedException("Projects and containers collections should have the same size"); //$NON-NLS-1$
4714
		if (affectedProjects.length == 1) {
4715
			IClasspathContainer container = respectiveContainers[0];
4716
			if (container != null) {
4717
				JavaModelManager manager = JavaModelManager.getJavaModelManager();
4718
				IJavaProject project = affectedProjects[0];
4719
				IClasspathContainer existingCointainer = manager.containerGet(project, containerPath);
4720
				if (existingCointainer == JavaModelManager.CONTAINER_INITIALIZATION_IN_PROGRESS) {
4721
					manager.containerBeingInitializedPut(project, containerPath, container);
4722
					return;
4723
				}
4724
			}
4725
		}
4714
		SetContainerOperation operation = new SetContainerOperation(containerPath, affectedProjects, respectiveContainers);
4726
		SetContainerOperation operation = new SetContainerOperation(containerPath, affectedProjects, respectiveContainers);
4715
		operation.runOperation(monitor);
4727
		operation.runOperation(monitor);
4716
	}
4728
	}

Return to bug 259607