Debian Codegraph @

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

raw
1 /*******************************************************************************
2 * Copyright (c) 2007, 2017 IBM Corporation 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 * IBM Corporation - initial API and implementation
13 *******************************************************************************/
14 package org.eclipse.equinox.p2.operations;
15
16 import org.eclipse.core.runtime.*;
17 import org.eclipse.equinox.p2.engine.*;
18
19 /**
20 * A job that modifies a profile according to a specified provisioning plan.
21 *
22 * @since 2.0
23 * @noextend This class is not intended to be subclassed by clients.
24 */
25 public class ProfileModificationJob extends ProvisioningJob implements IProfileChangeJob {
26
27 IProvisioningPlan plan;
28 String profileId;
29 IPhaseSet phaseSet = PhaseSetFactory.createDefaultPhaseSet();
30 ProvisioningContext provisioningContext;
31 int restartPolicy = ProvisioningJob.RESTART_OR_APPLY;
32 private String taskName;
33
34 /**
35 * Create a job that will update a profile according to the specified provisioning plan.
36 *
37 * @param name the name of the job
38 * @param session the provisioning session to use to obtain provisioning services
39 * @param profileId the id of the profile to be altered
40 * @param plan the provisioning plan describing how the profile is to be altered
41 * @param context the provisioning context describing how the operation is to be performed
42 */
43 public ProfileModificationJob(String name, ProvisioningSession session, String profileId, IProvisioningPlan plan, ProvisioningContext context) {
44 super(name, session);
45 this.plan = plan;
46 this.profileId = profileId;
47 this.provisioningContext = context;
48 }
49
50 /**
51 * Set the phase set to be used when running the provisioning plan. This method need only
52 * be used when the default phase set is not sufficient. For example, clients could
53 * use this method to perform a sizing or to download artifacts without provisioning them.
54 *
55 * @param phaseSet the provisioning phases to be run during provisioning.
56 */
57 public void setPhaseSet(IPhaseSet phaseSet) {
58 this.phaseSet = phaseSet;
59 }
60
61 @Override
62 public String getProfileId() {
63 return profileId;
64 }
65
66 @Override
67 public IStatus runModal(IProgressMonitor monitor) {
68 if (monitor == null)
69 monitor = new NullProgressMonitor();
70 String task = taskName;
71 IStatus status = Status.OK_STATUS;
72 if (task == null)
73 task = getName();
74 try {
75 SubMonitor subMonitor = SubMonitor.convert(monitor, task, 1000);
76 status = getSession().performProvisioningPlan(plan, phaseSet, provisioningContext, subMonitor);
77 } finally {
78 monitor.done();
79 }
80 return status;
81 }
82
83 /**
84 * Sets the top level task name for progress when running this operation.
85 *
86 * @param label the label to be used for the task name
87 */
88 public void setTaskName(String label) {
89 this.taskName = label;
90 }
91
92 @Override
93 public int getRestartPolicy() {
94 //if we are installing into self we must always use the restart policy
95 if (IProfileRegistry.SELF.equals(profileId))
96 return restartPolicy;
97 //otherwise only apply restart policy if the profile being modified is the one that is currently running
98 IProfile profile = getSession().getProfileRegistry().getProfile(IProfileRegistry.SELF);
99 String id = profile == null ? null : profile.getProfileId();
100 if (id != null && profileId.equals(id)) {
101 return restartPolicy;
102 }
103 return ProvisioningJob.RESTART_NONE;
104 }
105
106 /**
107 * Set the restart policy that describes whether restart is needed after
108 * performing this job. This policy will be consulted when the
109 * profile being changed is the profile of the running system.
110 *
111 * @param policy an integer describing the restart policy
112 * @see ProvisioningJob#RESTART_NONE
113 * @see ProvisioningJob#RESTART_ONLY
114 * @see ProvisioningJob#RESTART_OR_APPLY
115 */
116 public void setRestartPolicy(int policy) {
117 restartPolicy = policy;
118 }
119 }