Lines 19-24
Link Here
|
19 |
import java.util.ArrayList; |
19 |
import java.util.ArrayList; |
20 |
import java.util.HashMap; |
20 |
import java.util.HashMap; |
21 |
import java.util.HashSet; |
21 |
import java.util.HashSet; |
|
|
22 |
import java.util.Iterator; |
22 |
import java.util.List; |
23 |
import java.util.List; |
23 |
import java.util.Map; |
24 |
import java.util.Map; |
24 |
import java.util.Set; |
25 |
import java.util.Set; |
Lines 33-39
Link Here
|
33 |
import org.eclipse.core.resources.IWorkspaceRunnable; |
34 |
import org.eclipse.core.resources.IWorkspaceRunnable; |
34 |
import org.eclipse.core.resources.ResourcesPlugin; |
35 |
import org.eclipse.core.resources.ResourcesPlugin; |
35 |
import org.eclipse.core.runtime.CoreException; |
36 |
import org.eclipse.core.runtime.CoreException; |
|
|
37 |
import org.eclipse.core.runtime.IPath; |
36 |
import org.eclipse.core.runtime.IProgressMonitor; |
38 |
import org.eclipse.core.runtime.IProgressMonitor; |
|
|
39 |
import org.eclipse.core.runtime.Path; |
37 |
import org.eclipse.core.runtime.Platform; |
40 |
import org.eclipse.core.runtime.Platform; |
38 |
import org.eclipse.core.runtime.jobs.ILock; |
41 |
import org.eclipse.core.runtime.jobs.ILock; |
39 |
import org.eclipse.emf.common.util.URI; |
42 |
import org.eclipse.emf.common.util.URI; |
Lines 59-64
Link Here
|
59 |
private static final String JAVA_EXTENSION = "java"; //$NON-NLS-1$ |
62 |
private static final String JAVA_EXTENSION = "java"; //$NON-NLS-1$ |
60 |
private Set recentlySavedFiles = new HashSet(); |
63 |
private Set recentlySavedFiles = new HashSet(); |
61 |
private Map ignoredFilesCache = new HashMap(); |
64 |
private Map ignoredFilesCache = new HashMap(); |
|
|
65 |
private class SavedFileKey { |
66 |
private Resource res; |
67 |
private IFile savedFile; |
68 |
public SavedFileKey(Resource res, IFile savedFile) { |
69 |
super(); |
70 |
this.res = res; |
71 |
this.savedFile = savedFile; |
72 |
} |
73 |
public Resource getRes() { |
74 |
return res; |
75 |
} |
76 |
public void setRes(Resource res) { |
77 |
this.res = res; |
78 |
} |
79 |
public IFile getSavedFile() { |
80 |
return savedFile; |
81 |
} |
82 |
public void setSavedFile(IFile savedFile) { |
83 |
this.savedFile = savedFile; |
84 |
} |
85 |
public int hashCode() { |
86 |
final int prime = 31; |
87 |
int result = 1; |
88 |
result = prime * result + getOuterType().hashCode(); |
89 |
result = prime * result + ((res == null) ? 0 : res.hashCode()); |
90 |
result = prime * result + ((savedFile == null) ? 0 : savedFile.hashCode()); |
91 |
return result; |
92 |
} |
93 |
public boolean equals(Object obj) { |
94 |
if (this == obj) |
95 |
return true; |
96 |
if (obj == null) |
97 |
return false; |
98 |
if (getClass() != obj.getClass()) |
99 |
return false; |
100 |
SavedFileKey other = (SavedFileKey) obj; |
101 |
if (!getOuterType().equals(other.getOuterType())) |
102 |
return false; |
103 |
if (res == null) { |
104 |
if (other.res != null) |
105 |
return false; |
106 |
} else if (!res.equals(other.res)) |
107 |
return false; |
108 |
if (savedFile == null) { |
109 |
if (other.savedFile != null) |
110 |
return false; |
111 |
} else if (!savedFile.equals(other.savedFile)) |
112 |
return false; |
113 |
return true; |
114 |
} |
115 |
private ResourceSetWorkbenchEditSynchronizer getOuterType() { |
116 |
return ResourceSetWorkbenchEditSynchronizer.this; |
117 |
} |
118 |
} |
62 |
|
119 |
|
63 |
/** The emf resources to be removed from the resource set as a result of a delta */ |
120 |
/** The emf resources to be removed from the resource set as a result of a delta */ |
64 |
protected List deferredRemoveResources = new ArrayList(); |
121 |
protected List deferredRemoveResources = new ArrayList(); |
Lines 262-325
Link Here
|
262 |
*/ |
319 |
*/ |
263 |
protected boolean addedResource(IFile aFile) { |
320 |
protected boolean addedResource(IFile aFile) { |
264 |
boolean didProcess = false; |
321 |
boolean didProcess = false; |
265 |
Resource resource = getResource(aFile); |
322 |
List resources = getResources(aFile); |
266 |
if ((resource != null) || (recentlySavedFiles.contains(resource))){ |
323 |
for (Iterator iterator = resources.iterator(); iterator.hasNext();) { |
267 |
/* |
324 |
Resource resource = (Resource) iterator.next(); |
268 |
* The IFile was just added to the workspace but we have a resource |
325 |
|
269 |
* in memory. Need to decide if it should be unloaded. |
326 |
if ((resource != null) || (recentlySavedFilesContains(resource))) { |
270 |
*/ |
327 |
/* |
271 |
if (resource.isModified()) { |
328 |
* The IFile was just added to the workspace but we have a |
272 |
if (WorkbenchResourceHelper.isReferencedResource(resource)) { |
329 |
* resource in memory. Need to decide if it should be unloaded. |
273 |
ReferencedResource refRes = (ReferencedResource) resource; |
330 |
*/ |
274 |
if (refRes.shouldForceRefresh()) { |
331 |
if (resource.isModified()) { |
275 |
deferredUnloadResources.add(resource); |
332 |
if (WorkbenchResourceHelper.isReferencedResource(resource)) { |
276 |
didProcess = true; |
333 |
ReferencedResource refRes = (ReferencedResource) resource; |
277 |
} |
334 |
if (refRes.shouldForceRefresh()) { |
278 |
} |
335 |
deferredUnloadResources.add(resource); |
279 |
} else { |
336 |
didProcess = true; |
280 |
/*Unload if found and is not modified but inconsistent.*/ |
337 |
} |
281 |
if (resource.isLoaded()) { |
338 |
} |
282 |
if ( WorkbenchResourceHelper.isReferencedResource(resource)) { |
339 |
} else { |
283 |
if (!WorkbenchResourceHelper.isConsistent((ReferencedResource)resource)) { |
340 |
/* Unload if found and is not modified but inconsistent. */ |
284 |
deferredUnloadResources.add(resource); |
341 |
if (resource.isLoaded()) { |
285 |
didProcess = true; |
342 |
if (WorkbenchResourceHelper.isReferencedResource(resource)) { |
286 |
} |
343 |
if (!WorkbenchResourceHelper.isConsistent((ReferencedResource) resource)) { |
287 |
} else { |
344 |
deferredUnloadResources.add(resource); |
288 |
deferredUnloadResources.add(resource); |
345 |
didProcess = true; |
289 |
didProcess = true; |
346 |
} |
290 |
} |
347 |
} else { |
291 |
} |
348 |
deferredUnloadResources.add(resource); |
292 |
} |
349 |
didProcess = true; |
293 |
} else { |
350 |
} |
294 |
//Process resource as a refresh. |
351 |
} |
295 |
URI uri = URI.createPlatformResourceURI(aFile.getFullPath().toString()); |
352 |
} |
296 |
if ((autoloadResourcesURIs.contains(uri)) || (autoloadResourcesExts.contains(aFile.getFileExtension()))) { |
353 |
} else { |
297 |
deferredLoadResources.add(uri); |
354 |
// Process resource as a refresh. |
298 |
didProcess = true; |
355 |
URI uri = URI.createPlatformResourceURI(aFile.getFullPath().toString()); |
299 |
} |
356 |
if ((autoloadResourcesURIs.contains(uri)) || (autoloadResourcesExts.contains(aFile.getFileExtension()))) { |
300 |
} |
357 |
deferredLoadResources.add(uri); |
|
|
358 |
didProcess = true; |
359 |
} |
360 |
} |
361 |
} |
301 |
return didProcess; |
362 |
return didProcess; |
302 |
} |
363 |
} |
303 |
|
364 |
|
304 |
protected boolean processResource(IFile aFile, boolean isRemove) { |
365 |
private synchronized boolean recentlySavedFilesContains(Resource resource) { |
305 |
Resource resource = getResource(aFile); |
366 |
for (Iterator iterator = recentlySavedFiles.iterator(); iterator.hasNext();) { |
306 |
if ((resource != null) || (recentlySavedFiles.contains(resource))){ |
367 |
SavedFileKey key = (SavedFileKey) iterator.next(); |
307 |
if (resource.isModified()) { |
368 |
if (key.res.equals(resource)) |
308 |
if (WorkbenchResourceHelper.isReferencedResource(resource)) { |
369 |
return true; |
309 |
ReferencedResource refRes = (ReferencedResource) resource; |
|
|
310 |
if (!refRes.shouldForceRefresh()) |
311 |
return false; //Do not do anything |
312 |
} else |
313 |
return false; |
314 |
} |
370 |
} |
315 |
|
371 |
return false; |
316 |
if (isRemove) |
372 |
} |
317 |
deferredRemoveResources.add(resource); |
373 |
|
318 |
else if (resource.isLoaded()) { |
374 |
protected boolean processResource(IFile aFile, boolean isRemove) { |
319 |
if ( WorkbenchResourceHelper.isReferencedResource(resource)) { |
375 |
List resources = getResources(aFile); |
320 |
if(!WorkbenchResourceHelper.isConsistent((ReferencedResource)resource)) |
376 |
for (Iterator iterator = resources.iterator(); iterator.hasNext();) { |
321 |
deferredUnloadResources.add(resource); |
377 |
Resource resource = (Resource) iterator.next(); |
322 |
} else deferredUnloadResources.add(resource); |
378 |
if ((resource != null) || (recentlySavedFilesContains(resource))) { |
|
|
379 |
if (resource.isModified()) { |
380 |
if (WorkbenchResourceHelper.isReferencedResource(resource)) { |
381 |
ReferencedResource refRes = (ReferencedResource) resource; |
382 |
if (!refRes.shouldForceRefresh()) |
383 |
continue; // Do not do anything |
384 |
} else |
385 |
continue; |
386 |
} |
387 |
|
388 |
if (isRemove) |
389 |
deferredRemoveResources.add(resource); |
390 |
else if (resource.isLoaded()) { |
391 |
if (WorkbenchResourceHelper.isReferencedResource(resource)) { |
392 |
if (!WorkbenchResourceHelper.isConsistent((ReferencedResource) resource)) |
393 |
deferredUnloadResources.add(resource); |
394 |
} else |
395 |
deferredUnloadResources.add(resource); |
396 |
} |
323 |
} |
397 |
} |
324 |
} |
398 |
} |
325 |
return false; |
399 |
return false; |
Lines 350-355
Link Here
|
350 |
|
424 |
|
351 |
return resourceSet.getResource(URI.createPlatformResourceURI(aFile.getFullPath().toString()), false); |
425 |
return resourceSet.getResource(URI.createPlatformResourceURI(aFile.getFullPath().toString()), false); |
352 |
} |
426 |
} |
|
|
427 |
|
428 |
protected List getResources(IFile aFile) { |
429 |
|
430 |
List resources = new ArrayList(); |
431 |
List allResources = resourceSet.getResources(); |
432 |
for (Iterator iterator = allResources.iterator(); iterator.hasNext();) { |
433 |
Resource res = (Resource) iterator.next(); |
434 |
URI resURI = res.getURI(); |
435 |
IPath resURIPath; |
436 |
if (WorkbenchResourceHelper.isPlatformResourceURI(resURI)) |
437 |
resURIPath = new Path(URI.decode(resURI.path())).removeFirstSegments(2); |
438 |
else |
439 |
resURIPath = new Path(URI.decode(resURI.path())).removeFirstSegments(1); |
440 |
String resURIString = resURIPath.toString(); |
441 |
if (aFile.getFullPath().toString().indexOf(resURIString) != -1) |
442 |
resources.add(res); |
443 |
} |
444 |
return resources; |
445 |
} |
353 |
|
446 |
|
354 |
|
447 |
|
355 |
/** |
448 |
/** |
Lines 357-377
Link Here
|
357 |
*/ |
450 |
*/ |
358 |
public void preSave(IFile aFile) { |
451 |
public void preSave(IFile aFile) { |
359 |
if (aFile != null) { |
452 |
if (aFile != null) { |
360 |
recentlySavedFiles.add(aFile); |
453 |
recentlySavedFilesAdd(aFile,null); |
361 |
ignoredFilesCache.remove(aFile); |
454 |
ignoredFilesCache.remove(aFile); |
362 |
} |
455 |
} |
363 |
} |
456 |
} |
|
|
457 |
|
458 |
/** |
459 |
* This method should be called prior to writing to an IFile from a MOF resource. |
460 |
*/ |
461 |
public void preSave(IFile aFile, Resource res) { |
462 |
if (aFile != null) { |
463 |
recentlySavedFilesAdd(aFile, res); |
464 |
ignoredFilesCache.remove(aFile); |
465 |
} |
466 |
} |
467 |
|
468 |
private synchronized boolean recentlySavedFilesAdd(IFile file, Resource res) { |
469 |
return recentlySavedFiles.add(new SavedFileKey(res, file)); |
470 |
} |
364 |
|
471 |
|
365 |
/** |
472 |
/** |
366 |
* This method should be called after a preSave if the save fails |
473 |
* This method should be called after a preSave if the save fails |
367 |
*/ |
474 |
*/ |
368 |
public void removeFromRecentlySavedList(IFile aFile) { |
475 |
public void removeFromRecentlySavedList(IFile aFile) { |
369 |
if (aFile != null) { |
476 |
if (aFile != null) { |
370 |
recentlySavedFiles.remove(aFile); |
477 |
recentlySavedFilesForceRemove(aFile); |
371 |
ignoredFilesCache.remove(aFile); |
478 |
ignoredFilesCache.remove(aFile); |
372 |
} |
479 |
} |
373 |
} |
480 |
} |
374 |
|
481 |
|
|
|
482 |
private synchronized boolean recentlySavedFilesRemove(IFile file) { |
483 |
|
484 |
boolean removedFromList = false; |
485 |
for (Iterator iterator = recentlySavedFiles.iterator(); iterator.hasNext();) { |
486 |
SavedFileKey key = (SavedFileKey) iterator.next(); |
487 |
if (key.savedFile != null && key.savedFile.equals(file)) { |
488 |
List resources = getResources(file); |
489 |
if (resources.contains(key.res)) { |
490 |
iterator.remove(); |
491 |
removedFromList = true; |
492 |
break; |
493 |
} |
494 |
} |
495 |
} |
496 |
return removedFromList; |
497 |
} |
498 |
private synchronized boolean recentlySavedFilesForceRemove(IFile file) { |
499 |
|
500 |
boolean removedFromList = false; |
501 |
for (Iterator iterator = recentlySavedFiles.iterator(); iterator.hasNext();) { |
502 |
SavedFileKey key = (SavedFileKey) iterator.next(); |
503 |
if (key.savedFile != null && key.savedFile.equals(file)) { |
504 |
iterator.remove(); |
505 |
removedFromList = true; |
506 |
} |
507 |
} |
508 |
return removedFromList; |
509 |
} |
510 |
|
375 |
/** |
511 |
/** |
376 |
* This method should be called just after writing to an IFile from a MOF resource. |
512 |
* This method should be called just after writing to an IFile from a MOF resource. |
377 |
* |
513 |
* |
Lines 396-404
Link Here
|
396 |
String extension = aFile.getFileExtension(); |
532 |
String extension = aFile.getFileExtension(); |
397 |
if (CLASS_EXTENSION.equals(extension) || JAVA_EXTENSION.equals(extension)) |
533 |
if (CLASS_EXTENSION.equals(extension) || JAVA_EXTENSION.equals(extension)) |
398 |
return false; |
534 |
return false; |
399 |
if (recentlySavedFiles.remove(aFile)) { |
535 |
if (recentlySavedFilesRemove(aFile)) { |
400 |
cacheIgnored(aFile); |
536 |
cacheIgnored(aFile); |
401 |
return false; |
537 |
return false; |
402 |
} |
538 |
} |
403 |
return !hasIgnored(aFile); |
539 |
return !hasIgnored(aFile); |
404 |
} |
540 |
} |