Lines 22-27
Link Here
|
22 |
|
22 |
|
23 |
import org.eclipse.core.resources.*; |
23 |
import org.eclipse.core.resources.*; |
24 |
import org.eclipse.core.runtime.*; |
24 |
import org.eclipse.core.runtime.*; |
|
|
25 |
import org.eclipse.core.runtime.jobs.ISchedulingRule; |
25 |
import org.eclipse.jdt.core.*; |
26 |
import org.eclipse.jdt.core.*; |
26 |
import org.eclipse.jdt.core.compiler.CharOperation; |
27 |
import org.eclipse.jdt.core.compiler.CharOperation; |
27 |
import org.eclipse.jdt.internal.core.util.Util; |
28 |
import org.eclipse.jdt.internal.core.util.Util; |
Lines 93-99
Link Here
|
93 |
*/ |
94 |
*/ |
94 |
public void updateProjectReferencesIfNecessary() throws JavaModelException { |
95 |
public void updateProjectReferencesIfNecessary() throws JavaModelException { |
95 |
|
96 |
|
96 |
String[] oldRequired = this.oldResolvedPath == null ? CharOperation.NO_STRINGS : this.project.projectPrerequisites(this.oldResolvedPath); |
97 |
final String[] oldRequired = this.oldResolvedPath == null ? CharOperation.NO_STRINGS : this.project.projectPrerequisites(this.oldResolvedPath); |
97 |
|
98 |
|
98 |
if (this.newResolvedPath == null) { |
99 |
if (this.newResolvedPath == null) { |
99 |
if (this.newRawPath == null) |
100 |
if (this.newRawPath == null) |
Lines 106-164
Link Here
|
106 |
true/*generate marker on error*/, |
107 |
true/*generate marker on error*/, |
107 |
null/*no reverse map*/); |
108 |
null/*no reverse map*/); |
108 |
} |
109 |
} |
109 |
String[] newRequired = this.project.projectPrerequisites(this.newResolvedPath); |
110 |
final String[] newRequired = this.project.projectPrerequisites(this.newResolvedPath); |
110 |
try { |
111 |
final IProject projectResource = this.project.getProject(); |
111 |
IProject projectResource = this.project.getProject(); |
112 |
IWorkspaceRunnable runnable = new IWorkspaceRunnable() { |
112 |
IProjectDescription description = projectResource.getDescription(); |
113 |
public void run(IProgressMonitor monitor) throws CoreException { |
113 |
|
114 |
IProjectDescription description = projectResource.getDescription(); |
114 |
IProject[] projectReferences = description.getDynamicReferences(); |
115 |
|
115 |
|
116 |
IProject[] projectReferences = description.getDynamicReferences(); |
116 |
HashSet oldReferences = new HashSet(projectReferences.length); |
117 |
|
117 |
for (int i = 0; i < projectReferences.length; i++){ |
118 |
HashSet oldReferences = new HashSet(projectReferences.length); |
118 |
String projectName = projectReferences[i].getName(); |
119 |
for (int i = 0; i < projectReferences.length; i++){ |
119 |
oldReferences.add(projectName); |
120 |
String projectName = projectReferences[i].getName(); |
120 |
} |
121 |
oldReferences.add(projectName); |
121 |
HashSet newReferences = (HashSet)oldReferences.clone(); |
122 |
} |
122 |
|
123 |
HashSet newReferences = (HashSet)oldReferences.clone(); |
123 |
for (int i = 0; i < oldRequired.length; i++){ |
124 |
|
124 |
String projectName = oldRequired[i]; |
125 |
for (int i = 0; i < oldRequired.length; i++){ |
125 |
newReferences.remove(projectName); |
126 |
String projectName = oldRequired[i]; |
126 |
} |
127 |
newReferences.remove(projectName); |
127 |
for (int i = 0; i < newRequired.length; i++){ |
128 |
} |
128 |
String projectName = newRequired[i]; |
129 |
for (int i = 0; i < newRequired.length; i++){ |
129 |
newReferences.add(projectName); |
130 |
String projectName = newRequired[i]; |
130 |
} |
131 |
newReferences.add(projectName); |
131 |
|
132 |
} |
132 |
Iterator iter; |
133 |
|
133 |
int newSize = newReferences.size(); |
134 |
Iterator iter; |
134 |
|
135 |
int newSize = newReferences.size(); |
135 |
checkIdentity: { |
136 |
|
136 |
if (oldReferences.size() == newSize){ |
137 |
checkIdentity: { |
137 |
iter = newReferences.iterator(); |
138 |
if (oldReferences.size() == newSize){ |
138 |
while (iter.hasNext()){ |
139 |
iter = newReferences.iterator(); |
139 |
if (!oldReferences.contains(iter.next())){ |
140 |
while (iter.hasNext()){ |
140 |
break checkIdentity; |
141 |
if (!oldReferences.contains(iter.next())){ |
|
|
142 |
break checkIdentity; |
143 |
} |
141 |
} |
144 |
} |
|
|
145 |
return; |
142 |
} |
146 |
} |
143 |
return; |
|
|
144 |
} |
147 |
} |
|
|
148 |
String[] requiredProjectNames = new String[newSize]; |
149 |
int index = 0; |
150 |
iter = newReferences.iterator(); |
151 |
while (iter.hasNext()){ |
152 |
requiredProjectNames[index++] = (String)iter.next(); |
153 |
} |
154 |
Util.sort(requiredProjectNames); // ensure that if changed, the order is consistent |
155 |
|
156 |
IProject[] requiredProjectArray = new IProject[newSize]; |
157 |
IWorkspaceRoot wksRoot = projectResource.getWorkspace().getRoot(); |
158 |
for (int i = 0; i < newSize; i++){ |
159 |
requiredProjectArray[i] = wksRoot.getProject(requiredProjectNames[i]); |
160 |
} |
161 |
description.setDynamicReferences(requiredProjectArray); |
162 |
projectResource.setDescription(description, null); |
145 |
} |
163 |
} |
146 |
String[] requiredProjectNames = new String[newSize]; |
164 |
}; |
147 |
int index = 0; |
165 |
try { |
148 |
iter = newReferences.iterator(); |
166 |
// ensure that a sheduling rule is used so that the project description is not modified by another thread while we update it |
149 |
while (iter.hasNext()){ |
167 |
// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=214981 |
150 |
requiredProjectNames[index++] = (String)iter.next(); |
168 |
IWorkspace workspace = projectResource.getWorkspace(); |
151 |
} |
169 |
ISchedulingRule rule = workspace.getRuleFactory().modifyRule(projectResource); // sheduling rule for modifying the project |
152 |
Util.sort(requiredProjectNames); // ensure that if changed, the order is consistent |
170 |
workspace.run(runnable, rule, IWorkspace.AVOID_UPDATE, null); |
153 |
|
|
|
154 |
IProject[] requiredProjectArray = new IProject[newSize]; |
155 |
IWorkspaceRoot wksRoot = projectResource.getWorkspace().getRoot(); |
156 |
for (int i = 0; i < newSize; i++){ |
157 |
requiredProjectArray[i] = wksRoot.getProject(requiredProjectNames[i]); |
158 |
} |
159 |
description.setDynamicReferences(requiredProjectArray); |
160 |
projectResource.setDescription(description, null); |
161 |
|
162 |
} catch(CoreException e){ |
171 |
} catch(CoreException e){ |
163 |
if (!ExternalJavaProject.EXTERNAL_PROJECT_NAME.equals(this.project.getElementName())) |
172 |
if (!ExternalJavaProject.EXTERNAL_PROJECT_NAME.equals(this.project.getElementName())) |
164 |
throw new JavaModelException(e); |
173 |
throw new JavaModelException(e); |