Lines 10-15
Link Here
|
10 |
*******************************************************************************/ |
10 |
*******************************************************************************/ |
11 |
package org.eclipse.core.tests.resources; |
11 |
package org.eclipse.core.tests.resources; |
12 |
|
12 |
|
|
|
13 |
import java.nio.CharBuffer; |
14 |
|
15 |
import org.eclipse.core.runtime.jobs.Job; |
16 |
|
13 |
import java.io.*; |
17 |
import java.io.*; |
14 |
import java.net.URI; |
18 |
import java.net.URI; |
15 |
import java.util.HashMap; |
19 |
import java.util.HashMap; |
Lines 136-141
Link Here
|
136 |
Workspace.clear(resolve(nonExistingLocation).toFile()); |
140 |
Workspace.clear(resolve(nonExistingLocation).toFile()); |
137 |
} |
141 |
} |
138 |
|
142 |
|
|
|
143 |
/** |
144 |
* Bug251370 |
145 |
* Updating a .project file within a nested Project causes problems when the project is closed |
146 |
* and then reopened (having moved one of the linked resources) |
147 |
* |
148 |
* This test creates a linked resource between the inner project and outer project. |
149 |
* The first linked resource is relative to a path variable "ROOT" |
150 |
* The second is absolute |
151 |
* |
152 |
* It then closes and opens the inner project replacing the .project file between each open. |
153 |
* For me the test fails sometime between the first close and open and the ~20th |
154 |
*/ |
155 |
public void testChangingLinksWithNestedProjects() { |
156 |
// /ExistingProject/foo |
157 |
final String sOverlappingProject = "foo"; |
158 |
final IFolder overlappingFolder = existingProject.getFolder(sOverlappingProject); |
159 |
ensureExistsInFileSystem(overlappingFolder); |
160 |
|
161 |
// /foo -> /ExistingProject/foo |
162 |
final IProject overlappingProject = getWorkspace().getRoot().getProject(sOverlappingProject); |
163 |
IProjectDescription desc = getWorkspace().newProjectDescription(sOverlappingProject); |
164 |
desc.setLocation(overlappingFolder.getLocation()); |
165 |
try { |
166 |
overlappingProject.create(desc, getMonitor()); |
167 |
overlappingProject.open(getMonitor()); |
168 |
assertTrue("0.9",overlappingProject.exists()); |
169 |
} catch (CoreException e) { |
170 |
fail("1.0"); |
171 |
} |
172 |
|
173 |
// Create a path variable for the workspace root |
174 |
try { |
175 |
IPath ROOT = getWorkspace().getRoot().getLocation(); |
176 |
getWorkspace().getPathVariableManager().setValue("ROOT", ROOT); |
177 |
} catch (CoreException e) { |
178 |
fail("1.5"); |
179 |
} |
180 |
|
181 |
// Two linked resource paths: |
182 |
// 1) Uses path variable |
183 |
IPath l1 = new Path("ROOT").append(existingFolderInExistingProject.getFullPath()); |
184 |
// 2) uses absolute path |
185 |
IPath l2 = existingFolderInExistingProject.getLocation(); |
186 |
|
187 |
// Refresh Workspace |
188 |
try { |
189 |
getWorkspace().getRoot().refreshLocal(IResource.DEPTH_INFINITE, getMonitor()); |
190 |
} catch (CoreException e) { |
191 |
fail ("2.0"); |
192 |
} |
193 |
|
194 |
// Create a link to the folder in the existing project |
195 |
// /foo/linkedFolder -> /ExistingProject/existingFolderInExistingProject |
196 |
IFolder linkedFolder = overlappingProject.getFolder("linkedFolder"); |
197 |
try { |
198 |
linkedFolder.createLink(l1, IResource.REPLACE, getMonitor()); |
199 |
assertTrue("1.9",linkedFolder.exists()); |
200 |
} catch (CoreException e) { |
201 |
fail("3.0"); |
202 |
} |
203 |
|
204 |
// Create a backup of the .project file |
205 |
try { |
206 |
overlappingProject.getFile(".project").copy(new Path(".project1"), true, getMonitor()); |
207 |
} catch (CoreException e) { |
208 |
fail("4.0"); |
209 |
} |
210 |
|
211 |
// Change the variable to be relative to the ROOT variable |
212 |
try { |
213 |
linkedFolder.delete(true, getMonitor()); |
214 |
// linkedFolder.setLinkLocation(l2, IResource.NONE, getMonitor()); |
215 |
linkedFolder.createLink(l2, IResource.REPLACE, getMonitor()); |
216 |
assertTrue(linkedFolder.exists()); |
217 |
} catch (CoreException e) { |
218 |
fail("5.0"); |
219 |
} |
220 |
|
221 |
// Create a new .project file |
222 |
try { |
223 |
overlappingProject.getFile(".project").copy(new Path(".project2"), true, getMonitor()); |
224 |
} catch (CoreException e) { |
225 |
fail("6.0"); |
226 |
} |
227 |
|
228 |
for (int i = 0; i < 100; i++) { |
229 |
final String tdesc = i % 2 == 0 ? ".project1" : ".project2"; |
230 |
|
231 |
try { |
232 |
getWorkspace().getRoot().refreshLocal(IResource.DEPTH_INFINITE, getMonitor()); |
233 |
overlappingProject.close(getMonitor()); |
234 |
} catch (CoreException e) { |
235 |
fail("7.0"); |
236 |
} |
237 |
|
238 |
System.out.println("Round " + i); |
239 |
|
240 |
Job j = new Job ("") { |
241 |
protected IStatus run(IProgressMonitor monitor) { |
242 |
try { |
243 |
getWorkspace().run(new IWorkspaceRunnable() { |
244 |
|
245 |
public void run(IProgressMonitor monitor) throws CoreException { |
246 |
try { |
247 |
java.io.File projFile = overlappingFolder.getFile(".project").getLocation().toFile(); |
248 |
java.io.File tempFile = overlappingFolder.getFile(tdesc).getLocation().toFile(); |
249 |
CharBuffer cb = CharBuffer.allocate(100000); |
250 |
int len = new FileReader(tempFile).read(cb); |
251 |
Writer w = new FileWriter(projFile); |
252 |
w.write(cb.array(), 0, len); |
253 |
w.flush(); |
254 |
w.close(); |
255 |
} catch (Exception e) { |
256 |
fail("8.0"); |
257 |
} |
258 |
} |
259 |
}, getWorkspace().getRoot(), IWorkspace.AVOID_UPDATE, getMonitor()); |
260 |
} catch (Exception e) { |
261 |
fail("8.0"); |
262 |
} |
263 |
return Status.OK_STATUS; |
264 |
} |
265 |
}; |
266 |
j.schedule(); |
267 |
try { |
268 |
j.join(); |
269 |
} catch (InterruptedException e) {fail();} |
270 |
|
271 |
try { |
272 |
overlappingProject.open(getMonitor()); |
273 |
getWorkspace().getRoot().refreshLocal(IResource.DEPTH_INFINITE, getMonitor()); |
274 |
} catch (CoreException e) { |
275 |
fail ("10.0"); |
276 |
} |
277 |
} |
278 |
} |
279 |
|
139 |
/** |
280 |
/** |
140 |
* Tests creation of a linked resource whose corresponding file system |
281 |
* Tests creation of a linked resource whose corresponding file system |
141 |
* path does not exist. This should succeed but no operations will be |
282 |
* path does not exist. This should succeed but no operations will be |