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

Collapse All | Expand All

(-)model/org/eclipse/jdt/internal/core/ProjectReferenceChange.java (+3 lines)
Lines 97-100 Link Here
97
				throw new JavaModelException(e);
97
				throw new JavaModelException(e);
98
		}
98
		}
99
	}
99
	}
100
	public String toString() {
101
		return "ProjectRefenceChange: " + this.project.getElementName(); //$NON-NLS-1$
102
	}
100
}
103
}
(-)model/org/eclipse/jdt/internal/core/DeltaProcessor.java (-12 / +24 lines)
Lines 419-437 Link Here
419
						// workaround for bug 15168 circular errors not reported 
419
						// workaround for bug 15168 circular errors not reported 
420
						if (JavaProject.hasJavaNature(project)) {
420
						if (JavaProject.hasJavaNature(project)) {
421
							addToParentInfo(javaProject);
421
							addToParentInfo(javaProject);
422
							
422
							readRawClasspath(javaProject);
423
							try {
424
								// force to (re)read the .classpath file
425
								javaProject.getPerProjectInfo().readAndCacheClasspath(javaProject);
426
							} catch (JavaModelException e) {	
427
								if (VERBOSE) {
428
									e.printStackTrace();
429
								}
430
							}
431
							
432
							// ensure project references are updated (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=121569)
423
							// ensure project references are updated (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=121569)
433
							ClasspathChange change = (ClasspathChange) this.classpathChanges.get(project);
424
							checkProjectReferenceChange(project, javaProject);
434
							this.state.addProjectReferenceChange(javaProject, change == null ? null : change.oldResolvedClasspath);
435
						}
425
						}
436
						
426
						
437
						this.state.rootsAreStale = true; 
427
						this.state.rootsAreStale = true; 
Lines 448-453 Link Here
448
								if (project.isOpen()) {
438
								if (project.isOpen()) {
449
									if (JavaProject.hasJavaNature(project)) {
439
									if (JavaProject.hasJavaNature(project)) {
450
										addToParentInfo(javaProject);
440
										addToParentInfo(javaProject);
441
										readRawClasspath(javaProject);
442
										// ensure project references are updated
443
										checkProjectReferenceChange(project, javaProject);
451
									}
444
									}
452
								} else {
445
								} else {
453
									try {
446
									try {
Lines 472-477 Link Here
472
									// workaround for bug 15168 circular errors not reported 
465
									// workaround for bug 15168 circular errors not reported 
473
									if (isJavaProject) {
466
									if (isJavaProject) {
474
										this.addToParentInfo(javaProject);
467
										this.addToParentInfo(javaProject);
468
										readRawClasspath(javaProject);
469
										// ensure project references are updated (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=172666)
470
										checkProjectReferenceChange(project, javaProject);
475
									} else {
471
									} else {
476
										// remove classpath cache so that initializeRoots() will not consider the project has a classpath
472
										// remove classpath cache so that initializeRoots() will not consider the project has a classpath
477
										this.manager.removePerProjectInfo(javaProject);
473
										this.manager.removePerProjectInfo(javaProject);
Lines 556-561 Link Here
556
			}
552
			}
557
		}
553
		}
558
	}
554
	}
555
556
	private void checkProjectReferenceChange(IProject project, JavaProject javaProject) {
557
		ClasspathChange change = (ClasspathChange) this.classpathChanges.get(project);
558
		this.state.addProjectReferenceChange(javaProject, change == null ? null : change.oldResolvedClasspath);
559
	}
560
561
	private void readRawClasspath(JavaProject javaProject) {
562
		try {
563
			// force to (re)read the .classpath file
564
			javaProject.getPerProjectInfo().readAndCacheClasspath(javaProject);
565
		} catch (JavaModelException e) {	
566
			if (VERBOSE) {
567
				e.printStackTrace();
568
			}
569
		}
570
	}
559
	private void checkSourceAttachmentChange(IResourceDelta delta, IResource res) {
571
	private void checkSourceAttachmentChange(IResourceDelta delta, IResource res) {
560
		IPath rootPath = (IPath)this.state.sourceAttachments.get(res.getFullPath());
572
		IPath rootPath = (IPath)this.state.sourceAttachments.get(res.getFullPath());
561
		if (rootPath != null) {
573
		if (rootPath != null) {
(-)model/org/eclipse/jdt/internal/core/ClasspathChange.java (+4 lines)
Lines 497-500 Link Here
497
			}
497
			}
498
		}
498
		}
499
	}
499
	}
500
	
501
	public String toString() {
502
		return "ClasspathChange: " + this.project.getElementName(); //$NON-NLS-1$
503
	}
500
}
504
}
(-)src/org/eclipse/jdt/core/tests/model/JavaProjectTests.java (+129 lines)
Lines 23-28 Link Here
23
import org.eclipse.core.runtime.Path;
23
import org.eclipse.core.runtime.Path;
24
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
24
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
25
import org.eclipse.jdt.core.*;
25
import org.eclipse.jdt.core.*;
26
import org.eclipse.jdt.core.tests.model.ClasspathInitializerTests.DefaultContainerInitializer;
26
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
27
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
27
import org.eclipse.jdt.internal.core.JavaModelManager;
28
import org.eclipse.jdt.internal.core.JavaModelManager;
28
import org.eclipse.jdt.internal.core.UserLibrary;
29
import org.eclipse.jdt.internal.core.UserLibrary;
Lines 1069-1074 Link Here
1069
		deleteProjects(new String[] {"P1", "P2"});
1070
		deleteProjects(new String[] {"P1", "P2"});
1070
	}
1071
	}
1071
}
1072
}
1073
1074
/*
1075
 * Ensures that importing a project correctly update the project references
1076
 * (regression test for bug 172666 Importing pde.ui and dependencies as binary gives compile error)
1077
 */
1078
public void testProjectImport2() throws CoreException {
1079
	IResourceChangeListener resourceChangeListener = new IResourceChangeListener() {
1080
		public void resourceChanged(IResourceChangeEvent event) {
1081
			try {
1082
				ContainerInitializer.initializer.initialize(new Path("org.eclipse.jdt.core.tests.model.TEST_CONTAINER"), getJavaProject("P2"));
1083
			} catch (CoreException e) {
1084
				e.printStackTrace();
1085
			}
1086
		}
1087
	
1088
	};
1089
	try {
1090
		createJavaProject("P1");
1091
		createFile("/P1/lib.jar", "");
1092
		IWorkspaceRunnable runnable = new IWorkspaceRunnable() {
1093
			public void run(IProgressMonitor monitor) throws CoreException {
1094
				createProject("P2");
1095
				createFile(
1096
					"/P2/.classpath", 
1097
					"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
1098
					"<classpath>\n" +
1099
					"	<classpathentry kind=\"con\" path=\"org.eclipse.jdt.core.tests.model.TEST_CONTAINER\"/>\n" +
1100
					"</classpath>"
1101
				);
1102
				ContainerInitializer.setInitializer(new DefaultContainerInitializer(new String[] {"P2", "/P1/lib.jar"}));
1103
				getWorkspace().checkpoint(false/*don't build*/);
1104
				editFile(
1105
					"/P2/.project",
1106
					"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + 
1107
					"<projectDescription>\n" + 
1108
					"	<name>P2</name>\n" + 
1109
					"	<comment></comment>\n" + 
1110
					"	<projects>\n" + 
1111
					"	</projects>\n" + 
1112
					"	<buildSpec>\n" + 
1113
					"		<buildCommand>\n" + 
1114
					"			<name>org.eclipse.jdt.core.javabuilder</name>\n" + 
1115
					"			<arguments>\n" + 
1116
					"			</arguments>\n" + 
1117
					"		</buildCommand>\n" + 
1118
					"	</buildSpec>\n" + 
1119
					"	<natures>\n" + 
1120
					"		<nature>org.eclipse.jdt.core.javanature</nature>\n" + 
1121
					"	</natures>\n" + 
1122
					"</projectDescription>"
1123
				);
1124
				ContainerInitializer.setInitializer(new DefaultContainerInitializer(new String[] {"P2", "/P1"}));
1125
			}
1126
		};
1127
		JavaCore.addPreProcessingResourceChangedListener(resourceChangeListener, IResourceChangeEvent.POST_CHANGE);
1128
		getWorkspace().run(runnable, null);
1129
		waitForAutoBuild();
1130
		IProject[] referencedProjects = getProject("P2").getReferencedProjects();
1131
		assertResourcesEqual(
1132
			"Unexpected project references", 
1133
			"/P1", 
1134
			referencedProjects);
1135
	} finally {
1136
		JavaCore.removePreProcessingResourceChangedListener(resourceChangeListener);
1137
		deleteProjects(new String[] {"P1", "P2"});
1138
	}
1139
}
1140
1141
/*
1142
 * Ensures that importing a project correctly update the project references
1143
 * (regression test for bug 172666 Importing pde.ui and dependencies as binary gives compile error)
1144
 */
1145
public void testProjectImport3() throws CoreException {
1146
	IResourceChangeListener resourceChangeListener = new IResourceChangeListener() {
1147
		public void resourceChanged(IResourceChangeEvent event) {
1148
			try {
1149
				ContainerInitializer.initializer.initialize(new Path("org.eclipse.jdt.core.tests.model.TEST_CONTAINER"), getJavaProject("P2"));
1150
			} catch (CoreException e) {
1151
				e.printStackTrace();
1152
			}
1153
		}
1154
	
1155
	};
1156
	try {
1157
		createJavaProject("P1");
1158
		createFile("/P1/lib.jar", "");
1159
		createProject("P2");
1160
		createFile(
1161
			"/P2/.classpath", 
1162
			"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
1163
			"<classpath>\n" +
1164
			"	<classpathentry kind=\"con\" path=\"org.eclipse.jdt.core.tests.model.TEST_CONTAINER\"/>\n" +
1165
			"</classpath>"
1166
		);
1167
		ContainerInitializer.setInitializer(new DefaultContainerInitializer(new String[] {"P2", "/P1"}));
1168
		JavaCore.addPreProcessingResourceChangedListener(resourceChangeListener, IResourceChangeEvent.POST_CHANGE);
1169
		editFile(
1170
			"/P2/.project",
1171
			"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + 
1172
			"<projectDescription>\n" + 
1173
			"	<name>P2</name>\n" + 
1174
			"	<comment></comment>\n" + 
1175
			"	<projects>\n" + 
1176
			"	</projects>\n" + 
1177
			"	<buildSpec>\n" + 
1178
			"		<buildCommand>\n" + 
1179
			"			<name>org.eclipse.jdt.core.javabuilder</name>\n" + 
1180
			"			<arguments>\n" + 
1181
			"			</arguments>\n" + 
1182
			"		</buildCommand>\n" + 
1183
			"	</buildSpec>\n" + 
1184
			"	<natures>\n" + 
1185
			"		<nature>org.eclipse.jdt.core.javanature</nature>\n" + 
1186
			"	</natures>\n" + 
1187
			"</projectDescription>"
1188
		);
1189
		waitForAutoBuild();
1190
		IProject[] referencedProjects = getProject("P2").getReferencedProjects();
1191
		assertResourcesEqual(
1192
			"Unexpected project references", 
1193
			"/P1", 
1194
			referencedProjects);
1195
	} finally {
1196
		JavaCore.removePreProcessingResourceChangedListener(resourceChangeListener);
1197
		deleteProjects(new String[] {"P1", "P2"});
1198
	}
1199
}
1200
1072
/**
1201
/**
1073
 * Test that the correct package fragments exist in the project.
1202
 * Test that the correct package fragments exist in the project.
1074
 */
1203
 */

Return to bug 172666