Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 194662 Details for
Bug 337016
[operations] Simplify operation API to cater for self case
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
Patch correcting issues and completing the work
337016d.patch (text/plain), 15.92 KB, created by
Pascal Rapicault
on 2011-05-03 22:37:09 EDT
(
hide
)
Description:
Patch correcting issues and completing the work
Filename:
MIME Type:
Creator:
Pascal Rapicault
Created:
2011-05-03 22:37:09 EDT
Size:
15.92 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.equinox.p2.operations >Index: src/org/eclipse/equinox/internal/p2/operations/Messages.java >=================================================================== >RCS file: /cvsroot/rt/org.eclipse.equinox/p2/bundles/org.eclipse.equinox.p2.operations/src/org/eclipse/equinox/internal/p2/operations/Messages.java,v >retrieving revision 1.3 >diff -u -r1.3 Messages.java >--- src/org/eclipse/equinox/internal/p2/operations/Messages.java 2 May 2011 22:43:13 -0000 1.3 >+++ src/org/eclipse/equinox/internal/p2/operations/Messages.java 4 May 2011 02:34:10 -0000 >@@ -66,6 +66,9 @@ > public static String UpdateOperation_ResolveJobName; > public static String UpdateOperation_UpdateJobName; > >+ public static String OperationFactory_noAgent; >+ public static String OperationFactory_noIUFound; >+ > static { > // initialize resource bundle > NLS.initializeMessages(BUNDLE_NAME, Messages.class); >Index: src/org/eclipse/equinox/internal/p2/operations/messages.properties >=================================================================== >RCS file: /cvsroot/rt/org.eclipse.equinox/p2/bundles/org.eclipse.equinox.p2.operations/src/org/eclipse/equinox/internal/p2/operations/messages.properties,v >retrieving revision 1.4 >diff -u -r1.4 messages.properties >--- src/org/eclipse/equinox/internal/p2/operations/messages.properties 2 May 2011 22:43:13 -0000 1.4 >+++ src/org/eclipse/equinox/internal/p2/operations/messages.properties 4 May 2011 02:34:10 -0000 >@@ -42,3 +42,6 @@ > UpdateOperation_ProfileChangeRequestProgress=Computing update request > UpdateOperation_ResolveJobName=Computing Update Requirements > UpdateOperation_UpdateJobName=Updating Software >+ >+OperationFactory_noAgent=This installation has not been configured properly. No p2 agent can be found. >+OperationFactory_noIUFound=No IU could be found for {0}. >\ No newline at end of file >Index: src/org/eclipse/equinox/p2/operations/OperationFactory.java >=================================================================== >RCS file: /cvsroot/rt/org.eclipse.equinox/p2/bundles/org.eclipse.equinox.p2.operations/src/org/eclipse/equinox/p2/operations/OperationFactory.java,v >retrieving revision 1.2 >diff -u -r1.2 OperationFactory.java >--- src/org/eclipse/equinox/p2/operations/OperationFactory.java 25 Apr 2011 13:03:36 -0000 1.2 >+++ src/org/eclipse/equinox/p2/operations/OperationFactory.java 4 May 2011 02:34:10 -0000 >@@ -13,9 +13,9 @@ > > import java.net.URI; > import java.util.*; >-import org.eclipse.core.runtime.Assert; >-import org.eclipse.core.runtime.IProgressMonitor; >+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.IProvisioningAgent; > import org.eclipse.equinox.p2.core.ProvisionException; > import org.eclipse.equinox.p2.engine.*; >@@ -23,6 +23,7 @@ > import org.eclipse.equinox.p2.metadata.IInstallableUnit; > import org.eclipse.equinox.p2.metadata.IVersionedId; > import org.eclipse.equinox.p2.query.*; >+import org.eclipse.osgi.util.NLS; > import org.osgi.framework.InvalidSyntaxException; > import org.osgi.framework.ServiceReference; > >@@ -42,35 +43,32 @@ > //ignore can't happen since we write the filter ourselves > } > if (ref == null || ref.size() == 0) >- throw new IllegalStateException("p2 is not configured properly. No provisioning agent could be found."); >+ throw new IllegalStateException(Messages.OperationFactory_noAgent); > IProvisioningAgent agent = Activator.getContext().getService(ref.iterator().next()); > Activator.getContext().ungetService(ref.iterator().next()); > return agent; > } > >- private Collection<IInstallableUnit> gatherIUs(ProvisioningContext context, Collection<IVersionedId> ius, IProgressMonitor monitor) { >- Collection<IInstallableUnit> unitsToInstall = new ArrayList<IInstallableUnit>(ius.size()); >+ //Return a list of IUs from the list of versionedIDs originally provided >+ 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 (ius instanceof IInstallableUnit) { >- unitsToInstall.add((IInstallableUnit) versionedId); >+ if (!checkIUs && versionedId instanceof IInstallableUnit) { >+ gatheredIUs.add((IInstallableUnit) versionedId); > continue; > } > > IQuery<IInstallableUnit> installableUnits = QueryUtil.createIUQuery(versionedId.getId(), versionedId.getVersion()); >- IQueryResult<IInstallableUnit> matches = context.getMetadata(monitor).query(installableUnits, monitor); >- // if (ius.isEmpty()) >- // Do something smart. like throw an exception >+ 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(); >- unitsToInstall.add(iuIt.next()); >- >- if (iuIt.hasNext()) { >- // TODO >- System.out.println("Log the fact that we have a problem"); >- } >+ gatheredIUs.add(iuIt.next()); > } >- return unitsToInstall; >+ return gatheredIUs; > } > > private ProvisioningContext createProvisioningContext(Collection<URI> repos, IProvisioningAgent agent) { >@@ -92,11 +90,12 @@ > public InstallOperation createInstallOperation(Collection<IVersionedId> toInstall, Collection<URI> repos, IProgressMonitor monitor) throws ProvisionException { > Assert.isNotNull(toInstall); > IProvisioningAgent agent = getAgent(); >+ > //add the repos > ProvisioningContext ctx = createProvisioningContext(repos, agent); > > //find the ius to install and create the operation >- InstallOperation resultingOperation = new InstallOperation(new ProvisioningSession(agent), gatherIUs(ctx, toInstall, monitor)); >+ InstallOperation resultingOperation = new InstallOperation(new ProvisioningSession(agent), gatherIUs(ctx.getMetadata(monitor), toInstall, false, monitor)); > resultingOperation.setProvisioningContext(ctx); > resultingOperation.setProfileId(IProfileRegistry.SELF); > >@@ -116,7 +115,7 @@ > ProvisioningContext ctx = createProvisioningContext(repos, agent); > > //find the ius to uninstall and create the operation >- UninstallOperation resultingOperation = new UninstallOperation(new ProvisioningSession(agent), gatherIUs(ctx, toUninstall, monitor)); >+ UninstallOperation resultingOperation = new UninstallOperation(new ProvisioningSession(agent), gatherIUs(listInstalledElements(false, monitor), toUninstall, true, monitor)); > resultingOperation.setProvisioningContext(ctx); > resultingOperation.setProfileId(IProfileRegistry.SELF); > >@@ -149,7 +148,7 @@ > ProvisioningContext ctx = createProvisioningContext(repos, agent); > > //find the ius to update and create the operation >- UpdateOperation resultingOperation = new UpdateOperation(new ProvisioningSession(agent), toUpdate == null ? null : gatherIUs(ctx, toUpdate, monitor)); >+ UpdateOperation resultingOperation = new UpdateOperation(new ProvisioningSession(agent), toUpdate == null ? null : gatherIUs(listInstalledElements(false, monitor), toUpdate, false, monitor)); > resultingOperation.setProvisioningContext(ctx); > resultingOperation.setProfileId(IProfileRegistry.SELF); > >@@ -161,7 +160,7 @@ > * @param toInstall the elements to install. This can not be null. > * @param repos the repositories to install the elements from. > * @param monitor the progress monitor >- * @return an instance of {@link InstallOperation}. >+ * @return an instance of {@link SynchronizeOperation}. > */ > public SynchronizeOperation createSynchronizeOperation(Collection<IVersionedId> toInstall, Collection<URI> repos, IProgressMonitor monitor) throws ProvisionException { > IProvisioningAgent agent = getAgent(); >@@ -171,7 +170,7 @@ > if (toInstall == null) > iusToInstall = ctx.getMetadata(monitor).query(QueryUtil.createIUGroupQuery(), monitor).toUnmodifiableSet(); > else >- iusToInstall = gatherIUs(ctx, toInstall, monitor); >+ iusToInstall = gatherIUs(ctx.getMetadata(monitor), toInstall, false, monitor); > > SynchronizeOperation resultingOperation = new SynchronizeOperation(new ProvisioningSession(agent), iusToInstall); > resultingOperation.setProvisioningContext(ctx); >#P org.eclipse.equinox.p2.tests.ui >Index: src/org/eclipse/equinox/p2/tests/ui/operations/OperationFactoryTest.java >=================================================================== >RCS file: src/org/eclipse/equinox/p2/tests/ui/operations/OperationFactoryTest.java >diff -N src/org/eclipse/equinox/p2/tests/ui/operations/OperationFactoryTest.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/equinox/p2/tests/ui/operations/OperationFactoryTest.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,180 @@ >+/******************************************************************************* >+ * 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 >+ *******************************************************************************/ >+ >+package org.eclipse.equinox.p2.tests.ui.operations; >+ >+import java.lang.reflect.Field; >+import java.net.URI; >+import java.util.*; >+import org.eclipse.core.runtime.IStatus; >+import org.eclipse.core.runtime.NullProgressMonitor; >+import org.eclipse.equinox.internal.p2.engine.SimpleProfileRegistry; >+import org.eclipse.equinox.p2.core.ProvisionException; >+import org.eclipse.equinox.p2.engine.IProfileRegistry; >+import org.eclipse.equinox.p2.metadata.*; >+import org.eclipse.equinox.p2.operations.*; >+import org.eclipse.equinox.p2.query.IQueryResult; >+import org.eclipse.equinox.p2.tests.AbstractProvisioningTest; >+ >+public class OperationFactoryTest extends AbstractProvisioningTest { >+ >+ @Override >+ protected void setUp() throws Exception { >+ super.setUp(); >+ } >+ >+ public void testCreateInstallOperation() { >+ OperationFactory of = new OperationFactory(); >+ Collection<IVersionedId> versions = new ArrayList<IVersionedId>(); >+ versions.add(new VersionedId("aBundle", "1.0.0")); >+ Collection<URI> coll = new ArrayList<URI>(); >+ coll.add(getTestData("Simple repository", "testData/testRepos/simple.1").toURI()); >+ try { >+ of.createInstallOperation(versions, coll, new NullProgressMonitor()); >+ } catch (ProvisionException e) { >+ fail("Creation of the install operation failed", e); >+ } >+ } >+ >+ public void testCreateInstallOperationWithUnspecifiedVersion() { >+ OperationFactory of = new OperationFactory(); >+ Collection<IVersionedId> versions = new ArrayList<IVersionedId>(); >+ versions.add(new VersionedId("aBundle", (Version) null)); >+ Collection<URI> coll = new ArrayList<URI>(); >+ coll.add(getTestData("Simple repository", "testData/testRepos/simple.1").toURI()); >+ try { >+ of.createInstallOperation(versions, coll, new NullProgressMonitor()); >+ } catch (ProvisionException e) { >+ fail("Creation of the install operation failed", e); >+ } >+ } >+ >+ public void testMissingVersionedIdInInstallOperation() { >+ OperationFactory of = new OperationFactory(); >+ Collection<IVersionedId> versions = new ArrayList<IVersionedId>(); >+ versions.add(new VersionedId("aBundle", "1.0.0")); >+ Exception exceptionMet = null; >+ try { >+ of.createInstallOperation(versions, Collections.<URI> emptyList(), new NullProgressMonitor()); >+ } catch (ProvisionException e) { >+ exceptionMet = e; >+ } >+ assertNotNull("An exception was expected", exceptionMet); >+ } >+ >+ public void testMissingElementToUninstall() { >+ createProfileWithOneIU(getUniqueString()); >+ >+ //While we are at it, test the installedElements >+ OperationFactory of = new OperationFactory(); >+ IQueryResult<IInstallableUnit> installedElements = of.listInstalledElements(true, new NullProgressMonitor()); >+ assertEquals(1, installedElements.toSet().size()); >+ >+ //Now test various removal scenarios >+ testUninstall(new VersionedId("aBundle", (Version) null), false); >+ testUninstall(new VersionedId("aBundle", Version.create("1.0.0")), false); >+ testUninstall(new VersionedId("aBundle", Version.create("2.0.0")), true); >+ testUninstall(new VersionedId("missingBundle", (Version) null), true); >+ testUninstall(installedElements.toSet().iterator().next(), false); >+ testUninstall(createEclipseIU("doesNotExist"), true); >+ } >+ >+ private void createProfileWithOneIU(String profileName) { >+ //create a profile and set it as self >+ try { >+ IProfileRegistry profileRegistry = getProfileRegistry(); >+ profileRegistry.addProfile(profileName); >+ Field selfField = SimpleProfileRegistry.class.getDeclaredField("self"); //$NON-NLS-1$ >+ selfField.setAccessible(true); >+ previousSelfValue = selfField.get(profileRegistry); >+ selfField.set(profileRegistry, profileName); >+ } catch (Exception e) { >+ fail("Error while setting up uninstall test", e); >+ } >+ >+ //install something using the install operation >+ OperationFactory of = new OperationFactory(); >+ Collection<IVersionedId> versions = new ArrayList<IVersionedId>(); >+ versions.add(new VersionedId("aBundle", (Version) null)); >+ Collection<URI> coll = new ArrayList<URI>(); >+ coll.add(getTestData("Simple repository", "testData/testRepos/simple.1").toURI()); >+ try { >+ InstallOperation iop = of.createInstallOperation(versions, coll, new NullProgressMonitor()); >+ IStatus result = iop.resolveModal(new NullProgressMonitor()); >+ if (result.isOK()) { >+ iop.getProvisioningJob(new NullProgressMonitor()).runModal(new NullProgressMonitor()); >+ } >+ } catch (ProvisionException e) { >+ fail("Creation of the install operation failed", e); >+ } >+ >+ } >+ >+ private void testUninstall(IVersionedId vid, boolean shouldFail) { >+ OperationFactory of = new OperationFactory(); >+ Collection<IVersionedId> toRemove = new ArrayList<IVersionedId>(); >+ toRemove.add(vid); >+ Exception expectedException = null; >+ try { >+ of.createUninstallOperation(toRemove, Collections.<URI> emptyList(), new NullProgressMonitor()); >+ } catch (ProvisionException e) { >+ expectedException = e; >+ } >+ if (shouldFail) >+ assertNotNull(expectedException); >+ else >+ assertNull(expectedException); >+ } >+ >+ public void testUpdateOperation() { >+ createProfileWithOneIU(getUniqueString()); >+ OperationFactory of = new OperationFactory(); >+ { >+ Collection<IVersionedId> toUpdate = new ArrayList<IVersionedId>(); >+ toUpdate.add(new VersionedId("doesNotExist", (Version) null)); >+ Collection<URI> repos = new ArrayList<URI>(); >+ repos.add(getTestData("second repository", "testData/testRepos/simple.2").toURI()); >+ Exception expectedException = null; >+ try { >+ of.createUpdateOperation(toUpdate, repos, new NullProgressMonitor()); >+ } catch (ProvisionException e) { >+ expectedException = e; >+ } >+ assertNotNull(expectedException); >+ } >+ >+ { >+ Collection<IVersionedId> toUpdate = new ArrayList<IVersionedId>(); >+ toUpdate.add(new VersionedId("aBundle", Version.parseVersion("1.0.0"))); >+ Collection<URI> repos = new ArrayList<URI>(); >+ repos.add(getTestData("second repository", "testData/testRepos/simple.2").toURI()); >+ try { >+ UpdateOperation op = of.createUpdateOperation(toUpdate, repos, new NullProgressMonitor()); >+ op.resolveModal(new NullProgressMonitor()); >+ assertEquals(1, op.getPossibleUpdates().length); >+ } catch (ProvisionException e) { >+ fail("Exception not expected", e); >+ } >+ } >+ >+ { >+ Collection<URI> repos = new ArrayList<URI>(); >+ repos.add(getTestData("second repository", "testData/testRepos/simple.2").toURI()); >+ try { >+ UpdateOperation op = of.createUpdateOperation(null, repos, new NullProgressMonitor()); >+ op.resolveModal(new NullProgressMonitor()); >+ assertEquals(1, op.getPossibleUpdates().length); >+ } catch (ProvisionException e) { >+ fail("Exception not expected", e); >+ } >+ } >+ } >+}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 337016
:
188826
|
189995
|
193604
|
193772
|
194659
| 194662