diff options
author | Pascal Rapicault | 2011-06-01 18:30:51 +0000 |
---|---|---|
committer | Pascal Rapicault | 2011-06-01 18:30:51 +0000 |
commit | f876e87cf566e6b245f72c0d9e3c25ec184c9795 (patch) | |
tree | 478452a093111cda4c2b6898e2f30919223eb659 | |
parent | e10e254c90ad6f685900d8bbb89f01e92f188ed7 (diff) | |
download | rt.equinox.p2-f876e87cf566e6b245f72c0d9e3c25ec184c9795.tar.gz rt.equinox.p2-f876e87cf566e6b245f72c0d9e3c25ec184c9795.tar.xz rt.equinox.p2-f876e87cf566e6b245f72c0d9e3c25ec184c9795.zip |
Bug 345284 - [test][operations] Problems with SynchronizeOperation API
7 files changed, 120 insertions, 1 deletions
diff --git a/bundles/org.eclipse.equinox.p2.tests/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.p2.tests/META-INF/MANIFEST.MF index b04c990d9..64da2dd91 100644 --- a/bundles/org.eclipse.equinox.p2.tests/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.equinox.p2.tests/META-INF/MANIFEST.MF @@ -52,7 +52,8 @@ Require-Bundle: org.eclipse.equinox.frameworkadmin, org.eclipse.ant.core;bundle-version="3.2.200", org.apache.ant;bundle-version="1.7.1", org.eclipse.equinox.p2.transport.ecf;bundle-version="1.0.0", - org.eclipse.equinox.p2.publisher.eclipse;bundle-version="1.0.0" + org.eclipse.equinox.p2.publisher.eclipse;bundle-version="1.0.0", + org.eclipse.equinox.p2.operations;bundle-version="2.1.0" Eclipse-RegisterBuddy: org.eclipse.equinox.p2.artifact.repository Bundle-RequiredExecutionEnvironment: J2SE-1.5, J2SE-1.4 diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/SynchronizeOperationTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/SynchronizeOperationTest.java new file mode 100644 index 000000000..bc69a3310 --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/SynchronizeOperationTest.java @@ -0,0 +1,118 @@ +/******************************************************************************* + * Copyright (c) 2011 Sonatype, 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: + * Sonatype, Inc. - initial API and implementation + * IBM Corporation - Ongoing development + *******************************************************************************/ +package org.eclipse.equinox.p2.tests.planner; + +import java.net.URI; +import java.util.*; +import org.eclipse.core.runtime.*; +import org.eclipse.equinox.internal.p2.operations.Activator; +import org.eclipse.equinox.internal.p2.operations.Messages; +import org.eclipse.equinox.p2.core.*; +import org.eclipse.equinox.p2.engine.*; +import org.eclipse.equinox.p2.engine.query.UserVisibleRootQuery; +import org.eclipse.equinox.p2.metadata.*; +import org.eclipse.equinox.p2.operations.ProvisioningSession; +import org.eclipse.equinox.p2.operations.SynchronizeOperation; +import org.eclipse.equinox.p2.query.*; +import org.eclipse.equinox.p2.repository.metadata.IMetadataRepository; +import org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager; +import org.eclipse.equinox.p2.tests.AbstractProvisioningTest; +import org.eclipse.equinox.p2.tests.TestActivator; +import org.eclipse.osgi.util.NLS; +import org.osgi.framework.ServiceReference; + +public class SynchronizeOperationTest extends AbstractProvisioningTest { + public void testSyncOperation() throws ProvisionException { + ServiceReference providerRef = TestActivator.context.getServiceReference(IProvisioningAgentProvider.class.getName()); + IProvisioningAgentProvider provider = (IProvisioningAgentProvider) TestActivator.context.getService(providerRef); + + URI p2location = getTestData("p2 location", "testData/synchronizeOperation/p2").toURI(); + URI repoLocation = getTestData("p2 location", "testData/synchronizeOperation/repo").toURI(); + IProvisioningAgent firstAgent = provider.createAgent(p2location); + IMetadataRepositoryManager mgr = (IMetadataRepositoryManager) firstAgent.getService(IMetadataRepositoryManager.SERVICE_NAME); + IMetadataRepository repo = mgr.loadRepository(repoLocation, new NullProgressMonitor()); + ProvisioningSession session = new ProvisioningSession(firstAgent); + SynchronizeOperation sync = new SynchronizeOperation(session, repo.query(QueryUtil.ALL_UNITS, new NullProgressMonitor()).toUnmodifiableSet()); + Set<IInstallableUnit> installedIUs = ((IProfileRegistry) firstAgent.getService(IProfileRegistry.SERVICE_NAME)).getProfile("DefaultProfile").query(new UserVisibleRootQuery(), new NullProgressMonitor()).toUnmodifiableSet(); + System.out.println(installedIUs); + sync.setProfileId("DefaultProfile"); + sync.resolveModal(new NullProgressMonitor()); + IProvisioningPlan plan = sync.getProvisioningPlan(); + assertOK(plan.getStatus()); + } + + public void testCopyOfHelper() throws ProvisionException { + // payload.feature.feature.group + ServiceReference providerRef = TestActivator.context.getServiceReference(IProvisioningAgentProvider.class.getName()); + IProvisioningAgentProvider provider = (IProvisioningAgentProvider) TestActivator.context.getService(providerRef); + + URI p2location = getTestData("p2 location", "testData/synchronizeOperation/p2").toURI(); + URI repoLocation = getTestData("p2 location", "testData/synchronizeOperation/repo").toURI(); + IProvisioningAgent firstAgent = provider.createAgent(p2location); + IVersionedId v = new VersionedId("payload.feature.feature.group", (String) null); + Collection<IVersionedId> toInstall = new ArrayList<IVersionedId>(); + toInstall.add(v); + List<URI> repos = new ArrayList<URI>(); + repos.add(repoLocation); + SynchronizeOperation operation = createSynchronizeOperation(toInstall, repos, new NullProgressMonitor(), firstAgent); + operation.setProfileId("DefaultProfile"); + operation.resolveModal(new NullProgressMonitor()); + assertOK(operation.getProvisioningPlan().getStatus()); + } + + private SynchronizeOperation createSynchronizeOperation(Collection<IVersionedId> toInstall, Collection<URI> repos, IProgressMonitor monitor, IProvisioningAgent agent) throws ProvisionException { + // IProvisioningAgent agent = getAgent(); + ProvisioningContext ctx = createProvisioningContext(repos, agent); + + Collection<IInstallableUnit> iusToInstall; + if (toInstall == null) + iusToInstall = ctx.getMetadata(monitor).query(QueryUtil.createIUGroupQuery(), monitor).toUnmodifiableSet(); + else + iusToInstall = gatherIUs(ctx.getMetadata(monitor), toInstall, false, monitor); + + SynchronizeOperation resultingOperation = new SynchronizeOperation(new ProvisioningSession(agent), iusToInstall); + resultingOperation.setProvisioningContext(ctx); + resultingOperation.setProfileId(IProfileRegistry.SELF); + + return resultingOperation; + } + + private ProvisioningContext createProvisioningContext(Collection<URI> repos, IProvisioningAgent agent) { + ProvisioningContext ctx = new ProvisioningContext(agent); + if (repos != null) { + ctx.setMetadataRepositories(repos.toArray(new URI[repos.size()])); + ctx.setArtifactRepositories(repos.toArray(new URI[repos.size()])); + } + return ctx; + } + + private Collection<IInstallableUnit> gatherIUs(IQueryable<IInstallableUnit> searchContext, Collection<IVersionedId> ius, boolean checkIUs, IProgressMonitor monitor) throws ProvisionException { + Collection<IInstallableUnit> gatheredIUs = new ArrayList<IInstallableUnit>(ius.size()); + + for (IVersionedId versionedId : ius) { + if (!checkIUs && versionedId instanceof IInstallableUnit) { + gatheredIUs.add((IInstallableUnit) versionedId); + continue; + } + + IQuery<IInstallableUnit> installableUnits = QueryUtil.createIUQuery(versionedId.getId(), versionedId.getVersion()); + IQueryResult<IInstallableUnit> matches = searchContext.query(installableUnits, monitor); + if (matches.isEmpty()) + throw new ProvisionException(new Status(IStatus.ERROR, Activator.ID, NLS.bind(Messages.OperationFactory_noIUFound, versionedId))); + + //Add the first IU + Iterator<IInstallableUnit> iuIt = matches.iterator(); + gatheredIUs.add(iuIt.next()); + } + return gatheredIUs; + } +} diff --git a/bundles/org.eclipse.equinox.p2.tests/testData/synchronizeOperation/p2/org.eclipse.equinox.p2.engine/profileRegistry/DefaultProfile.profile/1306859416687.profile.gz b/bundles/org.eclipse.equinox.p2.tests/testData/synchronizeOperation/p2/org.eclipse.equinox.p2.engine/profileRegistry/DefaultProfile.profile/1306859416687.profile.gz Binary files differnew file mode 100644 index 000000000..c17a36908 --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.tests/testData/synchronizeOperation/p2/org.eclipse.equinox.p2.engine/profileRegistry/DefaultProfile.profile/1306859416687.profile.gz diff --git a/bundles/org.eclipse.equinox.p2.tests/testData/synchronizeOperation/p2/org.eclipse.equinox.p2.engine/profileRegistry/DefaultProfile.profile/1306859416890.profile.gz b/bundles/org.eclipse.equinox.p2.tests/testData/synchronizeOperation/p2/org.eclipse.equinox.p2.engine/profileRegistry/DefaultProfile.profile/1306859416890.profile.gz Binary files differnew file mode 100644 index 000000000..589dfab46 --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.tests/testData/synchronizeOperation/p2/org.eclipse.equinox.p2.engine/profileRegistry/DefaultProfile.profile/1306859416890.profile.gz diff --git a/bundles/org.eclipse.equinox.p2.tests/testData/synchronizeOperation/p2/org.eclipse.equinox.p2.engine/profileRegistry/DefaultProfile.profile/1306859425859.profile.gz b/bundles/org.eclipse.equinox.p2.tests/testData/synchronizeOperation/p2/org.eclipse.equinox.p2.engine/profileRegistry/DefaultProfile.profile/1306859425859.profile.gz Binary files differnew file mode 100644 index 000000000..cd7b74b56 --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.tests/testData/synchronizeOperation/p2/org.eclipse.equinox.p2.engine/profileRegistry/DefaultProfile.profile/1306859425859.profile.gz diff --git a/bundles/org.eclipse.equinox.p2.tests/testData/synchronizeOperation/p2/org.eclipse.equinox.p2.engine/profileRegistry/DefaultProfile.profile/1306859426687.profile.gz b/bundles/org.eclipse.equinox.p2.tests/testData/synchronizeOperation/p2/org.eclipse.equinox.p2.engine/profileRegistry/DefaultProfile.profile/1306859426687.profile.gz Binary files differnew file mode 100644 index 000000000..977e77903 --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.tests/testData/synchronizeOperation/p2/org.eclipse.equinox.p2.engine/profileRegistry/DefaultProfile.profile/1306859426687.profile.gz diff --git a/bundles/org.eclipse.equinox.p2.tests/testData/synchronizeOperation/repo/content.jar b/bundles/org.eclipse.equinox.p2.tests/testData/synchronizeOperation/repo/content.jar Binary files differnew file mode 100644 index 000000000..c5494cda7 --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.tests/testData/synchronizeOperation/repo/content.jar |