Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use equinox preferences APIs in FileSystemResourceManager class #497 #573

Merged
merged 1 commit into from
Jul 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,16 @@
import org.eclipse.core.runtime.MultiStatus;
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Preferences;
import org.eclipse.core.runtime.Preferences.PropertyChangeEvent;
import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.core.runtime.preferences.IEclipsePreferences.IPreferenceChangeListener;
import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.osgi.util.NLS;
import org.xml.sax.InputSource;

/**
* Manages the synchronization between the workspace's view and the file system.
*/
public class FileSystemResourceManager implements ICoreConstants, IManager, Preferences.IPropertyChangeListener {
public class FileSystemResourceManager implements ICoreConstants, IManager {

/**
* The history store is initialized lazily - always use the accessor method
Expand All @@ -91,6 +91,13 @@ public class FileSystemResourceManager implements ICoreConstants, IManager, Pref

private volatile boolean lightweightAutoRefreshEnabled;

private IPreferenceChangeListener lightweightAutoRefreshPrefListener = event -> {
if (ResourcesPlugin.PREF_LIGHTWEIGHT_AUTO_REFRESH.equals(event.getKey())) {
lightweightAutoRefreshEnabled = Platform.getPreferencesService().getBoolean(ResourcesPlugin.PI_RESOURCES,
ResourcesPlugin.PREF_LIGHTWEIGHT_AUTO_REFRESH, false, null);
}
};

public FileSystemResourceManager(Workspace workspace) {
this.workspace = workspace;
}
Expand Down Expand Up @@ -864,13 +871,6 @@ public void move(IResource source, IFileStore destination, int flags, IProgressM
getStore(source).move(destination, EFS.NONE, monitor);
}

@Deprecated
@Override
public void propertyChange(PropertyChangeEvent event) {
if (ResourcesPlugin.PREF_LIGHTWEIGHT_AUTO_REFRESH.equals(event.getProperty()))
lightweightAutoRefreshEnabled = Boolean.parseBoolean(event.getNewValue().toString());
}

public InputStream read(IFile target, boolean force, IProgressMonitor monitor) throws CoreException {
IFileStore store = getStore(target);
if (lightweightAutoRefreshEnabled || !force) {
Expand Down Expand Up @@ -1124,14 +1124,16 @@ public void setResourceAttributes(IResource resource, ResourceAttributes attribu
public void shutdown(IProgressMonitor monitor) throws CoreException {
if (_historyStore != null)
_historyStore.shutdown(monitor);
ResourcesPlugin.getPlugin().getPluginPreferences().removePropertyChangeListener(this);
InstanceScope.INSTANCE.getNode(ResourcesPlugin.PI_RESOURCES)
.removePreferenceChangeListener(lightweightAutoRefreshPrefListener);
}

@Override
public void startup(IProgressMonitor monitor) {
Preferences preferences = ResourcesPlugin.getPlugin().getPluginPreferences();
preferences.addPropertyChangeListener(this);
lightweightAutoRefreshEnabled = preferences.getBoolean(ResourcesPlugin.PREF_LIGHTWEIGHT_AUTO_REFRESH);
InstanceScope.INSTANCE.getNode(ResourcesPlugin.PI_RESOURCES)
.addPreferenceChangeListener(lightweightAutoRefreshPrefListener);
lightweightAutoRefreshEnabled = Platform.getPreferencesService().getBoolean(ResourcesPlugin.PI_RESOURCES,
ResourcesPlugin.PREF_LIGHTWEIGHT_AUTO_REFRESH, false, null);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.core.tests.internal.filesystem.bug440110.Bug440110FileSystem;
import org.junit.Test;

Expand Down Expand Up @@ -400,6 +401,17 @@ public void testBug547691() throws CoreException {
assertEquals("Expected location of project to not change after delete", location, locationAfterDelete);
}

@Test
public void testLightweightAutoRefreshPrefChange() {
FileSystemResourceManager manager = ((Workspace) getWorkspace()).getFileSystemManager();
InstanceScope.INSTANCE.getNode(ResourcesPlugin.PI_RESOURCES)
.putBoolean(ResourcesPlugin.PREF_LIGHTWEIGHT_AUTO_REFRESH, false);
assertFalse(manager.isLightweightAutoRefreshEnabled());
InstanceScope.INSTANCE.getNode(ResourcesPlugin.PI_RESOURCES)
.putBoolean(ResourcesPlugin.PREF_LIGHTWEIGHT_AUTO_REFRESH, true);
assertTrue(manager.isLightweightAutoRefreshEnabled());
}

protected void write(final IFile file, final InputStream contents, final boolean force, IProgressMonitor monitor)
throws CoreException {
try {
Expand Down