Debian Codegraph @

bundles/org.eclipse.equinox.p2.operations/src/org/eclipse/equinox/p2/operations/SynchronizeOperation.java

raw
1 /*******************************************************************************
2 * Copyright (c) 2011, 2017 Sonatype, Inc. and others.
3 *
4 * This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License 2.0
6 * which accompanies this distribution, and is available at
7 * https://www.eclipse.org/legal/epl-2.0/
8 *
9 * SPDX-License-Identifier: EPL-2.0
10 *
11 * Contributors:
12 * Sonatype, Inc. - initial API and implementation
13 * IBM Corporation - Ongoing development
14 *******************************************************************************/
15 package org.eclipse.equinox.p2.operations;
16
17 import java.util.Collection;
18 import org.eclipse.core.runtime.*;
19 import org.eclipse.equinox.internal.p2.director.ProfileChangeRequest;
20 import org.eclipse.equinox.internal.p2.operations.Messages;
21 import org.eclipse.equinox.p2.engine.IProfile;
22 import org.eclipse.equinox.p2.engine.query.UserVisibleRootQuery;
23 import org.eclipse.equinox.p2.metadata.IInstallableUnit;
24 import org.eclipse.equinox.p2.planner.ProfileInclusionRules;
25 import org.eclipse.equinox.p2.query.QueryUtil;
26
27 /**
28 * A {@link SynchronizeOperation} describes an operation that will modify the installation to
29 * exclusively include the InstallableUnit mentioned. Note that all the Installable Units necessary
30 * to satisfy the dependencies of the Installable Units installed will also be installed.
31 *
32 * The following snippet shows how one might use an SynchronizeOperation to perform a synchronous resolution and
33 * then kick off an install in the background:
34 *
35 * <pre>
36 * SynchronizeOperation op = new SynchronizeOperation(session, new IInstallableUnit [] { myIU });
37 * IStatus result = op.resolveModal(monitor);
38 * if (result.isOK()) {
39 * op.getProvisioningJob(monitor).schedule();
40 * }
41 * </pre>
42 *
43 * @since 2.1
44 * @see ProfileChangeOperation
45 * @noextend This class is not intended to be subclassed by clients.
46 */
47 public class SynchronizeOperation extends InstallOperation {
48
49 public SynchronizeOperation(ProvisioningSession session, Collection<IInstallableUnit> toInstall) {
50 super(session, toInstall);
51 }
52
53 @Override
54 protected void computeProfileChangeRequest(MultiStatus status, IProgressMonitor monitor) {
55 request = ProfileChangeRequest.createByProfileId(session.getProvisioningAgent(), profileId);
56 IProfile profile;
57 SubMonitor sub = SubMonitor.convert(monitor, Messages.InstallOperation_ComputeProfileChangeProgress, toInstall.size());
58 profile = session.getProfileRegistry().getProfile(profileId);
59 request.removeAll(profile.query(new UserVisibleRootQuery(), sub).toUnmodifiableSet());
60 request.addAll(toInstall);
61 for (IInstallableUnit entryToInstall : toInstall) {
62 // If the user is installing a patch, we mark it optional. This allows the patched IU to be updated later by removing the patch.
63 if (QueryUtil.isPatch(entryToInstall))
64 request.setInstallableUnitInclusionRules(entryToInstall, ProfileInclusionRules.createOptionalInclusionRule(entryToInstall));
65 else
66 request.setInstallableUnitProfileProperty(entryToInstall, IProfile.PROP_PROFILE_ROOT_IU, Boolean.toString(true));
67
68 sub.worked(1);
69 }
70 sub.done();
71 }
72 }