Blob Blame History Raw
diff --git a/bundles/org.eclipse.equinox.p2.core/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.p2.core/META-INF/MANIFEST.MF
index 2392378..526183c 100644
--- rt.equinox.p2/bundles/org.eclipse.equinox.p2.core/META-INF/MANIFEST.MF
+++ rt.equinox.p2/bundles/org.eclipse.equinox.p2.core/META-INF/MANIFEST.MF
@@ -7,7 +7,7 @@
 Bundle-Activator: org.eclipse.equinox.internal.p2.core.Activator
 Bundle-Vendor: %providerName
 Bundle-Localization: plugin
-Export-Package: org.eclipse.equinox.internal.p2.core;x-friends:="org.eclipse.equinox.p2.publisher,org.eclipse.equinox.p2.repository",
+Export-Package: org.eclipse.equinox.internal.p2.core;x-friends:="org.eclipse.equinox.p2.publisher,org.eclipse.equinox.p2.repository,org.eclipse.equinox.p2.engine",
  org.eclipse.equinox.internal.p2.core.helpers;
   x-friends:="org.eclipse.equinox.frameworkadmin.test,
    org.eclipse.equinox.p2.artifact.optimizers,
diff --git a/bundles/org.eclipse.equinox.p2.engine/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.p2.engine/META-INF/MANIFEST.MF
index cb812be2..21ba682 100644
--- rt.equinox.p2/bundles/org.eclipse.equinox.p2.engine/META-INF/MANIFEST.MF
+++ rt.equinox.p2/bundles/org.eclipse.equinox.p2.engine/META-INF/MANIFEST.MF
@@ -25,16 +25,19 @@
  J2SE-1.4,
  CDC-1.1/Foundation-1.1
 Bundle-ActivationPolicy: lazy
-Service-Component: OSGI-INF/profileRegistry.xml, OSGI-INF/engine.xml
+Service-Component: OSGI-INF/profileRegistry.xml, OSGI-INF/engine.xml,
+ OSGI-INF/MasterRepositoryPreferenceProvider.xml
 Import-Package: javax.xml.parsers,
  org.eclipse.core.internal.preferences,
  org.eclipse.core.runtime.preferences,
+ org.eclipse.equinox.internal.p2.core,
  org.eclipse.equinox.internal.p2.core.helpers,
  org.eclipse.equinox.internal.p2.metadata,
  org.eclipse.equinox.internal.p2.metadata.index,
  org.eclipse.equinox.internal.p2.metadata.repository.io,
  org.eclipse.equinox.internal.p2.persistence,
  org.eclipse.equinox.internal.p2.repository,
+ org.eclipse.equinox.internal.p2.repository.helpers,
  org.eclipse.equinox.internal.provisional.p2.core.eventbus,
  org.eclipse.equinox.internal.provisional.p2.repository,
  org.eclipse.equinox.p2.core;version="[2.0.0,3.0.0)",
diff --git a/bundles/org.eclipse.equinox.p2.engine/MasterRepositoryPreferenceProvider.xml b/bundles/org.eclipse.equinox.p2.engine/MasterRepositoryPreferenceProvider.xml
new file mode 100644
index 0000000..026fa0e
--- /dev/null
+++ rt.equinox.p2/bundles/org.eclipse.equinox.p2.engine/OSGI-INF/MasterRepositoryPreferenceProvider.xml
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="org.eclipse.equinox.p2.engine.IMasterRepositoryPreferenceProviderService">
+   <implementation class="org.eclipse.equinox.p2.engine.MasterProfilePreferencesProvider"/>
+   <service>
+      <provide interface="org.eclipse.equinox.internal.p2.repository.helpers.IMasterProfilePreferencesProvider"/>
+   </service>
+</scr:component>
diff --git a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/p2/engine/MasterProfilePreferencesProvider.java b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/p2/engine/MasterProfilePreferencesProvider.java
new file mode 100644
index 0000000..0fef156
--- /dev/null
+++ rt.equinox.p2/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/p2/engine/MasterProfilePreferencesProvider.java
@@ -0,0 +1,65 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Red Hat,Inc. 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:
+ *     Red Hat,Inc. - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.equinox.p2.engine;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.Hashtable;
+import org.eclipse.core.runtime.URIUtil;
+import org.eclipse.equinox.internal.p2.core.ProvisioningAgent;
+import org.eclipse.equinox.internal.p2.engine.EngineActivator;
+import org.eclipse.equinox.internal.p2.repository.Activator;
+import org.eclipse.equinox.internal.p2.repository.helpers.IMasterProfilePreferencesProvider;
+import org.eclipse.equinox.p2.core.IAgentLocation;
+import org.eclipse.equinox.p2.core.IProvisioningAgent;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.prefs.Preferences;
+
+public class MasterProfilePreferencesProvider implements IMasterProfilePreferencesProvider {
+
+   public Preferences getMasterPreferences(String profileName, String node) {
+
+       URI location;
+       try {
+           String sharedConfig = Activator.getContext().getProperty("osgi.sharedConfiguration.area"); //$NON-NLS-1$
+
+           if (sharedConfig == null)
+               return null;
+           //find where the profile is located by default
+           location = URIUtil.fromString(sharedConfig + "../p2" + '/'); //$NON-NLS-1$
+
+       } catch (URISyntaxException e1) {
+           //should not happen as Equinox will complain first.
+           return null;
+       }
+
+       if (location == null) {
+           // no master location, quit
+           return null;
+       }
+
+       // This is copied from tests
+       ProvisioningAgent agent = new ProvisioningAgent();
+       agent.setLocation(location);
+       agent.setBundleContext(EngineActivator.getContext());
+       IAgentLocation agentLocation = (IAgentLocation) agent.getService(IAgentLocation.SERVICE_NAME);
+       Hashtable<String, String> props = new Hashtable<String, String>();
+       props.put("locationURI", location.toString()); //$NON-NLS-1$
+
+       @SuppressWarnings("rawtypes")
+       ServiceRegistration reg = EngineActivator.getContext().registerService(IProvisioningAgent.SERVICE_NAME, agent, props);
+       try {
+           return new ProfileScope(agentLocation, profileName).getNode(node);
+       } finally {
+           reg.unregister();
+       }
+   }
+}
diff --git a/bundles/org.eclipse.equinox.p2.repository/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.p2.repository/META-INF/MANIFEST.MF
index e32ff0f..b1d12c1 100644
--- rt.equinox.p2/bundles/org.eclipse.equinox.p2.repository/META-INF/MANIFEST.MF
+++ rt.equinox.p2/bundles/org.eclipse.equinox.p2.repository/META-INF/MANIFEST.MF
@@ -26,7 +26,8 @@
    org.eclipse.equinox.p2.operations,
    org.eclipse.equinox.p2.repository.tools,
    org.eclipse.equinox.p2.ui,
-   org.eclipse.equinox.p2.updatesite",
+   org.eclipse.equinox.p2.updatesite,
+   org.eclipse.equinox.p2.engine",
  org.eclipse.equinox.internal.provisional.p2.repository,
  org.eclipse.equinox.p2.repository;version="2.0.0",
  org.eclipse.equinox.p2.repository.artifact;version="2.1.0",
@@ -41,6 +42,7 @@
  CDC-1.1/Foundation-1.1
 Bundle-ActivationPolicy: lazy
 Import-Package: javax.xml.parsers,
+ org.eclipse.core.internal.preferences,
  org.eclipse.core.runtime.jobs,
  org.eclipse.core.runtime.preferences;version="3.2.0",
  org.eclipse.equinox.internal.p2.core,
diff --git a/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/helpers/IMasterProfilePreferencesProvider.java b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/helpers/IMasterProfilePreferencesProvider.java
new file mode 100644
index 0000000..fac54ea
--- /dev/null
+++ rt.equinox.p2/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/helpers/IMasterProfilePreferencesProvider.java
@@ -0,0 +1,22 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Red Hat,Inc. 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:
+ *     Red Hat,Inc. - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.equinox.internal.p2.repository.helpers;
+
+import org.osgi.service.prefs.Preferences;
+
+/**
+ * This service does its best to locate master profile and get preferences
+ * stored in master ProfileScope.
+ *
+ */
+public interface IMasterProfilePreferencesProvider {
+   public Preferences getMasterPreferences(String profileName, String node);
+}
--- rt.equinox.p2/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/helpers/AbstractRepositoryManager.java.orig	2012-05-05 15:24:03.000000000 +0200
+++ rt.equinox.p2/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/helpers/AbstractRepositoryManager.java	2012-05-18 16:18:18.029669647 +0200
@@ -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;
 
@@ -33,6 +34,7 @@
 import org.eclipse.osgi.util.NLS;
 import org.osgi.service.prefs.BackingStoreException;
 import org.osgi.service.prefs.Preferences;
+import org.osgi.util.tracker.ServiceTracker;
 
 /**
  * Common code shared between artifact and metadata repository managers.
@@ -981,6 +983,61 @@
 		saveToPreferences();
 	}
 
+   private void restoreFromMasterPreferences() {
+       // restore the list of repositories from the preference store
+       Preferences node = getPreferences();
+       if (node == null)
+           return;
+
+       {
+           ServiceTracker<IMasterProfilePreferencesProvider, IMasterProfilePreferencesProvider> tracker = new ServiceTracker<IMasterProfilePreferencesProvider, IMasterProfilePreferencesProvider>(Activator.getContext(), IMasterProfilePreferencesProvider.class.getName(), null);
+           tracker.open();
+           IMasterProfilePreferencesProvider pprovider = tracker.getService();
+	    if(pprovider == null) return;
+           String profileName = node.parent().parent().name();
+           String nodeName = node.parent().name();
+
+           Preferences rootNode = pprovider.getMasterPreferences(profileName, nodeName);
+
+           if (rootNode == null)
+               return;
+
+           /*repositories*/
+           node = rootNode.node(NODE_REPOSITORIES);
+       }
+
+       String[] children;
+       try {
+           children = node.childrenNames();
+       } catch (BackingStoreException e) {
+           log("Error restoring repositories from preferences", e); //$NON-NLS-1$
+           return;
+       }
+
+       for (int i = 0; i < children.length; i++) {
+           Preferences child = node.node(children[i]);
+           URI location = getRepositoryLocation(child);
+           if (location == null) {
+               try {
+                   child.removeNode();
+                   continue;
+               } catch (BackingStoreException e) {
+                   log("Error removing invalid repository", e); //$NON-NLS-1$
+               }
+           }
+           RepositoryInfo<T> info = new RepositoryInfo<T>();
+           info.location = location;
+           info.name = child.get(KEY_NAME, null);
+           info.nickname = child.get(KEY_NICKNAME, null);
+           info.description = child.get(KEY_DESCRIPTION, null);
+           info.isSystem = child.getBoolean(KEY_SYSTEM, false);
+           info.isEnabled = child.getBoolean(KEY_ENABLED, true);
+           info.suffix = child.get(KEY_SUFFIX, null);
+           repositories.put(getKey(info.location), info);
+        }
+    }
+
+
 	private void restoreFromSystemProperty() {
 		String locationString = Activator.getContext().getProperty(getRepositorySystemProperty());
 		if (locationString != null) {
@@ -1004,6 +1062,7 @@
 			restoreSpecialRepositories();
 			restoreFromSystemProperty();
 			restoreFromPreferences();
+			restoreFromMasterPreferences();
 		}
 	}