diff options
author | Alexander Kurtakov | 2019-06-28 13:12:15 +0000 |
---|---|---|
committer | Alexander Kurtakov | 2019-07-01 13:09:05 +0000 |
commit | bb27e7b3fc060a62805281221eac19e21803b40f (patch) | |
tree | 8e38f4d2a6c119f777e9d0963e7fc85cb5a06a4a /bundles/org.eclipse.equinox.p2.director | |
parent | 0406e1d0248310054a35232f5840b5c3c50ab5fd (diff) | |
download | rt.equinox.p2-bb27e7b3fc060a62805281221eac19e21803b40f.tar.gz rt.equinox.p2-bb27e7b3fc060a62805281221eac19e21803b40f.tar.xz rt.equinox.p2-bb27e7b3fc060a62805281221eac19e21803b40f.zip |
Convert to the generic IProvisioningAgent.getService()
Change-Id: If595ceb183461e5a9565d58ccd6a432291f2281b
Signed-off-by: Alexander Kurtakov <akurtako@redhat.com>
Diffstat (limited to 'bundles/org.eclipse.equinox.p2.director')
4 files changed, 32 insertions, 35 deletions
diff --git a/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/DirectorComponent.java b/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/DirectorComponent.java index 9294a565a..3014510f2 100644 --- a/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/DirectorComponent.java +++ b/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/DirectorComponent.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 * Sonatype, Inc. - ongoing development @@ -23,8 +23,8 @@ public class DirectorComponent implements IAgentServiceFactory { @Override public Object createService(IProvisioningAgent agent) { - IEngine engine = (IEngine) agent.getService(IEngine.SERVICE_NAME); - IPlanner planner = (IPlanner) agent.getService(IPlanner.SERVICE_NAME); + IEngine engine = agent.getService(IEngine.class); + IPlanner planner = agent.getService(IPlanner.class); return new SimpleDirector(engine, planner); } diff --git a/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/ProfileChangeRequest.java b/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/ProfileChangeRequest.java index 1d5368104..3bf49a105 100644 --- a/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/ProfileChangeRequest.java +++ b/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/ProfileChangeRequest.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 * Sonatype, Inc. - ongoing development @@ -25,7 +25,7 @@ import org.eclipse.equinox.p2.planner.IProfileChangeRequest; /** * @noreference This class was unintentionally left in the provisional API package and - * is intended to be made internal in Eclipse 3.7. Clients should create and manipulate + * is intended to be made internal in Eclipse 3.7. Clients should create and manipulate * profile change requests via the API {@link IPlanner#createChangeRequest(IProfile)} * and methods on {@link IProfileChangeRequest}. */ @@ -41,7 +41,7 @@ public class ProfileChangeRequest implements Cloneable, IProfileChangeRequest { private ArrayList<IRequirement> additionalRequirements; public static ProfileChangeRequest createByProfileId(IProvisioningAgent agent, String profileId) { - IProfileRegistry profileRegistry = (IProfileRegistry) agent.getService(IProfileRegistry.SERVICE_NAME); + IProfileRegistry profileRegistry = agent.getService(IProfileRegistry.class); if (profileRegistry == null) throw new IllegalStateException(Messages.Planner_no_profile_registry); IProfile profile = profileRegistry.getProfile(profileId); @@ -181,7 +181,7 @@ public class ProfileChangeRequest implements Cloneable, IProfileChangeRequest { return propertiesToAdd; } - // map of iu->list of property keys to be removed for an iu + // map of iu->list of property keys to be removed for an iu public Map<IInstallableUnit, List<String>> getInstallableUnitProfilePropertiesToRemove() { if (iuPropertiesToRemove == null) return Collections.emptyMap(); 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 160281a80..e78041838 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 @@ -78,8 +78,8 @@ public class SimplePlanner implements IPlanner { } catch (Throwable e) { // ignore } - for (int i = 0; i < operands.length; i++) { - Tracing.debug(operands[i].toString()); + for (Object operand : operands) { + Tracing.debug(operand.toString()); } } @@ -147,7 +147,7 @@ public class SimplePlanner implements IPlanner { /** * Converts a list of {@link Projector#getExplanation(IProgressMonitor) resolver * explanations} to a human-readable status object - * + * * @param explanations List of resolver explanations ordered by logical * causality. I.e. read from start to end should forms * logical chain of statements as to why resolution failed. @@ -205,7 +205,7 @@ public class SimplePlanner implements IPlanner { /** * TODO Find a way to emit INFO status. The issue is that all * {@link IStatus#isOK()} calls will fail. - * + * * @param requestChanges * @param requestSideEffects * @return the {@link IStatus} @@ -260,8 +260,8 @@ public class SimplePlanner implements IPlanner { // First deal with profile properties to remove. String[] toRemove = profileChangeRequest.getPropertiesToRemove(); - for (int i = 0; i < toRemove.length; i++) { - plan.setProfileProperty(toRemove[i], null); + for (String element : toRemove) { + plan.setProfileProperty(element, null); } // Now deal with profile property changes/additions Map<String, String> propertyChanges = profileChangeRequest.getPropertiesToAdd(); @@ -340,9 +340,9 @@ public class SimplePlanner implements IPlanner { ProvisioningContext context, IProgressMonitor monitor) { Map<String, IInstallableUnit> resultsMap = new HashMap<>(); if (additionalSource != null) { - for (int i = 0; i < additionalSource.length; i++) { - String key = additionalSource[i].getId() + "_" + additionalSource[i].getVersion().toString(); //$NON-NLS-1$ - resultsMap.put(key, additionalSource[i]); + for (IInstallableUnit element : additionalSource) { + String key = element.getId() + "_" + element.getVersion().toString(); //$NON-NLS-1$ + resultsMap.put(key, element); } } if (context == null) { @@ -357,8 +357,7 @@ public class SimplePlanner implements IPlanner { IQueryable<IInstallableUnit> queryable = context.getMetadata(sub.newChild(500)); IQueryResult<IInstallableUnit> matches = queryable.query(QueryUtil.createIUQuery(null, VersionRange.emptyRange), sub.newChild(500)); - for (Iterator<IInstallableUnit> it = matches.iterator(); it.hasNext();) { - IInstallableUnit iu = it.next(); + for (IInstallableUnit iu : matches) { String key = iu.getId() + "_" + iu.getVersion().toString(); //$NON-NLS-1$ IInstallableUnit currentIU = resultsMap.get(key); if (currentIU == null || hasHigherFidelity(iu, currentIU)) @@ -379,8 +378,8 @@ public class SimplePlanner implements IPlanner { public SimplePlanner(IProvisioningAgent agent) { Assert.isNotNull(agent); this.agent = agent; - this.engine = (IEngine) agent.getService(IEngine.SERVICE_NAME); - this.profileRegistry = (IProfileRegistry) agent.getService(IProfileRegistry.SERVICE_NAME); + this.engine = agent.getService(IEngine.class); + this.profileRegistry = agent.getService(IProfileRegistry.class); Assert.isNotNull(engine); Assert.isNotNull(profileRegistry); } @@ -400,11 +399,11 @@ public class SimplePlanner implements IPlanner { /** * Performs a provisioning request resolution - * + * * @param profileChangeRequest The requested change. * @param context The context for the resolution pass * @param monitor - * + * * @return Return a {@link Projector} that captures the complete future state of * the profile that satisfies the request. If the request can't be * satisfied return an {@link IProvisioningPlan} where the error is @@ -606,8 +605,7 @@ public class SimplePlanner implements IPlanner { allMetaRequirements.addAll(iu.getMetaRequirements()); } IQueryResult<IInstallableUnit> queryResult = plan.getRemovals().query(QueryUtil.createIUAnyQuery(), null); - for (Iterator<IInstallableUnit> iterator = queryResult.iterator(); iterator.hasNext();) { - IInstallableUnit iu = iterator.next(); + for (IInstallableUnit iu : queryResult) { allMetaRequirements.addAll(iu.getMetaRequirements()); } return allMetaRequirements; @@ -631,8 +629,8 @@ public class SimplePlanner implements IPlanner { return initialPlan; } - IProfile installerProfile = ((IProfileRegistry) ((IProvisioningAgent) agent - .getService(IProvisioningAgent.INSTALLER_AGENT)).getService(IProfileRegistry.SERVICE_NAME)) + IProfile installerProfile = ((IProvisioningAgent) agent + .getService(IProvisioningAgent.INSTALLER_AGENT)).getService(IProfileRegistry.class) .getProfile((String) agent.getService(IProvisioningAgent.INSTALLER_PROFILEID)); if (installerProfile == null) return initialPlan; @@ -671,8 +669,8 @@ public class SimplePlanner implements IPlanner { return false; if (agent1 == agent2) return true; - IAgentLocation thisLocation = (IAgentLocation) agent1.getService(IAgentLocation.SERVICE_NAME); - IAgentLocation otherLocation = (IAgentLocation) agent2.getService(IAgentLocation.SERVICE_NAME); + IAgentLocation thisLocation = agent1.getService(IAgentLocation.class); + IAgentLocation otherLocation = agent2.getService(IAgentLocation.class); if (thisLocation == null || otherLocation == null || (thisLocation == null && otherLocation == null)) return false; return thisLocation.getRootLocation().equals(otherLocation.getRootLocation()); @@ -754,8 +752,8 @@ public class SimplePlanner implements IPlanner { agentRequest.setProfileProperty(entry.getKey(), entry.getValue()); } String[] removedProperties = initialRequest.getPropertiesToRemove(); - for (int i = 0; i < removedProperties.length; i++) { - agentRequest.removeProfileProperty(removedProperties[i]); + for (String removedPropertie : removedProperties) { + agentRequest.removeProfileProperty(removedPropertie); } Map<IInstallableUnit, List<String>> removedIUProperties = initialRequest .getInstallableUnitProfilePropertiesToRemove(); @@ -948,8 +946,7 @@ public class SimplePlanner implements IPlanner { } // Process the IUs that were already there - for (Iterator<IInstallableUnit> iterator = alreadyInstalled.iterator(); iterator.hasNext();) { - IInstallableUnit iu = iterator.next(); + for (IInstallableUnit iu : alreadyInstalled) { Map<String, String> propertiesForIU = iuPropertiesToAdd.get(iu); IRequirement profileRequirement = null; // Test if the value has changed @@ -1002,8 +999,7 @@ public class SimplePlanner implements IPlanner { SubMonitor sub = SubMonitor.convert(monitor, 1000); IQueryable<IInstallableUnit> queryable = context.getMetadata(sub.newChild(500)); IQueryResult<IInstallableUnit> matches = queryable.query(new UpdateQuery(toUpdate), sub.newChild(500)); - for (Iterator<IInstallableUnit> it = matches.iterator(); it.hasNext();) { - IInstallableUnit iu = it.next(); + for (IInstallableUnit iu : matches) { String key = iu.getId() + "_" + iu.getVersion().toString(); //$NON-NLS-1$ IInstallableUnit currentIU = resultsMap.get(key); if (currentIU == null || hasHigherFidelity(iu, currentIU)) diff --git a/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/provisional/p2/director/PlanExecutionHelper.java b/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/provisional/p2/director/PlanExecutionHelper.java index 32603b6d2..4c51ca1a9 100644 --- a/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/provisional/p2/director/PlanExecutionHelper.java +++ b/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/provisional/p2/director/PlanExecutionHelper.java @@ -32,7 +32,8 @@ public class PlanExecutionHelper { return result.getStatus(); if (result.getInstallerPlan() != null) { - IStatus installerPlanStatus = ((IEngine) result.getInstallerPlan().getProfile().getProvisioningAgent().getService(IEngine.SERVICE_NAME)).perform(result.getInstallerPlan(), phaseSet, progress); + IStatus installerPlanStatus = result.getInstallerPlan().getProfile().getProvisioningAgent() + .getService(IEngine.class).perform(result.getInstallerPlan(), phaseSet, progress); if (!installerPlanStatus.isOK()) return installerPlanStatus; Configurator configChanger = ServiceHelper.getService(DirectorActivator.context, Configurator.class); |