Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDJ Houghton2008-04-24 17:08:12 -0400
committerDJ Houghton2008-04-24 17:08:12 -0400
commite267de0a16666b252342c0825188808651bd038a (patch)
tree6b879d261286ec7c910f4630b15c33ca8f89ab45 /bundles
parent4d8a6529516307c9b1a866c239c54c1678bc5d80 (diff)
downloadrt.equinox.p2-e267de0a16666b252342c0825188808651bd038a.tar.gz
rt.equinox.p2-e267de0a16666b252342c0825188808651bd038a.tar.xz
rt.equinox.p2-e267de0a16666b252342c0825188808651bd038a.zip
Bug 228523 - Multiple repositories on same location
Diffstat (limited to 'bundles')
-rw-r--r--bundles/org.eclipse.equinox.p2.extensionlocation/src/org/eclipse/equinox/internal/p2/extensionlocation/ExtensionLocationMetadataRepository.java2
-rw-r--r--bundles/org.eclipse.equinox.p2.metadata.repository/META-INF/MANIFEST.MF2
-rw-r--r--bundles/org.eclipse.equinox.p2.reconciler.dropins/META-INF/MANIFEST.MF1
-rw-r--r--bundles/org.eclipse.equinox.p2.reconciler.dropins/src/org/eclipse/equinox/internal/p2/reconciler/dropins/Activator.java117
-rw-r--r--bundles/org.eclipse.equinox.p2.reconciler.dropins/src/org/eclipse/equinox/internal/p2/reconciler/dropins/PlatformXmlListener.java24
-rw-r--r--bundles/org.eclipse.equinox.p2.reconciler/META-INF/MANIFEST.MF1
-rw-r--r--bundles/org.eclipse.equinox.p2.reconciler/src/org/eclipse/equinox/internal/p2/reconciler/dropins/Activator.java117
-rw-r--r--bundles/org.eclipse.equinox.p2.reconciler/src/org/eclipse/equinox/internal/p2/reconciler/dropins/PlatformXmlListener.java24
8 files changed, 148 insertions, 140 deletions
diff --git a/bundles/org.eclipse.equinox.p2.extensionlocation/src/org/eclipse/equinox/internal/p2/extensionlocation/ExtensionLocationMetadataRepository.java b/bundles/org.eclipse.equinox.p2.extensionlocation/src/org/eclipse/equinox/internal/p2/extensionlocation/ExtensionLocationMetadataRepository.java
index b1ef5d9d8..bd044ddd5 100644
--- a/bundles/org.eclipse.equinox.p2.extensionlocation/src/org/eclipse/equinox/internal/p2/extensionlocation/ExtensionLocationMetadataRepository.java
+++ b/bundles/org.eclipse.equinox.p2.extensionlocation/src/org/eclipse/equinox/internal/p2/extensionlocation/ExtensionLocationMetadataRepository.java
@@ -61,7 +61,7 @@ public class ExtensionLocationMetadataRepository extends AbstractMetadataReposit
if (location.getPath().endsWith(POOLED))
listener = new BundlePoolFilteredListener(listener);
if (site != null)
- listener = new SiteListener(site, listener);
+ listener = new SiteListener(site, new BundlePoolFilteredListener(listener));
watcher.addListener(listener);
watcher.poll();
diff --git a/bundles/org.eclipse.equinox.p2.metadata.repository/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.p2.metadata.repository/META-INF/MANIFEST.MF
index 61099e91e..2a37cc5b8 100644
--- a/bundles/org.eclipse.equinox.p2.metadata.repository/META-INF/MANIFEST.MF
+++ b/bundles/org.eclipse.equinox.p2.metadata.repository/META-INF/MANIFEST.MF
@@ -5,7 +5,7 @@ Bundle-Name: %pluginName
Bundle-Vendor: %providerName
Bundle-Localization: plugin
Bundle-Version: 0.1.0.qualifier
-Export-Package: org.eclipse.equinox.internal.p2.metadata.repository;x-friends:="org.eclipse.equinox.p2.metadata.generator,org.eclipse.equinox.p2.engine",
+Export-Package: org.eclipse.equinox.internal.p2.metadata.repository;x-friends:="org.eclipse.equinox.p2.engine,org.eclipse.equinox.p2.metadata.generator,org.eclipse.equinox.p2.reconciler.dropins",
org.eclipse.equinox.internal.p2.metadata.repository.io;x-friends:="org.eclipse.equinox.p2.engine",
org.eclipse.equinox.internal.provisional.p2.metadata.repository,
org.eclipse.equinox.internal.provisional.spi.p2.metadata.repository
diff --git a/bundles/org.eclipse.equinox.p2.reconciler.dropins/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.p2.reconciler.dropins/META-INF/MANIFEST.MF
index afdab1075..1a365a51c 100644
--- a/bundles/org.eclipse.equinox.p2.reconciler.dropins/META-INF/MANIFEST.MF
+++ b/bundles/org.eclipse.equinox.p2.reconciler.dropins/META-INF/MANIFEST.MF
@@ -10,6 +10,7 @@ Bundle-RequiredExecutionEnvironment: J2SE-1.4,
CDC-1.1/Foundation-1.1
Import-Package: org.eclipse.equinox.internal.p2.core.helpers,
org.eclipse.equinox.internal.p2.extensionlocation,
+ org.eclipse.equinox.internal.p2.metadata.repository,
org.eclipse.equinox.internal.p2.update,
org.eclipse.equinox.internal.provisional.configurator,
org.eclipse.equinox.internal.provisional.p2.artifact.repository,
diff --git a/bundles/org.eclipse.equinox.p2.reconciler.dropins/src/org/eclipse/equinox/internal/p2/reconciler/dropins/Activator.java b/bundles/org.eclipse.equinox.p2.reconciler.dropins/src/org/eclipse/equinox/internal/p2/reconciler/dropins/Activator.java
index c8edc4b3a..3d6b7a5f4 100644
--- a/bundles/org.eclipse.equinox.p2.reconciler.dropins/src/org/eclipse/equinox/internal/p2/reconciler/dropins/Activator.java
+++ b/bundles/org.eclipse.equinox.p2.reconciler.dropins/src/org/eclipse/equinox/internal/p2/reconciler/dropins/Activator.java
@@ -10,11 +10,13 @@
package org.eclipse.equinox.internal.p2.reconciler.dropins;
import java.io.File;
+import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.*;
import org.eclipse.core.runtime.*;
import org.eclipse.equinox.internal.p2.core.helpers.*;
+import org.eclipse.equinox.internal.p2.metadata.repository.MetadataRepositoryManager;
import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRepository;
import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRepositoryManager;
import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException;
@@ -31,7 +33,6 @@ public class Activator implements BundleActivator {
public static final String ID = "org.eclipse.equinox.p2.reconciler.dropins"; //$NON-NLS-1$
private static final String DROPINS_DIRECTORY = "org.eclipse.equinox.p2.reconciler.dropins.directory"; //$NON-NLS-1$
- private static final String OSGI_CONFIGURATION_AREA = "osgi.configuration.area"; //$NON-NLS-1$
private static final String DROPINS = "dropins"; //$NON-NLS-1$
private static final String LINKS = "links"; //$NON-NLS-1$
// private static final String PROFILE_EXTENSION = "profile.extension"; //$NON-NLS-1$
@@ -66,6 +67,24 @@ public class Activator implements BundleActivator {
}
}
+ /*
+ * Helper method to add the given metadata repository to the manager's list.
+ */
+ public static void addRepository(IMetadataRepository repo) {
+ BundleContext context = getContext();
+ ServiceReference reference = context.getServiceReference(IMetadataRepositoryManager.class.getName());
+ IMetadataRepositoryManager manager = null;
+ if (reference != null)
+ manager = (IMetadataRepositoryManager) context.getService(reference);
+ if (manager == null)
+ throw new IllegalStateException("MetadataRepositoryManager not registered."); //$NON-NLS-1$
+ try {
+ ((MetadataRepositoryManager) manager).addRepository(repo);
+ } finally {
+ context.ungetService(reference);
+ }
+ }
+
/**
* Helper method to load an artifact repository from the given URL.
* This method never returns <code>null</code>.
@@ -88,14 +107,6 @@ public class Activator implements BundleActivator {
}
}
- protected static Collection getDropinRepositories() {
- return dropinRepositories == null ? new ArrayList(0) : dropinRepositories;
- }
-
- protected static Collection getConfigurationRepositories() {
- return configurationRepositories == null ? new ArrayList(0) : configurationRepositories;
- }
-
/* (non-Javadoc)
* @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
*/
@@ -134,14 +145,21 @@ public class Activator implements BundleActivator {
private void watchEclipseProduct() {
try {
- URL baseURL = new URL(bundleContext.getProperty(OSGI_CONFIGURATION_AREA));
- URL pooledURL = new URL(baseURL, "../.pooled"); //$NON-NLS-1$
+ File configurationLocation = getConfigurationLocation();
+ if (configurationLocation == null) {
+ LogHelper.log(new Status(IStatus.ERROR, ID, "Unable to determine configuration location."));
+ return;
+ }
+ File pool = new File(configurationLocation, "../.pooled").getCanonicalFile(); //$NON-NLS-1$
+ URL pooledURL = pool.toURL();
loadArtifactRepository(pooledURL);
eclipseProductRepository = loadMetadataRepository(pooledURL);
} catch (MalformedURLException e) {
LogHelper.log(new Status(IStatus.ERROR, ID, "Error occurred while loading repository.", e));
} catch (ProvisionException e) {
LogHelper.log(new Status(IStatus.ERROR, ID, "Error occurred while loading repository.", e));
+ } catch (IOException e) {
+ LogHelper.log(new Status(IStatus.ERROR, ID, "Error occurred while loading repository.", e));
}
}
@@ -185,16 +203,17 @@ public class Activator implements BundleActivator {
* Watch the platform.xml file.
*/
private void watchConfiguration() {
- // TODO get the real config area
- File configFile = new File("configuration/org.eclipse.update/platform.xml"); //$NON-NLS-1$
+ File configFile = getConfigurationLocation();
+ if (configFile == null) {
+ LogHelper.log(new Status(IStatus.ERROR, ID, "Unable to determine configuration location."));
+ return;
+ }
+ configFile = new File(configFile, "org.eclipse.update/platform.xml"); //$NON-NLS-1$
DirectoryWatcher watcher = new DirectoryWatcher(configFile.getParentFile());
PlatformXmlListener listener = new PlatformXmlListener(configFile);
watcher.addListener(listener);
watcher.poll();
- Collection repositories = listener.getMetadataRepositories();
- if (repositories != null)
- configurationRepositories = repositories;
-
+ configurationRepositories = listener.getMetadataRepositories();
}
/*
@@ -240,6 +259,24 @@ public class Activator implements BundleActivator {
return bundleContext;
}
+ /*
+ * Helper method to get the configuration location. Return null if
+ * it is unavailable.
+ */
+ public static File getConfigurationLocation() {
+ Location configurationLocation = (Location) ServiceHelper.getService(getContext(), Location.class.getName(), Location.CONFIGURATION_FILTER);
+ if (configurationLocation == null || !configurationLocation.isSet())
+ return null;
+ URL url = configurationLocation.getURL();
+ if (url == null)
+ return null;
+ return URLUtil.toFile(url);
+ }
+
+ /*
+ * Helper method to return the eclipse.home location. Return
+ * null if it is unavailable.
+ */
public static File getEclipseHome() {
Location eclipseHome = (Location) ServiceHelper.getService(getContext(), Location.class.getName(), Location.ECLIPSE_HOME_FILTER);
if (eclipseHome == null || !eclipseHome.isSet())
@@ -263,52 +300,6 @@ public class Activator implements BundleActivator {
return root == null ? null : new File(root, DROPINS);
}
- // Disabled for now
-
- // private void removeUnwatchedRepositories(BundleContext context, Profile profile, File watchedFolder) {
- // removeUnwatchedMetadataRepositories(context, profile, watchedFolder);
- // removeUnwatchedArtifactRepositories(context, profile, watchedFolder);
- // }
- //
- // private void removeUnwatchedArtifactRepositories(BundleContext context, Profile profile, File watchedFolder) {
- // ServiceReference reference = context.getServiceReference(IArtifactRepositoryManager.class.getName());
- // IArtifactRepositoryManager manager = (IArtifactRepositoryManager) context.getService(reference);
- // try {
- // IArtifactRepository[] repositories = manager.getKnownRepositories();
- // for (int i = 0; i < repositories.length; i++) {
- // Map properties = repositories[i].getProperties();
- // String profileId = (String) properties.get("profileId");
- // String folderName = (String) properties.get("folder");
- //
- // if (profile.getProfileId().equals(profileId) && !watchedFolder.getAbsolutePath().equals(folderName)) {
- // manager.removeRepository(repositories[i]);
- // }
- // }
- // } finally {
- // context.ungetService(reference);
- // }
- // }
- //
- // private void removeUnwatchedMetadataRepositories(BundleContext context, Profile profile, File watchedFolder) {
- // ServiceReference reference = context.getServiceReference(IMetadataRepositoryManager.class.getName());
- // IMetadataRepositoryManager manager = (IMetadataRepositoryManager) context.getService(reference);
- // try {
- // IMetadataRepository[] repositories = manager.getKnownRepositories();
- // for (int i = 0; i < repositories.length; i++) {
- // Map properties = repositories[i].getProperties();
- // String profileId = (String) properties.get("profileId");
- // if (profile.getProfileId().equals(profileId)) {
- // String folderName = (String) properties.get("folder");
- // if ((folderName != null) && !watchedFolder.getAbsolutePath().equals(folderName)) {
- // manager.removeRepository(repositories[i].getLocation());
- // }
- // }
- // }
- // } finally {
- // context.ungetService(reference);
- // }
- // }
-
public static IProfile getCurrentProfile(BundleContext context) {
ServiceReference reference = context.getServiceReference(IProfileRegistry.class.getName());
if (reference == null)
diff --git a/bundles/org.eclipse.equinox.p2.reconciler.dropins/src/org/eclipse/equinox/internal/p2/reconciler/dropins/PlatformXmlListener.java b/bundles/org.eclipse.equinox.p2.reconciler.dropins/src/org/eclipse/equinox/internal/p2/reconciler/dropins/PlatformXmlListener.java
index de869d5c7..f090428d9 100644
--- a/bundles/org.eclipse.equinox.p2.reconciler.dropins/src/org/eclipse/equinox/internal/p2/reconciler/dropins/PlatformXmlListener.java
+++ b/bundles/org.eclipse.equinox.p2.reconciler.dropins/src/org/eclipse/equinox/internal/p2/reconciler/dropins/PlatformXmlListener.java
@@ -26,6 +26,11 @@ import org.eclipse.osgi.service.datalocation.Location;
import org.eclipse.osgi.util.NLS;
/**
+ * This class watches a platform.xml file. Note that we don't really need to use the DirectoryChangeListener
+ * framework since we are doing a single poll on startup, but we will leave the code here in case we
+ * want to watch for changes during a session. Note that the code to actually synchronize the repositories
+ * is on the Activator so we will need to call out to that if this behaviour is changed.
+ *
* @since 1.0
*/
public class PlatformXmlListener extends DirectoryChangeListener {
@@ -123,6 +128,11 @@ public class PlatformXmlListener extends DirectoryChangeListener {
return configRepositories;
}
+ /*
+ * Look through the given list of repositories and see if there is one
+ * currently associated with the given url string. Return null if one could not
+ * be found.
+ */
private IMetadataRepository getMatchingRepo(Collection repositoryList, String urlString) {
if (repositoryList == null)
return null;
@@ -136,6 +146,9 @@ public class PlatformXmlListener extends DirectoryChangeListener {
return null;
}
+ /*
+ * Ensure that we have a repository for each site in the given configuration.
+ */
protected void synchronizeConfiguration(Configuration config) {
List sites = config.getSites();
Set newRepos = new LinkedHashSet();
@@ -144,13 +157,12 @@ public class PlatformXmlListener extends DirectoryChangeListener {
String siteURL = site.getUrl();
if (siteURL.startsWith("file:") && siteURL.endsWith("/eclipse/")) //$NON-NLS-1$//$NON-NLS-2$
siteURL = siteURL.substring(0, siteURL.length() - 8);
- IMetadataRepository match = getMatchingRepo(Activator.getConfigurationRepositories(), siteURL);
- if (match == null)
- match = getMatchingRepo(configRepositories, siteURL);
+ IMetadataRepository match = getMatchingRepo(configRepositories, siteURL);
if (match == null) {
try {
URL repoURL = new URL(siteURL);
IMetadataRepository newRepo = new ExtensionLocationMetadataRepository(repoURL, site, null);
+ Activator.addRepository(newRepo);
Activator.loadArtifactRepository(repoURL);
newRepos.add(newRepo);
} catch (MalformedURLException e) {
@@ -158,10 +170,10 @@ public class PlatformXmlListener extends DirectoryChangeListener {
} catch (ProvisionException e) {
LogHelper.log(new Status(IStatus.ERROR, Activator.ID, NLS.bind(Messages.errorLoadingRepository, siteURL), e));
}
+ } else {
+ newRepos.add(match);
}
}
- // if we didn't add any new repos then there is no work to do
- if (!newRepos.isEmpty())
- configRepositories = newRepos;
+ configRepositories = newRepos;
}
}
diff --git a/bundles/org.eclipse.equinox.p2.reconciler/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.p2.reconciler/META-INF/MANIFEST.MF
index afdab1075..1a365a51c 100644
--- a/bundles/org.eclipse.equinox.p2.reconciler/META-INF/MANIFEST.MF
+++ b/bundles/org.eclipse.equinox.p2.reconciler/META-INF/MANIFEST.MF
@@ -10,6 +10,7 @@ Bundle-RequiredExecutionEnvironment: J2SE-1.4,
CDC-1.1/Foundation-1.1
Import-Package: org.eclipse.equinox.internal.p2.core.helpers,
org.eclipse.equinox.internal.p2.extensionlocation,
+ org.eclipse.equinox.internal.p2.metadata.repository,
org.eclipse.equinox.internal.p2.update,
org.eclipse.equinox.internal.provisional.configurator,
org.eclipse.equinox.internal.provisional.p2.artifact.repository,
diff --git a/bundles/org.eclipse.equinox.p2.reconciler/src/org/eclipse/equinox/internal/p2/reconciler/dropins/Activator.java b/bundles/org.eclipse.equinox.p2.reconciler/src/org/eclipse/equinox/internal/p2/reconciler/dropins/Activator.java
index c8edc4b3a..3d6b7a5f4 100644
--- a/bundles/org.eclipse.equinox.p2.reconciler/src/org/eclipse/equinox/internal/p2/reconciler/dropins/Activator.java
+++ b/bundles/org.eclipse.equinox.p2.reconciler/src/org/eclipse/equinox/internal/p2/reconciler/dropins/Activator.java
@@ -10,11 +10,13 @@
package org.eclipse.equinox.internal.p2.reconciler.dropins;
import java.io.File;
+import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.*;
import org.eclipse.core.runtime.*;
import org.eclipse.equinox.internal.p2.core.helpers.*;
+import org.eclipse.equinox.internal.p2.metadata.repository.MetadataRepositoryManager;
import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRepository;
import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRepositoryManager;
import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException;
@@ -31,7 +33,6 @@ public class Activator implements BundleActivator {
public static final String ID = "org.eclipse.equinox.p2.reconciler.dropins"; //$NON-NLS-1$
private static final String DROPINS_DIRECTORY = "org.eclipse.equinox.p2.reconciler.dropins.directory"; //$NON-NLS-1$
- private static final String OSGI_CONFIGURATION_AREA = "osgi.configuration.area"; //$NON-NLS-1$
private static final String DROPINS = "dropins"; //$NON-NLS-1$
private static final String LINKS = "links"; //$NON-NLS-1$
// private static final String PROFILE_EXTENSION = "profile.extension"; //$NON-NLS-1$
@@ -66,6 +67,24 @@ public class Activator implements BundleActivator {
}
}
+ /*
+ * Helper method to add the given metadata repository to the manager's list.
+ */
+ public static void addRepository(IMetadataRepository repo) {
+ BundleContext context = getContext();
+ ServiceReference reference = context.getServiceReference(IMetadataRepositoryManager.class.getName());
+ IMetadataRepositoryManager manager = null;
+ if (reference != null)
+ manager = (IMetadataRepositoryManager) context.getService(reference);
+ if (manager == null)
+ throw new IllegalStateException("MetadataRepositoryManager not registered."); //$NON-NLS-1$
+ try {
+ ((MetadataRepositoryManager) manager).addRepository(repo);
+ } finally {
+ context.ungetService(reference);
+ }
+ }
+
/**
* Helper method to load an artifact repository from the given URL.
* This method never returns <code>null</code>.
@@ -88,14 +107,6 @@ public class Activator implements BundleActivator {
}
}
- protected static Collection getDropinRepositories() {
- return dropinRepositories == null ? new ArrayList(0) : dropinRepositories;
- }
-
- protected static Collection getConfigurationRepositories() {
- return configurationRepositories == null ? new ArrayList(0) : configurationRepositories;
- }
-
/* (non-Javadoc)
* @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
*/
@@ -134,14 +145,21 @@ public class Activator implements BundleActivator {
private void watchEclipseProduct() {
try {
- URL baseURL = new URL(bundleContext.getProperty(OSGI_CONFIGURATION_AREA));
- URL pooledURL = new URL(baseURL, "../.pooled"); //$NON-NLS-1$
+ File configurationLocation = getConfigurationLocation();
+ if (configurationLocation == null) {
+ LogHelper.log(new Status(IStatus.ERROR, ID, "Unable to determine configuration location."));
+ return;
+ }
+ File pool = new File(configurationLocation, "../.pooled").getCanonicalFile(); //$NON-NLS-1$
+ URL pooledURL = pool.toURL();
loadArtifactRepository(pooledURL);
eclipseProductRepository = loadMetadataRepository(pooledURL);
} catch (MalformedURLException e) {
LogHelper.log(new Status(IStatus.ERROR, ID, "Error occurred while loading repository.", e));
} catch (ProvisionException e) {
LogHelper.log(new Status(IStatus.ERROR, ID, "Error occurred while loading repository.", e));
+ } catch (IOException e) {
+ LogHelper.log(new Status(IStatus.ERROR, ID, "Error occurred while loading repository.", e));
}
}
@@ -185,16 +203,17 @@ public class Activator implements BundleActivator {
* Watch the platform.xml file.
*/
private void watchConfiguration() {
- // TODO get the real config area
- File configFile = new File("configuration/org.eclipse.update/platform.xml"); //$NON-NLS-1$
+ File configFile = getConfigurationLocation();
+ if (configFile == null) {
+ LogHelper.log(new Status(IStatus.ERROR, ID, "Unable to determine configuration location."));
+ return;
+ }
+ configFile = new File(configFile, "org.eclipse.update/platform.xml"); //$NON-NLS-1$
DirectoryWatcher watcher = new DirectoryWatcher(configFile.getParentFile());
PlatformXmlListener listener = new PlatformXmlListener(configFile);
watcher.addListener(listener);
watcher.poll();
- Collection repositories = listener.getMetadataRepositories();
- if (repositories != null)
- configurationRepositories = repositories;
-
+ configurationRepositories = listener.getMetadataRepositories();
}
/*
@@ -240,6 +259,24 @@ public class Activator implements BundleActivator {
return bundleContext;
}
+ /*
+ * Helper method to get the configuration location. Return null if
+ * it is unavailable.
+ */
+ public static File getConfigurationLocation() {
+ Location configurationLocation = (Location) ServiceHelper.getService(getContext(), Location.class.getName(), Location.CONFIGURATION_FILTER);
+ if (configurationLocation == null || !configurationLocation.isSet())
+ return null;
+ URL url = configurationLocation.getURL();
+ if (url == null)
+ return null;
+ return URLUtil.toFile(url);
+ }
+
+ /*
+ * Helper method to return the eclipse.home location. Return
+ * null if it is unavailable.
+ */
public static File getEclipseHome() {
Location eclipseHome = (Location) ServiceHelper.getService(getContext(), Location.class.getName(), Location.ECLIPSE_HOME_FILTER);
if (eclipseHome == null || !eclipseHome.isSet())
@@ -263,52 +300,6 @@ public class Activator implements BundleActivator {
return root == null ? null : new File(root, DROPINS);
}
- // Disabled for now
-
- // private void removeUnwatchedRepositories(BundleContext context, Profile profile, File watchedFolder) {
- // removeUnwatchedMetadataRepositories(context, profile, watchedFolder);
- // removeUnwatchedArtifactRepositories(context, profile, watchedFolder);
- // }
- //
- // private void removeUnwatchedArtifactRepositories(BundleContext context, Profile profile, File watchedFolder) {
- // ServiceReference reference = context.getServiceReference(IArtifactRepositoryManager.class.getName());
- // IArtifactRepositoryManager manager = (IArtifactRepositoryManager) context.getService(reference);
- // try {
- // IArtifactRepository[] repositories = manager.getKnownRepositories();
- // for (int i = 0; i < repositories.length; i++) {
- // Map properties = repositories[i].getProperties();
- // String profileId = (String) properties.get("profileId");
- // String folderName = (String) properties.get("folder");
- //
- // if (profile.getProfileId().equals(profileId) && !watchedFolder.getAbsolutePath().equals(folderName)) {
- // manager.removeRepository(repositories[i]);
- // }
- // }
- // } finally {
- // context.ungetService(reference);
- // }
- // }
- //
- // private void removeUnwatchedMetadataRepositories(BundleContext context, Profile profile, File watchedFolder) {
- // ServiceReference reference = context.getServiceReference(IMetadataRepositoryManager.class.getName());
- // IMetadataRepositoryManager manager = (IMetadataRepositoryManager) context.getService(reference);
- // try {
- // IMetadataRepository[] repositories = manager.getKnownRepositories();
- // for (int i = 0; i < repositories.length; i++) {
- // Map properties = repositories[i].getProperties();
- // String profileId = (String) properties.get("profileId");
- // if (profile.getProfileId().equals(profileId)) {
- // String folderName = (String) properties.get("folder");
- // if ((folderName != null) && !watchedFolder.getAbsolutePath().equals(folderName)) {
- // manager.removeRepository(repositories[i].getLocation());
- // }
- // }
- // }
- // } finally {
- // context.ungetService(reference);
- // }
- // }
-
public static IProfile getCurrentProfile(BundleContext context) {
ServiceReference reference = context.getServiceReference(IProfileRegistry.class.getName());
if (reference == null)
diff --git a/bundles/org.eclipse.equinox.p2.reconciler/src/org/eclipse/equinox/internal/p2/reconciler/dropins/PlatformXmlListener.java b/bundles/org.eclipse.equinox.p2.reconciler/src/org/eclipse/equinox/internal/p2/reconciler/dropins/PlatformXmlListener.java
index de869d5c7..f090428d9 100644
--- a/bundles/org.eclipse.equinox.p2.reconciler/src/org/eclipse/equinox/internal/p2/reconciler/dropins/PlatformXmlListener.java
+++ b/bundles/org.eclipse.equinox.p2.reconciler/src/org/eclipse/equinox/internal/p2/reconciler/dropins/PlatformXmlListener.java
@@ -26,6 +26,11 @@ import org.eclipse.osgi.service.datalocation.Location;
import org.eclipse.osgi.util.NLS;
/**
+ * This class watches a platform.xml file. Note that we don't really need to use the DirectoryChangeListener
+ * framework since we are doing a single poll on startup, but we will leave the code here in case we
+ * want to watch for changes during a session. Note that the code to actually synchronize the repositories
+ * is on the Activator so we will need to call out to that if this behaviour is changed.
+ *
* @since 1.0
*/
public class PlatformXmlListener extends DirectoryChangeListener {
@@ -123,6 +128,11 @@ public class PlatformXmlListener extends DirectoryChangeListener {
return configRepositories;
}
+ /*
+ * Look through the given list of repositories and see if there is one
+ * currently associated with the given url string. Return null if one could not
+ * be found.
+ */
private IMetadataRepository getMatchingRepo(Collection repositoryList, String urlString) {
if (repositoryList == null)
return null;
@@ -136,6 +146,9 @@ public class PlatformXmlListener extends DirectoryChangeListener {
return null;
}
+ /*
+ * Ensure that we have a repository for each site in the given configuration.
+ */
protected void synchronizeConfiguration(Configuration config) {
List sites = config.getSites();
Set newRepos = new LinkedHashSet();
@@ -144,13 +157,12 @@ public class PlatformXmlListener extends DirectoryChangeListener {
String siteURL = site.getUrl();
if (siteURL.startsWith("file:") && siteURL.endsWith("/eclipse/")) //$NON-NLS-1$//$NON-NLS-2$
siteURL = siteURL.substring(0, siteURL.length() - 8);
- IMetadataRepository match = getMatchingRepo(Activator.getConfigurationRepositories(), siteURL);
- if (match == null)
- match = getMatchingRepo(configRepositories, siteURL);
+ IMetadataRepository match = getMatchingRepo(configRepositories, siteURL);
if (match == null) {
try {
URL repoURL = new URL(siteURL);
IMetadataRepository newRepo = new ExtensionLocationMetadataRepository(repoURL, site, null);
+ Activator.addRepository(newRepo);
Activator.loadArtifactRepository(repoURL);
newRepos.add(newRepo);
} catch (MalformedURLException e) {
@@ -158,10 +170,10 @@ public class PlatformXmlListener extends DirectoryChangeListener {
} catch (ProvisionException e) {
LogHelper.log(new Status(IStatus.ERROR, Activator.ID, NLS.bind(Messages.errorLoadingRepository, siteURL), e));
}
+ } else {
+ newRepos.add(match);
}
}
- // if we didn't add any new repos then there is no work to do
- if (!newRepos.isEmpty())
- configRepositories = newRepos;
+ configRepositories = newRepos;
}
}

Back to the top