| 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.engine; |
| 15 |
|
| 16 |
import java.util.*; |
| 17 |
import org.eclipse.equinox.internal.p2.engine.*; |
| 18 |
import org.eclipse.equinox.internal.p2.engine.phases.*; |
| 19 |
|
| 20 |
/** |
| 21 |
* @since 2.0 |
| 22 |
* @noextend This class is not intended to be subclassed by clients. |
| 23 |
*/ |
| 24 |
public class PhaseSetFactory { |
| 25 |
|
| 26 |
private static final boolean forcedUninstall = Boolean.parseBoolean(EngineActivator.getContext().getProperty("org.eclipse.equinox.p2.engine.forcedUninstall")); //$NON-NLS-1$ |
| 27 |
|
| 28 |
/** |
| 29 |
* A phase id (value "checkTrust") describing the certificate trust check phase. |
| 30 |
* This phase examines the code signing certificates of the artifacts being installed |
| 31 |
* to ensure they are signed and trusted by the running system. |
| 32 |
*/ |
| 33 |
public static String PHASE_CHECK_TRUST = "checkTrust"; //$NON-NLS-1$ |
| 34 |
/** |
| 35 |
* A phase id (value "collect") describing the collect phase. |
| 36 |
* This phase gathers all the artifacts to be installed, typically by copying them |
| 37 |
* from some repository into a suitable local location for the application being installed. |
| 38 |
*/ |
| 39 |
public static String PHASE_COLLECT = "collect"; //$NON-NLS-1$ |
| 40 |
/** |
| 41 |
* A phase id (value "configure") describing the configuration phase. |
| 42 |
* This phase writes configuration data related to the software being provisioned. |
| 43 |
* Until configuration occurs the end user of the software will be have access to |
| 44 |
* the installed functionality. |
| 45 |
*/ |
| 46 |
public static String PHASE_CONFIGURE = "configure"; //$NON-NLS-1$ |
| 47 |
/** |
| 48 |
* A phase id (value "install") describing the install phase. |
| 49 |
* This phase performs any necessary transformations on the downloaded |
| 50 |
* artifacts to put them in the correct shape for the running application, such |
| 51 |
* as decompressing or moving content, setting file permissions, etc). |
| 52 |
*/ |
| 53 |
public static String PHASE_INSTALL = "install"; //$NON-NLS-1$ |
| 54 |
/** |
| 55 |
* A phase id (value "property") describing the property modification phase. |
| 56 |
* This phase performs changes to profile properties. |
| 57 |
*/ |
| 58 |
public static String PHASE_PROPERTY = "property"; //$NON-NLS-1$ |
| 59 |
/** |
| 60 |
* A phase id (value "unconfigure") describing the unconfigure phase. |
| 61 |
* This phase removes configuration data related to the software being removed. |
| 62 |
* This phase is the inverse of the changes performed in the configure phase. |
| 63 |
*/ |
| 64 |
public static String PHASE_UNCONFIGURE = "unconfigure"; //$NON-NLS-1$ |
| 65 |
/** |
| 66 |
* A phase id (value "uninstall") describing the uninstall phase. |
| 67 |
* This phase removes artifacts from the system being provisioned that are |
| 68 |
* no longer required in the new profile. |
| 69 |
*/ |
| 70 |
public static String PHASE_UNINSTALL = "uninstall"; //$NON-NLS-1$ |
| 71 |
|
| 72 |
private static final List<String> ALL_PHASES_LIST = Arrays.asList(new String[] {PHASE_COLLECT, PHASE_UNCONFIGURE, PHASE_UNINSTALL, PHASE_PROPERTY, PHASE_CHECK_TRUST, PHASE_INSTALL, PHASE_CONFIGURE}); |
| 73 |
|
| 74 |
/** |
| 75 |
* Creates a default phase set that covers all the provisioning operations. |
| 76 |
* Phases can be specified for exclusion. |
| 77 |
* |
| 78 |
* @param exclude - A set of bit options that specify the phases to exclude. |
| 79 |
* See {@link PhaseSetFactory} for possible options |
| 80 |
* @return the {@link PhaseSet} |
| 81 |
*/ |
| 82 |
public static final IPhaseSet createDefaultPhaseSetExcluding(String[] exclude) { |
| 83 |
if (exclude == null || exclude.length == 0) |
| 84 |
return createDefaultPhaseSet(); |
| 85 |
List<String> excludeList = Arrays.asList(exclude); |
| 86 |
List<String> includeList = new ArrayList<>(ALL_PHASES_LIST); |
| 87 |
includeList.removeAll(excludeList); |
| 88 |
return createPhaseSetIncluding(includeList.toArray(new String[includeList.size()])); |
| 89 |
} |
| 90 |
|
| 91 |
/** |
| 92 |
* Creates a default phase set that covers all the provisioning operations. |
| 93 |
* Phases can be specified for inclusion. |
| 94 |
* |
| 95 |
* @param include - A set of bit options that specify the phases to include. |
| 96 |
* See {@link PhaseSetFactory} for possible options |
| 97 |
* @return the {@link PhaseSet} |
| 98 |
*/ |
| 99 |
public static final IPhaseSet createPhaseSetIncluding(String[] include) { |
| 100 |
if (include == null || include.length == 0) |
| 101 |
return new PhaseSet(new Phase[0]); |
| 102 |
List<String> includeList = Arrays.asList(include); |
| 103 |
ArrayList<Phase> phases = new ArrayList<>(); |
| 104 |
if (includeList.contains(PHASE_COLLECT)) |
| 105 |
phases.add(new Collect(100)); |
| 106 |
if (includeList.contains(PHASE_CHECK_TRUST)) |
| 107 |
phases.add(new CheckTrust(10)); |
| 108 |
if (includeList.contains(PHASE_UNCONFIGURE)) |
| 109 |
phases.add(new Unconfigure(10, forcedUninstall)); |
| 110 |
if (includeList.contains(PHASE_UNINSTALL)) |
| 111 |
phases.add(new Uninstall(50, forcedUninstall)); |
| 112 |
if (includeList.contains(PHASE_PROPERTY)) |
| 113 |
phases.add(new Property(1)); |
| 114 |
if (includeList.contains(PHASE_INSTALL)) |
| 115 |
phases.add(new Install(50)); |
| 116 |
if (includeList.contains(PHASE_CONFIGURE)) |
| 117 |
phases.add(new Configure(10)); |
| 118 |
return new PhaseSet(phases.toArray(new Phase[phases.size()])); |
| 119 |
} |
| 120 |
|
| 121 |
public static IPhaseSet createDefaultPhaseSet() { |
| 122 |
return createPhaseSetIncluding(ALL_PHASES_LIST.toArray(new String[ALL_PHASES_LIST.size()])); |
| 123 |
} |
| 124 |
|
| 125 |
public static ISizingPhaseSet createSizingPhaseSet() { |
| 126 |
return new SizingPhaseSet(); |
| 127 |
} |
| 128 |
} |