diff options
author | Simon Kaegi | 2009-03-09 17:25:16 +0000 |
---|---|---|
committer | Simon Kaegi | 2009-03-09 17:25:16 +0000 |
commit | 1f2742db036cb2a808ce310bc6fab4c3c5a9a292 (patch) | |
tree | ccecb380e8ca441ab71c4c73cadc8af7e9472f1c | |
parent | 0be8e87e677de15d0a7fa3d9c8bfcda9f6c661dd (diff) | |
download | rt.equinox.p2-1f2742db036cb2a808ce310bc6fab4c3c5a9a292.tar.gz rt.equinox.p2-1f2742db036cb2a808ce310bc6fab4c3c5a9a292.tar.xz rt.equinox.p2-1f2742db036cb2a808ce310bc6fab4c3c5a9a292.zip |
Bug 267567 [engine] Profile presented as a repo should honor the roaming flag
3 files changed, 99 insertions, 10 deletions
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 8d96d57e3..516fc6d92 100644 --- a/bundles/org.eclipse.equinox.p2.core/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.equinox.p2.core/META-INF/MANIFEST.MF @@ -161,7 +161,8 @@ Export-Package: org.eclipse.equinox.internal.p2.core;x-friends:="org.eclipse.equ x-friends:="org.eclipse.equinox.p2.artifact.repository, org.eclipse.equinox.p2.metadata.repository, org.eclipse.equinox.p2.extensionlocation, - org.eclipse.equinox.p2.updatesite" + org.eclipse.equinox.p2.updatesite, + org.eclipse.equinox.p2.engine" Eclipse-LazyStart: true Bundle-ClassPath: . Bundle-RequiredExecutionEnvironment: J2SE-1.4, diff --git a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/ProfileMetadataRepository.java b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/ProfileMetadataRepository.java index 00e40e354..6c6a76988 100644 --- a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/ProfileMetadataRepository.java +++ b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/ProfileMetadataRepository.java @@ -20,6 +20,7 @@ import org.eclipse.osgi.util.NLS; public class ProfileMetadataRepository extends AbstractMetadataRepository { + private static final String ARTIFACTS_XML = "artifacts.xml"; //$NON-NLS-1$ private static final String FILE_SCHEME = "file"; //$NON-NLS-1$ private static final String DOT_PROFILE = ".profile"; //$NON-NLS-1$ public static final String TYPE = "org.eclipse.equinox.p2.engine.repo.metadataRepository"; //$NON-NLS-1$ @@ -38,10 +39,33 @@ public class ProfileMetadataRepository extends AbstractMetadataRepository { } private void publishArtifactRepos() { + List artifactRepos = findArtifactRepos(); + + IProvisioningEventBus bus = (IProvisioningEventBus) ServiceHelper.getService(EngineActivator.getContext(), IProvisioningEventBus.SERVICE_NAME); + if (bus == null) + return; + for (Iterator it = artifactRepos.iterator(); it.hasNext();) { + URI repo = (URI) it.next(); + bus.publishEvent(new RepositoryEvent(repo, IRepository.TYPE_ARTIFACT, RepositoryEvent.DISCOVERED, true)); + } + } + + private List findArtifactRepos() { List artifactRepos = new ArrayList(); String bundlePool = profile.getProperty(IProfile.PROP_CACHE); - if (bundlePool != null) - artifactRepos.add(new File(bundlePool).toURI()); + if (bundlePool != null) { + File bundlePoolFile = new File(bundlePool); + if (bundlePoolFile.exists()) + artifactRepos.add(bundlePoolFile.toURI()); + else if (Boolean.valueOf(profile.getProperty(IProfile.PROP_ROAMING)).booleanValue()) { + // the profile has not been used yet but is a roaming profile + // best effort to add "just" the default bundle pool + bundlePoolFile = findDefaultBundlePool(); + if (bundlePoolFile != null) + artifactRepos.add(bundlePoolFile.toURI()); + return artifactRepos; + } + } String sharedBundlePool = profile.getProperty(IProfile.PROP_SHARED_CACHE); if (sharedBundlePool != null) @@ -60,14 +84,33 @@ public class ProfileMetadataRepository extends AbstractMetadataRepository { } } } + return artifactRepos; + } - IProvisioningEventBus bus = (IProvisioningEventBus) ServiceHelper.getService(EngineActivator.getContext(), IProvisioningEventBus.SERVICE_NAME); - if (bus == null) - return; - for (Iterator it = artifactRepos.iterator(); it.hasNext();) { - URI repo = (URI) it.next(); - bus.publishEvent(new RepositoryEvent(repo, IRepository.TYPE_ARTIFACT, RepositoryEvent.DISCOVERED, true)); - } + private File findDefaultBundlePool() { + File target = new File(location); + if (target.isFile()) + target = target.getParentFile(); + + // by default the profile registry is in {product}/p2/org.eclipse.equinox.p2.engine/profileRegistry + // the default bundle pool is in the {product} folder + File profileRegistryDirectory = target.getParentFile(); + if (profileRegistryDirectory == null) + return null; + + File p2EngineDirectory = profileRegistryDirectory.getParentFile(); + if (p2EngineDirectory == null) + return null; + + File p2Directory = p2EngineDirectory.getParentFile(); + if (p2Directory == null) + return null; + + File productDirectory = p2Directory.getParentFile(); + if (productDirectory == null || !(new File(productDirectory, ARTIFACTS_XML).exists())) + return null; + + return productDirectory; } public void initialize(RepositoryState state) { diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/engine/ProfileMetadataRepositoryTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/engine/ProfileMetadataRepositoryTest.java index 7b2260102..6188fade4 100644 --- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/engine/ProfileMetadataRepositoryTest.java +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/engine/ProfileMetadataRepositoryTest.java @@ -12,12 +12,16 @@ package org.eclipse.equinox.p2.tests.engine; import java.io.File; import org.eclipse.core.runtime.IStatus; +import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper; import org.eclipse.equinox.internal.p2.engine.*; +import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRepositoryManager; import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException; import org.eclipse.equinox.internal.provisional.p2.engine.IProfile; import org.eclipse.equinox.internal.provisional.p2.metadata.query.InstallableUnitQuery; import org.eclipse.equinox.internal.provisional.p2.query.Collector; +import org.eclipse.equinox.internal.provisional.spi.p2.artifact.repository.SimpleArtifactRepositoryFactory; import org.eclipse.equinox.p2.tests.AbstractProvisioningTest; +import org.eclipse.equinox.p2.tests.TestActivator; /** * Simple test of the engine API. @@ -115,4 +119,45 @@ public class ProfileMetadataRepositoryTest extends AbstractProvisioningTest { assertFalse(repoCollector.isEmpty()); assertTrue(repoCollector.toCollection().containsAll(profileCollector.toCollection())); } + + public void testDefaultBundlePoolFromProfileRepo() { + File testData = getTestData("0.1", "testData/sdkpatchingtest"); + // /p2/org.eclipse.equinox.p2.engine/profileRegistry"); + File tempFolder = getTempFolder(); + copy("0.2", testData, tempFolder); + + new SimpleArtifactRepositoryFactory().create(tempFolder.toURI(), "", "", null); + + File profileRegistryFolder = new File(tempFolder, "p2/org.eclipse.equinox.p2.engine/profileRegistry"); + SimpleProfileRegistry registry = new SimpleProfileRegistry(profileRegistryFolder, null, false); + IProfile profile = registry.getProfile("SDKProfile"); + assertNotNull(profile); + + Collector profileCollector = profile.query(InstallableUnitQuery.ANY, new Collector(), getMonitor()); + assertFalse(profileCollector.isEmpty()); + + File simpleProfileFolder = new File(profileRegistryFolder, "SDKProfile.profile"); + assertTrue(simpleProfileFolder.exists()); + + File timeStampedProfile = new File(simpleProfileFolder, "" + profile.getTimestamp() + ".profile"); + assertTrue(timeStampedProfile.exists()); + + IArtifactRepositoryManager manager = (IArtifactRepositoryManager) ServiceHelper.getService(TestActivator.context, IArtifactRepositoryManager.class.getName()); + assertNotNull(manager); + assertFalse(manager.contains(tempFolder.toURI())); + + ProfileMetadataRepositoryFactory factory = new ProfileMetadataRepositoryFactory(); + ProfileMetadataRepository repo = null; + try { + repo = (ProfileMetadataRepository) factory.load(timeStampedProfile.toURI(), 0, getMonitor()); + } catch (ProvisionException e1) { + fail(); + } + + Collector repoCollector = repo.query(InstallableUnitQuery.ANY, new Collector(), getMonitor()); + assertFalse(repoCollector.isEmpty()); + assertTrue(repoCollector.toCollection().containsAll(profileCollector.toCollection())); + + assertTrue(manager.contains(tempFolder.toURI())); + } } |