From 4fc3821bc12bef1c77f9e3855d625bf655b0f0bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20L=C3=A4ubrich?= Date: Thu, 25 Jan 2024 12:55:23 +0100 Subject: [PATCH] Migrate p2 engine to agent properties Now that agent properties are possible we should use them in the engine, to not rely on only static OSGi context properties. --- .../.settings/.api_filters | 47 +++++++++++ .../META-INF/MANIFEST.MF | 2 +- .../internal/p2/engine/DebugHelper.java | 2 +- .../equinox/internal/p2/engine/Engine.java | 4 +- .../internal/p2/engine/EngineActivator.java | 14 +++- .../equinox/internal/p2/engine/PhaseSet.java | 83 ++++++++++++++----- .../p2/engine/SimpleProfileRegistry.java | 2 +- .../p2/engine/SurrogateProfileHandler.java | 12 +-- .../p2/engine/phases/AuthorityChecker.java | 2 +- .../p2/engine/phases/CertificateChecker.java | 2 +- .../equinox/p2/engine/PhaseSetFactory.java | 55 +++++------- .../equinox/p2/tests/engine/PhaseSetTest.java | 2 +- 12 files changed, 156 insertions(+), 71 deletions(-) create mode 100644 bundles/org.eclipse.equinox.p2.engine/.settings/.api_filters diff --git a/bundles/org.eclipse.equinox.p2.engine/.settings/.api_filters b/bundles/org.eclipse.equinox.p2.engine/.settings/.api_filters new file mode 100644 index 0000000000..cd22b134bf --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.engine/.settings/.api_filters @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/bundles/org.eclipse.equinox.p2.engine/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.p2.engine/META-INF/MANIFEST.MF index e96219af21..18c3eb4c23 100644 --- a/bundles/org.eclipse.equinox.p2.engine/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.equinox.p2.engine/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %pluginName Bundle-SymbolicName: org.eclipse.equinox.p2.engine;singleton:=true -Bundle-Version: 2.9.100.qualifier +Bundle-Version: 2.10.0.qualifier Bundle-Activator: org.eclipse.equinox.internal.p2.engine.EngineActivator Bundle-Vendor: %providerName Bundle-Localization: plugin diff --git a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/DebugHelper.java b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/DebugHelper.java index f4472ab2a6..0e2f03e3f9 100644 --- a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/DebugHelper.java +++ b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/DebugHelper.java @@ -129,7 +129,7 @@ public static String formatInstallableUnitOperand(InstallableUnitOperand iuOpera public static String formatPhaseSet(PhaseSet phaseSet) { StringBuilder buffer = new StringBuilder(phaseSet.getClass().getName()); - buffer.append(DebugHelper.formatArray(Arrays.asList(phaseSet.getPhases()), false, false)); + buffer.append(DebugHelper.formatArray(Arrays.asList(phaseSet.getPhaseIds()), false, false)); return buffer.toString(); } diff --git a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/Engine.java b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/Engine.java index 3669861af9..a8bc2a6d5e 100644 --- a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/Engine.java +++ b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/Engine.java @@ -83,7 +83,7 @@ public IStatus perform(IProfile iprofile, IPhaseSet phases, Operand[] operands, String property = context.getProperty(ProvisioningContext.CHECK_AUTHORITIES); if (property == null) { // Allow a system property to force the property. - property = EngineActivator.getContext().getProperty(ProvisioningContext.CHECK_AUTHORITIES); + property = EngineActivator.getProperty(ProvisioningContext.CHECK_AUTHORITIES, agent); if (property == null) { // Otherwise, if we are checking trust, also check the authorities. if (Arrays.asList(phases.getPhaseIds()).contains(PhaseSetFactory.PHASE_CHECK_TRUST)) { @@ -136,7 +136,7 @@ protected IStatus validate(IProfile iprofile, PhaseSet phaseSet, Operand[] opera monitor = new NullProgressMonitor(); ActionManager actionManager = agent.getService(ActionManager.class); - return phaseSet.validate(actionManager, iprofile, operands, context, monitor); + return phaseSet.validate(actionManager, iprofile, operands, context, agent, monitor); } @Override diff --git a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/EngineActivator.java b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/EngineActivator.java index 7b73545f55..1af7af2f28 100644 --- a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/EngineActivator.java +++ b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/EngineActivator.java @@ -7,7 +7,7 @@ * https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 - * + * * Contributors: * IBM Corporation - initial API and implementation * Red Hat, Inc - fragments support added @@ -22,6 +22,7 @@ import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; import org.eclipse.equinox.internal.p2.core.helpers.LogHelper; +import org.eclipse.equinox.p2.core.IProvisioningAgent; import org.eclipse.osgi.util.NLS; import org.osgi.framework.BundleActivator; import org.osgi.framework.BundleContext; @@ -175,4 +176,15 @@ private static ArrayList getInfoFilesFromLocation(String locationToCheck) } return result; } + + public static String getProperty(String key, IProvisioningAgent agent) { + if (agent != null) { + return agent.getProperty(key); + } + BundleContext bc = EngineActivator.getContext(); + if (bc != null) { + return bc.getProperty(key); + } + return System.getProperty(key); + } } diff --git a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/PhaseSet.java b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/PhaseSet.java index 71d68e852e..9674a8ccdc 100644 --- a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/PhaseSet.java +++ b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/PhaseSet.java @@ -15,36 +15,51 @@ import java.util.*; import org.eclipse.core.runtime.*; +import org.eclipse.equinox.internal.p2.engine.phases.*; +import org.eclipse.equinox.p2.core.IProvisioningAgent; import org.eclipse.equinox.p2.engine.*; import org.eclipse.equinox.p2.engine.spi.ProvisioningAction; import org.eclipse.osgi.util.NLS; public class PhaseSet implements IPhaseSet { - private final Phase[] phases; + private static final Set SUPPORTED_PHASES = Set.of(PhaseSetFactory.PHASE_COLLECT, + PhaseSetFactory.PHASE_UNCONFIGURE, PhaseSetFactory.PHASE_UNINSTALL, PhaseSetFactory.PHASE_PROPERTY, + PhaseSetFactory.PHASE_CHECK_TRUST, PhaseSetFactory.PHASE_INSTALL, PhaseSetFactory.PHASE_CONFIGURE); + + private Phase[] phases; private boolean isRunning = false; private boolean isPaused = false; + private String[] phaseIds; public PhaseSet(Phase[] phases) { - if (phases == null) + if (phases == null) { throw new IllegalArgumentException(Messages.null_phases); - + } this.phases = phases; } + public PhaseSet(String[] phases) { + if (phases == null) { + throw new IllegalArgumentException(Messages.null_phases); + } + this.phaseIds = Arrays.stream(phases).filter(SUPPORTED_PHASES::contains).toArray(String[]::new); + } + public final MultiStatus perform(EngineSession session, Operand[] operands, IProgressMonitor monitor) { MultiStatus status = new MultiStatus(EngineActivator.ID, IStatus.OK, null, null); - int[] weights = getProgressWeights(operands); + Phase[] array = getPhases(session.getAgent()); + int[] weights = getProgressWeights(operands, array); int totalWork = getTotalWork(weights); SubMonitor pm = SubMonitor.convert(monitor, totalWork); try { isRunning = true; - for (int i = 0; i < phases.length; i++) { + for (int i = 0; i < array.length; i++) { if (pm.isCanceled()) { status.add(Status.CANCEL_STATUS); return status; } - Phase phase = phases[i]; + Phase phase = array[i]; phase.actionManager = session.getAgent().getService(ActionManager.class); try { phase.perform(status, session, operands, pm.newChild(weights[i])); @@ -80,9 +95,9 @@ public final MultiStatus perform(EngineSession session, Operand[] operands, IPro } public synchronized boolean pause() { - if (isRunning && !isPaused) { + if (isRunning && !isPaused && this.phases != null) { isPaused = true; - for (Phase phase : phases) { + for (Phase phase : this.phases) { phase.setPaused(isPaused); } return true; @@ -91,9 +106,9 @@ public synchronized boolean pause() { } public synchronized boolean resume() { - if (isRunning && isPaused) { + if (isRunning && isPaused && this.phases != null) { isPaused = false; - for (Phase phase : phases) { + for (Phase phase : this.phases) { phase.setPaused(isPaused); } return true; @@ -101,9 +116,10 @@ public synchronized boolean resume() { return false; } - public final IStatus validate(ActionManager actionManager, IProfile profile, Operand[] operands, ProvisioningContext context, IProgressMonitor monitor) { + public final IStatus validate(ActionManager actionManager, IProfile profile, Operand[] operands, + ProvisioningContext context, IProvisioningAgent agent, IProgressMonitor monitor) { Set missingActions = new HashSet<>(); - for (Phase phase2 : phases) { + for (Phase phase2 : getPhases(agent)) { Phase phase = phase2; phase.actionManager = actionManager; try { @@ -151,14 +167,14 @@ private int getTotalWork(int[] weights) { return sum; } - private int[] getProgressWeights(Operand[] operands) { - int[] weights = new int[phases.length]; - for (int i = 0; i < phases.length; i += 1) { + private int[] getProgressWeights(Operand[] operands, Phase[] array) { + int[] weights = new int[array.length]; + for (int i = 0; i < array.length; i += 1) { if (operands.length > 0) //alter weights according to the number of operands applicable to that phase - weights[i] = (phases[i].weight * countApplicable(phases[i], operands) / operands.length); + weights[i] = (array[i].weight * countApplicable(array[i], operands) / operands.length); else - weights[i] = phases[i].weight; + weights[i] = array[i].weight; } return weights; } @@ -174,14 +190,37 @@ private int countApplicable(Phase phase, Operand[] operands) { @Override public String[] getPhaseIds() { - String[] ids = new String[phases.length]; - for (int i = 0; i < ids.length; i++) { - ids[i] = phases[i].phaseId; + if (phaseIds != null) { + return phaseIds.clone(); } - return ids; + if (phases != null) { + return Arrays.stream(phases).map(p -> p.phaseId).toArray(String[]::new); + } + return new String[0]; } - public Phase[] getPhases() { + private Phase[] getPhases(IProvisioningAgent agent) { + if (phases == null) { + boolean forcedUninstall = Boolean + .parseBoolean(EngineActivator.getProperty("org.eclipse.equinox.p2.engine.forcedUninstall", agent)); //$NON-NLS-1$ + List includeList = Arrays.asList(phaseIds); + List list = new ArrayList<>(); + if (includeList.contains(PhaseSetFactory.PHASE_COLLECT)) + list.add(new Collect(100)); + if (includeList.contains(PhaseSetFactory.PHASE_CHECK_TRUST)) + list.add(new CheckTrust(10)); + if (includeList.contains(PhaseSetFactory.PHASE_UNCONFIGURE)) + list.add(new Unconfigure(10, forcedUninstall)); + if (includeList.contains(PhaseSetFactory.PHASE_UNINSTALL)) + list.add(new Uninstall(50, forcedUninstall)); + if (includeList.contains(PhaseSetFactory.PHASE_PROPERTY)) + list.add(new Property(1)); + if (includeList.contains(PhaseSetFactory.PHASE_INSTALL)) + list.add(new Install(50)); + if (includeList.contains(PhaseSetFactory.PHASE_CONFIGURE)) + list.add(new Configure(10)); + this.phases = list.toArray(Phase[]::new); + } return phases; } } diff --git a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/SimpleProfileRegistry.java b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/SimpleProfileRegistry.java index cb15a71c7d..2f196ee9b6 100644 --- a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/SimpleProfileRegistry.java +++ b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/SimpleProfileRegistry.java @@ -635,7 +635,7 @@ public void setEventBus(IProvisioningEventBus bus) { */ private boolean shouldGzipFile(Profile profile) { //check system property controlling compression - String format = EngineActivator.getContext().getProperty(EngineActivator.PROP_PROFILE_FORMAT); + String format = EngineActivator.getProperty(EngineActivator.PROP_PROFILE_FORMAT, agent); if (format != null && format.equals(EngineActivator.PROFILE_FORMAT_UNCOMPRESSED)) return false; diff --git a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/SurrogateProfileHandler.java b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/SurrogateProfileHandler.java index 3d9ffa548a..ae2ca24830 100644 --- a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/SurrogateProfileHandler.java +++ b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/SurrogateProfileHandler.java @@ -54,7 +54,8 @@ public class SurrogateProfileHandler implements ISurrogateProfileHandler { private SoftReference cachedProfile; - private static void addSharedProfileBaseIUs(final IProfile sharedProfile, final Profile userProfile) { + private static void addSharedProfileBaseIUs(final IProfile sharedProfile, final Profile userProfile, + IProvisioningAgent agent) { IQuery rootIUQuery = QueryUtil.createMatchQuery( // "profileProperties[$0] == 'true' || (touchpointType != null && touchpointType.id == $1)", //$NON-NLS-1$ IProfile.PROP_PROFILE_ROOT_IU, NATIVE_TOUCHPOINT_TYPE); @@ -62,8 +63,7 @@ private static void addSharedProfileBaseIUs(final IProfile sharedProfile, final for (IInstallableUnit iu : rootIUs) { userProfile.addInstallableUnit(iu); userProfile.addInstallableUnitProperties(iu, sharedProfile.getInstallableUnitProperties(iu)); - String profileLockedIUSystemProperty = EngineActivator.getContext() - .getProperty(IProfile.PROP_PROFILE_LOCKED_IU); + String profileLockedIUSystemProperty = EngineActivator.getProperty(IProfile.PROP_PROFILE_LOCKED_IU, agent); if (profileLockedIUSystemProperty == null) { userProfile.setInstallableUnitProperty(iu, IProfile.PROP_PROFILE_LOCKED_IU, IU_LOCKED); } else { @@ -150,7 +150,7 @@ public SurrogateProfileHandler(IProvisioningAgent agent) { private synchronized SimpleProfileRegistry getProfileRegistry() { if (profileRegistry == null) { - String installArea = EngineActivator.getContext().getProperty(OSGI_INSTALL_AREA); + String installArea = EngineActivator.getProperty(OSGI_INSTALL_AREA, agent); try { URL registryURL = new URL(installArea + P2_ENGINE_DIR + SimpleProfileRegistry.DEFAULT_STORAGE_DIR); File sharedRegistryDirectory = URIUtil.toFile(URIUtil.toURI(registryURL)); @@ -233,7 +233,7 @@ public IProfile createProfile(String id) { userProfile.setProperty(PROP_SURROGATE, Boolean.TRUE.toString()); userProfile.setSurrogateProfileHandler(this); updateProperties(sharedProfile, userProfile); - addSharedProfileBaseIUs(sharedProfile, userProfile); + addSharedProfileBaseIUs(sharedProfile, userProfile, agent); return userProfile; } @@ -279,7 +279,7 @@ public IProfile createProfile(String id) { userProfile.setProperty(PROP_SURROGATE, Boolean.TRUE.toString()); userProfile.setSurrogateProfileHandler(this); updateProperties(sharedProfile, userProfile); - addSharedProfileBaseIUs(sharedProfile, userProfile); + addSharedProfileBaseIUs(sharedProfile, userProfile, agent); return userProfile; } diff --git a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/phases/AuthorityChecker.java b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/phases/AuthorityChecker.java index bdd791e8c6..118e041419 100644 --- a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/phases/AuthorityChecker.java +++ b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/phases/AuthorityChecker.java @@ -179,7 +179,7 @@ public Set getPreferenceTrustedAuthorities() { var result = new LinkedHashSet(); var preferences = getEnngineProfilePreferences(); if (preferences != null) { - String defaultValue = EngineActivator.getContext().getProperty("p2.trustedAuthorities"); + String defaultValue = EngineActivator.getProperty("p2.trustedAuthorities", agent); if (defaultValue == null) { defaultValue = "https://download.eclipse.org https://archive.eclipse.org"; } else { diff --git a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/phases/CertificateChecker.java b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/phases/CertificateChecker.java index f521c70029..f9d34ebe06 100644 --- a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/phases/CertificateChecker.java +++ b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/phases/CertificateChecker.java @@ -490,7 +490,7 @@ public Set getPreferenceTrustedCertificates() { * Return the policy on unsigned content. */ private String getUnsignedContentPolicy() { - String policy = EngineActivator.getContext().getProperty(EngineActivator.PROP_UNSIGNED_POLICY); + String policy = EngineActivator.getProperty(EngineActivator.PROP_UNSIGNED_POLICY, agent); if (policy == null) policy = EngineActivator.UNSIGNED_PROMPT; return policy; diff --git a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/p2/engine/PhaseSetFactory.java b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/p2/engine/PhaseSetFactory.java index 68e292f723..f649d6b9b0 100644 --- a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/p2/engine/PhaseSetFactory.java +++ b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/p2/engine/PhaseSetFactory.java @@ -7,7 +7,7 @@ * https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 - * + * * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ @@ -15,7 +15,6 @@ import java.util.*; import org.eclipse.equinox.internal.p2.engine.*; -import org.eclipse.equinox.internal.p2.engine.phases.*; /** * @since 2.0 @@ -23,58 +22,61 @@ */ public class PhaseSetFactory { - private static final boolean forcedUninstall = Boolean.parseBoolean(EngineActivator.getContext().getProperty("org.eclipse.equinox.p2.engine.forcedUninstall")); //$NON-NLS-1$ - /** * A phase id (value "checkTrust") describing the certificate trust check phase. * This phase examines the code signing certificates of the artifacts being installed * to ensure they are signed and trusted by the running system. */ - public static String PHASE_CHECK_TRUST = "checkTrust"; //$NON-NLS-1$ + public static final String PHASE_CHECK_TRUST = "checkTrust"; //$NON-NLS-1$ /** * A phase id (value "collect") describing the collect phase. * This phase gathers all the artifacts to be installed, typically by copying them * from some repository into a suitable local location for the application being installed. */ - public static String PHASE_COLLECT = "collect"; //$NON-NLS-1$ + public static final String PHASE_COLLECT = "collect"; //$NON-NLS-1$ /** * A phase id (value "configure") describing the configuration phase. * This phase writes configuration data related to the software being provisioned. * Until configuration occurs the end user of the software will be have access to * the installed functionality. */ - public static String PHASE_CONFIGURE = "configure"; //$NON-NLS-1$ + public static final String PHASE_CONFIGURE = "configure"; //$NON-NLS-1$ /** * A phase id (value "install") describing the install phase. * This phase performs any necessary transformations on the downloaded * artifacts to put them in the correct shape for the running application, such * as decompressing or moving content, setting file permissions, etc). */ - public static String PHASE_INSTALL = "install"; //$NON-NLS-1$ + public static final String PHASE_INSTALL = "install"; //$NON-NLS-1$ /** * A phase id (value "property") describing the property modification phase. * This phase performs changes to profile properties. */ - public static String PHASE_PROPERTY = "property"; //$NON-NLS-1$ + public static final String PHASE_PROPERTY = "property"; //$NON-NLS-1$ /** * A phase id (value "unconfigure") describing the unconfigure phase. * This phase removes configuration data related to the software being removed. * This phase is the inverse of the changes performed in the configure phase. */ - public static String PHASE_UNCONFIGURE = "unconfigure"; //$NON-NLS-1$ + public static final String PHASE_UNCONFIGURE = "unconfigure"; //$NON-NLS-1$ /** * A phase id (value "uninstall") describing the uninstall phase. * This phase removes artifacts from the system being provisioned that are * no longer required in the new profile. */ - public static String PHASE_UNINSTALL = "uninstall"; //$NON-NLS-1$ + public static final String PHASE_UNINSTALL = "uninstall"; //$NON-NLS-1$ + + /** + * @since 2.10 + */ + public static final String NATIVE_ARTIFACTS = "nativeArtifacts"; //$NON-NLS-1$ private static final List ALL_PHASES_LIST = Arrays.asList(new String[] {PHASE_COLLECT, PHASE_UNCONFIGURE, PHASE_UNINSTALL, PHASE_PROPERTY, PHASE_CHECK_TRUST, PHASE_INSTALL, PHASE_CONFIGURE}); /** * Creates a default phase set that covers all the provisioning operations. * Phases can be specified for exclusion. - * + * * @param exclude - A set of bit options that specify the phases to exclude. * See {@link PhaseSetFactory} for possible options * @return the {@link PhaseSet} @@ -91,35 +93,20 @@ public static final IPhaseSet createDefaultPhaseSetExcluding(String[] exclude) { /** * Creates a default phase set that covers all the provisioning operations. * Phases can be specified for inclusion. - * - * @param include - A set of bit options that specify the phases to include. - * See {@link PhaseSetFactory} for possible options + * + * @param include - A set of bit options that specify the phases to include. See + * {@link PhaseSetFactory} for possible options * @return the {@link PhaseSet} */ public static final IPhaseSet createPhaseSetIncluding(String[] include) { - if (include == null || include.length == 0) + if (include == null || include.length == 0) { return new PhaseSet(new Phase[0]); - List includeList = Arrays.asList(include); - ArrayList phases = new ArrayList<>(); - if (includeList.contains(PHASE_COLLECT)) - phases.add(new Collect(100)); - if (includeList.contains(PHASE_CHECK_TRUST)) - phases.add(new CheckTrust(10)); - if (includeList.contains(PHASE_UNCONFIGURE)) - phases.add(new Unconfigure(10, forcedUninstall)); - if (includeList.contains(PHASE_UNINSTALL)) - phases.add(new Uninstall(50, forcedUninstall)); - if (includeList.contains(PHASE_PROPERTY)) - phases.add(new Property(1)); - if (includeList.contains(PHASE_INSTALL)) - phases.add(new Install(50)); - if (includeList.contains(PHASE_CONFIGURE)) - phases.add(new Configure(10)); - return new PhaseSet(phases.toArray(new Phase[phases.size()])); + } + return new PhaseSet(include); } public static IPhaseSet createDefaultPhaseSet() { - return createPhaseSetIncluding(ALL_PHASES_LIST.toArray(new String[ALL_PHASES_LIST.size()])); + return createPhaseSetIncluding(ALL_PHASES_LIST.toArray(String[]::new)); } public static ISizingPhaseSet createSizingPhaseSet() { diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/engine/PhaseSetTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/engine/PhaseSetTest.java index ed40ada6a3..265e333233 100644 --- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/engine/PhaseSetTest.java +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/engine/PhaseSetTest.java @@ -75,7 +75,7 @@ public PhaseSetTest() { public void testNullPhases() { assertThrows(IllegalArgumentException.class, () -> - new PhaseSet(null) { + new PhaseSet((Phase[]) null) { // empty PhaseSet }); }