|
Lines 14-27
Link Here
|
| 14 |
import java.util.*; |
14 |
import java.util.*; |
| 15 |
import org.eclipse.core.internal.preferences.EclipsePreferences; |
15 |
import org.eclipse.core.internal.preferences.EclipsePreferences; |
| 16 |
import org.eclipse.core.runtime.*; |
16 |
import org.eclipse.core.runtime.*; |
|
|
17 |
import org.eclipse.core.runtime.jobs.Job; |
| 17 |
import org.eclipse.core.runtime.preferences.IEclipsePreferences; |
18 |
import org.eclipse.core.runtime.preferences.IEclipsePreferences; |
| 18 |
import org.eclipse.equinox.internal.p2.core.helpers.*; |
19 |
import org.eclipse.equinox.internal.p2.core.helpers.*; |
| 19 |
import org.eclipse.equinox.internal.provisional.p2.core.location.AgentLocation; |
20 |
import org.eclipse.equinox.internal.provisional.p2.core.location.AgentLocation; |
| 20 |
import org.eclipse.equinox.internal.provisional.p2.engine.*; |
21 |
import org.eclipse.equinox.internal.provisional.p2.engine.*; |
| 21 |
import org.eclipse.osgi.util.NLS; |
22 |
import org.eclipse.osgi.util.NLS; |
|
|
23 |
import org.osgi.framework.Bundle; |
| 24 |
import org.osgi.framework.BundleContext; |
| 22 |
import org.osgi.service.prefs.BackingStoreException; |
25 |
import org.osgi.service.prefs.BackingStoreException; |
| 23 |
|
26 |
|
|
|
27 |
/** |
| 28 |
* A preference implementation that stores preferences in the engine's profile |
| 29 |
* data area. There is one preference file per profile, with an additional file |
| 30 |
* that is used when there is no currently running profile. |
| 31 |
*/ |
| 24 |
public class ProfilePreferences extends EclipsePreferences { |
32 |
public class ProfilePreferences extends EclipsePreferences { |
|
|
33 |
private static final long SAVE_SCHEDULE_DELAY = 500; |
| 34 |
public static final Object PROFILE_SAVE_JOB_FAMILY = new Object(); |
| 35 |
|
| 36 |
private class SaveJob extends Job { |
| 37 |
SaveJob() { |
| 38 |
super(Messages.ProfilePreferences_saving); |
| 39 |
setSystem(true); |
| 40 |
} |
| 41 |
|
| 42 |
protected IStatus run(IProgressMonitor monitor) { |
| 43 |
try { |
| 44 |
doSave(); |
| 45 |
} catch (BackingStoreException e) { |
| 46 |
LogHelper.log(new Status(IStatus.WARNING, EngineActivator.ID, "Exception saving profile preferences", e)); //$NON-NLS-1$ |
| 47 |
} |
| 48 |
return Status.OK_STATUS; |
| 49 |
} |
| 50 |
|
| 51 |
public boolean belongsTo(Object family) { |
| 52 |
return family == PROFILE_SAVE_JOB_FAMILY; |
| 53 |
} |
| 54 |
} |
| 55 |
|
| 25 |
private int segmentCount; |
56 |
private int segmentCount; |
| 26 |
private String qualifier; |
57 |
private String qualifier; |
| 27 |
//private IPath location; |
58 |
//private IPath location; |
|
Lines 30-35
Link Here
|
| 30 |
private static Set loadedNodes = new HashSet(); |
61 |
private static Set loadedNodes = new HashSet(); |
| 31 |
|
62 |
|
| 32 |
private Object profileLock; |
63 |
private Object profileLock; |
|
|
64 |
private SaveJob saveJob; |
| 33 |
|
65 |
|
| 34 |
public ProfilePreferences() { |
66 |
public ProfilePreferences() { |
| 35 |
this(null, null); |
67 |
this(null, null); |
|
Lines 150-160
Link Here
|
| 150 |
return URLUtil.toFile(location.getDataArea(EngineActivator.ID)); |
182 |
return URLUtil.toFile(location.getDataArea(EngineActivator.ID)); |
| 151 |
} |
183 |
} |
| 152 |
|
184 |
|
|
|
185 |
/** |
| 186 |
* Schedules the save job. This method is synchronized to protect lazily initialization |
| 187 |
* of the save job instance. |
| 188 |
*/ |
| 189 |
protected synchronized void save() { |
| 190 |
if (saveJob == null) |
| 191 |
saveJob = new SaveJob(); |
| 192 |
//only schedule a save if the engine bundle is still running |
| 193 |
BundleContext context = EngineActivator.getContext(); |
| 194 |
if (context == null) |
| 195 |
return; |
| 196 |
try { |
| 197 |
if (context.getBundle().getState() == Bundle.ACTIVE) |
| 198 |
saveJob.schedule(SAVE_SCHEDULE_DELAY); |
| 199 |
} catch (IllegalStateException e) { |
| 200 |
//bundle has been stopped concurrently, so don't save |
| 201 |
} |
| 202 |
} |
| 203 |
|
| 153 |
/* |
204 |
/* |
| 154 |
* (non-Javadoc) |
205 |
* (non-Javadoc) |
| 155 |
* Create an Engine phase to save profile preferences |
206 |
* Create an Engine phase to save profile preferences |
| 156 |
*/ |
207 |
*/ |
| 157 |
protected void save() throws BackingStoreException { |
208 |
protected void doSave() throws BackingStoreException { |
| 158 |
synchronized (((ProfilePreferences) parent).profileLock) { |
209 |
synchronized (((ProfilePreferences) parent).profileLock) { |
| 159 |
String profileId = getSegment(absolutePath(), 1); |
210 |
String profileId = getSegment(absolutePath(), 1); |
| 160 |
IProfile profile = computeProfile(profileId); |
211 |
IProfile profile = computeProfile(profileId); |