| 1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2009, 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 |
* Sonatype, Inc. - ongoing development |
| 14 |
******************************************************************************/ |
| 15 |
package org.eclipse.equinox.p2.operations; |
| 16 |
|
| 17 |
import java.net.URI; |
| 18 |
import java.util.Collection; |
| 19 |
import org.eclipse.core.runtime.IProgressMonitor; |
| 20 |
import org.eclipse.core.runtime.MultiStatus; |
| 21 |
import org.eclipse.equinox.internal.p2.director.ProfileChangeRequest; |
| 22 |
import org.eclipse.equinox.internal.p2.operations.IFailedStatusEvaluator; |
| 23 |
import org.eclipse.equinox.internal.p2.operations.Messages; |
| 24 |
import org.eclipse.equinox.p2.engine.IProfile; |
| 25 |
import org.eclipse.equinox.p2.engine.ProvisioningContext; |
| 26 |
import org.eclipse.equinox.p2.metadata.IInstallableUnit; |
| 27 |
|
| 28 |
/** |
| 29 |
* An UninstallOperation describes an operation that uninstalls {@link IInstallableUnit}s from |
| 30 |
* a profile. |
| 31 |
* |
| 32 |
* The following snippet shows how one might use an UninstallOperation to perform a synchronous resolution and |
| 33 |
* then kick off an uninstall in the background: |
| 34 |
* |
| 35 |
* <pre> |
| 36 |
* UninstallOperation op = new UninstallOperation(session, new IInstallableUnit [] { removeThisIU }); |
| 37 |
* IStatus result = op.resolveModal(monitor); |
| 38 |
* if (result.isOK()) { |
| 39 |
* op.getProvisioningJob(monitor).schedule(); |
| 40 |
* } |
| 41 |
* </pre> |
| 42 |
* @noextend This class is not intended to be subclassed by clients. |
| 43 |
* @since 2.0 |
| 44 |
*/ |
| 45 |
public class UninstallOperation extends ProfileChangeOperation { |
| 46 |
|
| 47 |
private Collection<IInstallableUnit> toUninstall; |
| 48 |
|
| 49 |
/** |
| 50 |
* Create an uninstall operation on the specified provisioning session that uninstalls |
| 51 |
* the specified IInstallableUnits. Unless otherwise specified, the operation will |
| 52 |
* be associated with the currently running profile. |
| 53 |
* |
| 54 |
* @param session the session to use for obtaining provisioning services |
| 55 |
* @param toUninstall the IInstallableUnits to be installed into the profile. |
| 56 |
*/ |
| 57 |
public UninstallOperation(ProvisioningSession session, Collection<IInstallableUnit> toUninstall) { |
| 58 |
super(session); |
| 59 |
this.toUninstall = toUninstall; |
| 60 |
} |
| 61 |
|
| 62 |
@Override |
| 63 |
protected void computeProfileChangeRequest(MultiStatus status, IProgressMonitor monitor) { |
| 64 |
request = ProfileChangeRequest.createByProfileId(session.getProvisioningAgent(), profileId); |
| 65 |
request.removeAll(toUninstall); |
| 66 |
// See https://bugs.eclipse.org/bugs/show_bug.cgi?id=255984 |
| 67 |
// We ask to remove the the profile root property in addition to removing the IU. In theory this |
| 68 |
// should be redundant, but there are cases where the planner decides not to uninstall something because |
| 69 |
// it is needed by others. We still want to remove the root in this case. |
| 70 |
for (IInstallableUnit iuToUninstall : toUninstall) { |
| 71 |
request.removeInstallableUnitProfileProperty(iuToUninstall, IProfile.PROP_PROFILE_ROOT_IU); |
| 72 |
} |
| 73 |
|
| 74 |
} |
| 75 |
|
| 76 |
@Override |
| 77 |
protected String getProvisioningJobName() { |
| 78 |
return Messages.UninstallOperation_ProvisioningJobName; |
| 79 |
} |
| 80 |
|
| 81 |
@Override |
| 82 |
protected String getResolveJobName() { |
| 83 |
return Messages.UninstallOperation_ResolveJobName; |
| 84 |
} |
| 85 |
|
| 86 |
@Override |
| 87 |
ProvisioningContext getFirstPassProvisioningContext() { |
| 88 |
ProvisioningContext pc = new ProvisioningContext(session.getProvisioningAgent()); |
| 89 |
pc.setMetadataRepositories(new URI[0]); |
| 90 |
pc.setArtifactRepositories(new URI[0]); |
| 91 |
return pc; |
| 92 |
} |
| 93 |
|
| 94 |
@Override |
| 95 |
IFailedStatusEvaluator getSecondPassEvaluator() { |
| 96 |
return failedPlan -> context; |
| 97 |
} |
| 98 |
} |