Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPascal Rapicault (Ericsson)2012-09-13 11:56:58 -0400
committerPascal Rapicault2012-11-16 22:43:24 -0500
commit74e7bfd3f06c6a8dc1501a60a244babbcc6af73c (patch)
tree5929a3dc9b3584a79d468fc8eab946cedf53753d /bundles/org.eclipse.equinox.p2.engine/src
parentd709ac369fb457887ecb709a3680da983bb9d9cc (diff)
downloadrt.equinox.p2-74e7bfd3f06c6a8dc1501a60a244babbcc6af73c.tar.gz
rt.equinox.p2-74e7bfd3f06c6a8dc1501a60a244babbcc6af73c.tar.xz
rt.equinox.p2-74e7bfd3f06c6a8dc1501a60a244babbcc6af73c.zip
Bug 249133 - [shared] Default update site list blank in shared install
Diffstat (limited to 'bundles/org.eclipse.equinox.p2.engine/src')
-rw-r--r--bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/ProfilePreferences.java76
-rw-r--r--bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/SharedProfilePreferences.java92
-rw-r--r--bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/SimpleProfileRegistry.java7
3 files changed, 144 insertions, 31 deletions
diff --git a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/ProfilePreferences.java b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/ProfilePreferences.java
index dceeffa69..793b70548 100644
--- a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/ProfilePreferences.java
+++ b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/ProfilePreferences.java
@@ -72,12 +72,12 @@ public class ProfilePreferences extends EclipsePreferences {
private static final long SAVE_SCHEDULE_DELAY = 500;
//private IPath location;
- private IEclipsePreferences loadLevel;
- private Object profileLock;
- private String qualifier;
+ protected IEclipsePreferences loadLevel;
+ protected Object profileLock;
+ protected String qualifier;
private SaveJob saveJob;
- private int segmentCount;
+ protected int segmentCount;
public ProfilePreferences() {
this(null, null);
@@ -101,7 +101,7 @@ public class ProfilePreferences extends EclipsePreferences {
if (segmentCount < 4)
return;
// cache the qualifier
- qualifier = getSegment(path, 3);
+ qualifier = getQualifierSegment();
}
private boolean containsProfile(IProfileRegistry profileRegistry, String profileId) {
@@ -116,7 +116,7 @@ public class ProfilePreferences extends EclipsePreferences {
*/
protected void doSave(IProvisioningAgent agent) throws BackingStoreException {
synchronized (((ProfilePreferences) parent).profileLock) {
- String profileId = getSegment(absolutePath(), 2);
+ String profileId = getProfileIdSegment();
IProfileRegistry registry = (IProfileRegistry) agent.getService(IProfileRegistry.SERVICE_NAME);
//can't save anything without a profile registry
if (registry == null)
@@ -142,16 +142,21 @@ public class ProfilePreferences extends EclipsePreferences {
* Returns a reference to the agent service corresponding to the given encoded
* agent location. Never returns null; throws an exception if the agent could not be found.
*/
- private ServiceReference<IProvisioningAgent> getAgent(String segment) throws BackingStoreException {
+ protected IProvisioningAgent getAgent(String segment) throws BackingStoreException {
String locationString = EncodingUtils.decodeSlashes(segment);
Exception failure = null;
+ IProvisioningAgent result = null;
try {
String filter = "(locationURI=" + encodeForFilter(locationString) + ')'; //$NON-NLS-1$
final BundleContext context = EngineActivator.getContext();
if (context != null) {
Collection<ServiceReference<IProvisioningAgent>> refs = context.getServiceReferences(IProvisioningAgent.class, filter);
- if (!refs.isEmpty())
- return refs.iterator().next();
+ if (!refs.isEmpty()) {
+ ServiceReference<IProvisioningAgent> ref = refs.iterator().next();
+ result = EngineActivator.getContext().getService(ref);
+ EngineActivator.getContext().ungetService(ref);
+ return result;
+ }
}
} catch (InvalidSyntaxException e) {
failure = e;
@@ -220,6 +225,9 @@ public class ProfilePreferences extends EclipsePreferences {
}
protected EclipsePreferences internalCreate(EclipsePreferences nodeParent, String nodeName, Object context) {
+ if (nodeName.equals("shared") && segmentCount == 1) { //$NON-NLS-1$
+ return new SharedProfilePreferences(nodeParent, nodeName);
+ }
return new ProfilePreferences(nodeParent, nodeName);
}
@@ -237,28 +245,25 @@ public class ProfilePreferences extends EclipsePreferences {
*/
protected void load() throws BackingStoreException {
synchronized (((ProfilePreferences) parent).profileLock) {
- ServiceReference<IProvisioningAgent> agentRef = getAgent(getSegment(absolutePath(), 1));
- IProvisioningAgent agent = EngineActivator.getContext().getService(agentRef);
+ IProvisioningAgent agent = getAgent(getAgentLocationSegment());
+ if (agent == null)
+ return;
IProfileRegistry registry = (IProfileRegistry) agent.getService(IProfileRegistry.SERVICE_NAME);
- try {
- String profileId = getSegment(absolutePath(), 2);
- if (!containsProfile(registry, profileId)) {
- //use the default location for the self profile, otherwise just do nothing and return
- if (IProfileRegistry.SELF.equals(profileId)) {
- IPath location = getDefaultLocation(agent);
- if (location != null) {
- load(location);
- return;
- }
+ String profileId = getProfileIdSegment();
+ if (!containsProfile(registry, profileId)) {
+ //use the default location for the self profile, otherwise just do nothing and return
+ if (IProfileRegistry.SELF.equals(profileId)) {
+ IPath location = getDefaultLocation(agent);
+ if (location != null) {
+ load(location);
+ return;
}
- if (Tracing.DEBUG_PROFILE_PREFERENCES)
- Tracing.debug("Not loading preferences since there is no file for node: " + absolutePath()); //$NON-NLS-1$
- return;
}
- load(getProfileLocation(registry, profileId));
- } finally {
- EngineActivator.getContext().ungetService(agentRef);
+ if (Tracing.DEBUG_PROFILE_PREFERENCES)
+ Tracing.debug("Not loading preferences since there is no file for node: " + absolutePath()); //$NON-NLS-1$
+ return;
}
+ load(getProfileLocation(registry, profileId));
}
}
@@ -277,11 +282,9 @@ public class ProfilePreferences extends EclipsePreferences {
*/
protected synchronized void save() throws BackingStoreException {
try {
- ServiceReference<IProvisioningAgent> agentRef = getAgent(getSegment(absolutePath(), 1));
- IProvisioningAgent agent = EngineActivator.getContext().getService(agentRef);
+ IProvisioningAgent agent = getAgent(getAgentLocationSegment());
if (saveJob == null || saveJob.agent != agent)
saveJob = new SaveJob(agent);
- EngineActivator.getContext().ungetService(agentRef);
} catch (BackingStoreException e) {
if (Tracing.DEBUG_PROFILE_PREFERENCES)
e.printStackTrace();
@@ -299,4 +302,17 @@ public class ProfilePreferences extends EclipsePreferences {
//bundle has been stopped concurrently, so don't save
}
}
+
+ protected String getQualifierSegment() {
+ return getSegment(absolutePath(), 3);
+ }
+
+ protected String getProfileIdSegment() {
+ return getSegment(absolutePath(), 2);
+ }
+
+ protected String getAgentLocationSegment() {
+ return getSegment(absolutePath(), 1);
+ }
+
}
diff --git a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/SharedProfilePreferences.java b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/SharedProfilePreferences.java
new file mode 100644
index 000000000..d10fc272d
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/SharedProfilePreferences.java
@@ -0,0 +1,92 @@
+/*******************************************************************************
+ * Copyright (c) 2004, 2010 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.equinox.internal.p2.engine;
+
+import org.eclipse.core.internal.preferences.EclipsePreferences;
+import org.eclipse.core.runtime.preferences.IEclipsePreferences;
+import org.eclipse.equinox.p2.core.IProvisioningAgent;
+import org.osgi.service.prefs.BackingStoreException;
+
+/**
+ * A preference implementation that stores preferences in the engine's profile
+ * data area. There is one preference file per profile, with an additional file
+ * that is used when there is no currently running profile.
+ */
+public class SharedProfilePreferences extends ProfilePreferences {
+ public SharedProfilePreferences() {
+ this(null, null);
+ }
+
+ public SharedProfilePreferences(EclipsePreferences nodeParent, String nodeName) {
+ super(nodeParent, nodeName);
+
+ //path is /profile/shared/{agent location}/{profile id}/qualifier
+
+ // cache the segment count
+ String path = absolutePath();
+ segmentCount = getSegmentCount(path);
+
+ if (segmentCount <= 3)
+ return;
+
+ if (segmentCount == 4)
+ profileLock = new Object();
+
+ if (segmentCount < 5)
+ return;
+ // cache the qualifier
+ qualifier = getQualifierSegment();
+ }
+
+ protected IProvisioningAgent getAgent(String segment) throws BackingStoreException {
+ IProvisioningAgent agent = super.getAgent(segment);
+ return (IProvisioningAgent) agent.getService(IProvisioningAgent.SHARED_INSTALL_AGENT);
+ }
+
+ protected void doSave(IProvisioningAgent agent) throws BackingStoreException {
+ throw new BackingStoreException("Can't store in shared install");
+ }
+
+ protected EclipsePreferences internalCreate(EclipsePreferences nodeParent, String nodeName, Object context) {
+ return new SharedProfilePreferences(nodeParent, nodeName);
+ }
+
+ protected IEclipsePreferences getLoadLevel() {
+ if (loadLevel == null) {
+ if (qualifier == null)
+ return null;
+ // Make it relative to this node rather than navigating to it from the root.
+ // Walk backwards up the tree starting at this node.
+ // This is important to avoid a chicken/egg thing on startup.
+ IEclipsePreferences node = this;
+ for (int i = 5; i < segmentCount; i++)
+ node = (EclipsePreferences) node.parent();
+ loadLevel = node;
+ }
+ return loadLevel;
+ }
+
+ protected synchronized void save() throws BackingStoreException {
+ throw new BackingStoreException("Can't store in shared install");
+ }
+
+ protected String getQualifierSegment() {
+ return getSegment(absolutePath(), 4);
+ }
+
+ protected String getProfileIdSegment() {
+ return getSegment(absolutePath(), 3);
+ }
+
+ protected String getAgentLocationSegment() {
+ return getSegment(absolutePath(), 2);
+ }
+}
diff --git a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/SimpleProfileRegistry.java b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/SimpleProfileRegistry.java
index 0853c2c41..308e1e3af 100644
--- a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/SimpleProfileRegistry.java
+++ b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/SimpleProfileRegistry.java
@@ -96,6 +96,11 @@ public class SimpleProfileRegistry implements IProfileRegistry, IAgentService {
if (store.equals(getDefaultRegistryDirectory(location))) {
//we are the registry for the currently running system
self = context.getProperty("eclipse.p2.profile"); //$NON-NLS-1$
+ } else if (agent.getService(IProvisioningAgent.SHARED_CURRENT_AGENT) != null) {
+ // In shared mode, _SELF_ is the value of the current running profile for both agents current and shared
+ if (((IProvisioningAgent) agent.getService(IProvisioningAgent.SHARED_CURRENT_AGENT)).getService(IProvisioningAgent.SHARED_INSTALL_AGENT) == agent) {
+ self = context.getProperty("eclipse.p2.profile"); //$NON-NLS-1$
+ }
}
context.ungetService(ref);
}
@@ -161,7 +166,7 @@ public class SimpleProfileRegistry implements IProfileRegistry, IAgentService {
}
public synchronized String toString() {
- return getProfileMap().toString();
+ return "Profile registry for location: " + store.getAbsolutePath() + "\n" + getProfileMap().toString(); //$NON-NLS-1$
}
public synchronized IProfile getProfile(String id) {

Back to the top