Lines 23-35
Link Here
|
23 |
import org.eclipse.core.internal.utils.*; |
23 |
import org.eclipse.core.internal.utils.*; |
24 |
import org.eclipse.core.resources.*; |
24 |
import org.eclipse.core.resources.*; |
25 |
import org.eclipse.core.runtime.*; |
25 |
import org.eclipse.core.runtime.*; |
|
|
26 |
import org.eclipse.core.runtime.Preferences.PropertyChangeEvent; |
26 |
import org.eclipse.osgi.util.NLS; |
27 |
import org.eclipse.osgi.util.NLS; |
27 |
import org.xml.sax.InputSource; |
28 |
import org.xml.sax.InputSource; |
28 |
|
29 |
|
29 |
/** |
30 |
/** |
30 |
* Manages the synchronization between the workspace's view and the file system. |
31 |
* Manages the synchronization between the workspace's view and the file system. |
31 |
*/ |
32 |
*/ |
32 |
public class FileSystemResourceManager implements ICoreConstants, IManager { |
33 |
public class FileSystemResourceManager implements ICoreConstants, IManager, Preferences.IPropertyChangeListener { |
33 |
|
34 |
|
34 |
/** |
35 |
/** |
35 |
* The history store is initialized lazily - always use the accessor method |
36 |
* The history store is initialized lazily - always use the accessor method |
Lines 37-42
Link Here
|
37 |
protected IHistoryStore _historyStore; |
38 |
protected IHistoryStore _historyStore; |
38 |
protected Workspace workspace; |
39 |
protected Workspace workspace; |
39 |
|
40 |
|
|
|
41 |
private volatile boolean autoRefreshEnabled; |
42 |
|
40 |
public FileSystemResourceManager(Workspace workspace) { |
43 |
public FileSystemResourceManager(Workspace workspace) { |
41 |
this.workspace = workspace; |
44 |
this.workspace = workspace; |
42 |
} |
45 |
} |
Lines 124-129
Link Here
|
124 |
return results; |
127 |
return results; |
125 |
} |
128 |
} |
126 |
|
129 |
|
|
|
130 |
/** |
131 |
* Asynchronously auto-refresh the requested resource if Auto-Refresh is enabled |
132 |
* @param target |
133 |
*/ |
134 |
private void asyncRefresh(IResource target) { |
135 |
if (autoRefreshEnabled) |
136 |
workspace.getRefreshManager().refresh(target); |
137 |
} |
138 |
|
127 |
private void findLinkedResourcesPaths(URI inputLocation, final ArrayList<IPath> results) throws CoreException { |
139 |
private void findLinkedResourcesPaths(URI inputLocation, final ArrayList<IPath> results) throws CoreException { |
128 |
IPath suffix = null; |
140 |
IPath suffix = null; |
129 |
IFileStore fileStore = EFS.getStore(inputLocation); |
141 |
IFileStore fileStore = EFS.getStore(inputLocation); |
Lines 621-630
Link Here
|
621 |
return projectInfo.getLocalSyncInfo() == getStore(descriptionFile).fetchInfo().getLastModified(); |
633 |
return projectInfo.getLocalSyncInfo() == getStore(descriptionFile).fetchInfo().getLastModified(); |
622 |
} |
634 |
} |
623 |
|
635 |
|
624 |
/* (non-Javadoc) |
636 |
/** |
625 |
* Returns true if the given resource is synchronized with the file system |
637 |
* Returns true if the given resource is synchronized with the file system |
626 |
* to the given depth. Returns false otherwise. |
638 |
* to the given depth. Returns false otherwise. |
627 |
* |
639 |
* |
|
|
640 |
* Any discovered out-of-sync resources are scheduled to be brought back in sync. |
641 |
* |
628 |
* @see IResource#isSynchronized(int) |
642 |
* @see IResource#isSynchronized(int) |
629 |
*/ |
643 |
*/ |
630 |
public boolean isSynchronized(IResource target, int depth) { |
644 |
public boolean isSynchronized(IResource target, int depth) { |
Lines 661-672
Link Here
|
661 |
Policy.log(e); |
675 |
Policy.log(e); |
662 |
return false; |
676 |
return false; |
663 |
} catch (IsSynchronizedVisitor.ResourceChangedException e) { |
677 |
} catch (IsSynchronizedVisitor.ResourceChangedException e) { |
|
|
678 |
// Ask refresh manager to bring out-of-sync resource back into sync when convenient |
679 |
asyncRefresh(e.target); |
664 |
//visitor throws an exception if out of sync |
680 |
//visitor throws an exception if out of sync |
665 |
return false; |
681 |
return false; |
666 |
} |
682 |
} |
667 |
return true; |
683 |
return true; |
668 |
} |
684 |
} |
669 |
|
685 |
|
|
|
686 |
/** |
687 |
* @return whether this FSRM is automatically refreshing discovered out-of-sync resources |
688 |
*/ |
689 |
public boolean isAsyncAutoRefreshEnabled() { |
690 |
return autoRefreshEnabled; |
691 |
} |
692 |
|
670 |
public void link(Resource target, URI location, IFileInfo fileInfo) throws CoreException { |
693 |
public void link(Resource target, URI location, IFileInfo fileInfo) throws CoreException { |
671 |
initializeStore(target, location); |
694 |
initializeStore(target, location); |
672 |
ResourceInfo info = target.getResourceInfo(false, true); |
695 |
ResourceInfo info = target.getResourceInfo(false, true); |
Lines 716-733
Link Here
|
716 |
return null; |
739 |
return null; |
717 |
} |
740 |
} |
718 |
|
741 |
|
|
|
742 |
public void propertyChange(PropertyChangeEvent event) { |
743 |
String property = event.getProperty(); |
744 |
if (ResourcesPlugin.PREF_REFRESH_ASYNC.equals(property)) { |
745 |
Preferences preferences = ResourcesPlugin.getPlugin().getPluginPreferences(); |
746 |
autoRefreshEnabled = preferences.getBoolean(ResourcesPlugin.PREF_REFRESH_ASYNC); |
747 |
} |
748 |
} |
749 |
|
719 |
public InputStream read(IFile target, boolean force, IProgressMonitor monitor) throws CoreException { |
750 |
public InputStream read(IFile target, boolean force, IProgressMonitor monitor) throws CoreException { |
720 |
IFileStore store = getStore(target); |
751 |
IFileStore store = getStore(target); |
721 |
if (!force) { |
752 |
final IFileInfo fileInfo = store.fetchInfo(); |
722 |
final IFileInfo fileInfo = store.fetchInfo(); |
753 |
if (!fileInfo.exists()) { |
723 |
if (!fileInfo.exists()) { |
754 |
asyncRefresh(target); |
|
|
755 |
if (!force) { |
724 |
String message = NLS.bind(Messages.localstore_fileNotFound, store.toString()); |
756 |
String message = NLS.bind(Messages.localstore_fileNotFound, store.toString()); |
725 |
throw new ResourceException(IResourceStatus.FAILED_READ_LOCAL, target.getFullPath(), message, null); |
757 |
throw new ResourceException(IResourceStatus.FAILED_READ_LOCAL, target.getFullPath(), message, null); |
726 |
} |
758 |
} |
727 |
ResourceInfo info = ((Resource) target).getResourceInfo(true, false); |
759 |
} |
728 |
int flags = ((Resource) target).getFlags(info); |
760 |
ResourceInfo info = ((Resource) target).getResourceInfo(true, false); |
729 |
((Resource) target).checkExists(flags, true); |
761 |
int flags = ((Resource) target).getFlags(info); |
730 |
if (fileInfo.getLastModified() != info.getLocalSyncInfo()) { |
762 |
((Resource) target).checkExists(flags, true); |
|
|
763 |
if (fileInfo.getLastModified() != info.getLocalSyncInfo()) { |
764 |
asyncRefresh(target); |
765 |
if (!force) { |
731 |
String message = NLS.bind(Messages.localstore_resourceIsOutOfSync, target.getFullPath()); |
766 |
String message = NLS.bind(Messages.localstore_resourceIsOutOfSync, target.getFullPath()); |
732 |
throw new ResourceException(IResourceStatus.OUT_OF_SYNC_LOCAL, target.getFullPath(), message, null); |
767 |
throw new ResourceException(IResourceStatus.OUT_OF_SYNC_LOCAL, target.getFullPath(), message, null); |
733 |
} |
768 |
} |
Lines 962-971
Link Here
|
962 |
public void shutdown(IProgressMonitor monitor) throws CoreException { |
997 |
public void shutdown(IProgressMonitor monitor) throws CoreException { |
963 |
if (_historyStore != null) |
998 |
if (_historyStore != null) |
964 |
_historyStore.shutdown(monitor); |
999 |
_historyStore.shutdown(monitor); |
|
|
1000 |
ResourcesPlugin.getPlugin().getPluginPreferences().removePropertyChangeListener(this); |
965 |
} |
1001 |
} |
966 |
|
1002 |
|
967 |
public void startup(IProgressMonitor monitor) throws CoreException { |
1003 |
public void startup(IProgressMonitor monitor) throws CoreException { |
968 |
//nothing to do |
1004 |
Preferences preferences = ResourcesPlugin.getPlugin().getPluginPreferences(); |
|
|
1005 |
preferences.addPropertyChangeListener(this); |
1006 |
autoRefreshEnabled = preferences.getBoolean(ResourcesPlugin.PREF_REFRESH_ASYNC); |
969 |
} |
1007 |
} |
970 |
|
1008 |
|
971 |
/** |
1009 |
/** |
Lines 1006-1015
Link Here
|
1006 |
ResourceInfo info = ((Resource) target).getResourceInfo(true, false); |
1044 |
ResourceInfo info = ((Resource) target).getResourceInfo(true, false); |
1007 |
// test if timestamp is the same since last synchronization |
1045 |
// test if timestamp is the same since last synchronization |
1008 |
if (lastModified != info.getLocalSyncInfo()) { |
1046 |
if (lastModified != info.getLocalSyncInfo()) { |
|
|
1047 |
asyncRefresh(target); |
1009 |
String message = NLS.bind(Messages.localstore_resourceIsOutOfSync, target.getFullPath()); |
1048 |
String message = NLS.bind(Messages.localstore_resourceIsOutOfSync, target.getFullPath()); |
1010 |
throw new ResourceException(IResourceStatus.OUT_OF_SYNC_LOCAL, target.getFullPath(), message, null); |
1049 |
throw new ResourceException(IResourceStatus.OUT_OF_SYNC_LOCAL, target.getFullPath(), message, null); |
1011 |
} |
1050 |
} |
1012 |
if (!fileInfo.exists()) { |
1051 |
if (!fileInfo.exists()) { |
|
|
1052 |
asyncRefresh(target); |
1013 |
String message = NLS.bind(Messages.localstore_resourceDoesNotExist, target.getFullPath()); |
1053 |
String message = NLS.bind(Messages.localstore_resourceDoesNotExist, target.getFullPath()); |
1014 |
throw new ResourceException(IResourceStatus.NOT_FOUND_LOCAL, target.getFullPath(), message, null); |
1054 |
throw new ResourceException(IResourceStatus.NOT_FOUND_LOCAL, target.getFullPath(), message, null); |
1015 |
} |
1055 |
} |