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

(-)src/org/eclipse/jdt/core/tests/model/ClasspathInitializerTests.java (-3 / +28 lines)
Lines 830-842 Link Here
830
	try {
830
	try {
831
		createProject("P1");
831
		createProject("P1");
832
		createFile("/P1/lib.jar", "");
832
		createFile("/P1/lib.jar", "");
833
		ContainerInitializer.setInitializer(new DefaultContainerInitializer(new String[] {"P2", "/P1/lib.jar"}));
833
		ContainerInitializer.setInitializer(new DefaultContainerInitializer(new String[] {"P2", "/P1/lib.jar", "P3", "/P1/lib.jar"}));
834
		IJavaProject p2 = createJavaProject(
834
		IJavaProject p2 = createJavaProject(
835
				"P2", 
835
				"P2", 
836
				new String[] {}, 
836
				new String[] {}, 
837
				new String[] {"org.eclipse.jdt.core.tests.model.TEST_CONTAINER"}, 
837
				new String[] {"org.eclipse.jdt.core.tests.model.TEST_CONTAINER"}, 
838
				"");
838
				"");
839
		ContainerInitializer.setInitializer(new DefaultContainerInitializer(new String[] {"P3", "/P1/lib.jar"}));
840
		createJavaProject(
839
		createJavaProject(
841
				"P3", 
840
				"P3", 
842
				new String[] {}, 
841
				new String[] {}, 
Lines 849-855 Link Here
849
		getWorkspace().addResourceChangeListener(listener, IResourceChangeEvent.POST_CHANGE);
848
		getWorkspace().addResourceChangeListener(listener, IResourceChangeEvent.POST_CHANGE);
850
		
849
		
851
		// initialize to the same value
850
		// initialize to the same value
852
		ContainerInitializer.setInitializer(new DefaultContainerInitializer(new String[] {"P2", "/P1/lib.jar"}) {
851
		ContainerInitializer.setInitializer(new DefaultContainerInitializer(new String[] {"P2", "/P1/lib.jar", "P3", "/P1/lib.jar"}) {
853
	        public void initialize(IPath containerPath, IJavaProject project) throws CoreException {
852
	        public void initialize(IPath containerPath, IJavaProject project) throws CoreException {
854
	        	// simulate concurrency (another thread is initializing all containers in parallel and thus this flag is set to true)
853
	        	// simulate concurrency (another thread is initializing all containers in parallel and thus this flag is set to true)
855
	        	JavaModelManager.getJavaModelManager().batchContainerInitializations = true;
854
	        	JavaModelManager.getJavaModelManager().batchContainerInitializations = true;
Lines 870-875 Link Here
870
		deleteProject("P3");
869
		deleteProject("P3");
871
	}
870
	}
872
}
871
}
872
/*
873
 * Ensures that an unbound container marker is created if container is reset to null
874
 * (regression test for 182204 Deleting a JRE referenced by container does not result in unbound container problem)
875
 */
876
public void testContainerInitializer18() throws CoreException {
877
	try {
878
		ContainerInitializer.setInitializer(new DefaultContainerInitializer(new String[] {"P1", "/P1/lib.jar"}));
879
		IJavaProject p1 = createJavaProject(
880
				"P1", 
881
				new String[] {}, 
882
				new String[] {"org.eclipse.jdt.core.tests.model.TEST_CONTAINER"}, 
883
				"");
884
		createFile("/P1/lib.jar", "");
885
		p1.getResolvedClasspath(true);
886
		waitForAutoBuild();
887
		
888
		ContainerInitializer.setInitializer(new DefaultContainerInitializer(new String[0]));
889
		JavaCore.setClasspathContainer(new Path("org.eclipse.jdt.core.tests.model.TEST_CONTAINER"), new IJavaProject[] {p1}, new IClasspathContainer[] {null}, null);
890
		assertMarkers(
891
			"Unexpected markers", 
892
			"Unbound classpath container: \'org.eclipse.jdt.core.tests.model.TEST_CONTAINER\' in project \'P1\'",
893
			p1);
894
	} finally {
895
		deleteProject("P1");
896
	}
897
}
873
898
874
public void testVariableInitializer01() throws CoreException {
899
public void testVariableInitializer01() throws CoreException {
875
	try {
900
	try {
(-)model/org/eclipse/jdt/internal/core/JavaModelManager.java (-18 / +20 lines)
Lines 530-542 Link Here
530
		if (projectLength != 1) 
530
		if (projectLength != 1) 
531
			return false;
531
			return false;
532
		final IClasspathContainer container = respectiveContainers[0];
532
		final IClasspathContainer container = respectiveContainers[0];
533
		if (container == null)
534
			return false;
535
		IJavaProject project = projects[0];
533
		IJavaProject project = projects[0];
536
		// optimize only if initializing, otherwise we are in a regular setContainer(...) call
534
		// optimize only if initializing, otherwise we are in a regular setContainer(...) call
537
		if (!containerIsInitializationInProgress(project, containerPath)) 
535
		if (!containerIsInitializationInProgress(project, containerPath)) 
538
			return false;
536
			return false;
539
		IClasspathContainer previousContainer = containerGetDefaultToPreviousSession(project, containerPath);
537
		IClasspathContainer previousContainer = containerGetDefaultToPreviousSession(project, containerPath);
538
		if (container == null) {
539
			if (previousContainer == null) {
540
				containerPut(project, containerPath, null);
541
				return true;
542
			}
543
			return false;
544
		}
540
		final IClasspathEntry[] newEntries = container.getClasspathEntries();
545
		final IClasspathEntry[] newEntries = container.getClasspathEntries();
541
		if (previousContainer == null) 
546
		if (previousContainer == null) 
542
			if (newEntries.length == 0) {
547
			if (newEntries.length == 0) {
Lines 1528-1548 Link Here
1528
			} else {
1533
			} else {
1529
				container = initializeContainer(project, containerPath);
1534
				container = initializeContainer(project, containerPath);
1530
			}
1535
			}
1531
			if (container == null) { // initializer failed to do its job: redirect to the failure container
1532
				ClasspathContainerInitializer initializer = JavaCore.getClasspathContainerInitializer(containerPath.segment(0));
1533
				if (initializer == null) {
1534
					// create a dummy initializer and get the default failure container
1535
					container = (new ClasspathContainerInitializer() {
1536
						public void initialize(IPath path, IJavaProject javaProject) throws CoreException {
1537
							// not used
1538
						}
1539
					}).getFailureContainer(containerPath, project);
1540
				} else {
1541
					container = initializer.getFailureContainer(containerPath, project);
1542
				}
1543
				if (container != null)
1544
					containerPut(project, containerPath, container);
1545
			}
1546
		}
1536
		}
1547
		return container;			
1537
		return container;			
1548
	}
1538
	}
Lines 2206-2212 Link Here
2206
				
2196
				
2207
				// retrieve value (if initialization was successful)
2197
				// retrieve value (if initialization was successful)
2208
				container = containerGet(project, containerPath);
2198
				container = containerGet(project, containerPath);
2209
				if (container == CONTAINER_INITIALIZATION_IN_PROGRESS) return null; // break cycle
2199
				if (container == CONTAINER_INITIALIZATION_IN_PROGRESS) {
2200
					// initializer failed to do its job: redirect to the failure container
2201
					container = initializer.getFailureContainer(containerPath, project);
2202
					if (container == null)
2203
						return null; // break cycle
2204
					containerPut(project, containerPath, container);
2205
				}
2210
				ok = true;
2206
				ok = true;
2211
			} catch (CoreException e) {
2207
			} catch (CoreException e) {
2212
				if (e instanceof JavaModelException) {
2208
				if (e instanceof JavaModelException) {
Lines 2237-2242 Link Here
2237
			if (CP_RESOLVE_VERBOSE_ADVANCED)
2233
			if (CP_RESOLVE_VERBOSE_ADVANCED)
2238
				verbose_container_value_after_initialization(project, containerPath, container);
2234
				verbose_container_value_after_initialization(project, containerPath, container);
2239
		} else {
2235
		} else {
2236
			// create a dummy initializer and get the default failure container
2237
			container = (new ClasspathContainerInitializer() {
2238
				public void initialize(IPath path, IJavaProject javaProject) throws CoreException {
2239
					// not used
2240
				}
2241
			}).getFailureContainer(containerPath, project);
2240
			if (CP_RESOLVE_VERBOSE_ADVANCED)
2242
			if (CP_RESOLVE_VERBOSE_ADVANCED)
2241
				verbose_no_container_initializer_found(project, containerPath);
2243
				verbose_no_container_initializer_found(project, containerPath);
2242
		}
2244
		}

Return to bug 182204