Skip to main content
summaryrefslogtreecommitdiffstats
blob: e9899eaf581d236a7ce889e12c26bba207e87d0f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*******************************************************************************
 * Copyright (c) 2009, 2010 IBM Corporation 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:
 *     IBM Corporation - initial API and implementation
 *     Sonatype, Inc. - ongoing development
 ******************************************************************************/
package org.eclipse.equinox.p2.operations;

import java.net.URI;
import java.util.Collection;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.MultiStatus;
import org.eclipse.equinox.internal.p2.director.ProfileChangeRequest;
import org.eclipse.equinox.internal.p2.operations.IFailedStatusEvaluator;
import org.eclipse.equinox.internal.p2.operations.Messages;
import org.eclipse.equinox.p2.engine.*;
import org.eclipse.equinox.p2.metadata.IInstallableUnit;

/**
 * An UninstallOperation describes an operation that uninstalls {@link IInstallableUnit}s from
 * a profile.
 * 
 * The following snippet shows how one might use an UninstallOperation to perform a synchronous resolution and
 * then kick off an uninstall in the background:
 * 
 * <pre>
 * UninstallOperation op = new UninstallOperation(session, new IInstallableUnit [] { removeThisIU });
 * IStatus result = op.resolveModal(monitor);
 * if (result.isOK()) {
 *   op.getProvisioningJob(monitor).schedule();
 * }
 * </pre>
 * @noextend This class is not intended to be subclassed by clients.
 * @since 2.0
 */
public class UninstallOperation extends ProfileChangeOperation {

	private Collection<IInstallableUnit> toUninstall;

	/**
	 * Create an uninstall operation on the specified provisioning session that uninstalls
	 * the specified IInstallableUnits.  Unless otherwise specified, the operation will
	 * be associated with the currently running profile.
	 * 
	 * @param session the session to use for obtaining provisioning services
	 * @param toUninstall the IInstallableUnits to be installed into the profile.
	 */
	public UninstallOperation(ProvisioningSession session, Collection<IInstallableUnit> toUninstall) {
		super(session);
		this.toUninstall = toUninstall;
	}

	/* (non-Javadoc)
	 * @see org.eclipse.equinox.p2.operations.ProfileChangeOperation#computeProfileChangeRequest(org.eclipse.core.runtime.IProgressMonitor)
	 */
	protected void computeProfileChangeRequest(MultiStatus status, IProgressMonitor monitor) {
		request = ProfileChangeRequest.createByProfileId(session.getProvisioningAgent(), profileId);
		request.removeAll(toUninstall);
		// See https://bugs.eclipse.org/bugs/show_bug.cgi?id=255984
		// We ask to remove the the profile root property in addition to removing the IU.  In theory this
		// should be redundant, but there are cases where the planner decides not to uninstall something because
		// it is needed by others.  We still want to remove the root in this case.
		for (IInstallableUnit iuToUninstall : toUninstall) {
			request.removeInstallableUnitProfileProperty(iuToUninstall, IProfile.PROP_PROFILE_ROOT_IU);
		}

	}

	/* (non-Javadoc)
	 * @see org.eclipse.equinox.p2.operations.ProfileChangeOperation#getProvisioningJobName()
	 */
	protected String getProvisioningJobName() {
		return Messages.UninstallOperation_ProvisioningJobName;
	}

	/* (non-Javadoc)
	 * @see org.eclipse.equinox.p2.operations.ProfileChangeOperation#getResolveJobName()
	 */
	protected String getResolveJobName() {
		return Messages.UninstallOperation_ResolveJobName;
	}

	@Override
	ProvisioningContext getFirstPassProvisioningContext() {
		ProvisioningContext pc = new ProvisioningContext(session.getProvisioningAgent());
		pc.setMetadataRepositories(new URI[0]);
		pc.setArtifactRepositories(new URI[0]);
		return pc;
	}

	@Override
	IFailedStatusEvaluator getSecondPassEvaluator() {
		return new IFailedStatusEvaluator() {
			public ProvisioningContext getSecondPassProvisioningContext(IProvisioningPlan failedPlan) {
				return context;
			}
		};
	}
}

Back to the top