From 149315f48131e116cdcd9d6971ac4ca913dc5b9c Mon Sep 17 00:00:00 2001 From: Hannes Wellmann Date: Wed, 27 Sep 2023 21:48:19 +0200 Subject: [PATCH] Clean-up and simplify Slicer, PermissiveSlicer ans SimplePlanner --- .../p2/director/AttachmentHelper.java | 76 ++++------ .../p2/director/OptimizationFunction.java | 2 +- .../p2/director/PermissiveSlicer.java | 43 ++---- .../internal/p2/director/SimplePlanner.java | 139 +++++++----------- .../equinox/internal/p2/director/Slicer.java | 110 ++++++-------- .../repository/tools/MirrorApplication.java | 29 ++-- .../equinox/p2/tests/ant/MirrorTaskTest.java | 20 +-- .../p2/tests/planner/NegationTesting.java | 13 +- .../tests/planner/PermissiveSlicerTest.java | 24 +-- .../p2/tests/planner/SlicerBug365124Test.java | 2 +- .../equinox/p2/tests/planner/TychoUsage.java | 3 +- .../equinox/p2/tests/ql/PerformanceTest.java | 4 +- 12 files changed, 194 insertions(+), 271 deletions(-) diff --git a/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/AttachmentHelper.java b/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/AttachmentHelper.java index b9748f936c..3c4652ee00 100644 --- a/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/AttachmentHelper.java +++ b/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/AttachmentHelper.java @@ -14,64 +14,44 @@ package org.eclipse.equinox.internal.p2.director; import java.util.*; +import java.util.stream.Collectors; +import java.util.stream.Stream; import org.eclipse.equinox.p2.metadata.*; import org.eclipse.equinox.p2.query.QueryUtil; public class AttachmentHelper { private static final IInstallableUnitFragment[] NO_FRAGMENTS = new IInstallableUnitFragment[0]; - public static Collection attachFragments(Iterator toAttach, Map> fragmentsToIUs) { + public static Collection attachFragments(Stream toAttach, + Map> fragmentsToIUs) { Map fragmentBindings = new HashMap<>(); //Build a map inverse of the one provided in input (host --> List of fragments) Map> iusToFragment = new HashMap<>(fragmentsToIUs.size()); - for (Map.Entry> mapping : fragmentsToIUs.entrySet()) { - IInstallableUnitFragment fragment = mapping.getKey(); - List existingMatches = mapping.getValue(); - + fragmentsToIUs.forEach((fragment, existingMatches) -> { for (IInstallableUnit host : existingMatches) { - List potentialFragments = iusToFragment.get(host); - if (potentialFragments == null) { - potentialFragments = new ArrayList<>(); - iusToFragment.put(host, potentialFragments); - } - potentialFragments.add(fragment); + iusToFragment.computeIfAbsent(host, h -> new ArrayList<>()).add(fragment); } - } + }); - for (Map.Entry> entry : iusToFragment.entrySet()) { - IInstallableUnit hostIU = entry.getKey(); - List potentialIUFragments = entry.getValue(); - ArrayList applicableFragments = new ArrayList<>(); + iusToFragment.forEach((hostIU, potentialIUFragments) -> { + List applicableFragments = new ArrayList<>(); for (IInstallableUnitFragment potentialFragment : potentialIUFragments) { - if (hostIU.equals(potentialFragment)) + if (hostIU.equals(potentialFragment)) { continue; - + } // Check to make sure the host meets the requirements of the fragment Collection reqsFromFragment = potentialFragment.getHost(); - boolean match = true; - boolean requirementMatched = false; - for (Iterator iterator = reqsFromFragment.iterator(); iterator.hasNext() && match == true;) { - IRequirement reqs = iterator.next(); - requirementMatched = false; - if (hostIU.satisfies(reqs)) - requirementMatched = true; - if (requirementMatched == false) { - match = false; - break; - } - - } - if (match) { + if (reqsFromFragment.stream().allMatch(hostIU::satisfies)) { applicableFragments.add(potentialFragment); } } IInstallableUnitFragment theFragment = null; int specificityLevel = 0; - LinkedList fragments = new LinkedList<>(); + Deque fragments = new LinkedList<>(); for (IInstallableUnitFragment fragment : applicableFragments) { if (isTranslation(fragment)) { - fragments.add(fragment); + fragments.addLast(fragment); continue; } if (fragment.getHost().size() > specificityLevel) { @@ -79,29 +59,23 @@ public static Collection attachFragments(Iterator result = new HashSet<>(); - while (toAttach.hasNext()) { - IInstallableUnit iu = toAttach.next(); - if (iu == null) - continue; + return toAttach.filter(Objects::nonNull).map(iu -> { //just return fragments as they are if (QueryUtil.isFragment(iu)) { - result.add(iu); - continue; + return iu; } //return a new IU that combines the IU with its bound fragments - IInstallableUnitFragment[] fragments = fragmentBindings.get(iu); - if (fragments == null) - fragments = NO_FRAGMENTS; - result.add(MetadataFactory.createResolvedInstallableUnit(iu, fragments)); - } - return result; + IInstallableUnitFragment[] fragments = fragmentBindings.getOrDefault(iu, NO_FRAGMENTS); + return (MetadataFactory.createResolvedInstallableUnit(iu, fragments)); + }).collect(Collectors.toSet()); } private static boolean isTranslation(IInstallableUnitFragment fragment) { diff --git a/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/OptimizationFunction.java b/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/OptimizationFunction.java index 42672c6e9a..e6139038c3 100644 --- a/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/OptimizationFunction.java +++ b/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/OptimizationFunction.java @@ -48,7 +48,7 @@ public List> createOptimizationFunction(IInstal if (newRoots.isEmpty()) { transitiveClosure = Collections.emptySet(); } else { - IQueryable queryable = new Slicer(picker, selectionContext, false).slice(newRoots.toArray(new IInstallableUnit[newRoots.size()]), new NullProgressMonitor()); + IQueryable queryable = new Slicer(picker, selectionContext, false).slice(newRoots, null); if (queryable == null) { transitiveClosure = Collections.emptySet(); } else { diff --git a/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/PermissiveSlicer.java b/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/PermissiveSlicer.java index 2e0eb45a46..15eaf2b93a 100644 --- a/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/PermissiveSlicer.java +++ b/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/PermissiveSlicer.java @@ -17,6 +17,7 @@ import org.eclipse.equinox.internal.p2.metadata.RequiredCapability; import org.eclipse.equinox.p2.metadata.IInstallableUnit; import org.eclipse.equinox.p2.metadata.IRequirement; +import org.eclipse.equinox.p2.metadata.expression.IMatchExpression; import org.eclipse.equinox.p2.query.IQueryable; public class PermissiveSlicer extends Slicer { @@ -29,7 +30,7 @@ public class PermissiveSlicer extends Slicer { public PermissiveSlicer(IQueryable input, Map context, boolean includeOptionalDependencies, boolean everythingGreedy, boolean evalFilterTo, boolean considerOnlyStrictDependency, boolean onlyFilteredRequirements) { super(input, context, true); - this.considerFilter = (context != null && context.size() > 1) ? true : false; + this.considerFilter = context != null && context.size() > 1; this.includeOptionalDependencies = includeOptionalDependencies; this.everythingGreedy = everythingGreedy; this.evalFilterTo = evalFilterTo; @@ -39,45 +40,31 @@ public PermissiveSlicer(IQueryable input, Map @Override protected boolean isApplicable(IInstallableUnit iu) { - if (considerFilter) + if (considerFilter) { return super.isApplicable(iu); - if (iu.getFilter() == null) - return true; - return evalFilterTo; + } + return iu.getFilter() == null || evalFilterTo; } @Override protected boolean isApplicable(IRequirement req) { //Every filter in this method needs to continue except when the filter does not pass - if (!includeOptionalDependencies) - if (req.getMin() == 0) - return false; - - if (considerOnlyStrictDependency) { - if (!RequiredCapability.isStrictVersionRequirement(req.getMatches())) - return false; + if (!includeOptionalDependencies && req.getMin() == 0) { + return false; } - - //deal with filters - if (considerFilter) { - if (onlyFilteredRequirements && req.getFilter() == null) { - return false; - } - return super.isApplicable(req); + if (considerOnlyStrictDependency && !RequiredCapability.isStrictVersionRequirement(req.getMatches())) { + return false; } - if (req.getFilter() == null) { - if (onlyFilteredRequirements) - return false; - return true; + //deal with filters + IMatchExpression filter = req.getFilter(); + if (filter == null) { + return !onlyFilteredRequirements; } - return evalFilterTo; + return considerFilter ? filter.isMatch(selectionContext) : evalFilterTo; } @Override protected boolean isGreedy(IRequirement req) { - if (everythingGreedy) { - return true; - } - return super.isGreedy(req); + return everythingGreedy || super.isGreedy(req); } } diff --git a/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/SimplePlanner.java b/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/SimplePlanner.java index f06d4ea241..0541226c54 100644 --- a/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/SimplePlanner.java +++ b/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/SimplePlanner.java @@ -23,7 +23,6 @@ import static org.eclipse.equinox.internal.provisional.p2.director.RequestStatus.REMOVED; import java.lang.reflect.Method; -import java.net.URI; import java.util.*; import java.util.stream.Stream; import org.eclipse.core.runtime.*; @@ -47,7 +46,7 @@ import org.eclipse.osgi.util.NLS; public class SimplePlanner implements IPlanner { - private static boolean DEBUG = Tracing.DEBUG_PLANNER_OPERANDS; + private static final boolean DEBUG = Tracing.DEBUG_PLANNER_OPERANDS; private static final int ExpandWork = 12; private static final String INCLUDE_PROFILE_IUS = "org.eclipse.equinox.p2.internal.profileius"; //$NON-NLS-1$ @@ -156,15 +155,12 @@ private static IStatus convertExplanationToStatus(Set explanations) // for the PDE target platform into a general purpose profile. List forTargets = new ArrayList<>(0); for (Explanation next : explanations) { - if (next instanceof MissingIU) { - MissingIU missingIU = (MissingIU) next; - if (missingIU.req instanceof IRequiredCapability - && missingIU.req.getMatches().getParameters().length == 3 - && "A.PDE.Target.Platform".equals(((IRequiredCapability) missingIU.req).getNamespace())) {//$NON-NLS-1$ - // This IU requires the PDE target platform IU and it is missing. - // I.e. this IU is intended only for the PDE target platform. - forTargets.add(Status.error(Explanation.getUserReadableName(missingIU.iu))); - } + if (next instanceof MissingIU missingIU && missingIU.req instanceof IRequiredCapability requiredCapability + && requiredCapability.getMatches().getParameters().length == 3 + && "A.PDE.Target.Platform".equals(requiredCapability.getNamespace())) {//$NON-NLS-1$ + // This IU requires the PDE target platform IU and it is missing. + // I.e. this IU is intended only for the PDE target platform. + forTargets.add(Status.error(Explanation.getUserReadableName(missingIU.iu))); } } if (!forTargets.isEmpty()) { @@ -219,19 +215,11 @@ private static IStatus convertChangesToStatus(Map "Add"; //$NON-NLS-1$ + case REMOVED -> "Remove"; //$NON-NLS-1$ + default -> "UNKNOWN change type " + rs.getInitialRequestType(); //$NON-NLS-1$ + }; final IStatus status; if (!rs.isOK()) { String message = NLS.bind(Messages.Director_Unsatisfied_Change, change, @@ -366,10 +354,8 @@ private Collection gatherAvailableInstallableUnits(List props) { - if (props == null) - return true; - if (props.get(CONSIDER_METAREQUIREMENTS) == null - || "true".equalsIgnoreCase(props.get(CONSIDER_METAREQUIREMENTS))) //$NON-NLS-1$ + if (props == null) { return true; - return false; + } + return props.get(CONSIDER_METAREQUIREMENTS) == null + || Boolean.parseBoolean(props.get(CONSIDER_METAREQUIREMENTS)); } private boolean satisfyMetaRequirements(IProfile p) { @@ -429,8 +414,8 @@ private Object getSolutionFor(ProfileChangeRequest profileChangeRequest, Provisi sub.newChild(ExpandWork / 4)); Slicer slicer = new Slicer(new QueryableArray(availableIUs), newSelectionContext, satisfyMetaRequirements(profileChangeRequest.getProfileProperties())); - IQueryable slice = slicer - .slice(new IInstallableUnit[] { (IInstallableUnit) updatedPlan[0] }, sub.newChild(ExpandWork / 4)); + IQueryable slice = slicer.slice(List.of((IInstallableUnit) updatedPlan[0]), + sub.newChild(ExpandWork / 4)); if (slice == null) { IProvisioningPlan plan = engine.createPlan(profile, context); plan.setStatus(slicer.getStatus()); @@ -468,8 +453,8 @@ private Object getSolutionFor(ProfileChangeRequest profileChangeRequest, Provisi IStatus explanationStatus = convertExplanationToStatus(explanation); Map[] changes = buildDetailedErrors(profileChangeRequest); - Map requestChanges = (changes == null) ? null : changes[0]; - Map requestSideEffects = (changes == null) ? null : changes[1]; + Map requestChanges = changes[0]; + Map requestSideEffects = changes[1]; PlannerStatus plannerStatus = new PlannerStatus(explanationStatus, new RequestStatus(null, REMOVED, ERROR, explanation), requestChanges, requestSideEffects, null); @@ -508,16 +493,15 @@ public IProvisioningPlan getProvisioningPlan(IProfileChangeRequest request, Prov // Get the solution for the initial request Object resolutionResult = getSolutionFor(pcr, context, sub.newChild(ExpandWork / 2)); // a return value of a plan indicates failure when resolving so return. - if (resolutionResult instanceof IProvisioningPlan) { - return (IProvisioningPlan) resolutionResult; + if (resolutionResult instanceof IProvisioningPlan plan) { + return plan; } Projector projector = (Projector) resolutionResult; Collection newState = projector.extractSolution(); Collection fullState = new ArrayList<>(); fullState.addAll(newState); - newState = AttachmentHelper.attachFragments(newState.iterator(), - projector.getFragmentAssociation()); + newState = AttachmentHelper.attachFragments(newState.stream(), projector.getFragmentAssociation()); IProvisioningPlan temporaryPlan = generatePlan(projector, newState, pcr, context); projector.close(); @@ -646,8 +630,10 @@ private IProvisioningPlan createInstallerPlan(IProfile profile, ProfileChangeReq } if (satisfyMetaRequirements(profile) && !profile.getProfileId().equals(installerProfile.getProfileId())) { - return createInstallerPlanForCohostedCaseFromExternalInstaller(profile, initialRequest, initialPlan, - expectedState, initialContext, installerProfile, sub); + // co-hosted case from external installer + IProvisioningPlan planForProfile = generatePlan(null, expectedState, initialRequest, initialContext); + return createInstallerPlanForExternalInstaller(profile, initialRequest, planForProfile, expectedState, + initialContext, installerProfile, sub); } return createInstallerPlanForExternalInstaller(profile, initialRequest, initialPlan, expectedState, @@ -670,14 +656,6 @@ private boolean haveSameLocation(IProvisioningAgent agent1, IProvisioningAgent a return thisLocation.getRootLocation().equals(otherLocation.getRootLocation()); } - private IProvisioningPlan createInstallerPlanForCohostedCaseFromExternalInstaller(IProfile profile, - ProfileChangeRequest initialRequest, IProvisioningPlan initialPlan, Collection newState, - ProvisioningContext initialContext, IProfile agentProfile, SubMonitor sub) { - IProvisioningPlan planForProfile = generatePlan(null, newState, initialRequest, initialContext); - return createInstallerPlanForExternalInstaller(profile, initialRequest, planForProfile, newState, - initialContext, agentProfile, sub); - } - // Deal with the case where the agent profile is different than the one being // provisioned private IProvisioningPlan createInstallerPlanForExternalInstaller(IProfile targetedProfile, @@ -702,12 +680,12 @@ private IProvisioningPlan createInstallerPlanForExternalInstaller(IProfile targe agentRequest.add(actionsIU); if (previousActionsIU != null) agentRequest.remove(previousActionsIU); - Object externalInstallerPlan = getSolutionFor(agentRequest, initialContext, sub.newChild(10)); - if (externalInstallerPlan instanceof IProvisioningPlan - && ((IProvisioningPlan) externalInstallerPlan).getStatus().getSeverity() == ERROR) { + Object externalInstallerPlan = getSolutionFor(agentRequest, initialContext, sub.split(10)); + if (externalInstallerPlan instanceof IProvisioningPlan provPlan + && provPlan.getStatus().getSeverity() == ERROR) { MultiStatus externalInstallerStatus = new MultiStatus(PI_DIRECTOR, 0, Messages.Planner_can_not_install_preq, null); - externalInstallerStatus.add(((IProvisioningPlan) externalInstallerPlan).getStatus()); + externalInstallerStatus.add(provPlan.getStatus()); IProvisioningPlan plan = engine.createPlan(initialRequest.getProfile(), initialContext); plan.setStatus(externalInstallerStatus); IProvisioningPlan installerPlan = engine.createPlan(agentProfile, initialContext); @@ -728,7 +706,7 @@ private IProvisioningPlan createInstallerPlanForExternalInstaller(IProfile targe private IProvisioningPlan createInstallerPlanForCohostedCase(IProfile profile, ProfileChangeRequest initialRequest, IProvisioningPlan initialPlan, Collection unattachedState, Collection expectedState, ProvisioningContext initialContext, SubMonitor monitor) { - Collection metaRequirements = initialRequest.getRemovals().size() == 0 + Collection metaRequirements = initialRequest.getRemovals().isEmpty() ? areMetaRequirementsSatisfied(profile, expectedState, initialPlan) : extractMetaRequirements(expectedState, initialPlan); if (metaRequirements == null || metaRequirements.isEmpty()) @@ -749,28 +727,26 @@ private IProvisioningPlan createInstallerPlanForCohostedCase(IProfile profile, P for (String removedPropertie : removedProperties) { agentRequest.removeProfileProperty(removedPropertie); } - Map> removedIUProperties = initialRequest - .getInstallableUnitProfilePropertiesToRemove(); - for (Map.Entry> entry : removedIUProperties.entrySet()) { - for (String propKey : entry.getValue()) { - agentRequest.removeInstallableUnitProfileProperty(entry.getKey(), propKey); + initialRequest.getInstallableUnitProfilePropertiesToRemove().forEach((iu, propertyKeys) -> { + for (String propKey : propertyKeys) { + agentRequest.removeInstallableUnitProfileProperty(iu, propKey); } - } + }); if (previousMetaRequirementIU != null) agentRequest.remove(previousMetaRequirementIU); agentRequest.add(metaRequirementIU); ProvisioningContext agentCtx = new ProvisioningContext(agent); - agentCtx.setMetadataRepositories(new URI[0]); - ArrayList extraIUs = new ArrayList<>(unattachedState); + agentCtx.setMetadataRepositories(); + List extraIUs = new ArrayList<>(unattachedState); agentCtx.setExtraInstallableUnits(extraIUs); Object agentSolution = getSolutionFor(agentRequest, agentCtx, monitor.newChild(3)); - if (agentSolution instanceof IProvisioningPlan - && ((IProvisioningPlan) agentSolution).getStatus().getSeverity() == ERROR) { + if (agentSolution instanceof IProvisioningPlan solutionPlan + && solutionPlan.getStatus().getSeverity() == ERROR) { MultiStatus agentStatus = new MultiStatus(PI_DIRECTOR, 0, Messages.Planner_actions_and_software_incompatible, null); - agentStatus.add(((IProvisioningPlan) agentSolution).getStatus()); + agentStatus.add(solutionPlan.getStatus()); IProvisioningPlan plan = engine.createPlan(initialRequest.getProfile(), initialContext); plan.setStatus(agentStatus); IProvisioningPlan installerPlan = engine.createPlan(initialRequest.getProfile(), initialContext); @@ -783,7 +759,7 @@ private IProvisioningPlan createInstallerPlanForCohostedCase(IProfile profile, P // the profile and the solution we just computed Collection agentState = ((Projector) agentSolution).extractSolution(); agentState.remove(metaRequirementIU); // Remove the fake IU - agentState = AttachmentHelper.attachFragments(agentState.iterator(), + agentState = AttachmentHelper.attachFragments(agentState.stream(), ((Projector) agentSolution).getFragmentAssociation()); ProvisioningContext noRepoContext = createNoRepoContext(initialRequest); @@ -791,14 +767,13 @@ private IProvisioningPlan createInstallerPlanForCohostedCase(IProfile profile, P Object initialSolution = getSolutionFor( new ProfileChangeRequest(new EverythingOptionalProfile(initialRequest.getProfile())), noRepoContext, new NullProgressMonitor()); - if (initialSolution instanceof IProvisioningPlan) { + if (initialSolution instanceof IProvisioningPlan plan) { LogHelper.log(Status.error("The resolution of the previous state contained in profile " //$NON-NLS-1$ + initialRequest.getProfile().getProfileId() + " version " //$NON-NLS-1$ + initialRequest.getProfile().getTimestamp() + " failed.")); //$NON-NLS-1$ - return (IProvisioningPlan) initialSolution; + return plan; } - Iterator profileState = initialRequest.getProfile().query(QueryUtil.createIUAnyQuery(), null) - .iterator(); + var profileState = initialRequest.getProfile().query(QueryUtil.createIUAnyQuery(), null).stream(); Collection initialState = AttachmentHelper.attachFragments(profileState, ((Projector) initialSolution).getFragmentAssociation()); @@ -816,7 +791,7 @@ private IProvisioningPlan generatePlan(Projector newSolution, Collection profileState = request.getProfile().query(QueryUtil.createIUAnyQuery(), null) - .iterator(); + Stream profileState = request.getProfile().query(QueryUtil.createIUAnyQuery(), null).stream(); Collection initialState = AttachmentHelper.attachFragments(profileState, ((Projector) initialSolution).getFragmentAssociation()); @@ -841,8 +815,8 @@ private IProvisioningPlan generatePlan(Projector newSolution, Collection(request.getProfile() .query(QueryUtil.createIUAnyQuery(), new NullProgressMonitor()).toUnmodifiableSet())); @@ -868,14 +842,13 @@ private IInstallableUnit createIUForMetaRequirements(IProfile profile, Collectio description.setVersion(version); description.addRequirements(metaRequirements); - ArrayList providedCapabilities = new ArrayList<>(); + List providedCapabilities = new ArrayList<>(); IProvidedCapability providedCapability = MetadataFactory .createProvidedCapability(IInstallableUnit.NAMESPACE_IU_ID, id, version); providedCapabilities.add(providedCapability); description.addProvidedCapabilities(providedCapabilities); - IInstallableUnit actionsIU = MetadataFactory.createInstallableUnit(description); - return actionsIU; + return MetadataFactory.createInstallableUnit(description); } private IInstallableUnit createIURepresentingTheProfile(Set allRequirements) { @@ -908,7 +881,7 @@ private Object[] updatePlannerInfo(ProfileChangeRequest profileChangeRequest, Pr } // Remove the iu properties associated to the ius removed and the iu properties // being removed as well - if (removalRequested.size() != 0) { + if (!removalRequested.isEmpty()) { for (Iterator iterator = alreadyInstalled.iterator(); iterator.hasNext();) { IInstallableUnit iu = iterator.next(); for (IInstallableUnit removed : removalRequested) { diff --git a/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/Slicer.java b/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/Slicer.java index b751aacc55..cfbad1cc07 100644 --- a/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/Slicer.java +++ b/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/Slicer.java @@ -31,42 +31,42 @@ public class Slicer { private final IQueryable possibilites; private final boolean considerMetaRequirements; protected final IInstallableUnit selectionContext; - private final Map> slice; //The IUs that have been considered to be part of the problem - private final MultiStatus result; + /** The IUs that have been considered to be part of the problem */ + private final Map> slice = new HashMap<>(); + private final MultiStatus result = new MultiStatus(Slicer.class, 0, Messages.Planner_Problems_resolving_plan); - private LinkedList toProcess; - private Set considered; //IUs to add to the slice - private Set nonGreedyIUs = new HashSet<>(); //IUs that are brought in by non greedy dependencies + private Queue toProcess; + private Set considered; // IUs to add to the slice + private final Set nonGreedyIUs = new HashSet<>(); // IUs that are brought in by non greedy dependencies public Slicer(IQueryable input, Map context, boolean considerMetaRequirements) { this(input, InstallableUnit.contextIU(context), considerMetaRequirements); } - public Slicer(IQueryable possibilites, IInstallableUnit selectionContext, boolean considerMetaRequirements) { + public Slicer(IQueryable possibilites, IInstallableUnit selectionContext, + boolean considerMetaRequirements) { this.possibilites = possibilites; this.selectionContext = selectionContext; this.considerMetaRequirements = considerMetaRequirements; - slice = new HashMap<>(); - result = new MultiStatus(DirectorActivator.PI_DIRECTOR, IStatus.OK, Messages.Planner_Problems_resolving_plan, null); } - public IQueryable slice(IInstallableUnit[] ius, IProgressMonitor monitor) { + public IQueryable slice(Collection ius, IProgressMonitor monitor) { + monitor = IProgressMonitor.nullSafe(monitor); try { long start = 0; if (DEBUG) { start = System.currentTimeMillis(); System.out.println("Start slicing: " + start); //$NON-NLS-1$ } - validateInput(ius); - considered = new HashSet<>(Arrays.asList(ius)); + considered = new HashSet<>(ius); toProcess = new LinkedList<>(considered); while (!toProcess.isEmpty()) { if (monitor.isCanceled()) { result.merge(Status.CANCEL_STATUS); throw new OperationCanceledException(); } - processIU(toProcess.removeFirst()); + processIU(toProcess.remove()); } computeNonGreedyIUs(); if (DEBUG) { @@ -76,25 +76,26 @@ public IQueryable slice(IInstallableUnit[] ius, IProgressMonit } catch (IllegalStateException e) { result.add(Status.error(e.getMessage(), e)); } - if (Tracing.DEBUG && result.getSeverity() != IStatus.OK) + if (Tracing.DEBUG && result.getSeverity() != IStatus.OK) { LogHelper.log(result); - if (result.getSeverity() == IStatus.ERROR) + } + if (result.getSeverity() == IStatus.ERROR) { return null; + } return new QueryableArray(considered); } private void computeNonGreedyIUs() { IQueryable queryable = new QueryableArray(considered); - Iterator it = queryable.query(QueryUtil.ALL_UNITS, new NullProgressMonitor()).iterator(); - while (it.hasNext()) { - IInstallableUnit iu = it.next().unresolved(); + for (IInstallableUnit iu : queryable.query(QueryUtil.ALL_UNITS, new NullProgressMonitor())) { Collection reqs = getRequirements(iu); for (IRequirement req : reqs) { - if (!isApplicable(iu, req)) + if (!isApplicable(iu, req)) { continue; - + } if (!isGreedy(iu, req)) { - nonGreedyIUs.addAll(queryable.query(QueryUtil.createMatchQuery(req.getMatches()), null).toUnmodifiableSet()); + nonGreedyIUs.addAll( + queryable.query(QueryUtil.createMatchQuery(req.getMatches()), null).toUnmodifiableSet()); } } } @@ -104,8 +105,9 @@ public MultiStatus getStatus() { return result; } - //This is a shortcut to simplify the error reporting when the filter of the ius we are being asked to install does not pass - private void validateInput(IInstallableUnit[] ius) { + // This is a shortcut to simplify the error reporting when the filter of the ius + // we are being asked to install does not pass + private void validateInput(Collection ius) { for (IInstallableUnit iu : ius) { if (!isApplicable(iu)) { throw new IllegalStateException(NLS.bind(Messages.Explanation_missingRootFilter, iu)); @@ -131,30 +133,16 @@ protected boolean isApplicable(IInstallableUnit iu) { protected void processIU(IInstallableUnit iu) { iu = iu.unresolved(); - - Map iuSlice = slice.get(iu.getId()); - if (iuSlice == null) { - - iuSlice = new HashMap<>(); - slice.put(iu.getId(), iuSlice); - } + Map iuSlice = slice.computeIfAbsent(iu.getId(), i -> new HashMap<>()); iuSlice.put(iu.getVersion(), iu); if (!isApplicable(iu)) { return; } - Collection reqs = getRequirements(iu); - if (reqs.isEmpty()) - return; for (IRequirement req : reqs) { - if (!isApplicable(iu, req)) - continue; - - if (!isGreedy(iu, req)) { - continue; + if (isApplicable(iu, req) && isGreedy(iu, req)) { + expandRequirement(iu, req); } - - expandRequirement(iu, req); } } @@ -169,58 +157,58 @@ protected boolean isGreedy(IRequirement req) { private Collection getRequirements(IInstallableUnit iu) { boolean isPatch = iu instanceof IInstallableUnitPatch; boolean isFragment = iu instanceof IInstallableUnitFragment; - //Short-circuit for the case of an IInstallableUnit - if ((!isFragment) && (!isPatch) && iu.getMetaRequirements().size() == 0) + // Short-circuit for the case of an IInstallableUnit + if ((!isFragment) && (!isPatch) && iu.getMetaRequirements().isEmpty()) { return iu.getRequirements(); + } - ArrayList aggregatedRequirements = new ArrayList<>(iu.getRequirements().size() + iu.getMetaRequirements().size() + (isFragment ? ((IInstallableUnitFragment) iu).getHost().size() : 0) + (isPatch ? ((IInstallableUnitPatch) iu).getRequirementsChange().size() : 0)); + List aggregatedRequirements = new ArrayList<>(iu.getRequirements().size() + + iu.getMetaRequirements().size() + (isFragment ? ((IInstallableUnitFragment) iu).getHost().size() : 0) + + (isPatch ? ((IInstallableUnitPatch) iu).getRequirementsChange().size() : 0)); aggregatedRequirements.addAll(iu.getRequirements()); - if (iu instanceof IInstallableUnitFragment) { - aggregatedRequirements.addAll(((IInstallableUnitFragment) iu).getHost()); + if (iu instanceof IInstallableUnitFragment iuFragment) { + aggregatedRequirements.addAll(iuFragment.getHost()); } - - if (iu instanceof InstallableUnitPatch) { - IInstallableUnitPatch patchIU = (IInstallableUnitPatch) iu; + if (iu instanceof InstallableUnitPatch patchIU) { List changes = patchIU.getRequirementsChange(); - for (IRequirementChange change : changes) + for (IRequirementChange change : changes) { aggregatedRequirements.add(change.newValue()); + } } - - if (considerMetaRequirements) + if (considerMetaRequirements) { aggregatedRequirements.addAll(iu.getMetaRequirements()); + } return aggregatedRequirements; } private void expandRequirement(IInstallableUnit iu, IRequirement req) { - if (req.getMax() == 0) + if (req.getMax() == 0) { return; + } IQueryResult matches = possibilites.query(QueryUtil.createMatchQuery(req.getMatches()), null); int validMatches = 0; for (IInstallableUnit match : matches) { - if (!isApplicable(match)) + if (!isApplicable(match)) { continue; + } validMatches++; Map iuSlice = slice.get(match.getId()); - if (iuSlice == null || !iuSlice.containsKey(match.getVersion())) - consider(match); + if ((iuSlice == null || !iuSlice.containsKey(match.getVersion())) && considered.add(match)) { + toProcess.add(match); + } } - if (validMatches == 0) { if (req.getMin() == 0) { - if (DEBUG) + if (DEBUG) { System.out.println("No IU found to satisfy optional dependency of " + iu + " on req " + req); //$NON-NLS-1$//$NON-NLS-2$ + } } else { result.add(Status.warning(NLS.bind(Messages.Planner_Unsatisfied_dependency, iu, req))); } } } - private void consider(IInstallableUnit match) { - if (considered.add(match)) - toProcess.addLast(match); - } - Set getNonGreedyIUs() { return nonGreedyIUs; } diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/MirrorApplication.java b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/MirrorApplication.java index 72ccc01c06..d9762df9a8 100644 --- a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/MirrorApplication.java +++ b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/MirrorApplication.java @@ -101,9 +101,7 @@ public Object start(IApplicationContext context) throws Exception { } @Override - public void stop() { - // TODO Auto-generated method stub - + public void stop() { // nothing to do } /* @@ -119,7 +117,7 @@ public void setInitializationData(IConfigurationElement config, String propertyN } } - public void initializeFromArguments(String[] args) throws Exception { + public void initializeFromArguments(String[] args) { if (args == null) return; @@ -323,7 +321,7 @@ private void initializeIUs() throws ProvisionException { while (queryResult.hasNext()) sourceIUs.add(queryResult.next()); /* old metadata mirroring app did not throw an exception here */ - if (sourceIUs.size() == 0 && destinationMetadataRepository != null && metadataOrArtifacts == null) + if (sourceIUs.isEmpty() && destinationMetadataRepository != null && metadataOrArtifacts == null) throw new ProvisionException(Messages.MirrorApplication_no_IUs); } } @@ -363,18 +361,19 @@ private IQueryable performResolution(IProgressMonitor monitor) String profileId = "MirrorApplication-" + System.currentTimeMillis(); //$NON-NLS-1$ IProfile profile = registry.addProfile(profileId, slicingOptions.getFilter()); IPlanner planner = Activator.getAgent().getService(IPlanner.class); - if (planner == null) + if (planner == null) { throw new IllegalStateException(); + } IProfileChangeRequest pcr = planner.createChangeRequest(profile); pcr.addAll(sourceIUs); IProvisioningPlan plan = planner.getProvisioningPlan(pcr, null, monitor); registry.removeProfile(profileId); - @SuppressWarnings("unchecked") - IQueryable[] arr = new IQueryable[plan.getInstallerPlan() == null ? 1 : 2]; - arr[0] = plan.getAdditions(); - if (plan.getInstallerPlan() != null) - arr[1] = plan.getInstallerPlan().getAdditions(); - return new CompoundQueryable<>(arr); + List> queriables = new ArrayList<>(); + queriables.add(plan.getAdditions()); + if (plan.getInstallerPlan() != null) { + queriables.add(plan.getInstallerPlan().getAdditions()); + } + return new CompoundQueryable<>(queriables); } private IQueryable slice(IProgressMonitor monitor) throws ProvisionException { @@ -384,8 +383,7 @@ private IQueryable slice(IProgressMonitor monitor) throws Prov return performResolution(monitor); Slicer slicer = createSlicer(slicingOptions); - IQueryable slice = slicer.slice(sourceIUs.toArray(new IInstallableUnit[sourceIUs.size()]), - monitor); + IQueryable slice = slicer.slice(sourceIUs, monitor); if (slice != null && slicingOptions.latestVersionOnly()) { IQueryResult queryResult = slice.query(QueryUtil.createLatestIUQuery(), monitor); @@ -401,10 +399,9 @@ private IQueryable slice(IProgressMonitor monitor) throws Prov } protected Slicer createSlicer(SlicingOptions options) { - PermissiveSlicer slicer = new PermissiveSlicer(getCompositeMetadataRepository(), options.getFilter(), + return new PermissiveSlicer(getCompositeMetadataRepository(), options.getFilter(), options.includeOptionalDependencies(), options.isEverythingGreedy(), options.forceFilterTo(), options.considerStrictDependencyOnly(), options.followOnlyFilteredRequirements()); - return slicer; } public void setSlicingOptions(SlicingOptions options) { diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/ant/MirrorTaskTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/ant/MirrorTaskTest.java index 5db1f5cbaa..7ddd801c30 100644 --- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/ant/MirrorTaskTest.java +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/ant/MirrorTaskTest.java @@ -24,11 +24,11 @@ import java.util.Arrays; import java.util.Collections; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.Properties; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; - import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.URIUtil; @@ -360,7 +360,7 @@ public void testSlicingFollowStrict() { Map p = getSliceProperties(); p.put("org.eclipse.update.install.features", String.valueOf(true)); PermissiveSlicer slicer = new PermissiveSlicer(repo, p, true, true, true, true, false); - IQueryable result = slicer.slice(new IInstallableUnit[] {iu}, new NullProgressMonitor()); + IQueryable result = slicer.slice(List.of(iu), new NullProgressMonitor()); assertEquals("Different number of IUs", queryResultSize(result.query(QueryUtil.createIUAnyQuery(), new NullProgressMonitor())), getIUCount(destinationRepo)); try { @@ -388,7 +388,7 @@ public void testSlicingIncludeNonGreedy() { runAntTask(); PermissiveSlicer slicer = new PermissiveSlicer(repo, Collections.emptyMap(), true, false, true, false, false); - IQueryable result = slicer.slice(new IInstallableUnit[] {iu}, new NullProgressMonitor()); + IQueryable result = slicer.slice(List.of(iu), new NullProgressMonitor()); assertEquals("Different number of IUs", queryResultSize(result.query(QueryUtil.createIUAnyQuery(), new NullProgressMonitor())), getIUCount(destinationRepo)); try { @@ -418,7 +418,7 @@ public void testSlicingIncludeOptionalDependencies() { Map p = getSliceProperties(); p.put("org.eclipse.update.install.features", String.valueOf(true)); PermissiveSlicer slicer = new PermissiveSlicer(repo, p, false, true, true, false, false); - IQueryable result = slicer.slice(new IInstallableUnit[] {iu}, new NullProgressMonitor()); + IQueryable result = slicer.slice(List.of(iu), new NullProgressMonitor()); assertEquals("Different number of IUs", queryResultSize(result.query(QueryUtil.createIUAnyQuery(), new NullProgressMonitor())), getIUCount(destinationRepo)); try { assertIUContentEquals("IUs differ", result, getMetadataRepositoryManager().loadRepository(destinationRepo, null)); @@ -446,7 +446,7 @@ public void testSlicingFilter() { Map p = getSliceProperties(); PermissiveSlicer slicer = new PermissiveSlicer(repo, p, true, true, true, false, false); - IQueryable result = slicer.slice(new IInstallableUnit[] {iu}, new NullProgressMonitor()); + IQueryable result = slicer.slice(List.of(iu), new NullProgressMonitor()); assertEquals("Different number of IUs", queryResultSize(result.query(QueryUtil.createIUAnyQuery(), new NullProgressMonitor())), getIUCount(destinationRepo)); try { assertIUContentEquals("IUs differ", result, getMetadataRepositoryManager().loadRepository(destinationRepo, null)); @@ -478,7 +478,7 @@ public void testSlicingPlatformFilter() { Map p = getSliceProperties(); p.put("org.eclipse.update.install.features", String.valueOf(true)); PermissiveSlicer slicer = new PermissiveSlicer(repo, p, true, true, true, false, false); - IQueryable result = slicer.slice(new IInstallableUnit[] {iu}, new NullProgressMonitor()); + IQueryable result = slicer.slice(List.of(iu), new NullProgressMonitor()); assertEquals("Different number of IUs", queryResultSize(result.query(QueryUtil.createIUAnyQuery(), new NullProgressMonitor())), getIUCount(destinationRepo)); try { assertIUContentEquals("IUs differ", result, getMetadataRepositoryManager().loadRepository(destinationRepo, null)); @@ -510,7 +510,7 @@ public void testSlicingIncludeFeaturesFalse() { Map p = getSliceProperties(); PermissiveSlicer slicer = new PermissiveSlicer(repo, p, true, true, true, false, false); - IQueryable result = slicer.slice(new IInstallableUnit[] {iu}, new NullProgressMonitor()); + IQueryable result = slicer.slice(List.of(iu), new NullProgressMonitor()); assertEquals("Different number of IUs", queryResultSize(result.query(QueryUtil.createIUAnyQuery(), new NullProgressMonitor())), getIUCount(destinationRepo)); try { assertIUContentEquals("IUs differ", result, getMetadataRepositoryManager().loadRepository(destinationRepo, null)); @@ -542,7 +542,7 @@ public void testSlicingMetadataAndArtifactsMirrored() { Map p = getSliceProperties(); PermissiveSlicer slicer = new PermissiveSlicer(repo, p, true, true, true, false, false); - IQueryable result = slicer.slice(new IInstallableUnit[] {iu}, new NullProgressMonitor()); + IQueryable result = slicer.slice(List.of(iu), new NullProgressMonitor()); assertEquals("Different number of IUs", queryResultSize(result.query(QueryUtil.createIUAnyQuery(), new NullProgressMonitor())), getIUCount(destinationRepo)); assertEquals("Different number of ArtifactKeys", getArtifactKeyCount(result.query(QueryUtil.createIUAnyQuery(), new NullProgressMonitor())), getArtifactKeyCount(destinationRepo)); @@ -578,7 +578,7 @@ public void testMirrorSlicedIUtoArtifact() { Map p = getSliceProperties(); PermissiveSlicer slicer = new PermissiveSlicer(repo, p, true, true, true, false, false); - IQueryable result = slicer.slice(new IInstallableUnit[] {iu}, new NullProgressMonitor()); + IQueryable result = slicer.slice(List.of(iu), new NullProgressMonitor()); assertEquals("Different number of ArtifactKeys", getArtifactKeyCount(result.query(QueryUtil.createIUAnyQuery(), new NullProgressMonitor())), getArtifactKeyCount(destinationRepo)); assertArtifactKeyContentEquals("Different ArtifactKeys", result.query(QueryUtil.createIUAnyQuery(), new NullProgressMonitor()), destinationRepo); @@ -611,7 +611,7 @@ public void testMirrorSlicedMultipleIUsToArtifact() { Map p = getSliceProperties(); PermissiveSlicer slicer = new PermissiveSlicer(repo, p, true, true, true, false, false); - IQueryable result = slicer.slice(new IInstallableUnit[] {iu, iu2}, new NullProgressMonitor()); + IQueryable result = slicer.slice(List.of(iu, iu2), new NullProgressMonitor()); assertEquals("Different number of ArtifactKeys", getArtifactKeyCount(result.query(QueryUtil.createIUAnyQuery(), new NullProgressMonitor())), getArtifactKeyCount(destinationRepo)); assertArtifactKeyContentEquals("Different ArtifactKeys", result.query(QueryUtil.createIUAnyQuery(), new NullProgressMonitor()), destinationRepo); diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/NegationTesting.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/NegationTesting.java index e12cf22285..3d07f17fe0 100644 --- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/NegationTesting.java +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/NegationTesting.java @@ -18,6 +18,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; +import java.util.List; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.equinox.internal.p2.director.ProfileChangeRequest; import org.eclipse.equinox.internal.p2.director.Slicer; @@ -98,7 +99,7 @@ public void testNot4() { // Verify that the slice includes iu3 because the requirement from iu1 is a range including the provided capability of iu3. Slicer slicer = new Slicer(repo, Collections.emptyMap(), false); - IQueryable slice = slicer.slice(new IInstallableUnit[] {iu1}, new NullProgressMonitor()); + IQueryable slice = slicer.slice(List.of(iu1), new NullProgressMonitor()); assertEquals(3, queryResultSize(slice.query(QueryUtil.createIUAnyQuery(), new NullProgressMonitor()))); //Verify that the resolution succeeds and does not return iu3 since it is excluded by the requirement of iu1 @@ -156,7 +157,7 @@ public void testNot5() { //Test the slicer. The slice will not contain iu3 because none of the range of iu1 cause it to be brought in. Slicer slicer = new Slicer(repo, Collections.emptyMap(), false); - IQueryable slice = slicer.slice(new IInstallableUnit[] {iu1}, new NullProgressMonitor()); + IQueryable slice = slicer.slice(List.of(iu1), new NullProgressMonitor()); assertEquals(0, queryResultSize(slice.query(QueryUtil.createIUQuery("ProviderOf1_1_1"), new NullProgressMonitor()))); assertEquals(2, queryResultSize(slice.query(QueryUtil.createIUAnyQuery(), new NullProgressMonitor()))); } @@ -188,7 +189,7 @@ public void testNot6() { //Test the slicer. The slice will not contain iu3 because none of the range of iu1 cause it to be brought in. Slicer slicer = new Slicer(repo, Collections.emptyMap(), false); - IQueryable slice = slicer.slice(new IInstallableUnit[] {iu1}, new NullProgressMonitor()); + IQueryable slice = slicer.slice(List.of(iu1), new NullProgressMonitor()); assertEquals(0, queryResultSize(slice.query(QueryUtil.createIUQuery("ProviderOf1_1_1"), new NullProgressMonitor()))); assertEquals(2, queryResultSize(slice.query(QueryUtil.createIUAnyQuery(), new NullProgressMonitor()))); @@ -242,7 +243,7 @@ public void testNot7() { // Verify that the slice includes iu3 because the requirement from iu1 is a range including the provided capability of iu3. Slicer slicer = new Slicer(repo, Collections.emptyMap(), false); - IQueryable slice = slicer.slice(new IInstallableUnit[] {iu1}, new NullProgressMonitor()); + IQueryable slice = slicer.slice(List.of(iu1), new NullProgressMonitor()); assertEquals(3, queryResultSize(slice.query(QueryUtil.createIUAnyQuery(), new NullProgressMonitor()))); //Verify that the resolution succeeds and does not return iu3 since it is excluded by the requirement of iu1 @@ -311,12 +312,12 @@ public void testNot8() { // Verify that the slice includes iu3 Slicer slicer = new Slicer(repo, Collections.emptyMap(), false); - IQueryable slice = slicer.slice(new IInstallableUnit[] {iu1, iu4}, new NullProgressMonitor()); + IQueryable slice = slicer.slice(List.of(iu1, iu4), new NullProgressMonitor()); assertEquals(4, queryResultSize(slice.query(QueryUtil.createIUAnyQuery(), new NullProgressMonitor()))); // Verify that the slice includes iu3 Slicer slicer2 = new Slicer(repo, Collections.emptyMap(), false); - IQueryable slice2 = slicer2.slice(new IInstallableUnit[] {iu4}, new NullProgressMonitor()); + IQueryable slice2 = slicer2.slice(List.of(iu4), new NullProgressMonitor()); assertEquals(2, queryResultSize(slice2.query(QueryUtil.createIUAnyQuery(), new NullProgressMonitor()))); //Verify that the resolution succeeds and does not return iu3 since it is excluded by the requirement of iu1 diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/PermissiveSlicerTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/PermissiveSlicerTest.java index 1d9ea29827..d0846562b8 100644 --- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/PermissiveSlicerTest.java +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/PermissiveSlicerTest.java @@ -16,6 +16,7 @@ import java.io.File; import java.util.Collections; import java.util.HashMap; +import java.util.List; import java.util.Map; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.equinox.internal.p2.director.PermissiveSlicer; @@ -44,7 +45,7 @@ public void testSliceRCPOut() { PermissiveSlicer slicer = new PermissiveSlicer(repo, Collections.emptyMap(), true, false, true, false, false); IQueryResult c = repo.query(QueryUtil.createIUQuery("org.eclipse.rcp.feature.group"), new NullProgressMonitor()); IInstallableUnit iu = c.iterator().next(); - IQueryable result = slicer.slice(new IInstallableUnit[] {iu}, new NullProgressMonitor()); + IQueryable result = slicer.slice(List.of(iu), new NullProgressMonitor()); assertNotNull(result); queryResultSize(result.query(QueryUtil.createIUAnyQuery(), new NullProgressMonitor())); assertEquals(66, queryResultSize(result.query(QueryUtil.createIUAnyQuery(), new NullProgressMonitor()))); @@ -57,7 +58,7 @@ public void testSliceRCPWithOptionalPieces() { PermissiveSlicer slicer = new PermissiveSlicer(repo, Collections.emptyMap(), false, false, true, false, false); IQueryResult c = repo.query(QueryUtil.createIUQuery("org.eclipse.rcp.feature.group"), new NullProgressMonitor()); IInstallableUnit iu = c.iterator().next(); - IQueryable result = slicer.slice(new IInstallableUnit[] {iu}, new NullProgressMonitor()); + IQueryable result = slicer.slice(List.of(iu), new NullProgressMonitor()); assertNotNull(result); queryResultSize(result.query(QueryUtil.createIUAnyQuery(), new NullProgressMonitor())); assertEquals(64, queryResultSize(result.query(QueryUtil.createIUAnyQuery(), new NullProgressMonitor()))); @@ -68,7 +69,7 @@ public void testSliceRCPWithIgnoringGreed() { PermissiveSlicer slicer = new PermissiveSlicer(repo, Collections.emptyMap(), false, true, true, false, false); IQueryResult c = repo.query(QueryUtil.createIUQuery("org.eclipse.rcp.feature.group"), new NullProgressMonitor()); IInstallableUnit iu = c.iterator().next(); - IQueryable result = slicer.slice(new IInstallableUnit[] {iu}, new NullProgressMonitor()); + IQueryable result = slicer.slice(List.of(iu), new NullProgressMonitor()); assertNotNull(result); queryResultSize(result.query(QueryUtil.createIUAnyQuery(), new NullProgressMonitor())); assertEquals(64, queryResultSize(result.query(QueryUtil.createIUAnyQuery(), new NullProgressMonitor()))); @@ -83,7 +84,7 @@ public void testSliceRCPWithFilter() { PermissiveSlicer slicer = new PermissiveSlicer(repo, p, true, true, false, false, false); IQueryResult c = repo.query(QueryUtil.createIUQuery("org.eclipse.rcp.feature.group"), new NullProgressMonitor()); IInstallableUnit iu = c.iterator().next(); - IQueryable result = slicer.slice(new IInstallableUnit[] {iu}, new NullProgressMonitor()); + IQueryable result = slicer.slice(List.of(iu), new NullProgressMonitor()); assertNotNull(result); queryResultSize(result.query(QueryUtil.createIUAnyQuery(), new NullProgressMonitor())); assertEquals(0, queryResultSize(result.query(QueryUtil.createIUQuery("org.eclipse.swt.motif.linux.x86"), new NullProgressMonitor()))); @@ -99,7 +100,7 @@ public void testStrictDependency() { PermissiveSlicer slicer = new PermissiveSlicer(repo, p, true, false, false, true, false); IQueryResult c = repo.query(QueryUtil.createIUQuery("org.eclipse.rcp.feature.group"), new NullProgressMonitor()); IInstallableUnit iu = c.iterator().next(); - IQueryable result = slicer.slice(new IInstallableUnit[] {iu}, new NullProgressMonitor()); + IQueryable result = slicer.slice(List.of(iu), new NullProgressMonitor()); assertNotNull(result); queryResultSize(result.query(QueryUtil.createIUAnyQuery(), new NullProgressMonitor())); assertEquals(0, queryResultSize(result.query(QueryUtil.createIUQuery("org.eclipse.ecf"), new NullProgressMonitor()))); @@ -111,7 +112,7 @@ public void testExtractPlatformIndependentPieces() { PermissiveSlicer slicer = new PermissiveSlicer(repo, Collections.emptyMap(), true, false, false, false, false); IQueryResult c = repo.query(QueryUtil.createIUQuery("org.eclipse.rcp.feature.group"), new NullProgressMonitor()); IInstallableUnit iu = c.iterator().next(); - IQueryable result = slicer.slice(new IInstallableUnit[] {iu}, new NullProgressMonitor()); + IQueryable result = slicer.slice(List.of(iu), new NullProgressMonitor()); assertNotNull(result); queryResultSize(result.query(QueryUtil.createIUAnyQuery(), new NullProgressMonitor())); assertEquals(32, queryResultSize(result.query(QueryUtil.createIUAnyQuery(), new NullProgressMonitor()))); @@ -127,7 +128,7 @@ public void testMetaRequirements() { IInstallableUnit a = createIUWithMetaRequirement("A", DEFAULT_VERSION, true, NO_REQUIRES, metaReq); PermissiveSlicer slicer = new PermissiveSlicer(createTestMetdataRepository(new IInstallableUnit[] {a, act1}), Collections.emptyMap(), true, false, false, false, false); - IQueryable result = slicer.slice(new IInstallableUnit[] {a}, new NullProgressMonitor()); + IQueryable result = slicer.slice(List.of(a), new NullProgressMonitor()); assertEquals(1, queryResultSize(result.query(QueryUtil.createIUQuery("Action1"), null))); } @@ -139,7 +140,7 @@ public void testValidateIU() { PermissiveSlicer slicer = new PermissiveSlicer(repo, p, true, false, false, true, false); IQueryResult c = repo.query(QueryUtil.createIUQuery("org.eclipse.swt.cocoa.macosx"), new NullProgressMonitor()); IInstallableUnit iu = c.iterator().next(); - assertNull(slicer.slice(new IInstallableUnit[] {iu}, new NullProgressMonitor())); + assertNull(slicer.slice(List.of(iu), new NullProgressMonitor())); assertNotOK(slicer.getStatus()); } @@ -147,7 +148,7 @@ public void testMissingNecessaryPiece() { IRequirement[] req = createRequiredCapabilities("B", "B", new VersionRange("[0.0.0, 1.0.0]")); IInstallableUnit iuA = createIU("A", DEFAULT_VERSION, null, req, NO_PROVIDES, NO_PROPERTIES, null, NO_TP_DATA, true); PermissiveSlicer slicer = new PermissiveSlicer(createTestMetdataRepository(new IInstallableUnit[] {iuA}), Collections.emptyMap(), true, false, false, false, false); - IQueryable result = slicer.slice(new IInstallableUnit[] {iuA}, new NullProgressMonitor()); + IQueryable result = slicer.slice(List.of(iuA), new NullProgressMonitor()); assertNotNull(result); assertNotOK(slicer.getStatus()); } @@ -160,7 +161,7 @@ public void testExtractOnlyPlatformSpecificForOnePlatform() { PermissiveSlicer slicer = new PermissiveSlicer(repo, p, true, false, false, false, true); IQueryResult c = repo.query(QueryUtil.createIUQuery("org.eclipse.rcp.feature.group"), new NullProgressMonitor()); IInstallableUnit iu = c.iterator().next(); - IQueryResult resultCollector = slicer.slice(new IInstallableUnit[] {iu}, new NullProgressMonitor()).query(QueryUtil.createIUAnyQuery(), new NullProgressMonitor()); + IQueryResult resultCollector = slicer.slice(List.of(iu), new NullProgressMonitor()).query(QueryUtil.createIUAnyQuery(), new NullProgressMonitor()); assertEquals(3, queryResultSize(resultCollector)); } @@ -168,7 +169,8 @@ public void testExtractOnlyPlatformSpecific() { PermissiveSlicer slicer = new PermissiveSlicer(repo, Collections.emptyMap(), true, false, true, false, true); IQueryResult c = repo.query(QueryUtil.createIUQuery("org.eclipse.rcp.feature.group"), new NullProgressMonitor()); IInstallableUnit iu = c.iterator().next(); - IQueryResult resultCollector = slicer.slice(new IInstallableUnit[] {iu}, new NullProgressMonitor()).query(QueryUtil.createIUAnyQuery(), new NullProgressMonitor()); + IQueryResult resultCollector = slicer.slice(List.of(iu), new NullProgressMonitor()) + .query(QueryUtil.createIUAnyQuery(), new NullProgressMonitor()); assertEquals(35, queryResultSize(resultCollector)); } diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/SlicerBug365124Test.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/SlicerBug365124Test.java index c8c2c20baa..7e8f9fd7ae 100644 --- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/SlicerBug365124Test.java +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/SlicerBug365124Test.java @@ -54,7 +54,7 @@ private Map getProperties() { public void testSlice() { Slicer slicer = new Slicer(getProfile(IProfileRegistry.SELF), getProperties(), true); IQueryResult c = repo.query(QueryUtil.createIUAnyQuery(), new NullProgressMonitor()); - slicer.slice(c.toArray(IInstallableUnit.class), new NullProgressMonitor()); + slicer.slice(c.toUnmodifiableSet(), new NullProgressMonitor()); assertNotOK("1.0", slicer.getStatus()); } diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/TychoUsage.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/TychoUsage.java index edcf5fa72d..aed5648bbe 100644 --- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/TychoUsage.java +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/planner/TychoUsage.java @@ -5,6 +5,7 @@ import java.util.Collection; import java.util.HashMap; import java.util.HashSet; +import java.util.List; import java.util.Map; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.NullProgressMonitor; @@ -72,7 +73,7 @@ public void testTychoUsage() throws ProvisionException, URISyntaxException { context.put("org.eclipse.update.install.features", "true"); Slicer slicer = new Slicer(repo, context, false); - IQueryable slice = slicer.slice(new IInstallableUnit[] {topLevelIU}, new NullProgressMonitor()); + IQueryable slice = slicer.slice(List.of(topLevelIU), new NullProgressMonitor()); Projector p = new Projector(slice, context, new HashSet<>(), false); p.encode(topLevelIU, new IInstallableUnit[0], new Collector<>(), newRoots, new NullProgressMonitor()); diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/ql/PerformanceTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/ql/PerformanceTest.java index 734550617f..27911c3cca 100644 --- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/ql/PerformanceTest.java +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/ql/PerformanceTest.java @@ -367,7 +367,7 @@ public void testSlicerPerformance() throws Exception { startTime = System.currentTimeMillis(); Slicer slicer = new Slicer(new QueryableArray(gatherAvailableInstallableUnits(repo)), env, false); - slice = slicer.slice(roots, new NullProgressMonitor()); + slice = slicer.slice(r.toUnmodifiableSet(), new NullProgressMonitor()); sliceTime += (System.currentTimeMillis() - startTime); } // Check the size of the last slice to verify that it's the same as the traverse size @@ -413,7 +413,7 @@ public void testPermissiveSlicerPerformance() throws Exception { startTime = System.currentTimeMillis(); Slicer slicer = new PermissiveSlicer(repo, env, true, true, true, false, false); - slice = slicer.slice(roots, new NullProgressMonitor()); + slice = slicer.slice(r.toUnmodifiableSet(), new NullProgressMonitor()); sliceTime += (System.currentTimeMillis() - startTime); } // Check the size of the last slice to verify that it's the same as the traverse size