summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPascal Rapicault (Ericsson)2012-09-13 11:56:58 (EDT)
committerPascal Rapicault2012-11-16 22:43:24 (EST)
commit74e7bfd3f06c6a8dc1501a60a244babbcc6af73c (patch)
tree5929a3dc9b3584a79d468fc8eab946cedf53753d
parentd709ac369fb457887ecb709a3680da983bb9d9cc (diff)
downloadrt.equinox.p2-74e7bfd3f06c6a8dc1501a60a244babbcc6af73c.zip
rt.equinox.p2-74e7bfd3f06c6a8dc1501a60a244babbcc6af73c.tar.gz
rt.equinox.p2-74e7bfd3f06c6a8dc1501a60a244babbcc6af73c.tar.bz2
Bug 249133 - [shared] Default update site list blank in shared install
-rw-r--r--bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/p2/core/Activator.java43
-rw-r--r--bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/p2/core/AgentLocation.java6
-rw-r--r--bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/p2/core/IProvisioningAgent.java9
-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
-rw-r--r--bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/helpers/AbstractRepositoryManager.java25
-rw-r--r--bundles/org.eclipse.equinox.p2.tests.sharedinstall/.classpath7
-rw-r--r--bundles/org.eclipse.equinox.p2.tests.sharedinstall/.project28
-rw-r--r--bundles/org.eclipse.equinox.p2.tests.sharedinstall/.settings/org.eclipse.jdt.core.prefs7
-rw-r--r--bundles/org.eclipse.equinox.p2.tests.sharedinstall/META-INF/MANIFEST.MF12
-rw-r--r--bundles/org.eclipse.equinox.p2.tests.sharedinstall/build.properties5
-rw-r--r--bundles/org.eclipse.equinox.p2.tests.sharedinstall/src/SharedProfilePreferencesTest.java84
-rw-r--r--bundles/org.eclipse.equinox.p2.tests.sharedinstall/testData/sharedPreferences/baseInstall/p2/org.eclipse.equinox.p2.engine/profileRegistry/epp.package.java.profile/.data/.settings/org.eclipse.equinox.p2.artifact.repository.prefs13
-rw-r--r--bundles/org.eclipse.equinox.p2.tests.sharedinstall/testData/sharedPreferences/baseInstall/p2/org.eclipse.equinox.p2.engine/profileRegistry/epp.package.java.profile/.data/.settings/org.eclipse.equinox.p2.metadata.repository.prefs13
-rw-r--r--bundles/org.eclipse.equinox.p2.tests.sharedinstall/testData/sharedPreferences/baseInstall/p2/org.eclipse.equinox.p2.engine/profileRegistry/epp.package.java.profile/.lock0
-rw-r--r--bundles/org.eclipse.equinox.p2.tests.sharedinstall/testData/sharedPreferences/baseInstall/p2/org.eclipse.equinox.p2.engine/profileRegistry/epp.package.java.profile/1339695683273.profile4
-rw-r--r--bundles/org.eclipse.equinox.p2.tests.sharedinstall/testData/sharedPreferences/baseInstall/p2/org.eclipse.equinox.p2.engine/profileRegistry/epp.package.java.profile/state.properties1
-rw-r--r--bundles/org.eclipse.equinox.p2.tests.sharedinstall/testData/sharedPreferences/userHome/configuration/p2/org.eclipse.equinox.p2.engine/.settings/org.eclipse.equinox.p2.metadata.repository.prefs13
19 files changed, 410 insertions, 35 deletions
diff --git a/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/p2/core/Activator.java b/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/p2/core/Activator.java
index bfa77c3..52c10df 100644
--- a/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/p2/core/Activator.java
+++ b/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/p2/core/Activator.java
@@ -35,6 +35,7 @@ public class Activator implements BundleActivator {
private static final String PROP_AGENT_DATA_AREA = "eclipse.p2.data.area"; //$NON-NLS-1$
private static final String PROP_CONFIG_DIR = "osgi.configuration.area"; //$NON-NLS-1$
+ private static final String PROP_SHARED_CONFIG_DIR = "osgi.sharedConfiguration.area"; //$NON-NLS-1$
private static final String PROP_USER_DIR = "user.dir"; //$NON-NLS-1$
private static final String PROP_USER_HOME = "user.home"; //$NON-NLS-1$
@@ -185,6 +186,48 @@ public class Activator implements BundleActivator {
final String msg = "Unable to instantiate p2 agent at location " + agentDataLocation.getRootLocation(); //$NON-NLS-1$
LogHelper.log(new Status(IStatus.ERROR, ID, msg, e));
}
+ registerSharedAgent(agent, provider);
+ }
+
+ private URI computeLocationSharedAgent(IProvisioningAgent currentAgent, IProvisioningAgentProvider provider) {
+ //This figures out if we are running in shared mode and computes the location of the p2 folder in the base.
+ //Note that this logic only works for the case where the p2 location is colocated with the configuration area
+ //(configuration and p2 are sibling of each others).
+ //To make that work for other scenarios, the config.ini of the base would have to be read and interpreted.
+ URI location = null;
+ String sharedConfigArea = null;
+ try {
+ sharedConfigArea = context.getProperty(PROP_SHARED_CONFIG_DIR);
+ if (sharedConfigArea == null)
+ return null;
+
+ //Make sure the property has a trai
+ if (!sharedConfigArea.endsWith("/") && !sharedConfigArea.endsWith("\\")) //$NON-NLS-1$ //$NON-NLS-2$
+ sharedConfigArea += "/"; //$NON-NLS-1$
+ location = URIUtil.fromString(sharedConfigArea + DEFAULT_AGENT_LOCATION + '/');
+ } catch (URISyntaxException e) {
+ final String msg = "Unable to instantiate p2 agent for shared location " + sharedConfigArea; //$NON-NLS-1$
+ LogHelper.log(new Status(IStatus.WARNING, ID, msg, e));
+ return null;
+ }
+ return location;
+ }
+
+ private void registerSharedAgent(IProvisioningAgent currentAgent, IProvisioningAgentProvider provider) {
+ URI location = computeLocationSharedAgent(currentAgent, provider);
+ if (location == null) {
+ return;
+ }
+
+ IProvisioningAgent sharedAgent;
+ try {
+ sharedAgent = provider.createAgent(location);
+ currentAgent.registerService(IProvisioningAgent.SHARED_INSTALL_AGENT, sharedAgent);
+ sharedAgent.registerService(IProvisioningAgent.SHARED_CURRENT_AGENT, currentAgent);
+ } catch (ProvisionException e) {
+ final String msg = "Unable to instantiate p2 agent for shared location " + location; //$NON-NLS-1$
+ LogHelper.log(new Status(IStatus.WARNING, ID, msg, e));
+ }
}
public void start(BundleContext aContext) throws Exception {
diff --git a/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/p2/core/AgentLocation.java b/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/p2/core/AgentLocation.java
index 2be7743..f29e978 100644
--- a/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/p2/core/AgentLocation.java
+++ b/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/p2/core/AgentLocation.java
@@ -32,4 +32,10 @@ public class AgentLocation implements IAgentLocation {
public URI getDataArea(String touchpointId) {
return URIUtil.append(getRootLocation(), touchpointId + '/');
}
+
+ public String toString() {
+ if (location == null)
+ return "No location specified"; //$NON-NLS-1$
+ return location.toString();
+ }
}
diff --git a/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/p2/core/IProvisioningAgent.java b/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/p2/core/IProvisioningAgent.java
index b6c20e1..a603db7 100644
--- a/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/p2/core/IProvisioningAgent.java
+++ b/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/p2/core/IProvisioningAgent.java
@@ -39,6 +39,15 @@ public interface IProvisioningAgent {
public static final String INSTALLER_AGENT = "org.eclipse.equinox.p2.installer.agent"; //$NON-NLS-1$
public static final String INSTALLER_PROFILEID = "org.eclipse.equinox.p2.installer.profile.id"; //$NON-NLS-1$
+ /**
+ * When running in "shared mode", this allows to retrieve from the IProvisioningAgent the agent representing what is in the shared location
+ */
+ public static final String SHARED_INSTALL_AGENT = "org.eclipse.equinox.shared.install.agent"; //$NON-NLS-1$
+
+ /**
+ * When running in "shared mode", this allows to retrieve from the IProvisioningAgent identified by {@link #SHARED_INSTALL_AGENT} the current agent
+ */
+ public static final String SHARED_CURRENT_AGENT = "org.eclipse.equinox.shared.current.agent"; //$NON-NLS-1$
/**
* Service property identifying whether an agent is the default agent.
*
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 dceeffa..793b705 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 0000000..d10fc27
--- /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 0853c2c..308e1e3 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) {
diff --git a/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/helpers/AbstractRepositoryManager.java b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/helpers/AbstractRepositoryManager.java
index 207eebc..537e1c3 100644
--- a/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/helpers/AbstractRepositoryManager.java
+++ b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/helpers/AbstractRepositoryManager.java
@@ -9,6 +9,7 @@
* IBM Corporation - initial API and implementation
* Wind River - fix for bug 299227
* Sonatype, Inc. - transport split
+ * Red Hat,Inc. - fix for bug 249133
*******************************************************************************/
package org.eclipse.equinox.internal.p2.repository.helpers;
@@ -504,6 +505,21 @@ public abstract class AbstractRepositoryManager<T> implements IRepositoryManager
}
}
+ Preferences getSharedPreferences() {
+ if (agentLocation == null)
+ return null;
+ IPreferencesService prefService = (IPreferencesService) ServiceHelper.getService(Activator.getContext(), IPreferencesService.class.getName());
+ if (prefService == null)
+ return null;
+ try {
+ //see ProfileScope for preference path format
+ String locationString = EncodingUtils.encodeSlashes(agentLocation.getRootLocation().toString());
+ return prefService.getRootNode().node("/profile/shared/" + locationString + "/_SELF_/" + getBundleId() + '/' + NODE_REPOSITORIES); //$NON-NLS-1$ //$NON-NLS-2$
+ } catch (IllegalArgumentException e) {
+ return null;
+ }
+ }
+
/**
* Restores a repository location from the preferences.
*/
@@ -944,9 +960,8 @@ public abstract class AbstractRepositoryManager<T> implements IRepositoryManager
/*
* Load the list of repositories from the preferences.
*/
- private void restoreFromPreferences() {
+ private void basicRestoreFromPreferences(Preferences node, boolean save) {
// restore the list of repositories from the preference store
- Preferences node = getPreferences();
if (node == null)
return;
String[] children;
@@ -978,7 +993,8 @@ public abstract class AbstractRepositoryManager<T> implements IRepositoryManager
repositories.put(getKey(info.location), info);
}
// now that we have loaded everything, remember them
- saveToPreferences();
+ if (save)
+ saveToPreferences();
}
private void restoreFromSystemProperty() {
@@ -1003,7 +1019,8 @@ public abstract class AbstractRepositoryManager<T> implements IRepositoryManager
repositories = new HashMap<String, RepositoryInfo<T>>();
restoreSpecialRepositories();
restoreFromSystemProperty();
- restoreFromPreferences();
+ basicRestoreFromPreferences(getSharedPreferences(), false);
+ basicRestoreFromPreferences(getPreferences(), true);
}
}
diff --git a/bundles/org.eclipse.equinox.p2.tests.sharedinstall/.classpath b/bundles/org.eclipse.equinox.p2.tests.sharedinstall/.classpath
new file mode 100644
index 0000000..098194c
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.tests.sharedinstall/.classpath
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/bundles/org.eclipse.equinox.p2.tests.sharedinstall/.project b/bundles/org.eclipse.equinox.p2.tests.sharedinstall/.project
new file mode 100644
index 0000000..bdd5cce
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.tests.sharedinstall/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.equinox.p2.tests.sharedinstall</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
diff --git a/bundles/org.eclipse.equinox.p2.tests.sharedinstall/.settings/org.eclipse.jdt.core.prefs b/bundles/org.eclipse.equinox.p2.tests.sharedinstall/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..f42de36
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.tests.sharedinstall/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,7 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
+org.eclipse.jdt.core.compiler.compliance=1.7
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.7
diff --git a/bundles/org.eclipse.equinox.p2.tests.sharedinstall/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.p2.tests.sharedinstall/META-INF/MANIFEST.MF
new file mode 100644
index 0000000..1fa88a1
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.tests.sharedinstall/META-INF/MANIFEST.MF
@@ -0,0 +1,12 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Tests
+Bundle-SymbolicName: org.eclipse.equinox.p2.tests.sharedinstall
+Bundle-Version: 1.0.0.qualifier
+Fragment-Host: org.eclipse.equinox.p2.core
+Bundle-RequiredExecutionEnvironment: JavaSE-1.7
+Require-Bundle: org.eclipse.equinox.p2.tests;bundle-version="1.5.0",
+ org.eclipse.core.runtime;bundle-version="3.8.0",
+ org.eclipse.equinox.security;bundle-version="1.1.100",
+ org.junit4;bundle-version="4.8.1",
+ org.eclipse.equinox.p2.metadata;bundle-version="2.1.100"
diff --git a/bundles/org.eclipse.equinox.p2.tests.sharedinstall/build.properties b/bundles/org.eclipse.equinox.p2.tests.sharedinstall/build.properties
new file mode 100644
index 0000000..4c8022d
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.tests.sharedinstall/build.properties
@@ -0,0 +1,5 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .,\
+ testData/
diff --git a/bundles/org.eclipse.equinox.p2.tests.sharedinstall/src/SharedProfilePreferencesTest.java b/bundles/org.eclipse.equinox.p2.tests.sharedinstall/src/SharedProfilePreferencesTest.java
new file mode 100644
index 0000000..fb8b63b
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.tests.sharedinstall/src/SharedProfilePreferencesTest.java
@@ -0,0 +1,84 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Ericsson 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:
+ * Pascal Rapicault (Ericsson) - Initial API and implementation
+ *******************************************************************************/
+import java.io.File;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.URIUtil;
+import org.eclipse.core.runtime.preferences.IPreferencesService;
+import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper;
+import org.eclipse.equinox.p2.tests.AbstractProvisioningTest;
+import org.eclipse.equinox.p2.tests.TestActivator;
+import org.eclipse.equinox.security.storage.EncodingUtils;
+import org.osgi.framework.Bundle;
+import org.osgi.service.prefs.BackingStoreException;
+import org.osgi.service.prefs.Preferences;
+
+public class SharedProfilePreferencesTest extends AbstractProvisioningTest {
+ protected File getTestData(String message, String entry) {
+ if (entry == null)
+ fail(message + " entry is null.");
+ URL base = Platform.getBundle("org.eclipse.equinox.p2.tests.sharedinstall").getEntry(entry);
+ if (base == null)
+ fail(message + " entry not found in bundle: " + entry);
+ try {
+ String osPath = new Path(FileLocator.toFileURL(base).getPath()).toOSString();
+ File result = new File(osPath);
+ if (!result.getCanonicalPath().equals(result.getPath()))
+ fail(message + " result path: " + result.getPath() + " does not match canonical path: " + result.getCanonicalFile().getPath());
+ return result;
+ } catch (IOException e) {
+ fail(message, e);
+ }
+ // avoid compile error... should never reach this code
+ return null;
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ Bundle p2Core = Platform.getBundle("org.eclipse.equinox.p2.core");
+ p2Core.stop();
+
+ File baseInstall = getTestData("test shared install", "testData/sharedPreferences/baseInstall");
+ File userHome = getTestData("test shared install", "testData/sharedPreferences/userHome");
+ System.setProperty("osgi.sharedConfiguration.area", new File(baseInstall, "configuration").toURI().toString());
+ System.setProperty("osgi.configuration.area", new File(userHome, "configuration").toURI().toString());
+ System.setProperty("eclipse.p2.profile", "epp.package.java");
+
+ p2Core.start();
+ }
+
+ public void testCountReposInSharedInstallPreferences(){
+ IPreferencesService prefService = (IPreferencesService) ServiceHelper.getService(TestActivator.getContext(), IPreferencesService.class.getName());
+ assertNotNull(prefService);
+ try {
+ URI defaultLocation = URIUtil.fromString(TestActivator.getContext().getProperty("osgi.configuration.area") + "/p2/");
+ String locationString = EncodingUtils.encodeSlashes(defaultLocation.toString());
+ Preferences node = prefService.getRootNode().node("/profile/shared/" + locationString + "/_SELF_/org.eclipse.equinox.p2.metadata.repository/repositories"); //$NON-NLS-1$
+ String[] children = node.childrenNames();
+ assertEquals(3, children.length);
+ } catch (IllegalArgumentException e) {
+ fail("Exception", e);
+ } catch (URISyntaxException e) {
+ fail("Exception", e);
+ } catch (BackingStoreException e) {
+ fail("Exception", e);
+ }
+
+ }
+
+}
diff --git a/bundles/org.eclipse.equinox.p2.tests.sharedinstall/testData/sharedPreferences/baseInstall/p2/org.eclipse.equinox.p2.engine/profileRegistry/epp.package.java.profile/.data/.settings/org.eclipse.equinox.p2.artifact.repository.prefs b/bundles/org.eclipse.equinox.p2.tests.sharedinstall/testData/sharedPreferences/baseInstall/p2/org.eclipse.equinox.p2.engine/profileRegistry/epp.package.java.profile/.data/.settings/org.eclipse.equinox.p2.artifact.repository.prefs
new file mode 100644
index 0000000..8cb4991
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.tests.sharedinstall/testData/sharedPreferences/baseInstall/p2/org.eclipse.equinox.p2.engine/profileRegistry/epp.package.java.profile/.data/.settings/org.eclipse.equinox.p2.artifact.repository.prefs
@@ -0,0 +1,13 @@
+eclipse.preferences.version=1
+repositories/http\:__download.eclipse.org_eclipse_updates_4.2/count=1
+repositories/http\:__download.eclipse.org_eclipse_updates_4.2/enabled=true
+repositories/http\:__download.eclipse.org_eclipse_updates_4.2/nickname=The Eclipse Project Updates
+repositories/http\:__download.eclipse.org_eclipse_updates_4.2/uri=http\://download.eclipse.org/eclipse/updates/4.2
+repositories/http\:__download.eclipse.org_mylyn_releases_juno/count=3
+repositories/http\:__download.eclipse.org_mylyn_releases_juno/enabled=true
+repositories/http\:__download.eclipse.org_mylyn_releases_juno/nickname=Mylyn for Eclipse Juno
+repositories/http\:__download.eclipse.org_mylyn_releases_juno/uri=http\://download.eclipse.org/mylyn/releases/juno
+repositories/http\:__download.eclipse.org_releases_juno/count=1
+repositories/http\:__download.eclipse.org_releases_juno/enabled=true
+repositories/http\:__download.eclipse.org_releases_juno/nickname=Juno
+repositories/http\:__download.eclipse.org_releases_juno/uri=http\://download.eclipse.org/releases/juno
diff --git a/bundles/org.eclipse.equinox.p2.tests.sharedinstall/testData/sharedPreferences/baseInstall/p2/org.eclipse.equinox.p2.engine/profileRegistry/epp.package.java.profile/.data/.settings/org.eclipse.equinox.p2.metadata.repository.prefs b/bundles/org.eclipse.equinox.p2.tests.sharedinstall/testData/sharedPreferences/baseInstall/p2/org.eclipse.equinox.p2.engine/profileRegistry/epp.package.java.profile/.data/.settings/org.eclipse.equinox.p2.metadata.repository.prefs
new file mode 100644
index 0000000..8cb4991
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.tests.sharedinstall/testData/sharedPreferences/baseInstall/p2/org.eclipse.equinox.p2.engine/profileRegistry/epp.package.java.profile/.data/.settings/org.eclipse.equinox.p2.metadata.repository.prefs
@@ -0,0 +1,13 @@
+eclipse.preferences.version=1
+repositories/http\:__download.eclipse.org_eclipse_updates_4.2/count=1
+repositories/http\:__download.eclipse.org_eclipse_updates_4.2/enabled=true
+repositories/http\:__download.eclipse.org_eclipse_updates_4.2/nickname=The Eclipse Project Updates
+repositories/http\:__download.eclipse.org_eclipse_updates_4.2/uri=http\://download.eclipse.org/eclipse/updates/4.2
+repositories/http\:__download.eclipse.org_mylyn_releases_juno/count=3
+repositories/http\:__download.eclipse.org_mylyn_releases_juno/enabled=true
+repositories/http\:__download.eclipse.org_mylyn_releases_juno/nickname=Mylyn for Eclipse Juno
+repositories/http\:__download.eclipse.org_mylyn_releases_juno/uri=http\://download.eclipse.org/mylyn/releases/juno
+repositories/http\:__download.eclipse.org_releases_juno/count=1
+repositories/http\:__download.eclipse.org_releases_juno/enabled=true
+repositories/http\:__download.eclipse.org_releases_juno/nickname=Juno
+repositories/http\:__download.eclipse.org_releases_juno/uri=http\://download.eclipse.org/releases/juno
diff --git a/bundles/org.eclipse.equinox.p2.tests.sharedinstall/testData/sharedPreferences/baseInstall/p2/org.eclipse.equinox.p2.engine/profileRegistry/epp.package.java.profile/.lock b/bundles/org.eclipse.equinox.p2.tests.sharedinstall/testData/sharedPreferences/baseInstall/p2/org.eclipse.equinox.p2.engine/profileRegistry/epp.package.java.profile/.lock
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.tests.sharedinstall/testData/sharedPreferences/baseInstall/p2/org.eclipse.equinox.p2.engine/profileRegistry/epp.package.java.profile/.lock
diff --git a/bundles/org.eclipse.equinox.p2.tests.sharedinstall/testData/sharedPreferences/baseInstall/p2/org.eclipse.equinox.p2.engine/profileRegistry/epp.package.java.profile/1339695683273.profile b/bundles/org.eclipse.equinox.p2.tests.sharedinstall/testData/sharedPreferences/baseInstall/p2/org.eclipse.equinox.p2.engine/profileRegistry/epp.package.java.profile/1339695683273.profile
new file mode 100644
index 0000000..6f18bb0
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.tests.sharedinstall/testData/sharedPreferences/baseInstall/p2/org.eclipse.equinox.p2.engine/profileRegistry/epp.package.java.profile/1339695683273.profile
@@ -0,0 +1,4 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<?profile version='1.0.0'?>
+<profile id='epp.package.java' timestamp='1339695683273'>
+</profile>
diff --git a/bundles/org.eclipse.equinox.p2.tests.sharedinstall/testData/sharedPreferences/baseInstall/p2/org.eclipse.equinox.p2.engine/profileRegistry/epp.package.java.profile/state.properties b/bundles/org.eclipse.equinox.p2.tests.sharedinstall/testData/sharedPreferences/baseInstall/p2/org.eclipse.equinox.p2.engine/profileRegistry/epp.package.java.profile/state.properties
new file mode 100644
index 0000000..bd469b5
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.tests.sharedinstall/testData/sharedPreferences/baseInstall/p2/org.eclipse.equinox.p2.engine/profileRegistry/epp.package.java.profile/state.properties
@@ -0,0 +1 @@
+#Thu Jun 14 13:41:23 EDT 2012
diff --git a/bundles/org.eclipse.equinox.p2.tests.sharedinstall/testData/sharedPreferences/userHome/configuration/p2/org.eclipse.equinox.p2.engine/.settings/org.eclipse.equinox.p2.metadata.repository.prefs b/bundles/org.eclipse.equinox.p2.tests.sharedinstall/testData/sharedPreferences/userHome/configuration/p2/org.eclipse.equinox.p2.engine/.settings/org.eclipse.equinox.p2.metadata.repository.prefs
new file mode 100644
index 0000000..dd3534d
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.tests.sharedinstall/testData/sharedPreferences/userHome/configuration/p2/org.eclipse.equinox.p2.engine/.settings/org.eclipse.equinox.p2.metadata.repository.prefs
@@ -0,0 +1,13 @@
+eclipse.preferences.version=1
+repositories/http\:__download.eclipse.org_eclipse_updates_4.2/enabled=true
+repositories/http\:__download.eclipse.org_eclipse_updates_4.2/isSystem=false
+repositories/http\:__download.eclipse.org_eclipse_updates_4.2/nickname=The Eclipse Project Updates
+repositories/http\:__download.eclipse.org_eclipse_updates_4.2/uri=http\://download.eclipse.org/eclipse/updates/4.2
+repositories/http\:__download.eclipse.org_mylyn_releases_juno/enabled=true
+repositories/http\:__download.eclipse.org_mylyn_releases_juno/isSystem=false
+repositories/http\:__download.eclipse.org_mylyn_releases_juno/nickname=Mylyn for Eclipse Juno
+repositories/http\:__download.eclipse.org_mylyn_releases_juno/uri=http\://download.eclipse.org/mylyn/releases/juno
+repositories/http\:__download.eclipse.org_releases_juno/enabled=true
+repositories/http\:__download.eclipse.org_releases_juno/isSystem=false
+repositories/http\:__download.eclipse.org_releases_juno/nickname=Juno
+repositories/http\:__download.eclipse.org_releases_juno/uri=http\://download.eclipse.org/releases/juno