Skip to content

Commit 5fc5bed

Browse files
committed
Add ResourcesPlugin.FAMILY_SNAPSHOT API for DelayedSnapshotJob
DelayedSnapshotJob may in parallel to any other workspace job and triggers resource changes. Clients that rely on resource change events (like JDT core) should have a chance to wait for possible pending resource changes coming from this job. Added a family to the job & a constant in the ResourcesPlugin. See eclipse-jdt/eclipse.jdt.core#2716 (comment)
1 parent 8d5bfec commit 5fc5bed

File tree

2 files changed

+33
-7
lines changed

2 files changed

+33
-7
lines changed

resources/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/DelayedSnapshotJob.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,15 @@
1717
import org.eclipse.core.internal.utils.Messages;
1818
import org.eclipse.core.internal.utils.Policy;
1919
import org.eclipse.core.resources.ISaveContext;
20-
import org.eclipse.core.runtime.*;
20+
import org.eclipse.core.resources.ResourcesPlugin;
21+
import org.eclipse.core.runtime.CoreException;
22+
import org.eclipse.core.runtime.IProgressMonitor;
23+
import org.eclipse.core.runtime.IStatus;
24+
import org.eclipse.core.runtime.Status;
2125
import org.eclipse.core.runtime.jobs.Job;
2226

2327
/**
24-
* Performs periodic saving (snapshot) of the workspace.
28+
* Performs on demand or periodic saving (snapshot) of the workspace.
2529
*/
2630
public class DelayedSnapshotJob extends Job {
2731

@@ -37,9 +41,6 @@ public DelayedSnapshotJob(SaveManager manager, Workspace workspace) {
3741
setSystem(true);
3842
}
3943

40-
/*
41-
* @see Job#run()
42-
*/
4344
@Override
4445
public IStatus run(IProgressMonitor monitor) {
4546
if (monitor.isCanceled())
@@ -56,4 +57,9 @@ public IStatus run(IProgressMonitor monitor) {
5657
saveManager.snapshotRequested = false;
5758
}
5859
}
60+
61+
@Override
62+
public boolean belongsTo(Object family) {
63+
return DelayedSnapshotJob.class == family || ResourcesPlugin.FAMILY_SNAPSHOT == family;
64+
}
5965
}

resources/bundles/org.eclipse.core.resources/src/org/eclipse/core/resources/ResourcesPlugin.java

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,21 @@
2727
import org.eclipse.core.internal.resources.Workspace;
2828
import org.eclipse.core.internal.utils.Messages;
2929
import org.eclipse.core.internal.utils.Policy;
30-
import org.eclipse.core.runtime.*;
30+
import org.eclipse.core.runtime.CoreException;
31+
import org.eclipse.core.runtime.IProgressMonitor;
32+
import org.eclipse.core.runtime.IStatus;
33+
import org.eclipse.core.runtime.Platform;
34+
import org.eclipse.core.runtime.Plugin;
35+
import org.eclipse.core.runtime.Status;
3136
import org.eclipse.core.runtime.jobs.IJobManager;
3237
import org.eclipse.core.runtime.jobs.Job;
3338
import org.eclipse.osgi.service.datalocation.Location;
3439
import org.eclipse.osgi.service.debug.DebugOptions;
3540
import org.eclipse.osgi.service.debug.DebugOptionsListener;
36-
import org.osgi.framework.*;
41+
import org.osgi.framework.BundleActivator;
42+
import org.osgi.framework.BundleContext;
43+
import org.osgi.framework.ServiceReference;
44+
import org.osgi.framework.ServiceRegistration;
3745
import org.osgi.util.tracker.ServiceTracker;
3846
import org.osgi.util.tracker.ServiceTrackerCustomizer;
3947

@@ -169,6 +177,18 @@ public final class ResourcesPlugin extends Plugin {
169177
*/
170178
public static final Object FAMILY_MANUAL_REFRESH = new Object();
171179

180+
/**
181+
* Constant identifying the job family identifier for a background workspace
182+
* snapshot job. All clients that schedule background jobs for performing
183+
* background workspace snapshots should include this job family in their
184+
* implementation of <code>belongsTo</code>.
185+
*
186+
* @see IJobManager#join(Object, IProgressMonitor)
187+
* @see Job#belongsTo(Object)
188+
* @since 3.21
189+
*/
190+
public static final Object FAMILY_SNAPSHOT = new Object();
191+
172192
/**
173193
* Name of a preference indicating the encoding to use when reading text files
174194
* in the workspace. The value is a string, and may be the default empty string,

0 commit comments

Comments
 (0)