Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 266205
Collapse All | Expand All

(-)src/org/eclipse/equinox/internal/p2/engine/EngineActivator.java (+3 lines)
Lines 10-15 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.equinox.internal.p2.engine;
11
package org.eclipse.equinox.internal.p2.engine;
12
12
13
import org.eclipse.core.runtime.jobs.Job;
13
import org.eclipse.equinox.internal.provisional.p2.core.eventbus.IProvisioningEventBus;
14
import org.eclipse.equinox.internal.provisional.p2.core.eventbus.IProvisioningEventBus;
14
import org.eclipse.equinox.internal.provisional.p2.engine.Engine;
15
import org.eclipse.equinox.internal.provisional.p2.engine.Engine;
15
import org.eclipse.equinox.internal.provisional.p2.engine.IEngine;
16
import org.eclipse.equinox.internal.provisional.p2.engine.IEngine;
Lines 58-63 Link Here
58
	public void stop(BundleContext aContext) throws Exception {
59
	public void stop(BundleContext aContext) throws Exception {
59
		tracker.close();
60
		tracker.close();
60
		tracker = null;
61
		tracker = null;
62
		//ensure there are no more profile preference save jobs running
63
		Job.getJobManager().join(ProfilePreferences.PROFILE_SAVE_JOB_FAMILY, null);
61
64
62
		EngineActivator.context = null;
65
		EngineActivator.context = null;
63
	}
66
	}
(-)src/org/eclipse/equinox/internal/p2/engine/messages.properties (+1 lines)
Lines 49-54 Link Here
49
shared_profile_not_found=Shared profile {0} not found.
49
shared_profile_not_found=Shared profile {0} not found.
50
50
51
ProfilePreferences_save_failed=An error occurred while saving preferences for profile {0}
51
ProfilePreferences_save_failed=An error occurred while saving preferences for profile {0}
52
ProfilePreferences_saving=Saving profile preferences
52
ProfilePreferences_load_failed=An error occurred while loading preferences for profile {0}
53
ProfilePreferences_load_failed=An error occurred while loading preferences for profile {0}
53
ProfilePreferences_nullDir=Profile data directory is unexpectedly null
54
ProfilePreferences_nullDir=Profile data directory is unexpectedly null
54
ProfilePreferences_Profile_not_found=Requested profile {0} not located for preferences.
55
ProfilePreferences_Profile_not_found=Requested profile {0} not located for preferences.
(-)src/org/eclipse/equinox/internal/p2/engine/ProfilePreferences.java (-1 / +52 lines)
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);
(-)src/org/eclipse/equinox/internal/p2/engine/Messages.java (+2 lines)
Lines 39-44 Link Here
39
	public static String Profile_Parent_Not_Found;
39
	public static String Profile_Parent_Not_Found;
40
40
41
	public static String ProfilePreferences_save_failed;
41
	public static String ProfilePreferences_save_failed;
42
43
	public static String ProfilePreferences_saving;
42
	public static String ProfilePreferences_load_failed;
44
	public static String ProfilePreferences_load_failed;
43
45
44
	public static String ProfilePreferences_nullDir;
46
	public static String ProfilePreferences_nullDir;
(-)META-INF/MANIFEST.MF (-1 / +2 lines)
Lines 59-62 Link Here
59
Require-Bundle: org.eclipse.equinox.common,
59
Require-Bundle: org.eclipse.equinox.common,
60
 org.eclipse.equinox.registry,
60
 org.eclipse.equinox.registry,
61
 org.eclipse.osgi,
61
 org.eclipse.osgi,
62
 org.eclipse.equinox.p2.metadata.repository;bundle-version="1.0.100"
62
 org.eclipse.equinox.p2.metadata.repository;bundle-version="1.0.100",
63
 org.eclipse.core.jobs;bundle-version="[3.4.0,4.0.0)"
(-)src/org/eclipse/equinox/p2/tests/engine/ProfilePreferencesTest.java (-1 / +16 lines)
Lines 10-17 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.equinox.p2.tests.engine;
11
package org.eclipse.equinox.p2.tests.engine;
12
12
13
import org.eclipse.core.runtime.jobs.Job;
13
import org.eclipse.core.runtime.preferences.IPreferencesService;
14
import org.eclipse.core.runtime.preferences.IPreferencesService;
14
import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper;
15
import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper;
16
import org.eclipse.equinox.internal.p2.engine.ProfilePreferences;
15
import org.eclipse.equinox.p2.tests.AbstractProvisioningTest;
17
import org.eclipse.equinox.p2.tests.AbstractProvisioningTest;
16
import org.eclipse.equinox.p2.tests.TestActivator;
18
import org.eclipse.equinox.p2.tests.TestActivator;
17
import org.osgi.service.prefs.BackingStoreException;
19
import org.osgi.service.prefs.BackingStoreException;
Lines 58-70 Link Here
58
		} catch (BackingStoreException e) {
60
		} catch (BackingStoreException e) {
59
			fail("Unable to write to preferences: " + e.getMessage());
61
			fail("Unable to write to preferences: " + e.getMessage());
60
		}
62
		}
63
		waitForSave();
61
64
62
		try {
65
		try {
63
			pref.parent().removeNode();
66
			pref.parent().removeNode();
64
		} catch (BackingStoreException e) {
67
		} catch (BackingStoreException e) {
65
			//
68
			//
66
		}
69
		}
70
		waitForSave();
67
		pref = prefServ.getRootNode().node("/profile/_SELF_/testing");
71
		pref = prefServ.getRootNode().node("/profile/_SELF_/testing");
68
		assertTrue("Value not present after load", value.equals(pref.get(key, null)));
72
		assertEquals("Value not present after load", value, pref.get(key, null));
73
	}
74
75
	/**
76
	 * Wait for preferences to be flushed to disk
77
	 */
78
	private void waitForSave() {
79
		try {
80
			Job.getJobManager().join(ProfilePreferences.PROFILE_SAVE_JOB_FAMILY, null);
81
		} catch (InterruptedException e) {
82
			fail("4.99", e);
83
		}
69
	}
84
	}
70
}
85
}
(-)src/org/eclipse/equinox/internal/p2/core/helpers/AbstractRepositoryManager.java (-30 / +10 lines)
Lines 14-20 Link Here
14
import java.net.*;
14
import java.net.*;
15
import java.util.*;
15
import java.util.*;
16
import org.eclipse.core.runtime.*;
16
import org.eclipse.core.runtime.*;
17
import org.eclipse.core.runtime.jobs.Job;
18
import org.eclipse.core.runtime.preferences.IPreferencesService;
17
import org.eclipse.core.runtime.preferences.IPreferencesService;
19
import org.eclipse.equinox.internal.p2.core.Activator;
18
import org.eclipse.equinox.internal.p2.core.Activator;
20
import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException;
19
import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException;
Lines 44-67 Link Here
44
		}
43
		}
45
	}
44
	}
46
45
47
	private class SaveJob extends Job {
48
		SaveJob() {
49
			super(Messages.repoMan_save);
50
			setSystem(true);
51
		}
52
53
		protected IStatus run(IProgressMonitor monitor) {
54
			try {
55
				Preferences node = getPreferences();
56
				if (node != null)
57
					node.flush();
58
			} catch (BackingStoreException e) {
59
				log("Error while saving repositories in preferences", e); //$NON-NLS-1$
60
			}
61
			return Status.OK_STATUS;
62
		}
63
	}
64
65
	public static final String ATTR_SUFFIX = "suffix"; //$NON-NLS-1$
46
	public static final String ATTR_SUFFIX = "suffix"; //$NON-NLS-1$
66
	public static final String EL_FACTORY = "factory"; //$NON-NLS-1$
47
	public static final String EL_FACTORY = "factory"; //$NON-NLS-1$
67
	public static final String EL_FILTER = "filter"; //$NON-NLS-1$
48
	public static final String EL_FILTER = "filter"; //$NON-NLS-1$
Lines 78-84 Link Here
78
	public static final String KEY_VERSION = "version"; //$NON-NLS-1$
59
	public static final String KEY_VERSION = "version"; //$NON-NLS-1$
79
60
80
	public static final String NODE_REPOSITORIES = "repositories"; //$NON-NLS-1$
61
	public static final String NODE_REPOSITORIES = "repositories"; //$NON-NLS-1$
81
	private static final long SAVE_SCHEDULE_DELAY = 500;
82
62
83
	/**
63
	/**
84
	 * Map of String->RepositoryInfo, where String is the repository key
64
	 * Map of String->RepositoryInfo, where String is the repository key
Lines 100-107 Link Here
100
	 */
80
	 */
101
	private Map loadLocks = new HashMap();
81
	private Map loadLocks = new HashMap();
102
82
103
	private final Job saveJob = new SaveJob();
104
105
	protected AbstractRepositoryManager() {
83
	protected AbstractRepositoryManager() {
106
		IProvisioningEventBus bus = (IProvisioningEventBus) ServiceHelper.getService(Activator.getContext(), IProvisioningEventBus.SERVICE_NAME);
84
		IProvisioningEventBus bus = (IProvisioningEventBus) ServiceHelper.getService(Activator.getContext(), IProvisioningEventBus.SERVICE_NAME);
107
		if (bus != null)
85
		if (bus != null)
Lines 897-903 Link Here
897
	 * Save the list of repositories to the file-system.
875
	 * Save the list of repositories to the file-system.
898
	 */
876
	 */
899
	private void saveToPreferences() {
877
	private void saveToPreferences() {
900
		saveJob.schedule(SAVE_SCHEDULE_DELAY);
878
		try {
879
			Preferences node = getPreferences();
880
			if (node != null)
881
				node.flush();
882
		} catch (BackingStoreException e) {
883
			log("Error while saving repositories in preferences", e); //$NON-NLS-1$
884
		}
901
	}
885
	}
902
886
903
	/* (non-Javadoc)
887
	/* (non-Javadoc)
Lines 933-946 Link Here
933
				}
917
				}
934
			}
918
			}
935
		}
919
		}
936
		if (changed)
920
		if (changed) {
921
			if (Tracing.DEBUG)
922
				Tracing.debug("Unsaved preferences when shutting down " + getClass().getName()); //$NON-NLS-1$
937
			saveToPreferences();
923
			saveToPreferences();
938
		//if there is a save job waiting, make sure it runs immediately before we discard state
939
		saveJob.wakeUp();
940
		try {
941
			saveJob.join();
942
		} catch (InterruptedException e) {
943
			//ignore
944
		}
924
		}
945
		repositories = null;
925
		repositories = null;
946
		unavailableRepositories = null;
926
		unavailableRepositories = null;

Return to bug 266205