View | Details | Raw Unified | Return to bug 139446 | Differences between
and this patch

Collapse All | Expand All

(-)model/org/eclipse/jdt/internal/core/ClasspathChange.java (+10 lines)
Lines 227-232 Link Here
227
			if (this.oldRawClasspath != null && !JavaProject.areClasspathsEqual(this.oldRawClasspath, newRawClasspath, this.oldOutputLocation, newOutputLocation)) {
227
			if (this.oldRawClasspath != null && !JavaProject.areClasspathsEqual(this.oldRawClasspath, newRawClasspath, this.oldOutputLocation, newOutputLocation)) {
228
				delta.changed(this.project, IJavaElementDelta.F_CLASSPATH_CHANGED);
228
				delta.changed(this.project, IJavaElementDelta.F_CLASSPATH_CHANGED);
229
				result |= HAS_DELTA;
229
				result |= HAS_DELTA;
230
				
231
				// reset containers that are no longer on the classpath
232
				// (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=139446)
233
				for (int i = 0, length = this.oldRawClasspath.length; i < length; i++) {
234
					IClasspathEntry entry = this.oldRawClasspath[i];
235
					if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
236
						if (classpathContains(newRawClasspath, entry) == -1)
237
							manager.containerPut(this.project, entry.getPath(), null);
238
					}
239
				}
230
			}
240
			}
231
					
241
					
232
			// if no changes to resolved classpath, nothing more to do
242
			// if no changes to resolved classpath, nothing more to do
(-)src/org/eclipse/jdt/core/tests/model/ClasspathInitializerTests.java (+64 lines)
Lines 896-901 Link Here
896
	}
896
	}
897
}
897
}
898
898
899
/*
900
 * Ensures that a container is not kept in the cache if no longer referenced on the classpath
901
 * (regression test for 139446 [build path] bug in the Edit Library dialog box, when changing the default JRE, and switching from alternate JRE to workspace default)
902
 */
903
public void testContainerInitializer19() throws CoreException {
904
	try {
905
		// setup
906
		ContainerInitializer.setInitializer(new DefaultContainerInitializer(new String[] {"P1", "/P1/lib1.jar"}));
907
		IJavaProject p1 = createJavaProject(
908
				"P1", 
909
				new String[] {}, 
910
				new String[] {"org.eclipse.jdt.core.tests.model.TEST_CONTAINER"}, 
911
				"");
912
		createFile("/P1/lib1.jar", "");
913
		createFile("/P1/lib2.jar", "");
914
		p1.getResolvedClasspath(true);
915
		IClasspathEntry[] initialClasspath = p1.getRawClasspath();
916
		
917
		// remove reference to container, change initializer, and add reference to container back
918
		p1.setRawClasspath(new IClasspathEntry[0], null);
919
		ContainerInitializer.setInitializer(new DefaultContainerInitializer(new String[] {"P1", "/P1/lib2.jar"}));
920
		p1.setRawClasspath(initialClasspath, null);
921
		
922
		assertClasspathEquals(
923
			p1.getResolvedClasspath(true), 
924
			"/P1/lib2.jar[CPE_LIBRARY][K_BINARY][isExported:false]"
925
		);
926
	} finally {
927
		deleteProject("P1");
928
	}
929
}
930
931
/*
932
 * Ensures that container a container is not kept in the cache if no longer referenced on the classpath
933
 * (regression test for 136382 [classpath] Discard container if not referenced on classpath)
934
 */
935
public void testContainerInitializer20() throws CoreException {
936
	try {
937
		IJavaProject p = createJavaProject("P");
938
		final StringBuffer paths = new StringBuffer();
939
		DefaultContainerInitializer initializer = new DefaultContainerInitializer(new String[] {"P", "/P/lib.jar"}) {
940
			public void initialize(IPath containerPath, IJavaProject project) throws CoreException {
941
				paths.append(containerPath);
942
				paths.append('\n');
943
				super.initialize(containerPath, project);
944
			}
945
		};
946
		ContainerInitializer.setInitializer(initializer);
947
		
948
		setClasspath(p, new IClasspathEntry[] {JavaCore.newContainerEntry(new Path("org.eclipse.jdt.core.tests.model.TEST_CONTAINER/JRE1"))});
949
		setClasspath(p, new IClasspathEntry[] {JavaCore.newContainerEntry(new Path("org.eclipse.jdt.core.tests.model.TEST_CONTAINER/JRE2"))});
950
		setClasspath(p, new IClasspathEntry[] {JavaCore.newContainerEntry(new Path("org.eclipse.jdt.core.tests.model.TEST_CONTAINER/JRE1"))});
951
		assertStringEquals(
952
			"org.eclipse.jdt.core.tests.model.TEST_CONTAINER/JRE1\n" + 
953
			"org.eclipse.jdt.core.tests.model.TEST_CONTAINER/JRE2\n" + 
954
			"org.eclipse.jdt.core.tests.model.TEST_CONTAINER/JRE1\n",
955
			paths.toString(), 
956
			false);
957
	} finally {
958
		stopDeltas();
959
		deleteProject("P");
960
	}
961
}
962
899
public void testVariableInitializer01() throws CoreException {
963
public void testVariableInitializer01() throws CoreException {
900
	try {
964
	try {
901
		createProject("P1");
965
		createProject("P1");

Return to bug 139446