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 193772 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]
new patch
337016c.patch (text/plain), 13.16 KB, created by
Pascal Rapicault
on 2011-04-20 22:26:35 EDT
(
hide
)
Description:
new patch
Filename:
MIME Type:
Creator:
Pascal Rapicault
Created:
2011-04-20 22:26:35 EDT
Size:
13.16 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.equinox.p2.operations >Index: src/org/eclipse/equinox/p2/operations/InstallOperation.java >=================================================================== >RCS file: /cvsroot/rt/org.eclipse.equinox/p2/bundles/org.eclipse.equinox.p2.operations/src/org/eclipse/equinox/p2/operations/InstallOperation.java,v >retrieving revision 1.9 >diff -u -r1.9 InstallOperation.java >--- src/org/eclipse/equinox/p2/operations/InstallOperation.java 23 Sep 2010 19:28:31 -0000 1.9 >+++ src/org/eclipse/equinox/p2/operations/InstallOperation.java 21 Apr 2011 02:24:33 -0000 >@@ -46,7 +46,7 @@ > */ > public class InstallOperation extends ProfileChangeOperation { > >- private Collection<IInstallableUnit> toInstall; >+ protected Collection<IInstallableUnit> toInstall; > > /** > * Create an install operation on the specified provisioning session that installs >Index: src/org/eclipse/equinox/p2/operations/OperationFactory.java >=================================================================== >RCS file: src/org/eclipse/equinox/p2/operations/OperationFactory.java >diff -N src/org/eclipse/equinox/p2/operations/OperationFactory.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/equinox/p2/operations/OperationFactory.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,179 @@ >+/******************************************************************************* >+ * 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.operations; >+ >+import java.net.URI; >+import java.util.*; >+import org.eclipse.core.runtime.Assert; >+import org.eclipse.core.runtime.IProgressMonitor; >+import org.eclipse.equinox.internal.p2.operations.Activator; >+import org.eclipse.equinox.p2.core.IProvisioningAgent; >+import org.eclipse.equinox.p2.core.ProvisionException; >+import org.eclipse.equinox.p2.engine.*; >+import org.eclipse.equinox.p2.engine.query.UserVisibleRootQuery; >+import org.eclipse.equinox.p2.metadata.IInstallableUnit; >+import org.eclipse.equinox.p2.metadata.IVersionedId; >+import org.eclipse.equinox.p2.query.*; >+import org.osgi.framework.InvalidSyntaxException; >+import org.osgi.framework.ServiceReference; >+ >+/** >+ * OperationFactory provides a set of helpers to simplify dealing with the running installation. >+ * Among other things, it simplifies the installation, un-installation and update. >+ * If the system you are trying to modify is not the running one, you need to directly use the various subclass of {@link ProfileChangeOperation}. >+ * @since 2.1 >+ */ >+public class OperationFactory { >+ >+ private IProvisioningAgent getAgent() { >+ Collection<ServiceReference<IProvisioningAgent>> ref = null; >+ try { >+ ref = Activator.getContext().getServiceReferences(IProvisioningAgent.class, '(' + IProvisioningAgent.SERVICE_CURRENT + '=' + Boolean.TRUE.toString() + ')'); >+ } catch (InvalidSyntaxException e) { >+ //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."); >+ 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()); >+ >+ for (IVersionedId versionedId : ius) { >+ if (ius instanceof IInstallableUnit) { >+ unitsToInstall.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 >+ //Add the first IU >+ Iterator<IInstallableUnit> iuIt = matches.iterator(); >+ unitsToInstall.add(iuIt.next()); >+ >+ if (iuIt.hasNext()) >+ System.out.println("Log the fact that we have a problem"); >+ } >+ return unitsToInstall; >+ } >+ >+ 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; >+ } >+ >+ /** >+ * This factory method creates an {@link InstallOperation} to install all the elements listed from the specified repositories. >+ * @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 operation to install >+ */ >+ 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)); >+ resultingOperation.setProvisioningContext(ctx); >+ resultingOperation.setProfileId(IProfileRegistry.SELF); >+ >+ return resultingOperation; >+ } >+ >+ /** >+ * Create an {@link UninstallOperation} that will uninstall the listed elements from the running instance. >+ * @param toUninstall the elements to uninstall. This can not be null. >+ * @param repos the repositories to install the elements from. Passing null will >+ * @param monitor the progress monitor >+ * @return an operation to uninstall >+ */ >+ public UninstallOperation createUninstallOperation(Collection<IVersionedId> toUninstall, Collection<URI> repos, IProgressMonitor monitor) throws ProvisionException { >+ Assert.isNotNull(toUninstall); >+ IProvisioningAgent agent = getAgent(); >+ 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)); >+ resultingOperation.setProvisioningContext(ctx); >+ resultingOperation.setProfileId(IProfileRegistry.SELF); >+ >+ return resultingOperation; >+ } >+ >+ /** >+ * Return the {@link IInstallableUnit} that are installed in the running instance of eclipse. >+ * @param rootsOnly set to true to return only the elements that have been explicitly installed (aka roots). >+ * @param monitor the progress monitor >+ * @return the installable units installed >+ */ >+ public IQueryResult<IInstallableUnit> listInstalledElements(boolean rootsOnly, IProgressMonitor monitor) { >+ IProfileRegistry registry = (IProfileRegistry) getAgent().getService(IProfileRegistry.SERVICE_NAME); >+ IProfile profile = registry.getProfile(IProfileRegistry.SELF); >+ if (rootsOnly) >+ return profile.query(new UserVisibleRootQuery(), monitor); >+ return profile.query(QueryUtil.ALL_UNITS, monitor); >+ } >+ >+ /** >+ * Create an {@link UpdateOperation} that will update the elements specified. >+ * @param toUpdate >+ * @param repos >+ * @param monitor >+ * @return an instance of {@link UpdateOperation} >+ */ >+ public UpdateOperation createUpdateOperation(Collection<IVersionedId> toUpdate, Collection<URI> repos, IProgressMonitor monitor) throws ProvisionException { >+ IProvisioningAgent agent = getAgent(); >+ 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)); >+ resultingOperation.setProvisioningContext(ctx); >+ resultingOperation.setProfileId(IProfileRegistry.SELF); >+ >+ return resultingOperation; >+ } >+ >+ /** >+ * This factory method creates an {@link SynchronizeOperation} that will cause the current installation to exclusively contain the elements listed once executed. >+ * @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}. >+ */ >+ public SynchronizeOperation createSynchronizeOperation(Collection<IVersionedId> toInstall, Collection<URI> repos, IProgressMonitor monitor) 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, toInstall, monitor); >+ >+ SynchronizeOperation resultingOperation = new SynchronizeOperation(new ProvisioningSession(agent), iusToInstall); >+ resultingOperation.setProvisioningContext(ctx); >+ resultingOperation.setProfileId(IProfileRegistry.SELF); >+ >+ return resultingOperation; >+ } >+} >Index: src/org/eclipse/equinox/p2/operations/SynchronizeOperation.java >=================================================================== >RCS file: src/org/eclipse/equinox/p2/operations/SynchronizeOperation.java >diff -N src/org/eclipse/equinox/p2/operations/SynchronizeOperation.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/equinox/p2/operations/SynchronizeOperation.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,69 @@ >+/******************************************************************************* >+ * 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.operations; >+ >+import java.util.Collection; >+import org.eclipse.core.runtime.*; >+import org.eclipse.equinox.internal.p2.director.ProfileChangeRequest; >+import org.eclipse.equinox.internal.p2.operations.Messages; >+import org.eclipse.equinox.p2.engine.IProfile; >+import org.eclipse.equinox.p2.engine.query.UserVisibleRootQuery; >+import org.eclipse.equinox.p2.metadata.IInstallableUnit; >+import org.eclipse.equinox.p2.planner.ProfileInclusionRules; >+import org.eclipse.equinox.p2.query.QueryUtil; >+ >+/** >+ * A {@link SynchronizeOperation} describes an operation that will modify the installation to >+ * exclusively include the InstallableUnit mentioned. Note that all the Installable Units necessary >+ * to satisfy the dependencies of the Installable Units installed will also be installed. >+ * >+ * The following snippet shows how one might use an AbsoluteInstallOperation to perform a synchronous resolution and >+ * then kick off an install in the background: >+ * >+ * <pre> >+ * AbsoluteInstallOperation op = new AbsoluteInstallOperation(session, new IInstallableUnit [] { myIU }); >+ * IStatus result = op.resolveModal(monitor); >+ * if (result.isOK()) { >+ * op.getProvisioningJob(monitor).schedule(); >+ * } >+ * </pre> >+ * >+ * @since 2.1 >+ * @see ProfileChangeOperation >+ * @noextend This class is not intended to be subclassed by clients. >+ */ >+public class SynchronizeOperation extends InstallOperation { >+ >+ public SynchronizeOperation(ProvisioningSession session, Collection<IInstallableUnit> toInstall) { >+ super(session, toInstall); >+ } >+ >+ /* >+ * (non-Javadoc) >+ * @see org.eclipse.equinox.p2.operations.ProfileChangeOperation#computeProfileChangeRequest(org.eclipse.core.runtime.MultiStatus, org.eclipse.core.runtime.IProgressMonitor) >+ */ >+ protected void computeProfileChangeRequest(MultiStatus status, IProgressMonitor monitor) { >+ request = ProfileChangeRequest.createByProfileId(session.getProvisioningAgent(), profileId); >+ IProfile profile; >+ SubMonitor sub = SubMonitor.convert(monitor, Messages.InstallOperation_ComputeProfileChangeProgress, toInstall.size()); >+ profile = session.getProfileRegistry().getProfile(profileId); >+ request.removeAll(profile.query(new UserVisibleRootQuery(), sub).toUnmodifiableSet()); >+ request.addAll(toInstall); >+ for (IInstallableUnit entryToInstall : toInstall) { >+ // If the user is installing a patch, we mark it optional. This allows the patched IU to be updated later by removing the patch. >+ if (QueryUtil.isPatch(entryToInstall)) >+ request.setInstallableUnitInclusionRules(entryToInstall, ProfileInclusionRules.createOptionalInclusionRule(entryToInstall)); >+ >+ sub.worked(1); >+ } >+ sub.done(); >+ } >+}
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