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

Collapse All | Expand All

(-)model/org/eclipse/jdt/internal/core/ProjectReferenceChange.java (-50 / +62 lines)
Lines 15-22 Link Here
15
15
16
import org.eclipse.core.resources.IProject;
16
import org.eclipse.core.resources.IProject;
17
import org.eclipse.core.resources.IProjectDescription;
17
import org.eclipse.core.resources.IProjectDescription;
18
import org.eclipse.core.resources.IWorkspace;
18
import org.eclipse.core.resources.IWorkspaceRoot;
19
import org.eclipse.core.resources.IWorkspaceRoot;
20
import org.eclipse.core.resources.IWorkspaceRunnable;
19
import org.eclipse.core.runtime.CoreException;
21
import org.eclipse.core.runtime.CoreException;
22
import org.eclipse.core.runtime.IProgressMonitor;
23
import org.eclipse.core.runtime.jobs.ISchedulingRule;
20
import org.eclipse.jdt.core.IClasspathEntry;
24
import org.eclipse.jdt.core.IClasspathEntry;
21
import org.eclipse.jdt.core.JavaModelException;
25
import org.eclipse.jdt.core.JavaModelException;
22
import org.eclipse.jdt.core.compiler.CharOperation;
26
import org.eclipse.jdt.core.compiler.CharOperation;
Lines 37-97 Link Here
37
	 */
41
	 */
38
	public void updateProjectReferencesIfNecessary() throws JavaModelException {
42
	public void updateProjectReferencesIfNecessary() throws JavaModelException {
39
		
43
		
40
		String[] oldRequired = this.oldResolvedClasspath == null ? CharOperation.NO_STRINGS : this.project.projectPrerequisites(this.oldResolvedClasspath);
44
		final String[] oldRequired = this.oldResolvedClasspath == null ? CharOperation.NO_STRINGS : this.project.projectPrerequisites(this.oldResolvedClasspath);
41
		IClasspathEntry[] newResolvedClasspath = this.project.getResolvedClasspath();
45
		IClasspathEntry[] newResolvedClasspath = this.project.getResolvedClasspath();
42
		String[] newRequired = this.project.projectPrerequisites(newResolvedClasspath);
46
		final String[] newRequired = this.project.projectPrerequisites(newResolvedClasspath);
43
		try {
47
		final IProject projectResource = this.project.getProject();
44
			IProject projectResource = this.project.getProject();
48
		IWorkspaceRunnable runnable = new IWorkspaceRunnable() {
45
			IProjectDescription description = projectResource.getDescription();
49
			public void run(IProgressMonitor monitor) throws CoreException {
46
			 
50
				IProjectDescription description = projectResource.getDescription();
47
			IProject[] projectReferences = description.getDynamicReferences();
51
				 
48
			
52
				IProject[] projectReferences = description.getDynamicReferences();
49
			HashSet oldReferences = new HashSet(projectReferences.length);
53
				
50
			for (int i = 0; i < projectReferences.length; i++){
54
				HashSet oldReferences = new HashSet(projectReferences.length);
51
				String projectName = projectReferences[i].getName();
55
				for (int i = 0; i < projectReferences.length; i++){
52
				oldReferences.add(projectName);
56
					String projectName = projectReferences[i].getName();
53
			}
57
					oldReferences.add(projectName);
54
			HashSet newReferences = (HashSet)oldReferences.clone();
58
				}
55
	
59
				HashSet newReferences = (HashSet)oldReferences.clone();
56
			for (int i = 0; i < oldRequired.length; i++){
60
		
57
				String projectName = oldRequired[i];
61
				for (int i = 0; i < oldRequired.length; i++){
58
				newReferences.remove(projectName);
62
					String projectName = oldRequired[i];
59
			}
63
					newReferences.remove(projectName);
60
			for (int i = 0; i < newRequired.length; i++){
64
				}
61
				String projectName = newRequired[i];
65
				for (int i = 0; i < newRequired.length; i++){
62
				newReferences.add(projectName);
66
					String projectName = newRequired[i];
63
			}
67
					newReferences.add(projectName);
64
	
68
				}
65
			Iterator iter;
69
		
66
			int newSize = newReferences.size();
70
				Iterator iter;
67
			
71
				int newSize = newReferences.size();
68
			checkIdentity: {
72
				
69
				if (oldReferences.size() == newSize){
73
				checkIdentity: {
70
					iter = newReferences.iterator();
74
					if (oldReferences.size() == newSize){
71
					while (iter.hasNext()){
75
						iter = newReferences.iterator();
72
						if (!oldReferences.contains(iter.next())){
76
						while (iter.hasNext()){
73
							break checkIdentity;
77
							if (!oldReferences.contains(iter.next())){
78
								break checkIdentity;
79
							}
74
						}
80
						}
81
						return;
75
					}
82
					}
76
					return;
77
				}
83
				}
84
				String[] requiredProjectNames = new String[newSize];
85
				int index = 0;
86
				iter = newReferences.iterator();
87
				while (iter.hasNext()){
88
					requiredProjectNames[index++] = (String)iter.next();
89
				}
90
				Util.sort(requiredProjectNames); // ensure that if changed, the order is consistent
91
				
92
				IProject[] requiredProjectArray = new IProject[newSize];
93
				IWorkspaceRoot wksRoot = projectResource.getWorkspace().getRoot();
94
				for (int i = 0; i < newSize; i++){
95
					requiredProjectArray[i] = wksRoot.getProject(requiredProjectNames[i]);
96
				}
97
				description.setDynamicReferences(requiredProjectArray);
98
				projectResource.setDescription(description, null);
78
			}
99
			}
79
			String[] requiredProjectNames = new String[newSize];
100
		};
80
			int index = 0;
101
		try {
81
			iter = newReferences.iterator();
102
			// ensure that a sheduling rule is used so that the project description is not modified by another thread while we update it
82
			while (iter.hasNext()){
103
			// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=214981
83
				requiredProjectNames[index++] = (String)iter.next();
104
			IWorkspace workspace = projectResource.getWorkspace();
84
			}
105
			ISchedulingRule rule = workspace.getRuleFactory().modifyRule(projectResource); // sheduling rule for modifying the project
85
			Util.sort(requiredProjectNames); // ensure that if changed, the order is consistent
106
			workspace.run(runnable, rule, IWorkspace.AVOID_UPDATE, null);
86
			
87
			IProject[] requiredProjectArray = new IProject[newSize];
88
			IWorkspaceRoot wksRoot = projectResource.getWorkspace().getRoot();
89
			for (int i = 0; i < newSize; i++){
90
				requiredProjectArray[i] = wksRoot.getProject(requiredProjectNames[i]);
91
			}
92
			description.setDynamicReferences(requiredProjectArray);
93
			projectResource.setDescription(description, null);
94
	
95
		} catch(CoreException e){
107
		} catch(CoreException e){
96
			if (!ExternalJavaProject.EXTERNAL_PROJECT_NAME.equals(this.project.getElementName()))
108
			if (!ExternalJavaProject.EXTERNAL_PROJECT_NAME.equals(this.project.getElementName()))
97
				throw new JavaModelException(e);
109
				throw new JavaModelException(e);

Return to bug 214981