Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'bundles/org.eclipse.equinox.p2.director')
-rw-r--r--bundles/org.eclipse.equinox.p2.director/.classpath2
-rw-r--r--bundles/org.eclipse.equinox.p2.director/.settings/org.eclipse.jdt.core.prefs12
-rw-r--r--bundles/org.eclipse.equinox.p2.director/META-INF/MANIFEST.MF25
-rw-r--r--bundles/org.eclipse.equinox.p2.director/build.properties2
-rw-r--r--bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/ApplicablePatchQuery.java23
-rw-r--r--bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/AttachmentHelper.java58
-rw-r--r--bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/DirectorComponent.java16
-rw-r--r--bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/Explanation.java32
-rw-r--r--bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/HasMatchCollector.java30
-rw-r--r--bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/Messages.java1
-rw-r--r--bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/OperationGenerator.java107
-rw-r--r--bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/PermissiveSlicer.java18
-rw-r--r--bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/PlannerComponent.java4
-rw-r--r--bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/Projector.java463
-rw-r--r--bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/QueryableArray.java97
-rw-r--r--bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/SimpleDirector.java10
-rw-r--r--bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/SimplePlanner.java467
-rw-r--r--bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/Slicer.java127
-rw-r--r--bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/TwoTierMap.java354
-rw-r--r--bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/messages.properties3
-rw-r--r--bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/rollback/FormerState.java78
-rw-r--r--bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/provisional/p2/director/IDirector.java4
-rw-r--r--bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/provisional/p2/director/IPlanner.java9
-rw-r--r--bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/provisional/p2/director/PlanExecutionHelper.java11
-rw-r--r--bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/provisional/p2/director/PlannerHelper.java2
-rw-r--r--bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/provisional/p2/director/ProfileChangeRequest.java170
-rw-r--r--bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/provisional/p2/director/ProvisioningPlan.java130
-rw-r--r--bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/provisional/p2/director/RequestStatus.java39
28 files changed, 892 insertions, 1402 deletions
diff --git a/bundles/org.eclipse.equinox.p2.director/.classpath b/bundles/org.eclipse.equinox.p2.director/.classpath
index f4025822f..64c5e31b7 100644
--- a/bundles/org.eclipse.equinox.p2.director/.classpath
+++ b/bundles/org.eclipse.equinox.p2.director/.classpath
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/CDC-1.1%Foundation-1.1"/>
<classpathentry kind="output" path="bin"/>
</classpath>
diff --git a/bundles/org.eclipse.equinox.p2.director/.settings/org.eclipse.jdt.core.prefs b/bundles/org.eclipse.equinox.p2.director/.settings/org.eclipse.jdt.core.prefs
index b486accf6..5e1105ff0 100644
--- a/bundles/org.eclipse.equinox.p2.director/.settings/org.eclipse.jdt.core.prefs
+++ b/bundles/org.eclipse.equinox.p2.director/.settings/org.eclipse.jdt.core.prefs
@@ -1,4 +1,4 @@
-#Sat Feb 28 12:14:19 CET 2009
+#Mon Dec 21 23:16:26 CET 2009
eclipse.preferences.version=1
org.eclipse.jdt.core.builder.cleanOutputFolder=clean
org.eclipse.jdt.core.builder.duplicateResourceTask=warning
@@ -8,23 +8,23 @@ org.eclipse.jdt.core.circularClasspath=error
org.eclipse.jdt.core.classpath.exclusionPatterns=enabled
org.eclipse.jdt.core.classpath.multipleOutputLocations=enabled
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
-org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.2
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=jsr14
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
-org.eclipse.jdt.core.compiler.compliance=1.4
+org.eclipse.jdt.core.compiler.compliance=1.5
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.doc.comment.support=enabled
org.eclipse.jdt.core.compiler.maxProblemPerUnit=1000
org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning
-org.eclipse.jdt.core.compiler.problem.assertIdentifier=warning
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.autoboxing=ignore
org.eclipse.jdt.core.compiler.problem.deprecation=warning
org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled
org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=enabled
org.eclipse.jdt.core.compiler.problem.discouragedReference=error
org.eclipse.jdt.core.compiler.problem.emptyStatement=warning
-org.eclipse.jdt.core.compiler.problem.enumIdentifier=warning
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.fieldHiding=warning
org.eclipse.jdt.core.compiler.problem.finalParameterBound=ignore
org.eclipse.jdt.core.compiler.problem.finallyBlockNotCompletingNormally=warning
@@ -71,7 +71,7 @@ org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=en
org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=enabled
org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=error
org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
-org.eclipse.jdt.core.compiler.source=1.3
+org.eclipse.jdt.core.compiler.source=1.5
org.eclipse.jdt.core.formatter.align_type_members_on_columns=false
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant=16
diff --git a/bundles/org.eclipse.equinox.p2.director/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.p2.director/META-INF/MANIFEST.MF
index b78fefec8..2b7b838ec 100644
--- a/bundles/org.eclipse.equinox.p2.director/META-INF/MANIFEST.MF
+++ b/bundles/org.eclipse.equinox.p2.director/META-INF/MANIFEST.MF
@@ -5,25 +5,29 @@ Bundle-Name: %pluginName
Bundle-Vendor: %providerName
Bundle-Localization: plugin
Bundle-Version: 1.0.100.qualifier
-Import-Package: org.eclipse.equinox.internal.p2.core.helpers,
+Import-Package: org.eclipse.core.expressions,
+ org.eclipse.equinox.internal.p2.core.helpers,
+ org.eclipse.equinox.internal.p2.engine,
org.eclipse.equinox.internal.provisional.configurator,
org.eclipse.equinox.internal.provisional.p2.core,
- org.eclipse.equinox.internal.provisional.p2.engine,
org.eclipse.equinox.internal.provisional.p2.metadata,
- org.eclipse.equinox.internal.provisional.p2.metadata.query,
- org.eclipse.equinox.internal.provisional.p2.metadata.repository,
- org.eclipse.equinox.internal.provisional.p2.repository,
org.eclipse.equinox.p2.core,
org.eclipse.equinox.p2.core.spi,
+ org.eclipse.equinox.p2.engine,
+ org.eclipse.equinox.p2.engine.query,
+ org.eclipse.equinox.p2.metadata.query,
+ org.eclipse.equinox.p2.repository,
+ org.eclipse.equinox.p2.repository.metadata,
org.eclipse.osgi.util;version="1.0.0",
org.osgi.framework;version="1.3.0"
-Export-Package: org.eclipse.equinox.internal.p2.director;x-friends:="org.eclipse.equinox.p2.exemplarysetup,org.eclipse.pde.core",
+Export-Package: org.eclipse.equinox.internal.p2.director;x-friends:="org.eclipse.equinox.p2.exemplarysetup,org.eclipse.pde.core,org.eclipse.equinox.p2.repository.tools",
org.eclipse.equinox.internal.p2.rollback;x-friends:="org.eclipse.equinox.p2.ui",
org.eclipse.equinox.internal.provisional.p2.director;
x-friends:="org.eclipse.equinox.p2.console,
org.eclipse.equinox.p2.director.app,
org.eclipse.equinox.p2.installer,
org.eclipse.equinox.p2.reconciler.dropins,
+ org.eclipse.equinox.p2.operations,
org.eclipse.equinox.p2.ui,
org.eclipse.equinox.p2.ui.admin,
org.eclipse.equinox.p2.ui.sdk,
@@ -34,11 +38,12 @@ Export-Package: org.eclipse.equinox.internal.p2.director;x-friends:="org.eclipse
org.eclipse.pde.core"
Bundle-Activator: org.eclipse.equinox.internal.p2.director.DirectorActivator
Bundle-ActivationPolicy: lazy
-Bundle-RequiredExecutionEnvironment: CDC-1.1/Foundation-1.1,
- J2SE-1.4
-Require-Bundle: org.eclipse.equinox.common;bundle-version="[3.5.0,4.0.0)",
+Bundle-RequiredExecutionEnvironment: J2SE-1.5,
+ J2SE-1.4,
+ CDC-1.1/Foundation-1.1
+Require-Bundle: org.eclipse.equinox.common;bundle-version="[3.3.0,4.0.0)",
org.sat4j.core;bundle-version="2.1.0",
org.sat4j.pb;bundle-version="2.1.0",
- org.eclipse.core.jobs;bundle-version="3.4.100",
+ org.eclipse.core.jobs;bundle-version="3.3.0",
org.eclipse.equinox.p2.metadata
Service-Component: OSGI-INF/director.xml, OSGI-INF/planner.xml
diff --git a/bundles/org.eclipse.equinox.p2.director/build.properties b/bundles/org.eclipse.equinox.p2.director/build.properties
index 9334e284d..9ac550cbd 100644
--- a/bundles/org.eclipse.equinox.p2.director/build.properties
+++ b/bundles/org.eclipse.equinox.p2.director/build.properties
@@ -16,3 +16,5 @@ bin.includes = META-INF/,\
plugin.properties
src.includes = about.html
source.. = src/
+javacTarget=jsr14
+javacSource=1.5
diff --git a/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/ApplicablePatchQuery.java b/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/ApplicablePatchQuery.java
index 9a7b55291..4e6f0ba6f 100644
--- a/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/ApplicablePatchQuery.java
+++ b/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/ApplicablePatchQuery.java
@@ -10,25 +10,16 @@
*******************************************************************************/
package org.eclipse.equinox.internal.p2.director;
-import org.eclipse.equinox.internal.provisional.p2.metadata.query.MatchQuery;
-import org.eclipse.equinox.internal.provisional.p2.metadata.query.Query;
+import org.eclipse.equinox.p2.metadata.IInstallableUnitPatch;
-import org.eclipse.equinox.internal.provisional.p2.metadata.*;
+import org.eclipse.equinox.p2.metadata.IInstallableUnit;
+import org.eclipse.equinox.p2.metadata.IRequirement;
+import org.eclipse.equinox.p2.query.MatchQuery;
/**
* A query that accepts any patch that applies to a given installable unit.
*/
-public class ApplicablePatchQuery extends MatchQuery {
-
- /**
- * A query that matches any patch.
- */
- public static final Query ANY = new MatchQuery() {
- public boolean isMatch(Object candidate) {
- return candidate instanceof IInstallableUnitPatch;
- }
- };
-
+public class ApplicablePatchQuery extends MatchQuery<IInstallableUnit> {
IInstallableUnit iu;
/**
@@ -40,11 +31,11 @@ public class ApplicablePatchQuery extends MatchQuery {
this.iu = iu;
}
- public boolean isMatch(Object candidate) {
+ public boolean isMatch(IInstallableUnit candidate) {
if (!(candidate instanceof IInstallableUnitPatch))
return false;
IInstallableUnitPatch patchIU = (IInstallableUnitPatch) candidate;
- IRequiredCapability[][] scopeDescription = patchIU.getApplicabilityScope();
+ IRequirement[][] scopeDescription = patchIU.getApplicabilityScope();
if (scopeDescription.length == 0)
return true;
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 68d9d747a..547aca422 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
@@ -10,47 +10,46 @@
*******************************************************************************/
package org.eclipse.equinox.internal.p2.director;
+import org.eclipse.equinox.p2.metadata.IInstallableUnitFragment;
+
import java.util.*;
import java.util.Map.Entry;
-import org.eclipse.equinox.internal.provisional.p2.metadata.*;
+import org.eclipse.equinox.internal.provisional.p2.metadata.MetadataFactory;
+import org.eclipse.equinox.p2.metadata.IInstallableUnit;
+import org.eclipse.equinox.p2.metadata.IRequirement;
+import org.eclipse.equinox.p2.metadata.query.FragmentQuery;
public class AttachmentHelper {
private static final IInstallableUnitFragment[] NO_FRAGMENTS = new IInstallableUnitFragment[0];
- public static Collection attachFragments(Collection toAttach, Map fragmentsToIUs) {
- Map fragmentBindings = new HashMap();
+ public static Collection<IInstallableUnit> attachFragments(Iterator<IInstallableUnit> toAttach, Map<IInstallableUnitFragment, List<IInstallableUnit>> fragmentsToIUs) {
+ Map<IInstallableUnit, IInstallableUnitFragment> fragmentBindings = new HashMap<IInstallableUnit, IInstallableUnitFragment>();
//Build a map inverse of the one provided in input (host --> List of fragments)
- Map iusToFragment = new HashMap(fragmentsToIUs.size());
- for (Iterator iterator = fragmentsToIUs.entrySet().iterator(); iterator.hasNext();) {
- Entry mapping = (Entry) iterator.next();
- IInstallableUnitFragment fragment = (IInstallableUnitFragment) mapping.getKey();
- List existingMatches = (List) mapping.getValue();
+ Map<IInstallableUnit, List<IInstallableUnitFragment>> iusToFragment = new HashMap<IInstallableUnit, List<IInstallableUnitFragment>>(fragmentsToIUs.size());
+ for (Entry<IInstallableUnitFragment, List<IInstallableUnit>> mapping : fragmentsToIUs.entrySet()) {
+ IInstallableUnitFragment fragment = mapping.getKey();
+ List<IInstallableUnit> existingMatches = mapping.getValue();
- for (Iterator iterator2 = existingMatches.iterator(); iterator2.hasNext();) {
- Object host = iterator2.next();
- List potentialFragments = (List) iusToFragment.get(host);
+ for (IInstallableUnit host : existingMatches) {
+ List<IInstallableUnitFragment> potentialFragments = iusToFragment.get(host);
if (potentialFragments == null) {
- potentialFragments = new ArrayList();
+ potentialFragments = new ArrayList<IInstallableUnitFragment>();
iusToFragment.put(host, potentialFragments);
}
potentialFragments.add(fragment);
}
}
- for (Iterator iterator = iusToFragment.entrySet().iterator(); iterator.hasNext();) {
- Entry entry = (Entry) iterator.next();
- IInstallableUnit hostIU = (IInstallableUnit) entry.getKey();
- List potentialIUFragments = (List) entry.getValue();
- ArrayList applicableFragments = new ArrayList();
- for (Iterator iterator2 = potentialIUFragments.iterator(); iterator2.hasNext();) {
- IInstallableUnit dependentIU = (IInstallableUnitFragment) iterator2.next();
- if (hostIU.equals(dependentIU) || !dependentIU.isFragment())
+ for (Entry<IInstallableUnit, List<IInstallableUnitFragment>> entry : iusToFragment.entrySet()) {
+ IInstallableUnit hostIU = entry.getKey();
+ List<IInstallableUnitFragment> potentialIUFragments = entry.getValue();
+ ArrayList<IInstallableUnitFragment> applicableFragments = new ArrayList<IInstallableUnitFragment>();
+ for (IInstallableUnitFragment potentialFragment : potentialIUFragments) {
+ if (hostIU.equals(potentialFragment))
continue;
- IInstallableUnitFragment potentialFragment = (IInstallableUnitFragment) dependentIU;
-
// Check to make sure the host meets the requirements of the fragment
- IRequiredCapability reqsFromFragment[] = potentialFragment.getHost();
+ IRequirement reqsFromFragment[] = potentialFragment.getHost();
boolean match = true;
boolean requirementMatched = false;
for (int l = 0; l < reqsFromFragment.length && match == true; l++) {
@@ -70,8 +69,7 @@ public class AttachmentHelper {
IInstallableUnitFragment theFragment = null;
int specificityLevel = 0;
- for (Iterator iterator4 = applicableFragments.iterator(); iterator4.hasNext();) {
- IInstallableUnitFragment fragment = (IInstallableUnitFragment) iterator4.next();
+ for (IInstallableUnitFragment fragment : applicableFragments) {
if (fragment.getHost().length > specificityLevel) {
theFragment = fragment;
specificityLevel = fragment.getHost().length;
@@ -81,18 +79,18 @@ public class AttachmentHelper {
fragmentBindings.put(hostIU, theFragment);
}
//build the collection of resolved IUs
- Collection result = new HashSet(toAttach.size());
- for (Iterator iterator = toAttach.iterator(); iterator.hasNext();) {
- IInstallableUnit iu = (IInstallableUnit) iterator.next();
+ Collection<IInstallableUnit> result = new HashSet<IInstallableUnit>();
+ while (toAttach.hasNext()) {
+ IInstallableUnit iu = toAttach.next();
if (iu == null)
continue;
//just return fragments as they are
- if (iu.isFragment()) {
+ if (FragmentQuery.isFragment(iu)) {
result.add(iu);
continue;
}
//return a new IU that combines the IU with its bound fragments
- IInstallableUnitFragment fragment = (IInstallableUnitFragment) fragmentBindings.get(iu);
+ IInstallableUnitFragment fragment = fragmentBindings.get(iu);
IInstallableUnitFragment[] fragments;
if (fragment == null)
fragments = NO_FRAGMENTS;
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 b4f2a3044..2ab6904af 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
@@ -1,10 +1,3 @@
-package org.eclipse.equinox.internal.p2.director;
-
-import org.eclipse.equinox.internal.provisional.p2.director.IPlanner;
-import org.eclipse.equinox.internal.provisional.p2.engine.IEngine;
-import org.eclipse.equinox.p2.core.IProvisioningAgent;
-import org.eclipse.equinox.p2.core.spi.IAgentServiceFactory;
-
/*******************************************************************************
* Copyright (c) 2009 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
@@ -15,10 +8,13 @@ import org.eclipse.equinox.p2.core.spi.IAgentServiceFactory;
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
+package org.eclipse.equinox.internal.p2.director;
+
+import org.eclipse.equinox.internal.provisional.p2.director.IPlanner;
+import org.eclipse.equinox.p2.core.IProvisioningAgent;
+import org.eclipse.equinox.p2.core.spi.IAgentServiceFactory;
+import org.eclipse.equinox.p2.engine.IEngine;
-/**
- *
- */
public class DirectorComponent implements IAgentServiceFactory {
public Object createService(IProvisioningAgent agent) {
diff --git a/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/Explanation.java b/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/Explanation.java
index 0a85e5748..6dea4fcf6 100644
--- a/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/Explanation.java
+++ b/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/Explanation.java
@@ -10,17 +10,20 @@
******************************************************************************/
package org.eclipse.equinox.internal.p2.director;
+import org.eclipse.equinox.p2.metadata.IInstallableUnitPatch;
+
import java.util.Arrays;
import org.eclipse.core.runtime.*;
-import org.eclipse.equinox.internal.provisional.p2.metadata.*;
+import org.eclipse.equinox.p2.metadata.IInstallableUnit;
+import org.eclipse.equinox.p2.metadata.IRequirement;
import org.eclipse.osgi.util.NLS;
-public abstract class Explanation implements Comparable {
+public abstract class Explanation implements Comparable<Explanation> {
public static class PatchedHardRequirement extends Explanation {
public final IInstallableUnit iu;
public final IInstallableUnitPatch patch;
- public final IRequiredCapability req;
+ public final IRequirement req;
public PatchedHardRequirement(IInstallableUnit iu, IInstallableUnitPatch patch) {
this.iu = iu;
@@ -28,7 +31,7 @@ public abstract class Explanation implements Comparable {
this.patch = patch;
}
- public PatchedHardRequirement(IInstallableUnit iu, IRequiredCapability req, IInstallableUnitPatch patch) {
+ public PatchedHardRequirement(IInstallableUnit iu, IRequirement req, IInstallableUnitPatch patch) {
this.iu = iu;
this.req = req;
this.patch = patch;
@@ -53,9 +56,9 @@ public abstract class Explanation implements Comparable {
public static class HardRequirement extends Explanation {
public final IInstallableUnit iu;
- public final IRequiredCapability req;
+ public final IRequirement req;
- public HardRequirement(IInstallableUnit iu, IRequiredCapability req) {
+ public HardRequirement(IInstallableUnit iu, IRequirement req) {
this.iu = iu;
this.req = req;
}
@@ -118,9 +121,9 @@ public abstract class Explanation implements Comparable {
public static class MissingIU extends Explanation {
public final IInstallableUnit iu;
- public final IRequiredCapability req;
+ public final IRequirement req;
- public MissingIU(IInstallableUnit iu, IRequiredCapability req) {
+ public MissingIU(IInstallableUnit iu, IRequirement req) {
this.iu = iu;
this.req = req;
}
@@ -134,19 +137,17 @@ public abstract class Explanation implements Comparable {
}
public String toString() {
- String filter = req.getFilter();
- if (filter == null) {
+ if (req.getFilter() == null) {
return NLS.bind(Messages.Explanation_missingRequired, iu, req);
}
- return NLS.bind(Messages.Explanation_missingRequiredFilter, new Object[] {filter, iu, req});
+ return NLS.bind(Messages.Explanation_missingRequiredFilter, new Object[] {req.getFilter(), iu, req});
}
public IStatus toStatus() {
- String filter = req.getFilter();
- if (filter == null) {
+ if (req.getFilter() == null) {
return new Status(IStatus.ERROR, DirectorActivator.PI_DIRECTOR, NLS.bind(Messages.Explanation_missingRequired, getUserReadableName(iu), req));
}
- return new Status(IStatus.ERROR, DirectorActivator.PI_DIRECTOR, NLS.bind(Messages.Explanation_missingRequiredFilter, new Object[] {filter, getUserReadableName(iu), req}));
+ return new Status(IStatus.ERROR, DirectorActivator.PI_DIRECTOR, NLS.bind(Messages.Explanation_missingRequiredFilter, new Object[] {req.getFilter(), getUserReadableName(iu), req}));
}
}
@@ -197,8 +198,7 @@ public abstract class Explanation implements Comparable {
super();
}
- public int compareTo(Object arg0) {
- Explanation exp = (Explanation) arg0;
+ public int compareTo(Explanation exp) {
if (this.orderValue() == exp.orderValue()) {
return this.toString().compareTo(exp.toString());
}
diff --git a/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/HasMatchCollector.java b/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/HasMatchCollector.java
deleted file mode 100644
index 058e3b3a7..000000000
--- a/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/HasMatchCollector.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007, 2008 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.equinox.internal.p2.director;
-
-import org.eclipse.equinox.internal.provisional.p2.metadata.query.Collector;
-
-/**
- * A collector that short-circuits on the first match.
- */
-public class HasMatchCollector extends Collector {
- private boolean hasMatch = false;
-
- public boolean accept(Object object) {
- hasMatch = true;
- return false;
- }
-
- public boolean isEmpty() {
- return !hasMatch;
- }
-
-}
diff --git a/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/Messages.java b/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/Messages.java
index 831cf7e0a..cccc419a6 100644
--- a/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/Messages.java
+++ b/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/Messages.java
@@ -56,5 +56,6 @@ public class Messages extends NLS {
public static String Planner_can_not_install_preq;
public static String Planner_no_profile_registry;
public static String Planner_profile_out_of_sync;
+ public static String RequestStatus_message;
}
diff --git a/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/OperationGenerator.java b/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/OperationGenerator.java
index 444e514f8..87484914e 100644
--- a/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/OperationGenerator.java
+++ b/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/OperationGenerator.java
@@ -10,94 +10,72 @@
*******************************************************************************/
package org.eclipse.equinox.internal.p2.director;
-import org.eclipse.equinox.internal.provisional.p2.metadata.query.Collector;
+import org.eclipse.equinox.p2.metadata.IInstallableUnitFragment;
import java.util.*;
-import org.eclipse.equinox.internal.provisional.p2.engine.InstallableUnitOperand;
-import org.eclipse.equinox.internal.provisional.p2.metadata.*;
+import org.eclipse.equinox.internal.provisional.p2.metadata.MetadataFactory;
import org.eclipse.equinox.internal.provisional.p2.metadata.MetadataFactory.InstallableUnitDescription;
-import org.eclipse.equinox.internal.provisional.p2.metadata.query.InstallableUnitQuery;
+import org.eclipse.equinox.p2.engine.InstallableUnitOperand;
+import org.eclipse.equinox.p2.metadata.IInstallableUnit;
+import org.eclipse.equinox.p2.metadata.query.InstallableUnitQuery;
public class OperationGenerator {
private static final IInstallableUnit NULL_IU = MetadataFactory.createResolvedInstallableUnit(MetadataFactory.createInstallableUnit(new InstallableUnitDescription()), new IInstallableUnitFragment[0]);
- public InstallableUnitOperand[] generateOperation(Collection from_, Collection to_) {
- Collection intersection = new HashSet(from_);
+ public List<InstallableUnitOperand> generateOperation(Collection<IInstallableUnit> from_, Collection<IInstallableUnit> to_) {
+ Collection<IInstallableUnit> intersection = new HashSet<IInstallableUnit>(from_);
intersection.retainAll(to_);
- HashSet tmpFrom = new HashSet(from_);
- HashSet tmpTo = new HashSet(to_);
+ HashSet<IInstallableUnit> tmpFrom = new HashSet<IInstallableUnit>(from_);
+ HashSet<IInstallableUnit> tmpTo = new HashSet<IInstallableUnit>(to_);
tmpFrom.removeAll(intersection);
tmpTo.removeAll(intersection);
- List from = new ArrayList(tmpFrom);
+ List<IInstallableUnit> from = new ArrayList<IInstallableUnit>(tmpFrom);
Collections.sort(from);
- List to = new ArrayList(tmpTo);
+ List<IInstallableUnit> to = new ArrayList<IInstallableUnit>(tmpTo);
Collections.sort(to);
- ArrayList operations = new ArrayList();
+ ArrayList<InstallableUnitOperand> operations = new ArrayList<InstallableUnitOperand>();
generateUpdates(from, to, operations);
generateInstallUninstall(from, to, operations);
generateConfigurationChanges(to_, intersection, operations);
- InstallableUnitOperand[] ops = (InstallableUnitOperand[]) operations.toArray(new InstallableUnitOperand[operations.size()]);
- return ops;
+ return operations;
}
//This generates operations that are causing the IUs to be reconfigured.
- private void generateConfigurationChanges(Collection to_, Collection intersection, ArrayList operations) {
+ private void generateConfigurationChanges(Collection<IInstallableUnit> to_, Collection<IInstallableUnit> intersection, ArrayList<InstallableUnitOperand> operations) {
if (intersection.size() == 0)
return;
//We retain from each set the things that are the same.
//Note that despite the fact that they are the same, a different CU can be attached.
//The objects contained in the intersection are the one that were originally in the from collection.
- TreeSet to = new TreeSet(to_);
- for (Iterator iterator = intersection.iterator(); iterator.hasNext();) {
- IInstallableUnit fromIU = (IInstallableUnit) iterator.next();
- IInstallableUnit toIU = (IInstallableUnit) to.tailSet(fromIU).first();
+ TreeSet<IInstallableUnit> to = new TreeSet<IInstallableUnit>(to_);
+ for (IInstallableUnit fromIU : intersection) {
+ IInstallableUnit toIU = to.tailSet(fromIU).first();
generateConfigurationOperation(fromIU, toIU, operations);
}
}
- private void generateConfigurationOperation(IInstallableUnit fromIU, IInstallableUnit toIU, ArrayList operations) {
- IInstallableUnitFragment[] fromFragments = fromIU.getFragments();
- IInstallableUnitFragment[] toFragments = toIU.getFragments();
+ private void generateConfigurationOperation(IInstallableUnit fromIU, IInstallableUnit toIU, ArrayList<InstallableUnitOperand> operations) {
+ List<IInstallableUnitFragment> fromFragments = fromIU.getFragments();
+ List<IInstallableUnitFragment> toFragments = toIU.getFragments();
if (fromFragments == toFragments)
return;
//Check to see if the two arrays are equals independently of the order of the fragments
- boolean different = false;
- if (fromFragments != null && toFragments != null) {
- if (fromFragments.length != toFragments.length)
- different = true;
- else {
- for (int i = 0; i < fromFragments.length; i++) {
- boolean found = false;
- for (int j = 0; j < toFragments.length; j++) {
- if (fromFragments[i].equals(toFragments[j]))
- found = true;
- }
- if (!found) {
- different = true;
- break;
- }
- }
- }
- } else {
- //One of the two array is null
- different = true;
- }
- if (!different)
+ if (fromFragments.size() == toFragments.size() && fromFragments.containsAll(toFragments))
return;
operations.add(new InstallableUnitOperand(fromIU, toIU));
}
- private void generateInstallUninstall(List from, List to, ArrayList operations) {
+ private void generateInstallUninstall(List<IInstallableUnit> from, List<IInstallableUnit> to, ArrayList<InstallableUnitOperand> operations) {
int toIdx = 0;
int fromIdx = 0;
while (fromIdx != from.size() && toIdx != to.size()) {
- IInstallableUnit fromIU = (IInstallableUnit) from.get(fromIdx);
- IInstallableUnit toIU = (IInstallableUnit) to.get(toIdx);
+ IInstallableUnit fromIU = from.get(fromIdx);
+ IInstallableUnit toIU = to.get(toIdx);
int comparison = toIU.compareTo(fromIU);
if (comparison < 0) {
operations.add(createInstallOperation(toIU));
@@ -113,36 +91,35 @@ public class OperationGenerator {
}
if (fromIdx != from.size()) {
for (int i = fromIdx; i < from.size(); i++) {
- operations.add(createUninstallOperation((IInstallableUnit) from.get(i)));
+ operations.add(createUninstallOperation(from.get(i)));
}
}
if (toIdx != to.size()) {
for (int i = toIdx; i < to.size(); i++) {
- operations.add(createInstallOperation((IInstallableUnit) to.get(i)));
+ operations.add(createInstallOperation(to.get(i)));
}
}
}
- private void generateUpdates(List from, List to, ArrayList operations) {
- Set processed = new HashSet();
- Set removedFromTo = new HashSet();
-
+ private void generateUpdates(List<IInstallableUnit> from, List<IInstallableUnit> to, ArrayList<InstallableUnitOperand> operations) {
if (to.isEmpty() || from.isEmpty())
return;
- Map fromById = new HashMap();
- for (Iterator iterator = from.iterator(); iterator.hasNext();) {
- IInstallableUnit iuFrom = (IInstallableUnit) iterator.next();
- List ius = (List) fromById.get(iuFrom.getId());
+ Set<IInstallableUnit> processed = new HashSet<IInstallableUnit>();
+ Set<IInstallableUnit> removedFromTo = new HashSet<IInstallableUnit>();
+
+ Map<String, List<IInstallableUnit>> fromById = new HashMap<String, List<IInstallableUnit>>();
+ for (IInstallableUnit iuFrom : from) {
+ List<IInstallableUnit> ius = fromById.get(iuFrom.getId());
if (ius == null) {
- ius = new ArrayList();
+ ius = new ArrayList<IInstallableUnit>();
fromById.put(iuFrom.getId(), ius);
}
ius.add(iuFrom);
}
for (int toIdx = 0; toIdx < to.size(); toIdx++) {
- IInstallableUnit iuTo = (IInstallableUnit) to.get(toIdx);
+ IInstallableUnit iuTo = to.get(toIdx);
if (iuTo.getId().equals(next(to, toIdx).getId())) { //This handle the case where there are multiple versions of the same IU in the target. Eg we are trying to update from A 1.0.0 to A 1.1.1 and A 1.2.2
toIdx = skip(to, iuTo, toIdx) - 1;
//System.out.println("Can't update " + iuTo + " because another iu with same id is in the target state");
@@ -151,18 +128,18 @@ public class OperationGenerator {
if (iuTo.getUpdateDescriptor() == null)
continue;
- List fromIdIndexList = (List) fromById.get(iuTo.getUpdateDescriptor().getId());
+ List<IInstallableUnit> fromIdIndexList = fromById.get(iuTo.getUpdateDescriptor().getId());
if (fromIdIndexList == null)
continue;
//when the ui we update from is in the new state, skip (for example FROM is A, C, B & TO is C (update of
InstallableUnitQuery updateQuery = new InstallableUnitQuery(iuTo.getUpdateDescriptor().getId(), iuTo.getUpdateDescriptor().getRange());
- Iterator updates = updateQuery.perform(fromIdIndexList.iterator(), new Collector()).iterator();
+ Iterator<IInstallableUnit> updates = updateQuery.perform(fromIdIndexList.iterator()).iterator();
if (!updates.hasNext()) { //Nothing to update from.
continue;
}
- IInstallableUnit iuFrom = (IInstallableUnit) updates.next();
+ IInstallableUnit iuFrom = updates.next();
if (updates.hasNext()) { //There are multiple IUs to update from
//System.out.println("Can't update " + iuTo + " because there are multiple IUs to update from (" + toString(iusFrom) + ')');
continue;
@@ -194,17 +171,17 @@ public class OperationGenerator {
return new InstallableUnitOperand(from, to);
}
- private IInstallableUnit next(List l, int i) {
+ private IInstallableUnit next(List<IInstallableUnit> l, int i) {
i++;
if (i >= l.size())
return NULL_IU;
- return (IInstallableUnit) l.get(i);
+ return l.get(i);
}
- private int skip(List c, IInstallableUnit id, int idx) {
+ private int skip(List<IInstallableUnit> c, IInstallableUnit id, int idx) {
int i = idx;
for (; i < c.size(); i++) {
- if (!id.getId().equals(((IInstallableUnit) c.get(i)).getId()))
+ if (!id.getId().equals(c.get(i).getId()))
return i;
}
return i;
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 aff9e89ec..25604cbb4 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
@@ -8,11 +8,11 @@
******************************************************************************/
package org.eclipse.equinox.internal.p2.director;
-import org.eclipse.equinox.internal.provisional.p2.metadata.query.IQueryable;
-
import java.util.Dictionary;
-import org.eclipse.equinox.internal.provisional.p2.metadata.IInstallableUnit;
-import org.eclipse.equinox.internal.provisional.p2.metadata.IRequiredCapability;
+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.query.IQueryable;
public class PermissiveSlicer extends Slicer {
private boolean includeOptionalDependencies; //Cause optional dependencies not be followed as part of the
@@ -22,7 +22,7 @@ public class PermissiveSlicer extends Slicer {
private boolean evalFilterTo;
private boolean onlyFilteredRequirements;
- public PermissiveSlicer(IQueryable input, Dictionary context, boolean includeOptionalDependencies, boolean everythingGreedy, boolean evalFilterTo, boolean considerOnlyStrictDependency, boolean onlyFilteredRequirements) {
+ public PermissiveSlicer(IQueryable<IInstallableUnit> input, Dictionary<? extends Object, ? extends Object> 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.includeOptionalDependencies = includeOptionalDependencies;
@@ -40,14 +40,14 @@ public class PermissiveSlicer extends Slicer {
return evalFilterTo;
}
- protected boolean isApplicable(IRequiredCapability req) {
+ protected boolean isApplicable(IRequirement req) {
//Every filter in this method needs to continue except when the filter does not pass
if (!includeOptionalDependencies)
- if (req.isOptional())
+ if (req.getMin() == 0)
return false;
if (considerOnlyStrictDependency) {
- if (!req.getRange().getMinimum().equals(req.getRange().getMaximum()))
+ if (!RequiredCapability.isVersionStrict(req.getMatches()))
return false;
}
@@ -66,7 +66,7 @@ public class PermissiveSlicer extends Slicer {
return evalFilterTo;
}
- protected boolean isGreedy(IRequiredCapability req) {
+ protected boolean isGreedy(IRequirement req) {
if (everythingGreedy) {
return true;
}
diff --git a/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/PlannerComponent.java b/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/PlannerComponent.java
index e363ea236..771c70f01 100644
--- a/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/PlannerComponent.java
+++ b/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/PlannerComponent.java
@@ -10,10 +10,10 @@
*******************************************************************************/
package org.eclipse.equinox.internal.p2.director;
-import org.eclipse.equinox.internal.provisional.p2.engine.IProfileRegistry;
-import org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepositoryManager;
import org.eclipse.equinox.p2.core.IProvisioningAgent;
import org.eclipse.equinox.p2.core.spi.IAgentServiceFactory;
+import org.eclipse.equinox.p2.engine.IProfileRegistry;
+import org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager;
/**
* A service factory that provides planner implementations
diff --git a/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/Projector.java b/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/Projector.java
index 20575be58..0388be5e3 100644
--- a/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/Projector.java
+++ b/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/Projector.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2009 IBM Corporation and others. All rights reserved. This
+ * Copyright (c) 2007, 2010 IBM Corporation and others. All rights reserved. This
* program and the accompanying materials are made available under the terms of
* the Eclipse Public License v1.0 which accompanies this distribution, and is
* available at http://www.eclipse.org/legal/epl-v10.html
@@ -16,12 +16,15 @@ import java.util.*;
import java.util.Map.Entry;
import org.eclipse.core.runtime.*;
import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.equinox.internal.p2.core.helpers.CollectionUtils;
import org.eclipse.equinox.internal.p2.core.helpers.Tracing;
-import org.eclipse.equinox.internal.p2.metadata.NotRequirement;
-import org.eclipse.equinox.internal.provisional.p2.metadata.*;
-import org.eclipse.equinox.internal.provisional.p2.metadata.query.*;
+import org.eclipse.equinox.internal.p2.metadata.IRequiredCapability;
+import org.eclipse.equinox.p2.metadata.*;
+import org.eclipse.equinox.p2.metadata.query.*;
+import org.eclipse.equinox.p2.query.IQueryResult;
+import org.eclipse.equinox.p2.query.IQueryable;
import org.eclipse.osgi.util.NLS;
-import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.Filter;
import org.sat4j.pb.IPBSolver;
import org.sat4j.pb.SolverFactory;
import org.sat4j.pb.tools.DependencyHelper;
@@ -36,26 +39,28 @@ import org.sat4j.specs.*;
public class Projector {
static boolean DEBUG = Tracing.DEBUG_PLANNER_PROJECTOR;
private static boolean DEBUG_ENCODING = false;
- private IQueryable picker;
+ private IQueryable<IInstallableUnit> picker;
private QueryableArray patches;
- private Map noopVariables; //key IU, value AbstractVariable
- private List abstractVariables;
+ private Map<IInstallableUnit, AbstractVariable> noopVariables; //key IU, value AbstractVariable
+ private List<AbstractVariable> abstractVariables;
- private TwoTierMap slice; //The IUs that have been considered to be part of the problem
+ private Map<String, Map<Version, IInstallableUnit>> slice; //The IUs that have been considered to be part of the problem
- private Dictionary selectionContext;
+ private Dictionary<String, String> selectionContext;
- DependencyHelper dependencyHelper;
- private Collection solution;
- private Collection assumptions;
+ DependencyHelper<Object, Explanation> dependencyHelper;
+ private Collection<IInstallableUnit> solution;
+ private Collection<Object> assumptions;
private MultiStatus result;
- private Collection alreadyInstalledIUs;
+ private Collection<IInstallableUnit> alreadyInstalledIUs;
+ private IQueryable<IInstallableUnit> lastState;
+
private boolean considerMetaRequirements;
private IInstallableUnit entryPoint;
- private Map fragments = new HashMap();
+ private Map<IInstallableUnitFragment, Set<IInstallableUnit>> fragments = new HashMap<IInstallableUnitFragment, Set<IInstallableUnit>>();
static class AbstractVariable {
public String toString() {
@@ -67,7 +72,7 @@ public class Projector {
* Job for computing SAT failure explanation in the background.
*/
class ExplanationJob extends Job {
- private Set explanation;
+ private Set<Explanation> explanation;
public ExplanationJob() {
super(Messages.Planner_NoSolution);
@@ -84,7 +89,7 @@ public class Projector {
dependencyHelper.stopExplanation();
}
- public Set getExplanationResult() {
+ public Set<Explanation> getExplanationResult() {
return explanation;
}
@@ -100,8 +105,8 @@ public class Projector {
long stop = System.currentTimeMillis();
Tracing.debug("Explanation found: " + (stop - start)); //$NON-NLS-1$
Tracing.debug("Explanation:"); //$NON-NLS-1$
- for (Iterator i = explanation.iterator(); i.hasNext();) {
- Tracing.debug(i.next().toString());
+ for (Explanation ex : explanation) {
+ Tracing.debug(ex.toString());
}
}
} catch (TimeoutException e) {
@@ -110,7 +115,7 @@ public class Projector {
} finally {
//must never have a null result, because caller is waiting on result to be non-null
if (explanation == null)
- explanation = Collections.EMPTY_SET;
+ explanation = CollectionUtils.emptySet();
}
synchronized (this) {
ExplanationJob.this.notify();
@@ -120,19 +125,24 @@ public class Projector {
}
- public Projector(IQueryable q, Dictionary context, boolean considerMetaRequirements) {
+ public Projector(IQueryable<IInstallableUnit> q, Dictionary<String, String> context, boolean considerMetaRequirements) {
picker = q;
- noopVariables = new HashMap();
- slice = new TwoTierMap();
+ noopVariables = new HashMap<IInstallableUnit, AbstractVariable>();
+ slice = new HashMap<String, Map<Version, IInstallableUnit>>();
selectionContext = context;
- abstractVariables = new ArrayList();
+ abstractVariables = new ArrayList<AbstractVariable>();
result = new MultiStatus(DirectorActivator.PI_DIRECTOR, IStatus.OK, Messages.Planner_Problems_resolving_plan, null);
- assumptions = new ArrayList();
+ assumptions = new ArrayList<Object>();
this.considerMetaRequirements = considerMetaRequirements;
}
- public void encode(IInstallableUnit entryPointIU, IInstallableUnit[] alreadyExistingRoots, IInstallableUnit[] newRoots, IProgressMonitor monitor) {
+ protected boolean isInstalled(IInstallableUnit iu) {
+ return !lastState.query(new InstallableUnitQuery(iu), null).isEmpty();
+ }
+
+ public void encode(IInstallableUnit entryPointIU, IInstallableUnit[] alreadyExistingRoots, IQueryable<IInstallableUnit> installedIUs, IInstallableUnit[] newRoots, IProgressMonitor monitor) {
alreadyInstalledIUs = Arrays.asList(alreadyExistingRoots);
+ lastState = installedIUs;
this.entryPoint = entryPointIU;
try {
long start = 0;
@@ -147,12 +157,12 @@ public class Projector {
solver = SolverFactory.newEclipseP2();
}
solver.setTimeoutOnConflicts(1000);
- Collector collector = picker.query(InstallableUnitQuery.ANY, new Collector(), null);
- dependencyHelper = new DependencyHelper(solver);
+ IQueryResult<IInstallableUnit> queryResult = picker.query(InstallableUnitQuery.ANY, null);
+ dependencyHelper = new DependencyHelper<Object, Explanation>(solver);
- Iterator iusToEncode = collector.iterator();
+ Iterator<IInstallableUnit> iusToEncode = queryResult.iterator();
if (DEBUG) {
- List iusToOrder = new ArrayList();
+ List<IInstallableUnit> iusToOrder = new ArrayList<IInstallableUnit>();
while (iusToEncode.hasNext()) {
iusToOrder.add(iusToEncode.next());
}
@@ -164,7 +174,7 @@ public class Projector {
result.merge(Status.CANCEL_STATUS);
throw new OperationCanceledException();
}
- IInstallableUnit iuToEncode = (IInstallableUnit) iusToEncode.next();
+ IInstallableUnit iuToEncode = iusToEncode.next();
if (iuToEncode != entryPointIU) {
processIU(iuToEncode, false);
}
@@ -191,24 +201,24 @@ public class Projector {
//Create an optimization function favoring the highest version of each IU
private void createOptimizationFunction(IInstallableUnit metaIu) {
- List weightedObjects = new ArrayList();
+ List<WeightedObject<? extends Object>> weightedObjects = new ArrayList<WeightedObject<? extends Object>>();
- Set s = slice.entrySet();
+ Set<Entry<String, Map<Version, IInstallableUnit>>> s = slice.entrySet();
final BigInteger POWER = BigInteger.valueOf(2);
BigInteger maxWeight = POWER;
- for (Iterator iterator = s.iterator(); iterator.hasNext();) {
- Map.Entry entry = (Map.Entry) iterator.next();
- HashMap conflictingEntries = (HashMap) entry.getValue();
+ for (Entry<String, Map<Version, IInstallableUnit>> entry : s) {
+ Map<Version, IInstallableUnit> conflictingEntries = entry.getValue();
if (conflictingEntries.size() == 1) {
continue;
}
- List toSort = new ArrayList(conflictingEntries.values());
+ List<IInstallableUnit> toSort = new ArrayList<IInstallableUnit>(conflictingEntries.values());
Collections.sort(toSort, Collections.reverseOrder());
- BigInteger weight = BigInteger.ONE;
+ BigInteger weight = POWER;
int count = toSort.size();
for (int i = 0; i < count; i++) {
- weightedObjects.add(WeightedObject.newWO(toSort.get(i), weight));
+ IInstallableUnit iu = toSort.get(i);
+ weightedObjects.add(WeightedObject.newWO(iu, isInstalled(iu) ? BigInteger.ONE : weight));
weight = weight.multiply(POWER);
}
if (weight.compareTo(maxWeight) > 0)
@@ -218,40 +228,40 @@ public class Projector {
maxWeight = maxWeight.multiply(POWER);
// Weight the no-op variables beneath the abstract variables
- for (Iterator iterator = noopVariables.values().iterator(); iterator.hasNext();) {
- weightedObjects.add(WeightedObject.newWO(iterator.next(), maxWeight));
- }
+ for (AbstractVariable var : noopVariables.values())
+ weightedObjects.add(WeightedObject.newWO(var, maxWeight));
maxWeight = maxWeight.multiply(POWER);
// Add the abstract variables
BigInteger abstractWeight = maxWeight.negate();
- for (Iterator iterator = abstractVariables.iterator(); iterator.hasNext();) {
- weightedObjects.add(WeightedObject.newWO(iterator.next(), abstractWeight));
+ for (AbstractVariable var : abstractVariables) {
+ weightedObjects.add(WeightedObject.newWO(var, abstractWeight));
}
maxWeight = maxWeight.multiply(POWER);
BigInteger optionalWeight = maxWeight.negate();
long countOptional = 1;
- List requestedPatches = new ArrayList();
- IRequiredCapability[] reqs = metaIu.getRequiredCapabilities();
- for (int j = 0; j < reqs.length; j++) {
- if (!reqs[j].isOptional())
+ List<IInstallableUnit> requestedPatches = new ArrayList<IInstallableUnit>();
+ Collection<IRequirement> reqs = metaIu.getRequiredCapabilities();
+ for (IRequirement req : reqs) {
+ if (req.getMin() > 0)
continue;
- Collector matches = picker.query(new CapabilityQuery(reqs[j]), new Collector(), null);
- for (Iterator iterator = matches.iterator(); iterator.hasNext();) {
- IInstallableUnit match = (IInstallableUnit) iterator.next();
+ IQueryResult<IInstallableUnit> matches = picker.query(new ExpressionQuery<IInstallableUnit>(IInstallableUnit.class, req.getMatches()), null);
+ for (Iterator<IInstallableUnit> iterator = matches.iterator(); iterator.hasNext();) {
+ IInstallableUnit match = iterator.next();
if (match instanceof IInstallableUnitPatch) {
requestedPatches.add(match);
countOptional = countOptional + 1;
- } else
- weightedObjects.add(WeightedObject.newWO(match, optionalWeight));
+ } else {
+ weightedObjects.add(WeightedObject.newWO(match, isInstalled(match) ? BigInteger.ONE : optionalWeight));
+ }
}
}
BigInteger patchWeight = maxWeight.multiply(POWER).multiply(BigInteger.valueOf(countOptional)).negate();
- for (Iterator iterator = requestedPatches.iterator(); iterator.hasNext();) {
+ for (Iterator<IInstallableUnit> iterator = requestedPatches.iterator(); iterator.hasNext();) {
weightedObjects.add(WeightedObject.newWO(iterator.next(), patchWeight));
}
if (!weightedObjects.isEmpty()) {
@@ -259,11 +269,10 @@ public class Projector {
}
}
- private void createObjectiveFunction(List weightedObjects) {
+ private void createObjectiveFunction(List<WeightedObject<? extends Object>> weightedObjects) {
if (DEBUG) {
StringBuffer b = new StringBuffer();
- for (Iterator i = weightedObjects.iterator(); i.hasNext();) {
- WeightedObject object = (WeightedObject) i.next();
+ for (WeightedObject<? extends Object> object : weightedObjects) {
if (b.length() > 0)
b.append(", "); //$NON-NLS-1$
b.append(object.getWeight());
@@ -272,7 +281,9 @@ public class Projector {
}
Tracing.debug("objective function: " + b); //$NON-NLS-1$
}
- dependencyHelper.setObjectiveFunction((WeightedObject[]) weightedObjects.toArray(new WeightedObject[weightedObjects.size()]));
+ @SuppressWarnings("unchecked")
+ WeightedObject<Object>[] array = (WeightedObject<Object>[]) weightedObjects.toArray(new WeightedObject<?>[weightedObjects.size()]);
+ dependencyHelper.setObjectiveFunction(array);
}
private void createMustHave(IInstallableUnit iu, IInstallableUnit[] alreadyExistingRoots, IInstallableUnit[] newRoots) throws ContradictionException {
@@ -284,7 +295,7 @@ public class Projector {
assumptions.add(iu);
}
- private void createNegation(IInstallableUnit iu, IRequiredCapability req) throws ContradictionException {
+ private void createNegation(IInstallableUnit iu, IRequirement req) throws ContradictionException {
if (DEBUG) {
Tracing.debug(iu + "=0"); //$NON-NLS-1$
}
@@ -292,39 +303,26 @@ public class Projector {
}
// Check whether the requirement is applicable
- private boolean isApplicable(IRequiredCapability req) {
- String filter = req.getFilter();
- if (filter == null)
- return true;
- try {
- return DirectorActivator.context.createFilter(filter).match(selectionContext);
- } catch (InvalidSyntaxException e) {
- return false;
- }
+ private boolean isApplicable(IRequirement req) {
+ Filter filter = req.getFilter();
+ return filter == null || filter.match(selectionContext);
}
private boolean isApplicable(IInstallableUnit iu) {
- String enablementFilter = iu.getFilter();
- if (enablementFilter == null)
- return true;
- try {
- return DirectorActivator.context.createFilter(enablementFilter).match(selectionContext);
- } catch (InvalidSyntaxException e) {
- return false;
- }
+ Filter filter = iu.getFilter();
+ return filter == null || filter.match(selectionContext);
}
- private void expandNegatedRequirement(IRequiredCapability req, IInstallableUnit iu, List optionalAbstractRequirements, boolean isRootIu) throws ContradictionException {
- IRequiredCapability negatedReq = ((NotRequirement) req).getRequirement();
- if (!isApplicable(negatedReq))
+ private void expandNegatedRequirement(IRequirement req, IInstallableUnit iu, List<AbstractVariable> optionalAbstractRequirements, boolean isRootIu) throws ContradictionException {
+ if (!isApplicable(req))
return;
- List matches = getApplicableMatches(negatedReq);
+ List<IInstallableUnit> matches = getApplicableMatches(req);
if (matches.isEmpty()) {
return;
}
Explanation explanation;
if (isRootIu) {
- IInstallableUnit reqIu = (IInstallableUnit) matches.iterator().next();
+ IInstallableUnit reqIu = matches.get(0);
if (alreadyInstalledIUs.contains(reqIu)) {
explanation = new Explanation.IUInstalled(reqIu);
} else {
@@ -336,22 +334,22 @@ public class Projector {
createNegationImplication(iu, matches, explanation);
}
- private void expandRequirement(IRequiredCapability req, IInstallableUnit iu, List optionalAbstractRequirements, boolean isRootIu) throws ContradictionException {
- if (req.isNegation()) {
+ private void expandRequirement(IRequirement req, IInstallableUnit iu, List<AbstractVariable> optionalAbstractRequirements, boolean isRootIu) throws ContradictionException {
+ if (req.getMax() == 0) {
expandNegatedRequirement(req, iu, optionalAbstractRequirements, isRootIu);
return;
}
if (!isApplicable(req))
return;
- List matches = getApplicableMatches(req);
+ List<IInstallableUnit> matches = getApplicableMatches(req);
if (isHostRequirement(iu, req)) {
- rememberHostMatches(iu, matches);
+ rememberHostMatches((IInstallableUnitFragment) iu, matches);
}
- if (!req.isOptional()) {
+ if (req.getMin() > 0) {
if (matches.isEmpty()) {
missingRequirement(iu, req);
} else {
- IInstallableUnit reqIu = (IInstallableUnit) picker.query(new CapabilityQuery(req), new Collector(), null).iterator().next();
+ IInstallableUnit reqIu = matches.get(0);
Explanation explanation;
if (isRootIu) {
if (alreadyInstalledIUs.contains(reqIu)) {
@@ -373,13 +371,12 @@ public class Projector {
}
}
- private void expandRequirements(IRequiredCapability[] reqs, IInstallableUnit iu, boolean isRootIu) throws ContradictionException {
- if (reqs.length == 0) {
+ private void expandRequirements(Collection<IRequirement> reqs, IInstallableUnit iu, boolean isRootIu) throws ContradictionException {
+ if (reqs.isEmpty())
return;
- }
- List optionalAbstractRequirements = new ArrayList();
- for (int i = 0; i < reqs.length; i++) {
- expandRequirement(reqs[i], iu, optionalAbstractRequirements, isRootIu);
+ List<AbstractVariable> optionalAbstractRequirements = new ArrayList<AbstractVariable>();
+ for (IRequirement req : reqs) {
+ expandRequirement(req, iu, optionalAbstractRequirements, isRootIu);
}
createOptionalityExpression(iu, optionalAbstractRequirements);
}
@@ -387,16 +384,21 @@ public class Projector {
public void processIU(IInstallableUnit iu, boolean isRootIU) throws ContradictionException {
iu = iu.unresolved();
- slice.put(iu.getId(), iu.getVersion(), iu);
+ Map<Version, IInstallableUnit> iuSlice = slice.get(iu.getId());
+ if (iuSlice == null) {
+ iuSlice = new HashMap<Version, IInstallableUnit>();
+ slice.put(iu.getId(), iuSlice);
+ }
+ iuSlice.put(iu.getVersion(), iu);
if (!isApplicable(iu)) {
createNegation(iu, null);
return;
}
- Collector applicablePatches = getApplicablePatches(iu);
+ IQueryResult<IInstallableUnit> applicablePatches = getApplicablePatches(iu);
expandLifeCycle(iu, isRootIU);
//No patches apply, normal code path
- if (applicablePatches.size() == 0) {
+ if (applicablePatches.isEmpty()) {
expandRequirements(getRequiredCapabilities(iu), iu, isRootIU);
} else {
//Patches are applicable to the IU
@@ -404,21 +406,35 @@ public class Projector {
}
}
- private IRequiredCapability[] getRequiredCapabilities(IInstallableUnit iu) {
- if (considerMetaRequirements == false || iu.getMetaRequiredCapabilities().length == 0)
- return iu.getRequiredCapabilities();
- IRequiredCapability[] aggregatedCapabilities = new IRequiredCapability[iu.getRequiredCapabilities().length + iu.getMetaRequiredCapabilities().length];
- System.arraycopy(iu.getRequiredCapabilities(), 0, aggregatedCapabilities, 0, iu.getRequiredCapabilities().length);
- System.arraycopy(iu.getMetaRequiredCapabilities(), 0, aggregatedCapabilities, iu.getRequiredCapabilities().length, iu.getMetaRequiredCapabilities().length);
- return aggregatedCapabilities;
+ private Collection<IRequirement> getRequiredCapabilities(IInstallableUnit iu) {
+ Collection<IRequirement> rqs = iu.getRequiredCapabilities();
+ if (!considerMetaRequirements)
+ return rqs;
+
+ Collection<IRequirement> metaRqs = iu.getMetaRequiredCapabilities();
+ if (metaRqs.isEmpty())
+ return rqs;
+
+ ArrayList<IRequirement> aggregatedRqs = new ArrayList<IRequirement>(rqs.size() + metaRqs.size());
+ aggregatedRqs.addAll(rqs);
+ aggregatedRqs.addAll(metaRqs);
+ return aggregatedRqs;
+ }
+
+ static final class Pending {
+ List<IInstallableUnit> matches;
+ Explanation explanation;
+ Object left;
}
- private void expandRequirementsWithPatches(IInstallableUnit iu, Collector applicablePatches, boolean isRootIu) throws ContradictionException {
+ private void expandRequirementsWithPatches(IInstallableUnit iu, IQueryResult<IInstallableUnit> applicablePatches, boolean isRootIu) throws ContradictionException {
//Unmodified dependencies
- Map unchangedRequirements = new HashMap(getRequiredCapabilities(iu).length);
- for (Iterator iterator = applicablePatches.iterator(); iterator.hasNext();) {
+ Collection<IRequirement> iuRequirements = getRequiredCapabilities(iu);
+ Map<IRequirement, List<IInstallableUnitPatch>> unchangedRequirements = new HashMap<IRequirement, List<IInstallableUnitPatch>>(iuRequirements.size());
+ Map<IRequirement, Pending> nonPatchedRequirements = new HashMap<IRequirement, Pending>(iuRequirements.size());
+ for (Iterator<IInstallableUnit> iterator = applicablePatches.iterator(); iterator.hasNext();) {
IInstallableUnitPatch patch = (IInstallableUnitPatch) iterator.next();
- IRequiredCapability[][] reqs = mergeRequirements(iu, patch);
+ IRequirement[][] reqs = mergeRequirements(iu, patch);
if (reqs.length == 0)
return;
@@ -427,16 +443,16 @@ public class Projector {
// noop(IU)-> ~ABS
// IU -> (noop(IU) or ABS)
// Therefore we only need one optional requirement statement per IU
- List optionalAbstractRequirements = new ArrayList();
+ List<AbstractVariable> optionalAbstractRequirements = new ArrayList<AbstractVariable>();
for (int i = 0; i < reqs.length; i++) {
//The requirement is unchanged
if (reqs[i][0] == reqs[i][1]) {
if (!isApplicable(reqs[i][0]))
continue;
- List patchesAppliedElseWhere = (List) unchangedRequirements.get(reqs[i][0]);
+ List<IInstallableUnitPatch> patchesAppliedElseWhere = unchangedRequirements.get(reqs[i][0]);
if (patchesAppliedElseWhere == null) {
- patchesAppliedElseWhere = new ArrayList();
+ patchesAppliedElseWhere = new ArrayList<IInstallableUnitPatch>();
unchangedRequirements.put(reqs[i][0], patchesAppliedElseWhere);
}
patchesAppliedElseWhere.add(patch);
@@ -446,16 +462,16 @@ public class Projector {
//Generate dependency when the patch is applied
//P1 -> (A -> D) equiv. (P1 & A) -> D
if (isApplicable(reqs[i][1])) {
- IRequiredCapability req = reqs[i][1];
- List matches = getApplicableMatches(req);
+ IRequirement req = reqs[i][1];
+ List<IInstallableUnit> matches = getApplicableMatches(req);
if (isHostRequirement(iu, req)) {
- rememberHostMatches(iu, matches);
+ rememberHostMatches((IInstallableUnitFragment) iu, matches);
}
- if (!req.isOptional()) {
+ if (req.getMin() > 0) {
if (matches.isEmpty()) {
missingRequirement(patch, req);
} else {
- IInstallableUnit reqIu = (IInstallableUnit) picker.query(new CapabilityQuery(req), new Collector(), null).iterator().next();
+ IInstallableUnit reqIu = matches.get(0);
Explanation explanation;
if (isRootIu) {
if (alreadyInstalledIUs.contains(reqIu)) {
@@ -479,17 +495,26 @@ public class Projector {
//Generate dependency when the patch is not applied
//-P1 -> (A -> B) ( equiv. A -> (P1 or B) )
if (isApplicable(reqs[i][0])) {
- IRequiredCapability req = reqs[i][0];
- List matches = getApplicableMatches(req);
+ IRequirement req = reqs[i][0];
+
+ // Fix: if multiple patches apply to the same IU-req, we need to make sure we list each
+ // patch as an optional match
+ Pending pending = nonPatchedRequirements.get(req);
+ if (pending != null) {
+ pending.matches.add(patch);
+ continue;
+ }
+
+ List<IInstallableUnit> matches = getApplicableMatches(req);
if (isHostRequirement(iu, req)) {
- rememberHostMatches(iu, matches);
+ rememberHostMatches((IInstallableUnitFragment) iu, matches);
}
- if (!req.isOptional()) {
+ if (req.getMin() > 0) {
if (matches.isEmpty()) {
dependencyHelper.implication(new Object[] {iu}).implies(patch).named(new Explanation.HardRequirement(iu, null));
} else {
matches.add(patch);
- IInstallableUnit reqIu = (IInstallableUnit) picker.query(new CapabilityQuery(req), new Collector(), null).iterator().next();
+ IInstallableUnit reqIu = matches.get(0);///(IInstallableUnit) picker.query(new CapabilityQuery(req), new Collector(), null).iterator().next();
Explanation explanation;
if (isRootIu) {
@@ -501,13 +526,26 @@ public class Projector {
} else {
explanation = new Explanation.HardRequirement(iu, req);
}
- createImplication(iu, matches, explanation);
+
+ // Fix: make sure we collect all patches that will impact this IU-req, not just one
+ pending = new Pending();
+ pending.left = iu;
+ pending.explanation = explanation;
+ pending.matches = matches;
+ nonPatchedRequirements.put(req, pending);
}
} else {
if (!matches.isEmpty()) {
AbstractVariable abs = getAbstractVariable();
matches.add(patch);
- createImplication(new Object[] {abs, iu}, matches, Explanation.OPTIONAL_REQUIREMENT);
+
+ // Fix: make sure we collect all patches that will impact this IU-req, not just one
+ pending = new Pending();
+ pending.left = new Object[] {abs, iu};
+ pending.explanation = Explanation.OPTIONAL_REQUIREMENT;
+ pending.matches = matches;
+ nonPatchedRequirements.put(req, pending);
+
optionalAbstractRequirements.add(abs);
}
}
@@ -515,23 +553,28 @@ public class Projector {
}
createOptionalityExpression(iu, optionalAbstractRequirements);
}
- List optionalAbstractRequirements = new ArrayList();
- for (Iterator iterator = unchangedRequirements.entrySet().iterator(); iterator.hasNext();) {
- Entry entry = (Entry) iterator.next();
- List patchesApplied = (List) entry.getValue();
- List allPatches = new ArrayList(applicablePatches.toCollection());
- allPatches.removeAll(patchesApplied);
- List requiredPatches = new ArrayList();
- for (Iterator iterator2 = allPatches.iterator(); iterator2.hasNext();) {
- IInstallableUnitPatch patch = (IInstallableUnitPatch) iterator2.next();
- requiredPatches.add(patch);
+
+ // Fix: now create the pending non-patch requirements based on the full set of patches
+ for (Pending pending : nonPatchedRequirements.values()) {
+ createImplication(pending.left, pending.matches, pending.explanation);
+ }
+
+ List<AbstractVariable> optionalAbstractRequirements = new ArrayList<AbstractVariable>();
+ for (Entry<IRequirement, List<IInstallableUnitPatch>> entry : unchangedRequirements.entrySet()) {
+ List<IInstallableUnitPatch> patchesApplied = entry.getValue();
+ Iterator<IInstallableUnit> allPatches = applicablePatches.iterator();
+ List<IInstallableUnitPatch> requiredPatches = new ArrayList<IInstallableUnitPatch>();
+ while (allPatches.hasNext()) {
+ IInstallableUnitPatch patch = (IInstallableUnitPatch) allPatches.next();
+ if (!patchesApplied.contains(patch))
+ requiredPatches.add(patch);
}
- IRequiredCapability req = (IRequiredCapability) entry.getKey();
- List matches = getApplicableMatches(req);
+ IRequirement req = entry.getKey();
+ List<IInstallableUnit> matches = getApplicableMatches(req);
if (isHostRequirement(iu, req)) {
- rememberHostMatches(iu, matches);
+ rememberHostMatches((IInstallableUnitFragment) iu, matches);
}
- if (!req.isOptional()) {
+ if (req.getMin() > 0) {
if (matches.isEmpty()) {
if (requiredPatches.isEmpty()) {
missingRequirement(iu, req);
@@ -541,7 +584,7 @@ public class Projector {
} else {
if (!requiredPatches.isEmpty())
matches.addAll(requiredPatches);
- IInstallableUnit reqIu = (IInstallableUnit) picker.query(new CapabilityQuery(req), new Collector(), null).iterator().next();
+ IInstallableUnit reqIu = matches.get(0);//(IInstallableUnit) picker.query(new CapabilityQuery(req), new Collector(), null).iterator().next();
Explanation explanation;
if (isRootIu) {
if (alreadyInstalledIUs.contains(reqIu)) {
@@ -571,13 +614,13 @@ public class Projector {
if (!(iu instanceof IInstallableUnitPatch))
return;
IInstallableUnitPatch patch = (IInstallableUnitPatch) iu;
- IRequiredCapability req = patch.getLifeCycle();
+ IRequirement req = patch.getLifeCycle();
if (req == null)
return;
- expandRequirement(req, iu, Collections.EMPTY_LIST, isRootIu);
+ expandRequirement(req, iu, CollectionUtils.<AbstractVariable> emptyList(), isRootIu);
}
- private void missingRequirement(IInstallableUnit iu, IRequiredCapability req) throws ContradictionException {
+ private void missingRequirement(IInstallableUnit iu, IRequirement req) throws ContradictionException {
result.add(new Status(IStatus.WARNING, DirectorActivator.PI_DIRECTOR, NLS.bind(Messages.Planner_Unsatisfied_dependency, iu, req)));
createNegation(iu, req);
}
@@ -586,11 +629,11 @@ public class Projector {
* @param req
* @return a list of mandatory requirements if any, an empty list if req.isOptional().
*/
- private List getApplicableMatches(IRequiredCapability req) {
- List target = new ArrayList();
- Collector matches = picker.query(new CapabilityQuery(req), new Collector(), null);
- for (Iterator iterator = matches.iterator(); iterator.hasNext();) {
- IInstallableUnit match = (IInstallableUnit) iterator.next();
+ private List<IInstallableUnit> getApplicableMatches(IRequirement req) {
+ List<IInstallableUnit> target = new ArrayList<IInstallableUnit>();
+ IQueryResult<IInstallableUnit> matches = picker.query(new ExpressionQuery<IInstallableUnit>(IInstallableUnit.class, req.getMatches()), null);
+ for (Iterator<IInstallableUnit> iterator = matches.iterator(); iterator.hasNext();) {
+ IInstallableUnit match = iterator.next();
if (isApplicable(match)) {
target.add(match);
}
@@ -599,36 +642,37 @@ public class Projector {
}
//Return a new array of requirements representing the application of the patch
- private IRequiredCapability[][] mergeRequirements(IInstallableUnit iu, IInstallableUnitPatch patch) {
+ private IRequirement[][] mergeRequirements(IInstallableUnit iu, IInstallableUnitPatch patch) {
if (patch == null)
return null;
- IRequirementChange[] changes = patch.getRequirementsChange();
- IRequiredCapability[] originalRequirements = new IRequiredCapability[iu.getRequiredCapabilities().length];
- System.arraycopy(iu.getRequiredCapabilities(), 0, originalRequirements, 0, originalRequirements.length);
- List rrr = new ArrayList();
+ List<IRequirementChange> changes = patch.getRequirementsChange();
+ Collection<IRequirement> iuRequirements = iu.getRequiredCapabilities();
+ IRequirement[] originalRequirements = iuRequirements.toArray(new IRequirement[iuRequirements.size()]);
+ List<IRequirement[]> rrr = new ArrayList<IRequirement[]>();
boolean found = false;
- for (int i = 0; i < changes.length; i++) {
+ for (int i = 0; i < changes.size(); i++) {
+ IRequirementChange change = changes.get(i);
for (int j = 0; j < originalRequirements.length; j++) {
- if (originalRequirements[j] != null && changes[i].matches(originalRequirements[j])) {
+ if (originalRequirements[j] != null && change.matches((IRequiredCapability) originalRequirements[j])) {
found = true;
- if (changes[i].newValue() != null)
- rrr.add(new IRequiredCapability[] {originalRequirements[j], changes[i].newValue()});
+ if (change.newValue() != null)
+ rrr.add(new IRequirement[] {originalRequirements[j], change.newValue()});
else
// case where a requirement is removed
- rrr.add(new IRequiredCapability[] {originalRequirements[j], null});
+ rrr.add(new IRequirement[] {originalRequirements[j], null});
originalRequirements[j] = null;
}
// break;
}
- if (!found && changes[i].applyOn() == null && changes[i].newValue() != null) //Case where a new requirement is added
- rrr.add(new IRequiredCapability[] {null, changes[i].newValue()});
+ if (!found && change.applyOn() == null && change.newValue() != null) //Case where a new requirement is added
+ rrr.add(new IRequirement[] {null, change.newValue()});
}
//Add all the unmodified requirements to the result
for (int i = 0; i < originalRequirements.length; i++) {
if (originalRequirements[i] != null)
- rrr.add(new IRequiredCapability[] {originalRequirements[i], originalRequirements[i]});
+ rrr.add(new IRequirement[] {originalRequirements[i], originalRequirements[i]});
}
- return (IRequiredCapability[][]) rrr.toArray(new IRequiredCapability[rrr.size()][]);
+ return rrr.toArray(new IRequirement[rrr.size()][]);
}
/**
@@ -640,12 +684,11 @@ public class Projector {
* @param optionalRequirements
* @throws ContradictionException
*/
- private void createOptionalityExpression(IInstallableUnit iu, List optionalRequirements) throws ContradictionException {
+ private void createOptionalityExpression(IInstallableUnit iu, List<AbstractVariable> optionalRequirements) throws ContradictionException {
if (optionalRequirements.isEmpty())
return;
AbstractVariable noop = getNoOperationVariable(iu);
- for (Iterator i = optionalRequirements.iterator(); i.hasNext();) {
- AbstractVariable abs = (AbstractVariable) i.next();
+ for (AbstractVariable abs : optionalRequirements) {
createIncompatibleValues(abs, noop);
}
optionalRequirements.add(noop);
@@ -653,24 +696,22 @@ public class Projector {
}
//This will create as many implication as there is element in the right argument
- private void createNegationImplication(Object left, List right, Explanation name) throws ContradictionException {
+ private void createNegationImplication(Object left, List<?> right, Explanation name) throws ContradictionException {
if (DEBUG) {
Tracing.debug(name + ": " + left + "->" + right); //$NON-NLS-1$ //$NON-NLS-2$
}
- for (Iterator iterator = right.iterator(); iterator.hasNext();) {
- dependencyHelper.implication(new Object[] {left}).impliesNot(iterator.next()).named(name);
- }
-
+ for (Object r : right)
+ dependencyHelper.implication(new Object[] {left}).impliesNot(r).named(name);
}
- private void createImplication(Object left, List right, Explanation name) throws ContradictionException {
+ private void createImplication(Object left, List<?> right, Explanation name) throws ContradictionException {
if (DEBUG) {
Tracing.debug(name + ": " + left + "->" + right); //$NON-NLS-1$ //$NON-NLS-2$
}
dependencyHelper.implication(new Object[] {left}).implies(right.toArray()).named(name);
}
- private void createImplication(Object[] left, List right, Explanation name) throws ContradictionException {
+ private void createImplication(Object[] left, List<?> right, Explanation name) throws ContradictionException {
if (DEBUG) {
Tracing.debug(name + ": " + Arrays.asList(left) + "->" + right); //$NON-NLS-1$ //$NON-NLS-2$
}
@@ -678,28 +719,26 @@ public class Projector {
}
//Return IUPatches that are applicable for the given iu
- private Collector getApplicablePatches(IInstallableUnit iu) {
+ private IQueryResult<IInstallableUnit> getApplicablePatches(IInstallableUnit iu) {
if (patches == null)
- patches = new QueryableArray((IInstallableUnit[]) picker.query(ApplicablePatchQuery.ANY, new Collector(), null).toArray(IInstallableUnit.class));
+ patches = new QueryableArray(picker.query(new PatchQuery(), null).toArray(IInstallableUnit.class));
- return patches.query(new ApplicablePatchQuery(iu), new Collector(), null);
+ return patches.query(new ApplicablePatchQuery(iu), null);
}
//Create constraints to deal with singleton
//When there is a mix of singleton and non singleton, several constraints are generated
private void createConstraintsForSingleton() throws ContradictionException {
- Set s = slice.entrySet();
- for (Iterator iterator = s.iterator(); iterator.hasNext();) {
- Map.Entry entry = (Map.Entry) iterator.next();
- HashMap conflictingEntries = (HashMap) entry.getValue();
+ Set<Entry<String, Map<Version, IInstallableUnit>>> s = slice.entrySet();
+ for (Entry<String, Map<Version, IInstallableUnit>> entry : s) {
+ Map<Version, IInstallableUnit> conflictingEntries = entry.getValue();
if (conflictingEntries.size() < 2)
continue;
- Collection conflictingVersions = conflictingEntries.values();
- List singletons = new ArrayList();
- List nonSingletons = new ArrayList();
- for (Iterator conflictIterator = conflictingVersions.iterator(); conflictIterator.hasNext();) {
- IInstallableUnit iu = (IInstallableUnit) conflictIterator.next();
+ Collection<IInstallableUnit> conflictingVersions = conflictingEntries.values();
+ List<IInstallableUnit> singletons = new ArrayList<IInstallableUnit>();
+ List<IInstallableUnit> nonSingletons = new ArrayList<IInstallableUnit>();
+ for (IInstallableUnit iu : conflictingVersions) {
if (iu.isSingleton()) {
singletons.add(iu);
} else {
@@ -711,12 +750,12 @@ public class Projector {
IInstallableUnit[] singletonArray;
if (nonSingletons.isEmpty()) {
- singletonArray = (IInstallableUnit[]) singletons.toArray(new IInstallableUnit[singletons.size()]);
+ singletonArray = singletons.toArray(new IInstallableUnit[singletons.size()]);
createAtMostOne(singletonArray);
} else {
- singletonArray = (IInstallableUnit[]) singletons.toArray(new IInstallableUnit[singletons.size() + 1]);
- for (Iterator iterator2 = nonSingletons.iterator(); iterator2.hasNext();) {
- singletonArray[singletonArray.length - 1] = (IInstallableUnit) iterator2.next();
+ singletonArray = singletons.toArray(new IInstallableUnit[singletons.size() + 1]);
+ for (IInstallableUnit nonSingleton : nonSingletons) {
+ singletonArray[singletonArray.length - 1] = nonSingleton;
createAtMostOne(singletonArray);
}
}
@@ -731,7 +770,7 @@ public class Projector {
}
Tracing.debug("At most 1 of " + b); //$NON-NLS-1$
}
- dependencyHelper.atMost(1, ius).named(new Explanation.Singleton(ius));
+ dependencyHelper.atMost(1, (Object[]) ius).named(new Explanation.Singleton(ius));
}
private void createIncompatibleValues(AbstractVariable v1, AbstractVariable v2) throws ContradictionException {
@@ -743,7 +782,7 @@ public class Projector {
}
Tracing.debug("At most 1 of " + b); //$NON-NLS-1$
}
- dependencyHelper.atMost(1, vars).named(Explanation.OPTIONAL_REQUIREMENT);
+ dependencyHelper.atMost(1, (Object[]) vars).named(Explanation.OPTIONAL_REQUIREMENT);
}
private AbstractVariable getAbstractVariable() {
@@ -753,7 +792,7 @@ public class Projector {
}
private AbstractVariable getNoOperationVariable(IInstallableUnit iu) {
- AbstractVariable v = (AbstractVariable) noopVariables.get(iu);
+ AbstractVariable v = noopVariables.get(iu);
if (v == null) {
v = new AbstractVariable();
noopVariables.put(iu, v);
@@ -798,10 +837,10 @@ public class Projector {
}
private void backToIU() {
- solution = new ArrayList();
- IVec sat4jSolution = dependencyHelper.getSolution();
- for (Iterator i = sat4jSolution.iterator(); i.hasNext();) {
- Object var = i.next();
+ solution = new ArrayList<IInstallableUnit>();
+ IVec<Object> sat4jSolution = dependencyHelper.getSolution();
+ for (Iterator<Object> iter = sat4jSolution.iterator(); iter.hasNext();) {
+ Object var = iter.next();
if (var instanceof IInstallableUnit) {
IInstallableUnit iu = (IInstallableUnit) var;
if (iu == entryPoint)
@@ -811,23 +850,23 @@ public class Projector {
}
}
- private void printSolution(Collection state) {
- ArrayList l = new ArrayList(state);
+ private void printSolution(Collection<IInstallableUnit> state) {
+ ArrayList<IInstallableUnit> l = new ArrayList<IInstallableUnit>(state);
Collections.sort(l);
Tracing.debug("Solution:"); //$NON-NLS-1$
Tracing.debug("Numbers of IUs selected: " + l.size()); //$NON-NLS-1$
- for (Iterator iterator = l.iterator(); iterator.hasNext();) {
- Tracing.debug(iterator.next().toString());
+ for (IInstallableUnit s : l) {
+ Tracing.debug(s.toString());
}
}
- public Collection extractSolution() {
+ public Collection<IInstallableUnit> extractSolution() {
if (DEBUG)
printSolution(solution);
return solution;
}
- public Set getExplanation(IProgressMonitor monitor) {
+ public Set<Explanation> getExplanation(IProgressMonitor monitor) {
ExplanationJob job = new ExplanationJob();
job.schedule();
monitor.setTaskName(Messages.Planner_NoSolution);
@@ -855,16 +894,14 @@ public class Projector {
return job.getExplanationResult();
}
- public Map getFragmentAssociation() {
- Map resolvedFragments = new HashMap(fragments.size());
- for (Iterator iterator = fragments.entrySet().iterator(); iterator.hasNext();) {
- Entry fragment = (Entry) iterator.next();
+ public Map<IInstallableUnitFragment, List<IInstallableUnit>> getFragmentAssociation() {
+ Map<IInstallableUnitFragment, List<IInstallableUnit>> resolvedFragments = new HashMap<IInstallableUnitFragment, List<IInstallableUnit>>(fragments.size());
+ for (Entry<IInstallableUnitFragment, Set<IInstallableUnit>> fragment : fragments.entrySet()) {
if (!dependencyHelper.getBooleanValueFor(fragment.getKey()))
continue;
- Set potentialHosts = (Set) fragment.getValue();
- List resolvedHost = new ArrayList(potentialHosts.size());
- for (Iterator iterator2 = potentialHosts.iterator(); iterator2.hasNext();) {
- Object host = iterator2.next();
+ Set<IInstallableUnit> potentialHosts = fragment.getValue();
+ List<IInstallableUnit> resolvedHost = new ArrayList<IInstallableUnit>(potentialHosts.size());
+ for (IInstallableUnit host : potentialHosts) {
if (dependencyHelper.getBooleanValueFor(host))
resolvedHost.add(host);
}
@@ -874,26 +911,26 @@ public class Projector {
return resolvedFragments;
}
- private void rememberHostMatches(IInstallableUnit fragment, List matches) {
- Set existingMatches = (Set) fragments.get(fragment);
+ private void rememberHostMatches(IInstallableUnitFragment fragment, List<IInstallableUnit> matches) {
+ Set<IInstallableUnit> existingMatches = fragments.get(fragment);
if (existingMatches == null) {
- existingMatches = new HashSet();
+ existingMatches = new HashSet<IInstallableUnit>();
fragments.put(fragment, existingMatches);
existingMatches.addAll(matches);
}
existingMatches.retainAll(matches);
}
- private boolean isHostRequirement(IInstallableUnit iu, IRequiredCapability req) {
+ private boolean isHostRequirement(IInstallableUnit iu, IRequirement req) {
if (!(iu instanceof IInstallableUnitFragment))
return false;
IInstallableUnitFragment fragment = (IInstallableUnitFragment) iu;
- IRequiredCapability[] reqs = fragment.getHost();
+ IRequirement[] reqs = fragment.getHost();
for (int i = 0; i < reqs.length; i++) {
- if (req == reqs[i])
+ if (req.equals(reqs[i]))
return true;
}
- return true;
+ return false;
}
} \ No newline at end of file
diff --git a/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/QueryableArray.java b/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/QueryableArray.java
index 80f500296..1a250b301 100644
--- a/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/QueryableArray.java
+++ b/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/QueryableArray.java
@@ -12,70 +12,56 @@ package org.eclipse.equinox.internal.p2.director;
import java.util.*;
import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.equinox.internal.p2.metadata.ORRequirement;
-import org.eclipse.equinox.internal.provisional.p2.metadata.*;
-import org.eclipse.equinox.internal.provisional.p2.metadata.query.*;
+import org.eclipse.equinox.internal.p2.metadata.RequiredCapability;
+import org.eclipse.equinox.p2.metadata.IInstallableUnit;
+import org.eclipse.equinox.p2.metadata.IProvidedCapability;
+import org.eclipse.equinox.p2.metadata.expression.IMatchExpression;
+import org.eclipse.equinox.p2.metadata.query.ExpressionQuery;
+import org.eclipse.equinox.p2.query.*;
-public class QueryableArray implements IQueryable {
- static class IUCapability {
- final IInstallableUnit iu;
- final IProvidedCapability capability;
-
- public IUCapability(IInstallableUnit iu, IProvidedCapability capability) {
- this.iu = iu;
- this.capability = capability;
- }
- }
-
- private final List dataSet;
- private Map namedCapabilityIndex;
+public class QueryableArray implements IQueryable<IInstallableUnit> {
+ private final List<IInstallableUnit> dataSet;
+ private Map<String, List<IInstallableUnit>> namedCapabilityIndex;
public QueryableArray(IInstallableUnit[] ius) {
dataSet = Arrays.asList(ius);
}
- public Collector query(Query query, Collector collector, IProgressMonitor monitor) {
- if (query instanceof CapabilityQuery)
- return queryCapability((CapabilityQuery) query, collector, monitor);
- return query.perform(dataSet.iterator(), collector);
+ public IQueryResult<IInstallableUnit> query(IQuery<IInstallableUnit> query, IProgressMonitor monitor) {
+ if (query instanceof ExpressionQuery)
+ return queryCapability((ExpressionQuery) query, new Collector<IInstallableUnit>(), monitor);
+ return query.perform(dataSet.iterator());
}
- private Collector queryCapability(CapabilityQuery query, Collector collector, IProgressMonitor monitor) {
+ private Collector<IInstallableUnit> queryCapability(ExpressionQuery query, Collector<IInstallableUnit> collector, IProgressMonitor monitor) {
generateNamedCapabilityIndex();
- IRequiredCapability[] requiredCapabilities = query.getRequiredCapabilities();
- Collection resultIUs = null;
- for (int i = 0; i < requiredCapabilities.length; i++) {
- if (requiredCapabilities[i] instanceof ORRequirement) {
- query.perform(dataSet.iterator(), collector);
- continue;
- }
- Collection matchingIUs = findMatchingIUs(requiredCapabilities[i]);
- if (matchingIUs == null)
- return collector;
- if (resultIUs == null)
- resultIUs = matchingIUs;
- else
- resultIUs.retainAll(matchingIUs);
- }
+ Collection<IInstallableUnit> resultIUs = null;
+ Collection<IInstallableUnit> matchingIUs = findMatchingIUs(query.getExpression());
+ if (matchingIUs == null)
+ return collector;
+ if (resultIUs == null)
+ resultIUs = matchingIUs;
+ else
+ resultIUs.retainAll(matchingIUs);
if (resultIUs != null)
- for (Iterator iterator = resultIUs.iterator(); iterator.hasNext();)
+ for (Iterator<IInstallableUnit> iterator = resultIUs.iterator(); iterator.hasNext();)
collector.accept(iterator.next());
return collector;
}
- private Collection findMatchingIUs(IRequiredCapability requiredCapability) {
- List iuCapabilities = (List) namedCapabilityIndex.get(requiredCapability.getName());
- if (iuCapabilities == null)
+ private Collection<IInstallableUnit> findMatchingIUs(IMatchExpression requirementMatch) {
+ // TODO: This is a hack. Should be replaced by use of proper indexes
+ List<IInstallableUnit> ius = namedCapabilityIndex.get(RequiredCapability.extractName(requirementMatch));
+ if (ius == null)
return null;
- Set matchingIUs = new HashSet();
- for (Iterator iterator = iuCapabilities.iterator(); iterator.hasNext();) {
- IUCapability iuCapability = (IUCapability) iterator.next();
- if (iuCapability.capability.satisfies(requiredCapability))
- matchingIUs.add(iuCapability.iu);
+ Set<IInstallableUnit> matchingIUs = new HashSet<IInstallableUnit>();
+ for (IInstallableUnit iu : ius) {
+ if (requirementMatch.isMatch(iu))
+ matchingIUs.add(iu);
}
return matchingIUs;
}
@@ -84,19 +70,18 @@ public class QueryableArray implements IQueryable {
if (namedCapabilityIndex != null)
return;
- namedCapabilityIndex = new HashMap();
- for (Iterator iterator = dataSet.iterator(); iterator.hasNext();) {
- IInstallableUnit iu = (IInstallableUnit) iterator.next();
+ namedCapabilityIndex = new HashMap<String, List<IInstallableUnit>>();
+ for (IInstallableUnit iu : dataSet) {
- IProvidedCapability[] providedCapabilities = iu.getProvidedCapabilities();
- for (int i = 0; i < providedCapabilities.length; i++) {
- String name = providedCapabilities[i].getName();
- List iuCapabilities = (List) namedCapabilityIndex.get(name);
- if (iuCapabilities == null) {
- iuCapabilities = new ArrayList(5);
- namedCapabilityIndex.put(name, iuCapabilities);
+ Collection<IProvidedCapability> providedCapabilities = iu.getProvidedCapabilities();
+ for (IProvidedCapability pc : providedCapabilities) {
+ String name = pc.getName();
+ List<IInstallableUnit> ius = namedCapabilityIndex.get(name);
+ if (ius == null) {
+ ius = new ArrayList<IInstallableUnit>(5);
+ namedCapabilityIndex.put(name, ius);
}
- iuCapabilities.add(new IUCapability(iu, providedCapabilities[i]));
+ ius.add(iu);
}
}
}
diff --git a/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/SimpleDirector.java b/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/SimpleDirector.java
index 884c422f7..58bce1e85 100644
--- a/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/SimpleDirector.java
+++ b/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/SimpleDirector.java
@@ -10,8 +10,8 @@ package org.eclipse.equinox.internal.p2.director;
import org.eclipse.core.runtime.*;
import org.eclipse.equinox.internal.provisional.p2.director.*;
-import org.eclipse.equinox.internal.provisional.p2.engine.*;
-import org.eclipse.equinox.internal.provisional.p2.metadata.IInstallableUnit;
+import org.eclipse.equinox.p2.engine.*;
+import org.eclipse.equinox.p2.metadata.IInstallableUnit;
import org.eclipse.osgi.util.NLS;
public class SimpleDirector implements IDirector {
@@ -32,7 +32,7 @@ public class SimpleDirector implements IDirector {
public IStatus revert(IProfile currentProfile, IProfile revertProfile, ProvisioningContext context, IProgressMonitor monitor) {
SubMonitor sub = SubMonitor.convert(monitor, Messages.Director_Task_Updating, PlanWork + EngineWork);
try {
- ProvisioningPlan plan = planner.getDiffPlan(currentProfile, revertProfile, sub.newChild(PlanWork));
+ IProvisioningPlan plan = planner.getDiffPlan(currentProfile, revertProfile, sub.newChild(PlanWork));
return PlanExecutionHelper.executePlan(plan, engine, context, sub.newChild(EngineWork));
} finally {
sub.done();
@@ -46,9 +46,9 @@ public class SimpleDirector implements IDirector {
IInstallableUnit[] installRoots = request.getAddedInstallableUnits();
// mark the roots as such
for (int i = 0; i < installRoots.length; i++) {
- request.setInstallableUnitProfileProperty(installRoots[i], IInstallableUnit.PROP_PROFILE_ROOT_IU, Boolean.toString(true));
+ request.setInstallableUnitProfileProperty(installRoots[i], IProfile.PROP_PROFILE_ROOT_IU, Boolean.toString(true));
}
- ProvisioningPlan plan = planner.getProvisioningPlan(request, context, sub.newChild(PlanWork));
+ IProvisioningPlan plan = planner.getProvisioningPlan(request, context, sub.newChild(PlanWork));
return PlanExecutionHelper.executePlan(plan, engine, context, sub.newChild(EngineWork));
} finally {
sub.done();
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 719a69293..71304c460 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2009 IBM Corporation and others. All rights reserved. This
+ * Copyright (c) 2007, 2010 IBM Corporation and others. All rights reserved. This
* program and the accompanying materials are made available under the terms of
* the Eclipse Public License v1.0 which accompanies this distribution, and is
* available at http://www.eclipse.org/legal/epl-v10.html
@@ -16,16 +16,21 @@ import java.util.Map.Entry;
import org.eclipse.core.runtime.*;
import org.eclipse.equinox.internal.p2.core.helpers.LogHelper;
import org.eclipse.equinox.internal.p2.core.helpers.Tracing;
+import org.eclipse.equinox.internal.p2.metadata.query.UpdateQuery;
import org.eclipse.equinox.internal.p2.rollback.FormerState;
-import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException;
import org.eclipse.equinox.internal.provisional.p2.director.*;
-import org.eclipse.equinox.internal.provisional.p2.engine.*;
-import org.eclipse.equinox.internal.provisional.p2.metadata.*;
+import org.eclipse.equinox.internal.provisional.p2.metadata.MetadataFactory;
import org.eclipse.equinox.internal.provisional.p2.metadata.MetadataFactory.InstallableUnitDescription;
-import org.eclipse.equinox.internal.provisional.p2.metadata.query.*;
-import org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepository;
-import org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepositoryManager;
-import org.eclipse.equinox.internal.provisional.p2.repository.IRepositoryManager;
+import org.eclipse.equinox.p2.core.ProvisionException;
+import org.eclipse.equinox.p2.engine.*;
+import org.eclipse.equinox.p2.engine.query.IUProfilePropertyQuery;
+import org.eclipse.equinox.p2.metadata.*;
+import org.eclipse.equinox.p2.metadata.query.ExpressionQuery;
+import org.eclipse.equinox.p2.metadata.query.InstallableUnitQuery;
+import org.eclipse.equinox.p2.query.*;
+import org.eclipse.equinox.p2.repository.IRepositoryManager;
+import org.eclipse.equinox.p2.repository.metadata.IMetadataRepository;
+import org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager;
import org.eclipse.osgi.util.NLS;
public class SimplePlanner implements IPlanner {
@@ -41,39 +46,43 @@ public class SimplePlanner implements IPlanner {
private final IMetadataRepositoryManager repoManager;
private final IProfileRegistry profileRegistry;
- private ProvisioningPlan generateProvisioningPlan(Collection fromState, Collection toState, ProfileChangeRequest changeRequest, ProvisioningPlan installerPlan) {
- InstallableUnitOperand[] iuOperands = generateOperations(fromState, toState);
+ private ProvisioningPlan generateProvisioningPlan(Collection<IInstallableUnit> fromState, Collection<IInstallableUnit> toState, ProfileChangeRequest changeRequest, IProvisioningPlan installerPlan, ProvisioningContext context) {
+ List<InstallableUnitOperand> iuOperands = generateOperations(fromState, toState);
PropertyOperand[] propertyOperands = generatePropertyOperations(changeRequest);
- Operand[] operands = new Operand[iuOperands.length + propertyOperands.length];
- System.arraycopy(iuOperands, 0, operands, 0, iuOperands.length);
- System.arraycopy(propertyOperands, 0, operands, iuOperands.length, propertyOperands.length);
+ int iuOpsSize = iuOperands.size();
+ Operand[] operands = new Operand[iuOpsSize + propertyOperands.length];
+ for (int i = 0; i < iuOpsSize; ++i)
+ operands[i] = iuOperands.get(i);
+ System.arraycopy(propertyOperands, 0, operands, iuOpsSize, propertyOperands.length);
if (DEBUG) {
for (int i = 0; i < operands.length; i++) {
Tracing.debug(operands[i].toString());
}
}
- return new ProvisioningPlan(Status.OK_STATUS, operands, computeActualChangeRequest(toState, changeRequest), null, installerPlan, changeRequest, new QueryableArray((IInstallableUnit[]) toState.toArray(new IInstallableUnit[toState.size()])));
+ return new ProvisioningPlan(Status.OK_STATUS, operands, computeActualChangeRequest(toState, changeRequest), null, installerPlan, changeRequest.getProfile(), new QueryableArray(toState.toArray(new IInstallableUnit[toState.size()])), context);
}
- private Map[] buildDetailedErrors(ProfileChangeRequest changeRequest) {
+ private Map<IInstallableUnit, IStatus>[] buildDetailedErrors(ProfileChangeRequest changeRequest) {
IInstallableUnit[] added = changeRequest.getAddedInstallableUnits();
IInstallableUnit[] removed = changeRequest.getRemovedInstallableUnits();
- Map requestStatus = new HashMap(added.length + removed.length);
+ Map<IInstallableUnit, RequestStatus> requestStatus = new HashMap<IInstallableUnit, RequestStatus>(added.length + removed.length);
for (int i = 0; i < added.length; i++) {
requestStatus.put(added[i], new RequestStatus(added[i], RequestStatus.ADDED, IStatus.ERROR, null));
}
for (int i = 0; i < removed.length; i++) {
requestStatus.put(removed[i], new RequestStatus(removed[i], RequestStatus.REMOVED, IStatus.ERROR, null));
}
- return new Map[] {requestStatus, null};
+ @SuppressWarnings("unchecked")
+ Map<IInstallableUnit, IStatus>[] maps = new Map[] {requestStatus, null};
+ return maps;
}
- private Map[] computeActualChangeRequest(Collection toState, ProfileChangeRequest changeRequest) {
+ private Map<IInstallableUnit, IStatus>[] computeActualChangeRequest(Collection<IInstallableUnit> toState, ProfileChangeRequest changeRequest) {
IInstallableUnit[] added = changeRequest.getAddedInstallableUnits();
IInstallableUnit[] removed = changeRequest.getRemovedInstallableUnits();
- Map requestStatus = new HashMap(added.length + removed.length);
+ Map<IInstallableUnit, RequestStatus> requestStatus = new HashMap<IInstallableUnit, RequestStatus>(added.length + removed.length);
for (int i = 0; i < added.length; i++) {
if (toState.contains(added[i]))
requestStatus.put(added[i], new RequestStatus(added[i], RequestStatus.ADDED, IStatus.OK, null));
@@ -89,37 +98,34 @@ public class SimplePlanner implements IPlanner {
}
//Compute the side effect changes (e.g. things installed optionally going away)
- Collection includedIUs = new HashSet(changeRequest.getProfile().query(new IUProfilePropertyQuery(INCLUSION_RULES, null), new Collector(), null).toCollection());
- Map sideEffectStatus = new HashMap(includedIUs.size());
- includedIUs.removeAll(toState);
- for (Iterator iterator = includedIUs.iterator(); iterator.hasNext();) {
- IInstallableUnit removal = (IInstallableUnit) iterator.next();
- if (!requestStatus.containsKey(removal))
+ Iterator<IInstallableUnit> includedIUs = changeRequest.getProfile().query(new IUProfilePropertyQuery(INCLUSION_RULES, null), null).iterator();
+ Map<IInstallableUnit, RequestStatus> sideEffectStatus = new HashMap<IInstallableUnit, RequestStatus>();
+ while (includedIUs.hasNext()) {
+ IInstallableUnit removal = includedIUs.next();
+ if (!toState.contains(removal) && !requestStatus.containsKey(removal)) {
sideEffectStatus.put(removal, new RequestStatus(removal, RequestStatus.REMOVED, IStatus.INFO, null));
+ }
}
- return new Map[] {requestStatus, sideEffectStatus};
+ @SuppressWarnings("unchecked")
+ Map<IInstallableUnit, IStatus>[] maps = new Map[] {requestStatus, sideEffectStatus};
+ return maps;
}
/**
* Converts a set containing a list of resolver explanations into a human-readable status object.
*/
- private IStatus convertExplanationToStatus(Set explanations) {
+ private IStatus convertExplanationToStatus(Set<Explanation> explanations) {
if (explanations == null)
return new Status(IStatus.ERROR, DirectorActivator.PI_DIRECTOR, Messages.Director_Unsatisfied_Dependencies);
MultiStatus root = new MultiStatus(DirectorActivator.PI_DIRECTOR, 1, Messages.Director_Unsatisfied_Dependencies, null);
//try to find a more specific root message if possible
String specificMessage = null;
- for (Iterator it = explanations.iterator(); it.hasNext();) {
- final Object next = it.next();
- if (next instanceof Explanation) {
- root.add(((Explanation) next).toStatus());
- if (specificMessage == null && next instanceof Explanation.MissingIU)
- specificMessage = Messages.Explanation_rootMissing;
- else if (specificMessage == null && next instanceof Explanation.Singleton) {
- specificMessage = Messages.Explanation_rootSingleton;
- }
- } else
- root.add(new Status(IStatus.ERROR, DirectorActivator.PI_DIRECTOR, next.toString()));
+ for (Explanation next : explanations) {
+ root.add(next.toStatus());
+ if (specificMessage == null && next instanceof Explanation.MissingIU)
+ specificMessage = Messages.Explanation_rootMissing;
+ else if (specificMessage == null && next instanceof Explanation.Singleton)
+ specificMessage = Messages.Explanation_rootSingleton;
}
//use a more specific root message if available
if (specificMessage != null) {
@@ -132,60 +138,50 @@ public class SimplePlanner implements IPlanner {
private PropertyOperand[] generatePropertyOperations(ProfileChangeRequest profileChangeRequest) {
IProfile profile = profileChangeRequest.getProfile();
- List operands = new ArrayList();
+ List<PropertyOperand> operands = new ArrayList<PropertyOperand>();
// First deal with profile properties to remove. Only generate an operand if the property was there in the first place
String[] toRemove = profileChangeRequest.getPropertiesToRemove();
- Map existingProperties = profile.getProperties();
+ Map<String, String> existingProperties = profile.getProperties();
for (int i = 0; i < toRemove.length; i++) {
if (existingProperties.containsKey(toRemove[i]))
operands.add(new PropertyOperand(toRemove[i], existingProperties.get(toRemove[i]), null));
}
// Now deal with profile property changes/additions
- Map propertyChanges = profileChangeRequest.getPropertiesToAdd();
- Iterator iter = propertyChanges.entrySet().iterator();
- while (iter.hasNext()) {
- Map.Entry entry = (Map.Entry) iter.next();
- operands.add(new PropertyOperand((String) entry.getKey(), existingProperties.get(entry.getKey()), entry.getValue()));
+ Map<String, String> propertyChanges = profileChangeRequest.getPropertiesToAdd();
+ for (Entry<String, String> entry : propertyChanges.entrySet()) {
+ operands.add(new PropertyOperand(entry.getKey(), existingProperties.get(entry.getKey()), entry.getValue()));
}
// Now deal with iu property changes/additions.
// TODO we aren't yet checking that the IU will exist in the final profile, will the engine do this?
- Map allIUPropertyChanges = profileChangeRequest.getInstallableUnitProfilePropertiesToAdd();
- iter = allIUPropertyChanges.entrySet().iterator();
- while (iter.hasNext()) {
- Map.Entry entry = (Map.Entry) iter.next();
- IInstallableUnit iu = (IInstallableUnit) entry.getKey();
- Map iuPropertyChanges = (Map) entry.getValue();
- Iterator iuPropIter = iuPropertyChanges.entrySet().iterator();
- while (iuPropIter.hasNext()) {
- Map.Entry entry2 = (Map.Entry) iuPropIter.next();
- Object oldValue = profile.getInstallableUnitProperty(iu, (String) entry2.getKey());
- operands.add(new InstallableUnitPropertyOperand(iu, (String) entry2.getKey(), oldValue, entry2.getValue()));
+ Map<IInstallableUnit, Map<String, String>> allIUPropertyChanges = profileChangeRequest.getInstallableUnitProfilePropertiesToAdd();
+ for (Entry<IInstallableUnit, Map<String, String>> entry : allIUPropertyChanges.entrySet()) {
+ IInstallableUnit iu = entry.getKey();
+ for (Entry<String, String> entry2 : entry.getValue().entrySet()) {
+ Object oldValue = profile.getInstallableUnitProperty(iu, entry2.getKey());
+ operands.add(new InstallableUnitPropertyOperand(iu, entry2.getKey(), oldValue, entry2.getValue()));
}
}
// Now deal with iu property removals.
// TODO we could optimize by not generating property removals for IU's that aren't there or won't be there.
- Map allIUPropertyDeletions = profileChangeRequest.getInstallableUnitProfilePropertiesToRemove();
- iter = allIUPropertyDeletions.entrySet().iterator();
- while (iter.hasNext()) {
- Map.Entry entry = (Map.Entry) iter.next();
- IInstallableUnit iu = (IInstallableUnit) entry.getKey();
- Map existingIUProperties = profile.getInstallableUnitProperties(iu);
- List iuPropertyRemovals = (List) entry.getValue();
- for (Iterator it = iuPropertyRemovals.iterator(); it.hasNext();) {
- String key = (String) it.next();
+ Map<IInstallableUnit, List<String>> allIUPropertyDeletions = profileChangeRequest.getInstallableUnitProfilePropertiesToRemove();
+ for (Entry<IInstallableUnit, List<String>> entry : allIUPropertyDeletions.entrySet()) {
+ IInstallableUnit iu = entry.getKey();
+ Map<String, String> existingIUProperties = profile.getInstallableUnitProperties(iu);
+ List<String> iuPropertyRemovals = entry.getValue();
+ for (String key : iuPropertyRemovals) {
if (existingIUProperties.containsKey(key))
operands.add(new InstallableUnitPropertyOperand(iu, key, existingIUProperties.get(key), null));
}
}
- return (PropertyOperand[]) operands.toArray(new PropertyOperand[operands.size()]);
+ return operands.toArray(new PropertyOperand[operands.size()]);
}
- private InstallableUnitOperand[] generateOperations(Collection fromState, Collection toState) {
+ private List<InstallableUnitOperand> generateOperations(Collection<IInstallableUnit> fromState, Collection<IInstallableUnit> toState) {
return new OperationGenerator().generateOperation(fromState, toState);
}
- public ProvisioningPlan getDiffPlan(IProfile currentProfile, IProfile targetProfile, IProgressMonitor monitor) {
+ public IProvisioningPlan getDiffPlan(IProfile currentProfile, IProfile targetProfile, IProgressMonitor monitor) {
SubMonitor sub = SubMonitor.convert(monitor, ExpandWork);
sub.setTaskName(Messages.Director_Task_Resolving_Dependencies);
try {
@@ -193,7 +189,7 @@ public class SimplePlanner implements IPlanner {
ProvisioningContext context = new ProvisioningContext(new URI[0]);
if (context.getProperty(INCLUDE_PROFILE_IUS) == null)
context.setProperty(INCLUDE_PROFILE_IUS, Boolean.FALSE.toString());
- context.setExtraIUs(new ArrayList(targetProfile.available(InstallableUnitQuery.ANY, new Collector(), null).toCollection()));
+ context.setExtraIUs(Arrays.asList(targetProfile.available(InstallableUnitQuery.ANY, null).toArray(IInstallableUnit.class)));
return getProvisioningPlan(profileChangeRequest, context, sub.newChild(ExpandWork / 2));
} finally {
sub.done();
@@ -201,23 +197,13 @@ public class SimplePlanner implements IPlanner {
}
public static IInstallableUnit[] findPlannerMarkedIUs(final IProfile profile) {
- Query markerQuery = new MatchQuery() {
- public boolean isMatch(Object candidate) {
- if (!(candidate instanceof IInstallableUnit))
- return false;
-
- IInstallableUnit iu = (IInstallableUnit) candidate;
-
- String inclusion = profile.getInstallableUnitProperty(iu, INCLUSION_RULES);
- return (inclusion != null);
- }
- };
- return (IInstallableUnit[]) profile.query(markerQuery, new Collector(), null).toArray(IInstallableUnit.class);
+ IQuery<IInstallableUnit> markerQuery = new IUProfilePropertyQuery(INCLUSION_RULES, null);
+ return profile.query(markerQuery, null).toArray(IInstallableUnit.class);
}
- public static Dictionary createSelectionContext(Map properties) {
- Hashtable result = new Hashtable(properties);
- String environments = (String) properties.get(IProfile.PROP_ENVIRONMENTS);
+ public static Dictionary<String, String> createSelectionContext(Map<String, String> properties) {
+ Hashtable<String, String> result = new Hashtable<String, String>(properties);
+ String environments = properties.get(IProfile.PROP_ENVIRONMENTS);
if (environments == null)
return result;
for (StringTokenizer tokenizer = new StringTokenizer(environments, ","); tokenizer.hasMoreElements();) { //$NON-NLS-1$
@@ -231,7 +217,7 @@ public class SimplePlanner implements IPlanner {
}
private IInstallableUnit[] gatherAvailableInstallableUnits(IInstallableUnit[] additionalSource, URI[] repositories, ProvisioningContext context, IProgressMonitor monitor) {
- Map resultsMap = new HashMap();
+ Map<String, IInstallableUnit> resultsMap = new HashMap<String, IInstallableUnit>();
if (additionalSource != null) {
for (int i = 0; i < additionalSource.length; i++) {
String key = additionalSource[i].getId() + "_" + additionalSource[i].getVersion().toString(); //$NON-NLS-1$
@@ -239,8 +225,7 @@ public class SimplePlanner implements IPlanner {
}
}
if (context != null) {
- for (Iterator iter = context.getExtraIUs().iterator(); iter.hasNext();) {
- IInstallableUnit iu = (IInstallableUnit) iter.next();
+ for (IInstallableUnit iu : context.getExtraIUs()) {
String key = iu.getId() + '_' + iu.getVersion().toString();
resultsMap.put(key, iu);
}
@@ -256,11 +241,11 @@ public class SimplePlanner implements IPlanner {
throw new OperationCanceledException();
IMetadataRepository repository = repoManager.loadRepository(repositories[i], sub.newChild(100));
- Collector matches = repository.query(new InstallableUnitQuery(null, VersionRange.emptyRange), new Collector(), sub.newChild(100));
- for (Iterator it = matches.iterator(); it.hasNext();) {
- IInstallableUnit iu = (IInstallableUnit) it.next();
+ IQueryResult<IInstallableUnit> matches = repository.query(new InstallableUnitQuery(null, VersionRange.emptyRange), sub.newChild(100));
+ for (Iterator<IInstallableUnit> it = matches.iterator(); it.hasNext();) {
+ IInstallableUnit iu = it.next();
String key = iu.getId() + "_" + iu.getVersion().toString(); //$NON-NLS-1$
- IInstallableUnit currentIU = (IInstallableUnit) resultsMap.get(key);
+ IInstallableUnit currentIU = resultsMap.get(key);
if (currentIU == null || hasHigherFidelity(iu, currentIU))
resultsMap.put(key, iu);
}
@@ -269,8 +254,8 @@ public class SimplePlanner implements IPlanner {
}
}
sub.done();
- Collection results = resultsMap.values();
- return (IInstallableUnit[]) results.toArray(new IInstallableUnit[results.size()]);
+ Collection<IInstallableUnit> results = resultsMap.values();
+ return results.toArray(new IInstallableUnit[results.size()]);
}
private static boolean hasHigherFidelity(IInstallableUnit iu, IInstallableUnit currentIU) {
@@ -286,10 +271,10 @@ public class SimplePlanner implements IPlanner {
this.repoManager = repoManager;
}
- private boolean satisfyMetaRequirements(Map props) {
+ private boolean satisfyMetaRequirements(Map<String, String> props) {
if (props == null)
return true;
- if (props.get(CONSIDER_METAREQUIREMENTS) == null || "true".equalsIgnoreCase((String) props.get(CONSIDER_METAREQUIREMENTS))) //$NON-NLS-1$
+ if (props.get(CONSIDER_METAREQUIREMENTS) == null || "true".equalsIgnoreCase(props.get(CONSIDER_METAREQUIREMENTS))) //$NON-NLS-1$
return true;
return false;
}
@@ -308,33 +293,36 @@ public class SimplePlanner implements IPlanner {
Object[] updatedPlan = updatePlannerInfo(profileChangeRequest, context);
URI[] metadataRepositories = (context != null) ? context.getMetadataRepositories() : null;
- Dictionary newSelectionContext = createSelectionContext(profileChangeRequest.getProfileProperties());
+ Dictionary<String, String> newSelectionContext = createSelectionContext(profileChangeRequest.getProfileProperties());
- List extraIUs = new ArrayList(Arrays.asList(profileChangeRequest.getAddedInstallableUnits()));
+ List<IInstallableUnit> extraIUs = new ArrayList<IInstallableUnit>(Arrays.asList(profileChangeRequest.getAddedInstallableUnits()));
extraIUs.addAll(Arrays.asList(profileChangeRequest.getRemovedInstallableUnits()));
- if (context == null || context.getProperty(INCLUDE_PROFILE_IUS) == null || context.getProperty(INCLUDE_PROFILE_IUS).equalsIgnoreCase(Boolean.TRUE.toString()))
- extraIUs.addAll(profile.available(InstallableUnitQuery.ANY, new Collector(), null).toCollection());
+ if (context == null || context.getProperty(INCLUDE_PROFILE_IUS) == null || context.getProperty(INCLUDE_PROFILE_IUS).equalsIgnoreCase(Boolean.TRUE.toString())) {
+ Iterator<IInstallableUnit> itor = profile.available(InstallableUnitQuery.ANY, null).iterator();
+ while (itor.hasNext())
+ extraIUs.add(itor.next());
+ }
- IInstallableUnit[] availableIUs = gatherAvailableInstallableUnits((IInstallableUnit[]) extraIUs.toArray(new IInstallableUnit[extraIUs.size()]), metadataRepositories, context, sub.newChild(ExpandWork / 4));
+ IInstallableUnit[] availableIUs = gatherAvailableInstallableUnits(extraIUs.toArray(new IInstallableUnit[extraIUs.size()]), metadataRepositories, context, 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<IInstallableUnit> slice = slicer.slice(new IInstallableUnit[] {(IInstallableUnit) updatedPlan[0]}, sub.newChild(ExpandWork / 4));
if (slice == null)
- return new ProvisioningPlan(slicer.getStatus(), profileChangeRequest, null);
+ return new ProvisioningPlan(slicer.getStatus(), profile, null, context);
Projector projector = new Projector(slice, newSelectionContext, satisfyMetaRequirements(profileChangeRequest.getProfileProperties()));
- projector.encode((IInstallableUnit) updatedPlan[0], (IInstallableUnit[]) updatedPlan[1], profileChangeRequest.getAddedInstallableUnits(), sub.newChild(ExpandWork / 4));
+ projector.encode((IInstallableUnit) updatedPlan[0], (IInstallableUnit[]) updatedPlan[1], profile, profileChangeRequest.getAddedInstallableUnits(), sub.newChild(ExpandWork / 4));
IStatus s = projector.invokeSolver(sub.newChild(ExpandWork / 4));
if (s.getSeverity() == IStatus.CANCEL)
- return new ProvisioningPlan(s, profileChangeRequest, null);
+ return new ProvisioningPlan(s, profile, null, context);
if (s.getSeverity() == IStatus.ERROR) {
sub.setTaskName(Messages.Planner_NoSolution);
if (context != null && !(context.getProperty(EXPLANATION) == null || Boolean.TRUE.toString().equalsIgnoreCase(context.getProperty(EXPLANATION))))
- return new ProvisioningPlan(s, profileChangeRequest, null);
+ return new ProvisioningPlan(s, profile, null, context);
//Extract the explanation
- Set explanation = projector.getExplanation(sub.newChild(ExpandWork / 4));
+ Set<Explanation> explanation = projector.getExplanation(sub.newChild(ExpandWork / 4));
IStatus explanationStatus = convertExplanationToStatus(explanation);
- return new ProvisioningPlan(explanationStatus, new Operand[0], buildDetailedErrors(profileChangeRequest), new RequestStatus(null, RequestStatus.REMOVED, IStatus.ERROR, explanation), null, profileChangeRequest, null);
+ return new ProvisioningPlan(explanationStatus, new Operand[0], buildDetailedErrors(profileChangeRequest), new RequestStatus(null, RequestStatus.REMOVED, IStatus.ERROR, explanation), null, profile, null, context);
}
//The resolution succeeded. We can forget about the warnings since there is a solution.
if (Tracing.DEBUG && s.getSeverity() != IStatus.OK)
@@ -347,70 +335,88 @@ public class SimplePlanner implements IPlanner {
}
}
- public ProvisioningPlan getProvisioningPlan(ProfileChangeRequest profileChangeRequest, ProvisioningContext context, IProgressMonitor monitor) {
+ public IProvisioningPlan getProvisioningPlan(ProfileChangeRequest profileChangeRequest, ProvisioningContext context, IProgressMonitor monitor) {
+ if (profileChangeRequest.getAbsolute())
+ return generateAbsoluteProvisioningPlan(profileChangeRequest, context, monitor);
SubMonitor sub = SubMonitor.convert(monitor, ExpandWork);
sub.setTaskName(Messages.Director_Task_Resolving_Dependencies);
try {
//Get the solution for the initial request
Object resolutionResult = getSolutionFor(profileChangeRequest, context, sub.newChild(ExpandWork / 2));
- if (resolutionResult instanceof ProvisioningPlan)
+ if (resolutionResult instanceof IProvisioningPlan)
return (ProvisioningPlan) resolutionResult;
- Collection newState = ((Projector) resolutionResult).extractSolution();
- Collection fullState = new ArrayList();
+ Collection<IInstallableUnit> newState = ((Projector) resolutionResult).extractSolution();
+ Collection<IInstallableUnit> fullState = new ArrayList<IInstallableUnit>();
fullState.addAll(newState);
- newState = AttachmentHelper.attachFragments(newState, ((Projector) resolutionResult).getFragmentAssociation());
+ newState = AttachmentHelper.attachFragments(newState.iterator(), ((Projector) resolutionResult).getFragmentAssociation());
- ProvisioningPlan temporaryPlan = generatePlan((Projector) resolutionResult, newState, profileChangeRequest);
+ ProvisioningPlan temporaryPlan = generatePlan((Projector) resolutionResult, newState, profileChangeRequest, context);
//Create a plan for installing necessary pieces to complete the installation (e.g touchpoint actions)
return createInstallerPlan(profileChangeRequest.getProfile(), profileChangeRequest, fullState, newState, temporaryPlan, context, sub.newChild(ExpandWork / 2));
} catch (OperationCanceledException e) {
- return new ProvisioningPlan(Status.CANCEL_STATUS, profileChangeRequest, null);
+ return new ProvisioningPlan(Status.CANCEL_STATUS, profileChangeRequest.getProfile(), null, context);
} finally {
sub.done();
}
}
+ private IProvisioningPlan generateAbsoluteProvisioningPlan(ProfileChangeRequest profileChangeRequest, ProvisioningContext context, IProgressMonitor monitor) {
+ Set<IInstallableUnit> toState = profileChangeRequest.getProfile().query(InstallableUnitQuery.ANY, null).toSet();
+ HashSet<IInstallableUnit> fromState = new HashSet<IInstallableUnit>(toState);
+ toState.removeAll(Arrays.asList(profileChangeRequest.getRemovedInstallableUnits()));
+ toState.addAll(Arrays.asList(profileChangeRequest.getAddedInstallableUnits()));
+
+ List<InstallableUnitOperand> iuOperands = generateOperations(fromState, toState);
+ PropertyOperand[] propertyOperands = generatePropertyOperations(profileChangeRequest);
+
+ int iuOpsSize = iuOperands.size();
+ Operand[] operands = new Operand[iuOpsSize + propertyOperands.length];
+ for (int i = 0; i < iuOpsSize; ++i)
+ operands[i] = iuOperands.get(i);
+ System.arraycopy(propertyOperands, 0, operands, iuOpsSize, propertyOperands.length);
+
+ if (DEBUG) {
+ for (int i = 0; i < operands.length; i++) {
+ Tracing.debug(operands[i].toString());
+ }
+ }
+ return new ProvisioningPlan(Status.OK_STATUS, operands, computeActualChangeRequest(toState, profileChangeRequest), null, null, profileChangeRequest.getProfile(), new QueryableArray(toState.toArray(new IInstallableUnit[toState.size()])), context);
+
+ }
+
//Verify that all the meta requirements necessary to perform the uninstallation (if necessary) and all t
- private Collection areMetaRequirementsSatisfied(IProfile oldProfile, Collection newProfile, ProvisioningPlan initialPlan) {
- Collection allMetaRequirements = extractMetaRequirements(newProfile, initialPlan);
- for (Iterator iterator = allMetaRequirements.iterator(); iterator.hasNext();) {
- IRequiredCapability requirement = (IRequiredCapability) iterator.next();
- if (oldProfile.query(new CapabilityQuery(requirement), new HasMatchCollector(), null).isEmpty())
+ private Collection<IRequirement> areMetaRequirementsSatisfied(IProfile oldProfile, Collection<IInstallableUnit> newProfile, IProvisioningPlan initialPlan) {
+ Collection<IRequirement> allMetaRequirements = extractMetaRequirements(newProfile, initialPlan);
+ for (IRequirement requirement : allMetaRequirements) {
+ if (oldProfile.query(new LimitQuery<IInstallableUnit>(new ExpressionQuery<IInstallableUnit>(IInstallableUnit.class, requirement.getMatches()), 1), null).isEmpty())
return allMetaRequirements;
}
return null;
}
//Return all the meta requirements for the list of IU specified and all the meta requirements listed necessary to satisfy the uninstallation
- private Collection extractMetaRequirements(Collection ius, ProvisioningPlan plan) {
- Set allMetaRequirements = new HashSet();
- for (Iterator iterator = ius.iterator(); iterator.hasNext();) {
- IInstallableUnit iu = (IInstallableUnit) iterator.next();
- IRequiredCapability[] reqs = iu.getMetaRequiredCapabilities();
- for (int i = 0; i < reqs.length; i++) {
- allMetaRequirements.add(reqs[i]);
- }
+ private Collection<IRequirement> extractMetaRequirements(Collection<IInstallableUnit> ius, IProvisioningPlan plan) {
+ Set<IRequirement> allMetaRequirements = new HashSet<IRequirement>();
+ for (IInstallableUnit iu : ius) {
+ allMetaRequirements.addAll(iu.getMetaRequiredCapabilities());
}
- Collector c2 = plan.getRemovals().query(InstallableUnitQuery.ANY, new Collector(), null);
- for (Iterator iterator = c2.iterator(); iterator.hasNext();) {
- IInstallableUnit iu = (IInstallableUnit) iterator.next();
- IRequiredCapability[] reqs = iu.getMetaRequiredCapabilities();
- for (int i = 0; i < reqs.length; i++) {
- allMetaRequirements.add(reqs[i]);
- }
+ IQueryResult<IInstallableUnit> queryResult = plan.getRemovals().query(InstallableUnitQuery.ANY, null);
+ for (Iterator<IInstallableUnit> iterator = queryResult.iterator(); iterator.hasNext();) {
+ IInstallableUnit iu = iterator.next();
+ allMetaRequirements.addAll(iu.getMetaRequiredCapabilities());
}
return allMetaRequirements;
}
- private ProvisioningPlan createInstallerPlan(IProfile profile, ProfileChangeRequest initialRequest, Collection unattachedState, Collection expectedState, ProvisioningPlan initialPlan, ProvisioningContext initialContext, IProgressMonitor monitor) {
+ private ProvisioningPlan createInstallerPlan(IProfile profile, ProfileChangeRequest initialRequest, Collection<IInstallableUnit> unattachedState, Collection<IInstallableUnit> expectedState, ProvisioningPlan initialPlan, ProvisioningContext initialContext, IProgressMonitor monitor) {
SubMonitor sub = SubMonitor.convert(monitor, ExpandWork);
try {
sub.setTaskName(Messages.Director_Task_installer_plan);
if (profileRegistry == null)
- return new ProvisioningPlan(new Status(IStatus.ERROR, DirectorActivator.PI_DIRECTOR, Messages.Planner_no_profile_registry), initialRequest, null);
+ return new ProvisioningPlan(new Status(IStatus.ERROR, DirectorActivator.PI_DIRECTOR, Messages.Planner_no_profile_registry), profile, null, initialContext);
IProfile agentProfile = profileRegistry.getProfile(IProfileRegistry.SELF);
if (agentProfile == null)
@@ -418,7 +424,7 @@ public class SimplePlanner implements IPlanner {
if (profile.getProfileId().equals(agentProfile.getProfileId())) {
if (profile.getTimestamp() != agentProfile.getTimestamp())
- return new ProvisioningPlan(new Status(IStatus.ERROR, DirectorActivator.PI_DIRECTOR, NLS.bind(Messages.Planner_profile_out_of_sync, profile.getProfileId())), initialRequest, null);
+ return new ProvisioningPlan(new Status(IStatus.ERROR, DirectorActivator.PI_DIRECTOR, NLS.bind(Messages.Planner_profile_out_of_sync, profile.getProfileId())), profile, null, initialContext);
return createInstallerPlanForCohostedCase(profile, initialRequest, initialPlan, unattachedState, expectedState, initialContext, sub);
}
@@ -431,14 +437,14 @@ public class SimplePlanner implements IPlanner {
}
}
- private ProvisioningPlan createInstallerPlanForCohostedCaseFromExternalInstaller(IProfile profile, ProfileChangeRequest initialRequest, ProvisioningPlan initialPlan, Collection newState, ProvisioningContext initialContext, IProfile agentProfile, SubMonitor sub) {
- ProvisioningPlan planForProfile = generatePlan(null, newState, initialRequest);
+ private ProvisioningPlan createInstallerPlanForCohostedCaseFromExternalInstaller(IProfile profile, ProfileChangeRequest initialRequest, IProvisioningPlan initialPlan, Collection<IInstallableUnit> newState, ProvisioningContext initialContext, IProfile agentProfile, SubMonitor sub) {
+ ProvisioningPlan 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 ProvisioningPlan createInstallerPlanForExternalInstaller(IProfile targetedProfile, ProfileChangeRequest initialRequest, ProvisioningPlan initialPlan, Collection expectedState, ProvisioningContext initialContext, IProfile agentProfile, SubMonitor sub) {
- Collection metaRequirements = areMetaRequirementsSatisfied(agentProfile, expectedState, initialPlan);
+ private ProvisioningPlan createInstallerPlanForExternalInstaller(IProfile targetedProfile, ProfileChangeRequest initialRequest, ProvisioningPlan initialPlan, Collection<IInstallableUnit> expectedState, ProvisioningContext initialContext, IProfile agentProfile, SubMonitor sub) {
+ Collection<IRequirement> metaRequirements = areMetaRequirementsSatisfied(agentProfile, expectedState, initialPlan);
if (metaRequirements == null)
return initialPlan;
@@ -446,24 +452,24 @@ public class SimplePlanner implements IPlanner {
IInstallableUnit previousActionsIU = getPreviousIUForMetaRequirements(agentProfile, getActionGatheringIUId(targetedProfile), sub);
ProfileChangeRequest agentRequest = new ProfileChangeRequest(agentProfile);
- agentRequest.addInstallableUnits(new IInstallableUnit[] {actionsIU});
+ agentRequest.addInstallableUnits(actionsIU);
if (previousActionsIU != null)
- agentRequest.removeInstallableUnits(new IInstallableUnit[] {previousActionsIU});
+ agentRequest.removeInstallableUnit(previousActionsIU);
Object externalInstallerPlan = getSolutionFor(agentRequest, initialContext, sub.newChild(10));
- if (externalInstallerPlan instanceof ProvisioningPlan && ((ProvisioningPlan) externalInstallerPlan).getStatus().getSeverity() == IStatus.ERROR) {
+ if (externalInstallerPlan instanceof IProvisioningPlan && ((IProvisioningPlan) externalInstallerPlan).getStatus().getSeverity() == IStatus.ERROR) {
MultiStatus externalInstallerStatus = new MultiStatus(DirectorActivator.PI_DIRECTOR, 0, Messages.Planner_can_not_install_preq, null);
- externalInstallerStatus.add(((ProvisioningPlan) externalInstallerPlan).getStatus());
- return new ProvisioningPlan(externalInstallerStatus, initialRequest, new ProvisioningPlan(externalInstallerStatus, agentRequest, null));
+ externalInstallerStatus.add(((IProvisioningPlan) externalInstallerPlan).getStatus());
+ return new ProvisioningPlan(externalInstallerStatus, initialRequest.getProfile(), new ProvisioningPlan(externalInstallerStatus, agentProfile, null, initialContext), initialContext);
}
- initialPlan.setInstallerPlan(generatePlan((Projector) externalInstallerPlan, null, agentRequest));
+ initialPlan.setInstallerPlan(generatePlan((Projector) externalInstallerPlan, null, agentRequest, initialContext));
return initialPlan;
}
//Deal with the case where the actions needs to be installed in the same profile than the one we are performing the initial request
//The expectedState represents the result of the initialRequest where the metaRequirements have been satisfied.
- private ProvisioningPlan createInstallerPlanForCohostedCase(IProfile profile, ProfileChangeRequest initialRequest, ProvisioningPlan initialPlan, Collection unattachedState, Collection expectedState, ProvisioningContext initialContext, SubMonitor monitor) {
- Collection metaRequirements = initialRequest.getRemovedInstallableUnits().length == 0 ? areMetaRequirementsSatisfied(profile, expectedState, initialPlan) : extractMetaRequirements(expectedState, initialPlan);
+ private ProvisioningPlan createInstallerPlanForCohostedCase(IProfile profile, ProfileChangeRequest initialRequest, ProvisioningPlan initialPlan, Collection<IInstallableUnit> unattachedState, Collection<IInstallableUnit> expectedState, ProvisioningContext initialContext, SubMonitor monitor) {
+ Collection<IRequirement> metaRequirements = initialRequest.getRemovedInstallableUnits().length == 0 ? areMetaRequirementsSatisfied(profile, expectedState, initialPlan) : extractMetaRequirements(expectedState, initialPlan);
if (metaRequirements == null || metaRequirements.isEmpty())
return initialPlan;
@@ -473,102 +479,97 @@ public class SimplePlanner implements IPlanner {
//Create an agent request from the initial request
ProfileChangeRequest agentRequest = new ProfileChangeRequest(profile);
- for (Iterator it = initialRequest.getPropertiesToAdd().entrySet().iterator(); it.hasNext();) {
- Entry entry = (Entry) it.next();
- agentRequest.setProfileProperty((String) entry.getKey(), entry.getValue());
+ for (Entry<String, String> entry : initialRequest.getPropertiesToAdd().entrySet()) {
+ agentRequest.setProfileProperty(entry.getKey(), entry.getValue());
}
String[] removedProperties = initialRequest.getPropertiesToRemove();
for (int i = 0; i < removedProperties.length; i++) {
agentRequest.removeProfileProperty(removedProperties[i]);
}
- Map removedIUProperties = initialRequest.getInstallableUnitProfilePropertiesToRemove();
- for (Iterator iterator = removedIUProperties.entrySet().iterator(); iterator.hasNext();) {
- Entry entry = (Entry) iterator.next();
- ArrayList value = (ArrayList) entry.getValue();
- for (Iterator iterator2 = value.iterator(); iterator2.hasNext();) {
- agentRequest.removeInstallableUnitProfileProperty((IInstallableUnit) entry.getKey(), (String) iterator2.next());
+ Map<IInstallableUnit, List<String>> removedIUProperties = initialRequest.getInstallableUnitProfilePropertiesToRemove();
+ for (Entry<IInstallableUnit, List<String>> entry : removedIUProperties.entrySet()) {
+ for (String propKey : entry.getValue()) {
+ agentRequest.removeInstallableUnitProfileProperty(entry.getKey(), propKey);
}
}
if (previousMetaRequirementIU != null)
- agentRequest.removeInstallableUnits(new IInstallableUnit[] {previousMetaRequirementIU});
- agentRequest.addInstallableUnits(new IInstallableUnit[] {metaRequirementIU});
+ agentRequest.removeInstallableUnit(previousMetaRequirementIU);
+ agentRequest.addInstallableUnits(metaRequirementIU);
ProvisioningContext agentCtx = new ProvisioningContext(new URI[0]);
- ArrayList extraIUs = new ArrayList(unattachedState);
+ ArrayList<IInstallableUnit> extraIUs = new ArrayList<IInstallableUnit>(unattachedState);
agentCtx.setExtraIUs(extraIUs);
Object agentSolution = getSolutionFor(agentRequest, agentCtx, monitor.newChild(3));
- if (agentSolution instanceof ProvisioningPlan && ((ProvisioningPlan) agentSolution).getStatus().getSeverity() == IStatus.ERROR) {
+ if (agentSolution instanceof IProvisioningPlan && ((IProvisioningPlan) agentSolution).getStatus().getSeverity() == IStatus.ERROR) {
MultiStatus agentStatus = new MultiStatus(DirectorActivator.PI_DIRECTOR, 0, Messages.Planner_actions_and_software_incompatible, null);
- agentStatus.add(((ProvisioningPlan) agentSolution).getStatus());
- return new ProvisioningPlan(agentStatus, initialRequest, new ProvisioningPlan(agentStatus, agentRequest, null));
+ agentStatus.add(((IProvisioningPlan) agentSolution).getStatus());
+ return new ProvisioningPlan(agentStatus, initialRequest.getProfile(), new ProvisioningPlan(agentStatus, agentRequest.getProfile(), null, initialContext), initialContext);
}
//Compute the installer plan. It is the difference between what is currently in the profile and the solution we just computed
- Collection agentState = ((Projector) agentSolution).extractSolution();
+ Collection<IInstallableUnit> agentState = ((Projector) agentSolution).extractSolution();
agentState.remove(metaRequirementIU); //Remove the fake IU
- agentState = AttachmentHelper.attachFragments(agentState, ((Projector) agentSolution).getFragmentAssociation());
+ agentState = AttachmentHelper.attachFragments(agentState.iterator(), ((Projector) agentSolution).getFragmentAssociation());
ProvisioningContext noRepoContext = createNoRepoContext(initialRequest);
//...This computes the attachment of what is currently in the profile
Object initialSolution = getSolutionFor(new ProfileChangeRequest(new EverythingOptionalProfile(initialRequest.getProfile())), noRepoContext, new NullProgressMonitor());
- if (initialSolution instanceof ProvisioningPlan) {
+ if (initialSolution instanceof IProvisioningPlan) {
LogHelper.log(new Status(IStatus.ERROR, DirectorActivator.PI_DIRECTOR, "The resolution of the previous state contained in profile " + initialRequest.getProfile().getProfileId() + " version " + initialRequest.getProfile().getTimestamp() + " failed.")); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
return (ProvisioningPlan) initialSolution;
}
- Collection initialState = initialRequest.getProfile().query(InstallableUnitQuery.ANY, new Collector(), null).toCollection();
- initialState = AttachmentHelper.attachFragments(initialState, ((Projector) initialSolution).getFragmentAssociation());
+ Iterator<IInstallableUnit> profileState = initialRequest.getProfile().query(InstallableUnitQuery.ANY, null).iterator();
+ Collection<IInstallableUnit> initialState = AttachmentHelper.attachFragments(profileState, ((Projector) initialSolution).getFragmentAssociation());
- ProvisioningPlan agentPlan = generateProvisioningPlan(initialState, agentState, initialRequest, null);
+ IProvisioningPlan agentPlan = generateProvisioningPlan(initialState, agentState, initialRequest, null, initialContext);
//Compute the installation plan. It is the difference between the state after the installer plan has run and the expectedState.
- return generateProvisioningPlan(agentState, expectedState, initialRequest, agentPlan);
+ return generateProvisioningPlan(agentState, expectedState, initialRequest, agentPlan, initialContext);
}
//Compute the set of operands based on the solution obtained previously
- private ProvisioningPlan generatePlan(Projector newSolution, Collection newState, ProfileChangeRequest request) {
+ private ProvisioningPlan generatePlan(Projector newSolution, Collection<IInstallableUnit> newState, ProfileChangeRequest request, ProvisioningContext context) {
//Compute the attachment of the new state if not provided
if (newState == null) {
newState = newSolution.extractSolution();
- newState = AttachmentHelper.attachFragments(newState, newSolution.getFragmentAssociation());
+ newState = AttachmentHelper.attachFragments(newState.iterator(), newSolution.getFragmentAssociation());
}
ProvisioningContext noRepoContext = createNoRepoContext(request);
//Compute the attachment of the previous state
Object initialSolution = getSolutionFor(new ProfileChangeRequest(new EverythingOptionalProfile(request.getProfile())), noRepoContext, new NullProgressMonitor());
- if (initialSolution instanceof ProvisioningPlan) {
+ if (initialSolution instanceof IProvisioningPlan) {
LogHelper.log(new Status(IStatus.ERROR, DirectorActivator.PI_DIRECTOR, "The resolution of the previous state contained in profile " + request.getProfile().getProfileId() + " version " + request.getProfile().getTimestamp() + " failed.")); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
return (ProvisioningPlan) initialSolution;
}
- Collection initialState = request.getProfile().query(InstallableUnitQuery.ANY, new Collector(), null).toCollection();
- initialState = AttachmentHelper.attachFragments(initialState, ((Projector) initialSolution).getFragmentAssociation());
+ Iterator<IInstallableUnit> profileState = request.getProfile().query(InstallableUnitQuery.ANY, null).iterator();
+ Collection<IInstallableUnit> initialState = AttachmentHelper.attachFragments(profileState, ((Projector) initialSolution).getFragmentAssociation());
//Generate the plan
- return generateProvisioningPlan(initialState, newState, request, null);
+ return generateProvisioningPlan(initialState, newState, request, null, context);
}
private ProvisioningContext createNoRepoContext(ProfileChangeRequest request) {
ProvisioningContext noRepoContext = new ProvisioningContext(new URI[0]);
noRepoContext.setArtifactRepositories(new URI[0]);
noRepoContext.setProperty(INCLUDE_PROFILE_IUS, Boolean.FALSE.toString());
- ArrayList extraIUs = new ArrayList();
- extraIUs.addAll(request.getProfile().query(InstallableUnitQuery.ANY, new Collector(), new NullProgressMonitor()).toCollection());
- noRepoContext.setExtraIUs(extraIUs);
+ noRepoContext.setExtraIUs(new ArrayList<IInstallableUnit>(request.getProfile().query(InstallableUnitQuery.ANY, new NullProgressMonitor()).unmodifiableSet()));
return noRepoContext;
}
private IInstallableUnit getPreviousIUForMetaRequirements(IProfile profile, String iuId, IProgressMonitor monitor) {
- Collector c = profile.query(new InstallableUnitQuery(iuId), new Collector(), monitor);
- if (c.size() == 0)
+ IQueryResult<IInstallableUnit> c = profile.query(new InstallableUnitQuery(iuId), monitor);
+ if (c.isEmpty())
return null;
- return (IInstallableUnit) c.toArray(IInstallableUnit.class)[0];
+ return c.iterator().next();
}
private String getActionGatheringIUId(IProfile profile) {
return ID_IU_FOR_ACTIONS + '.' + profile.getProfileId();
}
- private IInstallableUnit createIUForMetaRequirements(IProfile profile, Collection metaRequirements) {
+ private IInstallableUnit createIUForMetaRequirements(IProfile profile, Collection<IRequirement> metaRequirements) {
InstallableUnitDescription description = new InstallableUnitDescription();
String id = getActionGatheringIUId(profile);
description.setId(id);
@@ -576,7 +577,7 @@ public class SimplePlanner implements IPlanner {
description.setVersion(version);
description.addRequiredCapabilities(metaRequirements);
- ArrayList providedCapabilities = new ArrayList();
+ ArrayList<IProvidedCapability> providedCapabilities = new ArrayList<IProvidedCapability>();
IProvidedCapability providedCapability = MetadataFactory.createProvidedCapability(IInstallableUnit.NAMESPACE_IU_ID, id, version);
providedCapabilities.add(providedCapability);
description.addProvidedCapabilities(providedCapabilities);
@@ -585,12 +586,12 @@ public class SimplePlanner implements IPlanner {
return actionsIU;
}
- private IInstallableUnit createIURepresentingTheProfile(ArrayList allRequirements) {
+ private IInstallableUnit createIURepresentingTheProfile(ArrayList<IRequirement> allRequirements) {
InstallableUnitDescription iud = new MetadataFactory.InstallableUnitDescription();
String time = Long.toString(System.currentTimeMillis());
iud.setId(time);
iud.setVersion(Version.createOSGi(0, 0, 0, time));
- iud.setRequiredCapabilities((IRequiredCapability[]) allRequirements.toArray(new IRequiredCapability[allRequirements.size()]));
+ iud.setRequiredCapabilities(allRequirements.toArray(new IRequirement[allRequirements.size()]));
return MetadataFactory.createInstallableUnit(iud);
}
@@ -598,21 +599,19 @@ public class SimplePlanner implements IPlanner {
//It returns at index 0 a meta IU representing everything that needs to be installed
//It returns at index 1 all the IUs that are in the profile after the removal have been done, but before the addition have been done
private Object[] updatePlannerInfo(ProfileChangeRequest profileChangeRequest, ProvisioningContext context) {
- Collection includedIUs = profileChangeRequest.getProfile().query(new IUProfilePropertyQuery(INCLUSION_RULES, null), new Collector(), null).toCollection();
- Collection alreadyInstalled = new HashSet(includedIUs);
+ IQueryResult<IInstallableUnit> alreadyInstalled = profileChangeRequest.getProfile().query(new IUProfilePropertyQuery(INCLUSION_RULES, null), null);
IInstallableUnit[] added = profileChangeRequest.getAddedInstallableUnits();
IInstallableUnit[] removed = profileChangeRequest.getRemovedInstallableUnits();
- for (Iterator iterator = profileChangeRequest.getInstallableUnitProfilePropertiesToRemove().entrySet().iterator(); iterator.hasNext();) {
- Map.Entry object = (Map.Entry) iterator.next();
- if (((List) object.getValue()).contains(INCLUSION_RULES))
- profileChangeRequest.setInstallableUnitProfileProperty((IInstallableUnit) object.getKey(), INCLUSION_RULES, PlannerHelper.createStrictInclusionRule((IInstallableUnit) object.getKey()));
+ for (Entry<IInstallableUnit, List<String>> object : profileChangeRequest.getInstallableUnitProfilePropertiesToRemove().entrySet()) {
+ if (object.getValue().contains(INCLUSION_RULES))
+ profileChangeRequest.setInstallableUnitProfileProperty(object.getKey(), INCLUSION_RULES, PlannerHelper.createStrictInclusionRule(object.getKey()));
}
//Remove the iu properties associated to the ius removed and the iu properties being removed as well
if (removed.length != 0) {
- for (Iterator iterator = alreadyInstalled.iterator(); iterator.hasNext();) {
- IInstallableUnit iu = (IInstallableUnit) iterator.next();
+ for (Iterator<IInstallableUnit> iterator = alreadyInstalled.iterator(); iterator.hasNext();) {
+ IInstallableUnit iu = iterator.next();
for (int i = 0; i < removed.length; i++) {
if (iu.equals(removed[i])) {
profileChangeRequest.removeInstallableUnitProfileProperty(removed[i], INCLUSION_RULES);
@@ -622,15 +621,15 @@ public class SimplePlanner implements IPlanner {
}
}
}
- ArrayList gatheredRequirements = new ArrayList();
+ ArrayList<IRequirement> gatheredRequirements = new ArrayList<IRequirement>();
//Process all the IUs being added
- Map iuPropertiesToAdd = profileChangeRequest.getInstallableUnitProfilePropertiesToAdd();
+ Map<IInstallableUnit, Map<String, String>> iuPropertiesToAdd = profileChangeRequest.getInstallableUnitProfilePropertiesToAdd();
for (int i = 0; i < added.length; i++) {
- Map propertiesForIU = (Map) iuPropertiesToAdd.get(added[i]);
- IRequiredCapability profileRequirement = null;
+ Map<String, String> propertiesForIU = iuPropertiesToAdd.get(added[i]);
+ IRequirement profileRequirement = null;
if (propertiesForIU != null) {
- profileRequirement = createRequirement(added[i], (String) propertiesForIU.get(INCLUSION_RULES));
+ profileRequirement = createRequirement(added[i], propertiesForIU.get(INCLUSION_RULES));
}
if (profileRequirement == null) {
profileChangeRequest.setInstallableUnitProfileProperty(added[i], INCLUSION_RULES, PlannerHelper.createStrictInclusionRule(added[i]));
@@ -640,13 +639,13 @@ public class SimplePlanner implements IPlanner {
}
//Process the IUs that were already there
- for (Iterator iterator = alreadyInstalled.iterator(); iterator.hasNext();) {
- IInstallableUnit iu = (IInstallableUnit) iterator.next();
- Map propertiesForIU = (Map) iuPropertiesToAdd.get(iu);
- IRequiredCapability profileRequirement = null;
+ for (Iterator<IInstallableUnit> iterator = alreadyInstalled.iterator(); iterator.hasNext();) {
+ IInstallableUnit iu = iterator.next();
+ Map<String, String> propertiesForIU = iuPropertiesToAdd.get(iu);
+ IRequirement profileRequirement = null;
//Test if the value has changed
if (propertiesForIU != null) {
- profileRequirement = createRequirement(iu, (String) propertiesForIU.get(INCLUSION_RULES));
+ profileRequirement = createRequirement(iu, propertiesForIU.get(INCLUSION_RULES));
}
if (profileRequirement == null) {
profileRequirement = createRequirement(iu, profileChangeRequest.getProfile().getInstallableUnitProperty(iu, INCLUSION_RULES));
@@ -657,10 +656,10 @@ public class SimplePlanner implements IPlanner {
//Now add any other requirement that we need to see satisfied
if (context != null && context.getAdditionalRequirements() != null)
gatheredRequirements.addAll(context.getAdditionalRequirements());
- return new Object[] {createIURepresentingTheProfile(gatheredRequirements), (IInstallableUnit[]) alreadyInstalled.toArray(new IInstallableUnit[alreadyInstalled.size()])};
+ return new Object[] {createIURepresentingTheProfile(gatheredRequirements), alreadyInstalled.toArray(IInstallableUnit.class)};
}
- private IRequiredCapability createRequirement(IInstallableUnit iu, String rule) {
+ private IRequirement createRequirement(IInstallableUnit iu, String rule) {
if (rule == null)
return null;
if (rule.equals(PlannerHelper.createStrictInclusionRule(iu))) {
@@ -672,16 +671,16 @@ public class SimplePlanner implements IPlanner {
return null;
}
- private IRequiredCapability createOptionalRequirement(IInstallableUnit iu) {
+ private IRequirement createOptionalRequirement(IInstallableUnit iu) {
return MetadataFactory.createRequiredCapability(IInstallableUnit.NAMESPACE_IU_ID, iu.getId(), new VersionRange(iu.getVersion(), true, iu.getVersion(), true), null, true, false, true);
}
- private IRequiredCapability createStrictRequirement(IInstallableUnit iu) {
+ private IRequirement createStrictRequirement(IInstallableUnit iu) {
return MetadataFactory.createRequiredCapability(IInstallableUnit.NAMESPACE_IU_ID, iu.getId(), new VersionRange(iu.getVersion(), true, iu.getVersion(), true), null, false, false, true);
}
public IInstallableUnit[] updatesFor(IInstallableUnit toUpdate, ProvisioningContext context, IProgressMonitor monitor) {
- Map resultsMap = new HashMap();
+ Map<String, IInstallableUnit> resultsMap = new HashMap<String, IInstallableUnit>();
URI[] repositories = context.getMetadataRepositories();
if (repositories == null)
@@ -693,11 +692,11 @@ public class SimplePlanner implements IPlanner {
if (sub.isCanceled())
throw new OperationCanceledException();
IMetadataRepository repository = repoManager.loadRepository(repositories[i], sub.newChild(100));
- Collector matches = repository.query(new UpdateQuery(toUpdate), new Collector(), sub.newChild(100));
- for (Iterator it = matches.iterator(); it.hasNext();) {
- IInstallableUnit iu = (IInstallableUnit) it.next();
+ IQueryResult<IInstallableUnit> matches = repository.query(new UpdateQuery(toUpdate), sub.newChild(100));
+ for (Iterator<IInstallableUnit> it = matches.iterator(); it.hasNext();) {
+ IInstallableUnit iu = it.next();
String key = iu.getId() + "_" + iu.getVersion().toString(); //$NON-NLS-1$
- IInstallableUnit currentIU = (IInstallableUnit) resultsMap.get(key);
+ IInstallableUnit currentIU = resultsMap.get(key);
if (currentIU == null || hasHigherFidelity(iu, currentIU))
resultsMap.put(key, iu);
}
@@ -706,8 +705,8 @@ public class SimplePlanner implements IPlanner {
}
}
sub.done();
- Collection results = resultsMap.values();
- return (IInstallableUnit[]) results.toArray(new IInstallableUnit[results.size()]);
+ Collection<IInstallableUnit> results = resultsMap.values();
+ return results.toArray(new IInstallableUnit[results.size()]);
}
//helper class to trick the resolver to believe that everything is optional
@@ -718,11 +717,11 @@ public class SimplePlanner implements IPlanner {
profile = p;
}
- public Collector available(Query query, Collector collector, IProgressMonitor monitor) {
- return profile.available(query, collector, monitor);
+ public IQueryResult<IInstallableUnit> available(IQuery<IInstallableUnit> query, IProgressMonitor monitor) {
+ return profile.available(query, monitor);
}
- public Map getInstallableUnitProperties(IInstallableUnit iu) {
+ public Map<String, String> getInstallableUnitProperties(IInstallableUnit iu) {
return profile.getInstallableUnitProperties(iu);
}
@@ -732,23 +731,11 @@ public class SimplePlanner implements IPlanner {
return profile.getInstallableUnitProperty(iu, key);
}
- public Map getLocalProperties() {
- return profile.getLocalProperties();
- }
-
- public String getLocalProperty(String key) {
- return profile.getLocalProperty(key);
- }
-
- public IProfile getParentProfile() {
- return profile.getParentProfile();
- }
-
public String getProfileId() {
return profile.getProfileId();
}
- public Map getProperties() {
+ public Map<String, String> getProperties() {
return profile.getProperties();
}
@@ -756,24 +743,12 @@ public class SimplePlanner implements IPlanner {
return profile.getProperty(key);
}
- public String[] getSubProfileIds() {
- return profile.getSubProfileIds();
- }
-
public long getTimestamp() {
return profile.getTimestamp();
}
- public boolean hasSubProfiles() {
- return profile.hasSubProfiles();
- }
-
- public boolean isRootProfile() {
- return profile.isRootProfile();
- }
-
- public Collector query(Query query, Collector collector, IProgressMonitor monitor) {
- return profile.query(query, collector, monitor);
+ public IQueryResult<IInstallableUnit> query(IQuery<IInstallableUnit> query, IProgressMonitor monitor) {
+ return profile.query(query, monitor);
}
}
}
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 ab629af91..0f84ef178 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2009 IBM Corporation and others.
+ * Copyright (c) 2007, 2010 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -14,33 +14,35 @@ import java.util.*;
import org.eclipse.core.runtime.*;
import org.eclipse.equinox.internal.p2.core.helpers.LogHelper;
import org.eclipse.equinox.internal.p2.core.helpers.Tracing;
-import org.eclipse.equinox.internal.provisional.p2.metadata.*;
-import org.eclipse.equinox.internal.provisional.p2.metadata.query.*;
+import org.eclipse.equinox.p2.metadata.*;
+import org.eclipse.equinox.p2.metadata.query.ExpressionQuery;
+import org.eclipse.equinox.p2.query.IQueryResult;
+import org.eclipse.equinox.p2.query.IQueryable;
import org.eclipse.osgi.util.NLS;
-import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.Filter;
public class Slicer {
private static boolean DEBUG = false;
- private IQueryable possibilites;
+ private IQueryable<IInstallableUnit> possibilites;
- private LinkedList toProcess;
- private Set considered; //IUs to add to the slice
- private TwoTierMap slice; //The IUs that have been considered to be part of the problem
+ private LinkedList<IInstallableUnit> toProcess;
+ private Set<IInstallableUnit> considered; //IUs to add to the slice
+ private Map<String, Map<Version, IInstallableUnit>> slice; //The IUs that have been considered to be part of the problem
- protected Dictionary selectionContext;
+ protected Dictionary<? extends Object, ? extends Object> selectionContext;
private MultiStatus result;
private boolean considerMetaRequirements = false;
- public Slicer(IQueryable input, Dictionary context, boolean considerMetaRequirements) {
+ public Slicer(IQueryable<IInstallableUnit> input, Dictionary<? extends Object, ? extends Object> context, boolean considerMetaRequirements) {
possibilites = input;
- slice = new TwoTierMap();
+ slice = new HashMap<String, Map<Version, IInstallableUnit>>();
selectionContext = context;
result = new MultiStatus(DirectorActivator.PI_DIRECTOR, IStatus.OK, Messages.Planner_Problems_resolving_plan, null);
this.considerMetaRequirements = considerMetaRequirements;
}
- public IQueryable slice(IInstallableUnit[] ius, IProgressMonitor monitor) {
+ public IQueryable<IInstallableUnit> slice(IInstallableUnit[] ius, IProgressMonitor monitor) {
try {
long start = 0;
if (DEBUG) {
@@ -49,14 +51,14 @@ public class Slicer {
}
validateInput(ius);
- considered = new HashSet(Arrays.asList(ius));
- toProcess = new LinkedList(considered);
+ considered = new HashSet<IInstallableUnit>(Arrays.asList(ius));
+ toProcess = new LinkedList<IInstallableUnit>(considered);
while (!toProcess.isEmpty()) {
if (monitor.isCanceled()) {
result.merge(Status.CANCEL_STATUS);
throw new OperationCanceledException();
}
- processIU((IInstallableUnit) toProcess.removeFirst());
+ processIU(toProcess.removeFirst());
}
if (DEBUG) {
long stop = System.currentTimeMillis();
@@ -69,7 +71,7 @@ public class Slicer {
LogHelper.log(result);
if (result.getSeverity() == IStatus.ERROR)
return null;
- return new QueryableArray((IInstallableUnit[]) considered.toArray(new IInstallableUnit[considered.size()]));
+ return new QueryableArray(considered.toArray(new IInstallableUnit[considered.size()]));
}
public MultiStatus getStatus() {
@@ -85,93 +87,92 @@ public class Slicer {
}
// Check whether the requirement is applicable
- protected boolean isApplicable(IRequiredCapability req) {
- String filter = req.getFilter();
- if (filter == null)
- return true;
- try {
- return DirectorActivator.context.createFilter(filter).match(selectionContext);
- } catch (InvalidSyntaxException e) {
- return false;
- }
+ protected boolean isApplicable(IRequirement req) {
+ Filter filter = req.getFilter();
+ return filter == null || filter.match(selectionContext);
}
protected boolean isApplicable(IInstallableUnit iu) {
- String enablementFilter = iu.getFilter();
- if (enablementFilter == null)
- return true;
- try {
- return DirectorActivator.context.createFilter(enablementFilter).match(selectionContext);
- } catch (InvalidSyntaxException e) {
- return false;
- }
+ Filter filter = iu.getFilter();
+ return filter == null || filter.match(selectionContext);
}
protected void processIU(IInstallableUnit iu) {
iu = iu.unresolved();
- slice.put(iu.getId(), iu.getVersion(), iu);
+ Map<Version, IInstallableUnit> iuSlice = slice.get(iu.getId());
+ if (iuSlice == null) {
+ iuSlice = new HashMap<Version, IInstallableUnit>();
+ slice.put(iu.getId(), iuSlice);
+ }
+ iuSlice.put(iu.getVersion(), iu);
if (!isApplicable(iu)) {
return;
}
- IRequiredCapability[] reqs = getRequiredCapabilities(iu);
- if (reqs.length == 0) {
+ Collection<IRequirement> reqs = getRequiredCapabilities(iu);
+ if (reqs.isEmpty())
return;
- }
- for (int i = 0; i < reqs.length; i++) {
- if (!isApplicable(reqs[i]))
+ for (IRequirement req : reqs) {
+ if (!isApplicable(req))
continue;
- if (!isGreedy(reqs[i])) {
+ if (!isGreedy(req)) {
continue;
}
- expandRequirement(iu, reqs[i]);
+ expandRequirement(iu, req);
}
}
- protected boolean isGreedy(IRequiredCapability req) {
+ protected boolean isGreedy(IRequirement req) {
return req.isGreedy();
}
- private IRequiredCapability[] getRequiredCapabilities(IInstallableUnit iu) {
+ private Collection<IRequirement> getRequiredCapabilities(IInstallableUnit iu) {
+ Collection<IRequirement> iuRequirements = iu.getRequiredCapabilities();
+ int initialRequirementCount = iuRequirements.size();
if (!(iu instanceof IInstallableUnitPatch)) {
- if (iu.getMetaRequiredCapabilities().length == 0 || considerMetaRequirements == false)
- return iu.getRequiredCapabilities();
- IRequiredCapability[] aggregatedCapabilities = new IRequiredCapability[iu.getRequiredCapabilities().length + iu.getMetaRequiredCapabilities().length];
- System.arraycopy(iu.getRequiredCapabilities(), 0, aggregatedCapabilities, 0, iu.getRequiredCapabilities().length);
- System.arraycopy(iu.getMetaRequiredCapabilities(), 0, aggregatedCapabilities, iu.getRequiredCapabilities().length, iu.getMetaRequiredCapabilities().length);
+ if (!considerMetaRequirements)
+ return iuRequirements;
+
+ Collection<IRequirement> iuMetaRequirements = iu.getMetaRequiredCapabilities();
+ int metaSize = iuMetaRequirements.size();
+ if (metaSize == 0)
+ return iuRequirements;
+
+ ArrayList<IRequirement> aggregatedCapabilities = new ArrayList<IRequirement>(initialRequirementCount + metaSize);
+ aggregatedCapabilities.addAll(iuRequirements);
+ aggregatedCapabilities.addAll(iuMetaRequirements);
return aggregatedCapabilities;
}
- IRequiredCapability[] aggregatedCapabilities;
+
IInstallableUnitPatch patchIU = (IInstallableUnitPatch) iu;
- IRequirementChange[] changes = patchIU.getRequirementsChange();
- int initialRequirementCount = iu.getRequiredCapabilities().length;
- aggregatedCapabilities = new IRequiredCapability[initialRequirementCount + changes.length];
- System.arraycopy(iu.getRequiredCapabilities(), 0, aggregatedCapabilities, 0, initialRequirementCount);
- for (int i = 0; i < changes.length; i++) {
- aggregatedCapabilities[initialRequirementCount++] = changes[i].newValue();
- }
+ List<IRequirementChange> changes = patchIU.getRequirementsChange();
+ ArrayList<IRequirement> aggregatedCapabilities = new ArrayList<IRequirement>(initialRequirementCount + changes.size());
+ aggregatedCapabilities.addAll(iuRequirements);
+ for (int i = 0; i < changes.size(); i++)
+ aggregatedCapabilities.add(changes.get(i).newValue());
return aggregatedCapabilities;
}
- private void expandRequirement(IInstallableUnit iu, IRequiredCapability req) {
- if (req.isNegation())
+ private void expandRequirement(IInstallableUnit iu, IRequirement req) {
+ if (req.getMax() == 0)
return;
- Collector matches = possibilites.query(new CapabilityQuery(req), new Collector(), null);
+ IQueryResult<IInstallableUnit> matches = possibilites.query(new ExpressionQuery<IInstallableUnit>(IInstallableUnit.class, req.getMatches()), null);
int validMatches = 0;
- for (Iterator iterator = matches.iterator(); iterator.hasNext();) {
- IInstallableUnit match = (IInstallableUnit) iterator.next();
+ for (Iterator<IInstallableUnit> iterator = matches.iterator(); iterator.hasNext();) {
+ IInstallableUnit match = iterator.next();
if (!isApplicable(match))
continue;
validMatches++;
- if (!slice.containsKey(match.getId(), match.getVersion()))
+ Map<Version, IInstallableUnit> iuSlice = slice.get(match.getId());
+ if (iuSlice == null || !iuSlice.containsKey(match.getVersion()))
consider(match);
}
if (validMatches == 0) {
- if (req.isOptional()) {
+ if (req.getMin() == 0) {
if (DEBUG)
System.out.println("No IU found to satisfy optional dependency of " + iu + " on req " + req); //$NON-NLS-1$//$NON-NLS-2$
} else {
diff --git a/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/TwoTierMap.java b/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/TwoTierMap.java
deleted file mode 100644
index 84ba95c06..000000000
--- a/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/TwoTierMap.java
+++ /dev/null
@@ -1,354 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007, 2009 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.equinox.internal.p2.director;
-
-import java.io.PrintStream;
-import java.io.Serializable;
-import java.util.*;
-
-/**
- * The purpose of this class is to provide a two-tier map.
- * MapOf(key1 => MapOf(key2 => value)).
- * Even though this class implements Map the behavior of
- * the methods aren't exactly the same as that of a real
- * Map - especially, entrySet(), keySet() etc. works off
- * the outer map while values() returns all the values of
- * all the inner maps.
- */
-public class TwoTierMap implements Map, Serializable {
-
- private static final long serialVersionUID = 362497720873186265L;
-
- private Map outerMap;
- private int policy;
-
- public static final int POLICY_NONE = 0, POLICY_BOTH_MAPS_PRESERVE_ORDERING = 1 << 0, POLICY_INNER_MAP_PRESERVE_EXISTING = 1 << 1, POLICY_INNER_MAP_SORTED_ASCENDING = 1 << 2, POLICY_INNER_MAP_SORTED_DESCENDING = 1 << 3, POLICY_INNER_MAP_ENSURE_SINGLETON = 1 << 4;
-
- private static final int POLICY_INNER_MAP_SORTED_MASK = POLICY_INNER_MAP_SORTED_ASCENDING | POLICY_INNER_MAP_SORTED_DESCENDING;
-
- public TwoTierMap() {
- this(8, POLICY_NONE);
- }
-
- public TwoTierMap(int initialCapacity) {
- this(initialCapacity, POLICY_NONE);
- }
-
- /**
- * Creates a two-tier map with the specified
- * initialCapacity and policy. The policy determines
- * whether the outer map is ordered, inner map is
- * sorted, clobber values of inner map etc.
- */
- public TwoTierMap(int initialCapacity, int policy) {
- this.policy = policy;
- this.outerMap = shouldUseOrderedMap() ? new LinkedHashMap(initialCapacity) : new HashMap(initialCapacity);
- }
-
- /**
- * Insert the value with key key1 into the inner map
- * that is obtained from the outer map with key key2.
- * If you have set POLICY_INNER_MAP_PRESERVE_EXISTING
- * at the time of creating this, it will not overwrite
- * if there is already a non-null value at key2.
- * The other POLICY_INNER_MAP_* policies determine
- * what kind of inner map is created.
- * @param key1 The key for outer map.
- * @param key2 The key for inner map.
- * @param value The value.
- * @return Existing value if any, otherwise null.
- */
- public Object put(Object key1, Object key2, Object value) {
- Map innerMap = (Map) this.outerMap.get(key1);
- if (innerMap == null) {
- if (shouldUseSingletonInnerMap()) {
- this.outerMap.put(key1, Collections.singletonMap(key2, value));
- return null;
- }
- innerMap = createInnerMap();
- this.outerMap.put(key1, innerMap);
- }
- // It is faster to check for already existing entry
- // this way instead of containsKey() check. Of course,
- // this will prevent us from recognizing a null entry,
- // which I think shouldn't be a problem.
- Object existing = innerMap.put(key2, value);
- if (existing != null && shouldPreserveExisting()) {
- innerMap.put(key2, existing);
- }
- return existing;
- }
-
- /**
- * Get the object stored in the inner map using key2
- * as key where the inner map is obtained from the
- * outer map using key1.
- * @param key1 The key for outer map.
- * @param key2 The key for inner map.
- * @return The object for key2 in inner map for key1
- * in the outer map.
- */
- public Object get(Object key1, Object key2) {
- if (key1 == null || key2 == null)
- return getAll(key1);
- Map innerMap = (Map) this.outerMap.get(key1);
- Object value = innerMap == null ? null : innerMap.get(key2);
- return value;
- }
-
- /**
- * Get all the values in the inner map for key1 in
- * the outer map.
- * @param key1 The key for outer map.
- * @return Collection of values in the inner map.
- */
- public Collection getAll(Object key1) {
- if (key1 == null)
- // return all
- return values();
- Map innerMap = (Map) this.outerMap.get(key1);
- return innerMap == null ? Collections.EMPTY_LIST : Collections.unmodifiableCollection(innerMap.values());
-
- }
-
- public Object remove(Object key1, Object key2) {
- if (key1 == null || key2 == null)
- return removeAll(key1);
- Map innerMap = (Map) this.outerMap.get(key1);
- if (innerMap == null)
- return null;
- if (shouldUseSingletonInnerMap()) {
- Object result = innerMap.get(key2);
- if (result != null) {
- this.outerMap.remove(key1);
- }
- return result;
- }
- Object result = innerMap.remove(key2);
- if (result != null && innerMap.isEmpty()) {
- this.outerMap.remove(key1);
- }
- return result;
- }
-
- public Collection removeAll(Object key1) {
- if (key1 == null)
- return Collections.EMPTY_LIST;
- Map innerMap = (Map) this.outerMap.remove(key1);
- return innerMap == null ? Collections.EMPTY_LIST : innerMap.values();
- }
-
- /**
- * Determine whether there exists a valid object for
- * key2 in the inner map for key1 in the outer map.
- * @param key1 The key for outer map.
- * @param key2 The key for inner map.
- * @return true if a non-null object exists; otherwise
- * false.
- */
- public boolean containsKey(Object key1, Object key2) {
- if (key1 == null)
- return false;
- if (key2 == null)
- return containsKey(key1);
- return get(key1, key2) != null;
- }
-
- /* (non-Javadoc)
- * @see java.util.Map#clear()
- */
- public void clear() {
- this.outerMap.clear();
- }
-
- /* (non-Javadoc)
- * @see java.util.Map#containsKey(java.lang.Object)
- */
- public boolean containsKey(Object key) {
- return this.outerMap.containsKey(key);
- }
-
- /* (non-Javadoc)
- * @see java.util.Map#containsValue(java.lang.Object)
- */
- public boolean containsValue(Object value) {
- for (Iterator it = entrySet().iterator(); it.hasNext();) {
- Map.Entry entry = (Map.Entry) it.next();
- Map innerMap = (Map) entry.getValue();
- if (innerMap.containsValue(value))
- return true;
- }
- return false;
- }
-
- /* (non-Javadoc)
- * @see java.util.Map#size()
- */
- public int size() {
- return this.outerMap.size();
- }
-
- /* (non-Javadoc)
- * @see java.util.Map#isEmpty()
- */
- public boolean isEmpty() {
- return this.size() == 0;
- }
-
- /* (non-Javadoc)
- * @see java.util.Map#entrySet()
- */
- public Set entrySet() {
- return Collections.unmodifiableSet(this.outerMap.entrySet());
- }
-
- /* (non-Javadoc)
- * @see java.util.Map#values()
- */
- public Collection values() {
- ArrayList result = new ArrayList(size());
- for (Iterator it = this.outerMap.keySet().iterator(); it.hasNext();) {
- Object key = it.next();
- // A null key will cause infinite recursion!
- if (key != null) {
- result.addAll(getAll(key));
- }
- }
- return result;
- }
-
- /* (non-Javadoc)
- * @see java.util.Map#get(java.lang.Object)
- */
- public Object get(Object key) {
- if (key instanceof Object[]) {
- Object[] keys = (Object[]) key;
- return get(keys[0], keys[1]);
- } else
- return getAll(key);
- }
-
- /* (non-Javadoc)
- * @see java.util.Map#keySet()
- */
- public Set keySet() {
- return Collections.unmodifiableSet(this.outerMap.keySet());
- }
-
- /* (non-Javadoc)
- * @see java.util.Map#put(java.lang.Object, java.lang.Object)
- */
- public Object put(Object key, Object value) {
- if (key instanceof Object[]) {
- Object[] keys = (Object[]) key;
- return put(keys[0], keys[1], value);
- }
- throw new IllegalArgumentException("First arg should be an array!"); //$NON-NLS-1$
- }
-
- /* (non-Javadoc)
- * @see java.util.Map#putAll(java.util.Map)
- */
- public void putAll(Map t) {
- throw new UnsupportedOperationException();
- }
-
- /* (non-Javadoc)
- * @see java.util.Map#remove(java.lang.Object)
- */
- public Object remove(Object key) {
- if (key instanceof Object[]) {
- Object[] keys = (Object[]) key;
- return remove(keys[0], keys[1]);
- } else
- return removeAll(key);
- }
-
- public String toString() {
- StringBuffer sb = new StringBuffer();
- if (this.outerMap.isEmpty()) {
- sb.append(" (Empty)"); //$NON-NLS-1$
- } else {
- for (Iterator it = this.outerMap.entrySet().iterator(); it.hasNext();) {
- Map.Entry entry = (Map.Entry) it.next();
- sb.append(" ").append(entry.getKey()) //$NON-NLS-1$
- .append(" = ") //$NON-NLS-1$
- .append(entry.getValue()).append('\n');
- }
- sb.setLength(sb.length() - 1);
- }
- return sb.toString();
- }
-
- public void dump(PrintStream ps) {
- if (ps == null) {
- ps = System.out;
- }
- ps.println(this.toString());
- }
-
- private Map createInnerMap() {
- Map innerMap;
- if (shouldUseSortedInnerMap()) {
- innerMap = new TreeMap(new ValueComparator(shouldSortInAscendingOrder()));
- } else if (shouldUseOrderedMap()) {
- innerMap = new LinkedHashMap(2);
- } else {
- innerMap = new HashMap(2);
- }
- return innerMap;
- }
-
- private boolean shouldPreserveExisting() {
- return (this.policy & POLICY_INNER_MAP_PRESERVE_EXISTING) == POLICY_INNER_MAP_PRESERVE_EXISTING;
- }
-
- private boolean shouldUseOrderedMap() {
- return (this.policy & POLICY_BOTH_MAPS_PRESERVE_ORDERING) == POLICY_BOTH_MAPS_PRESERVE_ORDERING;
- }
-
- private boolean shouldUseSortedInnerMap() {
- return (this.policy & POLICY_INNER_MAP_SORTED_MASK) != 0;
- }
-
- private boolean shouldSortInAscendingOrder() {
- return (this.policy & POLICY_INNER_MAP_SORTED_MASK) == POLICY_INNER_MAP_SORTED_ASCENDING;
- }
-
- private boolean shouldUseSingletonInnerMap() {
- return (this.policy & POLICY_INNER_MAP_ENSURE_SINGLETON) == POLICY_INNER_MAP_ENSURE_SINGLETON;
- }
-
- private static class ValueComparator implements Comparator, Serializable {
- private static final long serialVersionUID = 362497720873186266L;
- private boolean ascending;
-
- public ValueComparator(boolean ascending) {
- this.ascending = ascending;
- }
-
- /* (non-Javadoc)
- * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
- */
- public int compare(Object o1, Object o2) {
- try {
- if (o1 instanceof Comparable) {
- int cmp = ((Comparable) o1).compareTo(o2);
- return this.ascending ? cmp : (0 - cmp);
- }
- } catch (Exception e) {
- // Ignore
- }
- return 1;
- }
- }
-
-}
diff --git a/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/messages.properties b/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/messages.properties
index 5ca20c9e1..d6b5b7ed0 100644
--- a/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/messages.properties
+++ b/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/messages.properties
@@ -41,4 +41,5 @@ Planner_Unexpected_problem=An unexpected error occurred while resolving.
Planner_actions_and_software_incompatible=The actions required to successfully install the requested software are incompatible with the software to install.
Planner_can_not_install_preq=The actions required to successfully install the requested software can not be installed.
Planner_no_profile_registry=Profile Registry is not registered.
-Planner_profile_out_of_sync=The copies of profile {0} are not in sync. \ No newline at end of file
+Planner_profile_out_of_sync=The copies of profile {0} are not in sync.
+RequestStatus_message=Plan status for {0}
diff --git a/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/rollback/FormerState.java b/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/rollback/FormerState.java
index 94a3bfbeb..c0d30f031 100644
--- a/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/rollback/FormerState.java
+++ b/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/rollback/FormerState.java
@@ -10,15 +10,13 @@
*******************************************************************************/
package org.eclipse.equinox.internal.p2.rollback;
-import org.eclipse.equinox.internal.provisional.p2.metadata.query.Collector;
-
import java.util.*;
import java.util.Map.Entry;
import org.eclipse.equinox.internal.p2.director.SimplePlanner;
import org.eclipse.equinox.internal.provisional.p2.director.ProfileChangeRequest;
-import org.eclipse.equinox.internal.provisional.p2.engine.IProfile;
-import org.eclipse.equinox.internal.provisional.p2.metadata.IInstallableUnit;
-import org.eclipse.equinox.internal.provisional.p2.metadata.query.InstallableUnitQuery;
+import org.eclipse.equinox.p2.engine.IProfile;
+import org.eclipse.equinox.p2.metadata.IInstallableUnit;
+import org.eclipse.equinox.p2.metadata.query.InstallableUnitQuery;
public class FormerState {
@@ -33,43 +31,39 @@ public class FormerState {
}
private static void synchronizeAllIUProperties(ProfileChangeRequest request, IProfile current, IProfile target) {
- Collection currentIUs = current.query(InstallableUnitQuery.ANY, new Collector(), null).toCollection();
- Collection targetIUs = target.query(InstallableUnitQuery.ANY, new Collector(), null).toCollection();
- List iusToAdd = new ArrayList(targetIUs);
- iusToAdd.remove(currentIUs);
+ Set<IInstallableUnit> currentIUset = current.query(InstallableUnitQuery.ANY, null).unmodifiableSet();
+ Iterator<IInstallableUnit> targetIUs = target.query(InstallableUnitQuery.ANY, null).iterator();
+ List<IInstallableUnit> iusToAdd = new ArrayList<IInstallableUnit>();
+ List<IInstallableUnit> iusToUpdate = new ArrayList<IInstallableUnit>();
+ while (targetIUs.hasNext()) {
+ IInstallableUnit nxt = targetIUs.next();
+ if (currentIUset.contains(nxt))
+ iusToUpdate.add(nxt);
+ else
+ iusToAdd.add(nxt);
+ }
//additions
- for (Iterator iterator = iusToAdd.iterator(); iterator.hasNext();) {
- IInstallableUnit iu = (IInstallableUnit) iterator.next();
- for (Iterator it = target.getInstallableUnitProperties(iu).entrySet().iterator(); it.hasNext();) {
- Entry entry = (Entry) it.next();
- String key = (String) entry.getKey();
- String value = (String) entry.getValue();
- request.setInstallableUnitProfileProperty(iu, key, value);
+ for (IInstallableUnit iu : iusToAdd) {
+ for (Entry<String, String> entry : target.getInstallableUnitProperties(iu).entrySet()) {
+ request.setInstallableUnitProfileProperty(iu, entry.getKey(), entry.getValue());
}
}
// updates
- List iusToUpdate = new ArrayList(targetIUs);
- iusToUpdate.remove(iusToAdd);
- for (Iterator iterator = iusToUpdate.iterator(); iterator.hasNext();) {
- IInstallableUnit iu = (IInstallableUnit) iterator.next();
- Map propertiesToSet = new HashMap(target.getInstallableUnitProperties(iu));
- for (Iterator it = current.getInstallableUnitProperties(iu).entrySet().iterator(); it.hasNext();) {
- Entry entry = (Entry) it.next();
- String key = (String) entry.getKey();
- String newValue = (String) propertiesToSet.get(key);
+ for (IInstallableUnit iu : iusToUpdate) {
+ Map<String, String> propertiesToSet = new HashMap<String, String>(target.getInstallableUnitProperties(iu));
+ for (Entry<String, String> entry : current.getInstallableUnitProperties(iu).entrySet()) {
+ String key = entry.getKey();
+ String newValue = propertiesToSet.get(key);
if (newValue == null) {
request.removeInstallableUnitProfileProperty(iu, key);
} else if (newValue.equals(entry.getValue()))
propertiesToSet.remove(key);
}
- for (Iterator it = propertiesToSet.entrySet().iterator(); it.hasNext();) {
- Entry entry = (Entry) it.next();
- String key = (String) entry.getKey();
- String value = (String) entry.getValue();
- request.setInstallableUnitProfileProperty(iu, key, value);
+ for (Entry<String, String> entry : propertiesToSet.entrySet()) {
+ request.setInstallableUnitProfileProperty(iu, entry.getKey(), entry.getValue());
}
}
}
@@ -79,34 +73,30 @@ public class FormerState {
IInstallableUnit[] targetPlannerMarkedIUs = SimplePlanner.findPlannerMarkedIUs(target);
//additions
- List markedIUsToAdd = new ArrayList(Arrays.asList(targetPlannerMarkedIUs));
+ List<IInstallableUnit> markedIUsToAdd = new ArrayList<IInstallableUnit>(Arrays.asList(targetPlannerMarkedIUs));
markedIUsToAdd.removeAll(Arrays.asList(currentPlannerMarkedIUs));
- request.addInstallableUnits((IInstallableUnit[]) markedIUsToAdd.toArray(new IInstallableUnit[markedIUsToAdd.size()]));
+ request.addInstallableUnits(markedIUsToAdd);
// removes
- List markedIUsToRemove = new ArrayList(Arrays.asList(currentPlannerMarkedIUs));
+ List<IInstallableUnit> markedIUsToRemove = new ArrayList<IInstallableUnit>(Arrays.asList(currentPlannerMarkedIUs));
markedIUsToRemove.removeAll(Arrays.asList(targetPlannerMarkedIUs));
- request.removeInstallableUnits((IInstallableUnit[]) markedIUsToRemove.toArray(new IInstallableUnit[markedIUsToRemove.size()]));
+ request.removeInstallableUnits(markedIUsToRemove);
}
private static void synchronizeProfileProperties(ProfileChangeRequest request, IProfile current, IProfile target) {
- Map profilePropertiesToSet = new HashMap(target.getProperties());
- for (Iterator it = current.getProperties().entrySet().iterator(); it.hasNext();) {
- Entry entry = (Entry) it.next();
- String key = (String) entry.getKey();
+ Map<String, String> profilePropertiesToSet = new HashMap<String, String>(target.getProperties());
+ for (Entry<String, String> entry : current.getProperties().entrySet()) {
+ String key = entry.getKey();
- String newValue = (String) profilePropertiesToSet.get(key);
+ String newValue = profilePropertiesToSet.get(key);
if (newValue == null) {
request.removeProfileProperty(key);
} else if (newValue.equals(entry.getValue()))
profilePropertiesToSet.remove(key);
}
- for (Iterator it = profilePropertiesToSet.entrySet().iterator(); it.hasNext();) {
- Entry entry = (Entry) it.next();
- String key = (String) entry.getKey();
- String value = (String) entry.getValue();
- request.setProfileProperty(key, value);
+ for (Entry<String, String> entry : profilePropertiesToSet.entrySet()) {
+ request.setProfileProperty(entry.getKey(), entry.getValue());
}
}
}
diff --git a/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/provisional/p2/director/IDirector.java b/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/provisional/p2/director/IDirector.java
index caea4fa8c..585c89c72 100644
--- a/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/provisional/p2/director/IDirector.java
+++ b/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/provisional/p2/director/IDirector.java
@@ -12,8 +12,8 @@ package org.eclipse.equinox.internal.provisional.p2.director;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
-import org.eclipse.equinox.internal.provisional.p2.engine.IProfile;
-import org.eclipse.equinox.internal.provisional.p2.engine.ProvisioningContext;
+import org.eclipse.equinox.p2.engine.IProfile;
+import org.eclipse.equinox.p2.engine.ProvisioningContext;
/**
* Directors are responsible for determining what should be done to a given
diff --git a/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/provisional/p2/director/IPlanner.java b/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/provisional/p2/director/IPlanner.java
index 801be18ea..62102574d 100644
--- a/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/provisional/p2/director/IPlanner.java
+++ b/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/provisional/p2/director/IPlanner.java
@@ -11,9 +11,8 @@
package org.eclipse.equinox.internal.provisional.p2.director;
import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.equinox.internal.provisional.p2.engine.IProfile;
-import org.eclipse.equinox.internal.provisional.p2.engine.ProvisioningContext;
-import org.eclipse.equinox.internal.provisional.p2.metadata.IInstallableUnit;
+import org.eclipse.equinox.p2.engine.*;
+import org.eclipse.equinox.p2.metadata.IInstallableUnit;
/**
* Planners are responsible for determining what should be done to a given
@@ -28,10 +27,10 @@ public interface IPlanner {
*/
public static final String SERVICE_NAME = IPlanner.class.getName();
- public ProvisioningPlan getProvisioningPlan(ProfileChangeRequest profileChangeRequest, ProvisioningContext context, IProgressMonitor monitor);
+ public IProvisioningPlan getProvisioningPlan(ProfileChangeRequest profileChangeRequest, ProvisioningContext context, IProgressMonitor monitor);
public IInstallableUnit[] updatesFor(IInstallableUnit toUpdate, ProvisioningContext context, IProgressMonitor monitor);
- public ProvisioningPlan getDiffPlan(IProfile currentProfile, IProfile targetProfile, IProgressMonitor monitor);
+ public IProvisioningPlan getDiffPlan(IProfile currentProfile, IProfile targetProfile, IProgressMonitor monitor);
}
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 0f9ab3733..0ebf674d8 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
@@ -15,20 +15,21 @@ import org.eclipse.core.runtime.*;
import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper;
import org.eclipse.equinox.internal.p2.director.DirectorActivator;
import org.eclipse.equinox.internal.p2.director.Messages;
+import org.eclipse.equinox.internal.p2.engine.PhaseSet;
import org.eclipse.equinox.internal.provisional.configurator.Configurator;
-import org.eclipse.equinox.internal.provisional.p2.engine.*;
+import org.eclipse.equinox.p2.engine.*;
public class PlanExecutionHelper {
- public static IStatus executePlan(ProvisioningPlan result, IEngine engine, ProvisioningContext context, IProgressMonitor progress) {
+ public static IStatus executePlan(IProvisioningPlan result, IEngine engine, ProvisioningContext context, IProgressMonitor progress) {
return executePlan(result, engine, new DefaultPhaseSet(), context, progress);
}
- public static IStatus executePlan(ProvisioningPlan result, IEngine engine, PhaseSet phaseSet, ProvisioningContext context, IProgressMonitor progress) {
+ public static IStatus executePlan(IProvisioningPlan result, IEngine engine, PhaseSet phaseSet, ProvisioningContext context, IProgressMonitor progress) {
if (!result.getStatus().isOK())
return result.getStatus();
if (result.getInstallerPlan() != null) {
- IStatus installerPlanStatus = engine.perform(result.getInstallerPlan().getProfileChangeRequest().getProfile(), phaseSet, result.getInstallerPlan().getOperands(), context, progress);
+ IStatus installerPlanStatus = engine.perform(result.getInstallerPlan(), phaseSet, progress);
if (!installerPlanStatus.isOK())
return installerPlanStatus;
Configurator configChanger = (Configurator) ServiceHelper.getService(DirectorActivator.context, Configurator.class.getName());
@@ -38,6 +39,6 @@ public class PlanExecutionHelper {
return new Status(IStatus.ERROR, DirectorActivator.PI_DIRECTOR, Messages.Director_error_applying_configuration, e);
}
}
- return engine.perform(result.getProfileChangeRequest().getProfile(), phaseSet, result.getOperands(), context, progress);
+ return engine.perform(result, phaseSet, progress);
}
}
diff --git a/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/provisional/p2/director/PlannerHelper.java b/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/provisional/p2/director/PlannerHelper.java
index 6cac100c1..96fb859b7 100644
--- a/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/provisional/p2/director/PlannerHelper.java
+++ b/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/provisional/p2/director/PlannerHelper.java
@@ -10,7 +10,7 @@
*******************************************************************************/
package org.eclipse.equinox.internal.provisional.p2.director;
-import org.eclipse.equinox.internal.provisional.p2.metadata.IInstallableUnit;
+import org.eclipse.equinox.p2.metadata.IInstallableUnit;
public class PlannerHelper {
public static String createOptionalInclusionRule(IInstallableUnit iu) {
diff --git a/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/provisional/p2/director/ProfileChangeRequest.java b/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/provisional/p2/director/ProfileChangeRequest.java
index 99f267279..69572a6d6 100644
--- a/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/provisional/p2/director/ProfileChangeRequest.java
+++ b/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/provisional/p2/director/ProfileChangeRequest.java
@@ -11,24 +11,27 @@
package org.eclipse.equinox.internal.provisional.p2.director;
import java.util.*;
+import org.eclipse.equinox.internal.p2.core.helpers.CollectionUtils;
import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper;
import org.eclipse.equinox.internal.p2.director.*;
-import org.eclipse.equinox.internal.provisional.p2.engine.IProfile;
-import org.eclipse.equinox.internal.provisional.p2.engine.IProfileRegistry;
-import org.eclipse.equinox.internal.provisional.p2.metadata.IInstallableUnit;
+import org.eclipse.equinox.p2.engine.IProfile;
+import org.eclipse.equinox.p2.engine.IProfileRegistry;
+import org.eclipse.equinox.p2.metadata.IInstallableUnit;
+import org.eclipse.equinox.p2.query.IQueryResult;
public class ProfileChangeRequest implements Cloneable {
private final IProfile profile;
- private ArrayList iusToRemove = null; // list of ius to remove
- private ArrayList iusToAdd = null; // list of ius to add
- private ArrayList propertiesToRemove = null; // list of keys for properties to be removed
- private HashMap propertiesToAdd = null; // map of key->value for properties to be added
- private HashMap iuPropertiesToAdd = null; // map iu->map of key->value pairs for properties to be added for an iu
- private HashMap iuPropertiesToRemove = null; // map of iu->list of property keys to be removed for an iu
+ private ArrayList<IInstallableUnit> iusToRemove = null; // list of ius to remove
+ private ArrayList<IInstallableUnit> iusToAdd = null; // list of ius to add
+ private ArrayList<String> propertiesToRemove = null; // list of keys for properties to be removed
+ private HashMap<String, String> propertiesToAdd = null; // map of key->value for properties to be added
+ private HashMap<IInstallableUnit, Map<String, String>> iuPropertiesToAdd = null; // map iu->map of key->value pairs for properties to be added for an iu
+ private HashMap<IInstallableUnit, List<String>> iuPropertiesToRemove = null; // map of iu->list of property keys to be removed for an iu
+ private boolean isAbsolute = false; //Indicate whether or not the request is an absolute one
public static ProfileChangeRequest createByProfileId(String profileId) {
- IProfileRegistry profileRegistry = (IProfileRegistry) ServiceHelper.getService(DirectorActivator.context, IProfileRegistry.class.getName());
+ IProfileRegistry profileRegistry = (IProfileRegistry) ServiceHelper.getService(DirectorActivator.context, IProfileRegistry.SERVICE_NAME);
if (profileRegistry == null)
throw new IllegalStateException(Messages.Planner_no_profile_registry);
IProfile profile = profileRegistry.getProfile(profileId);
@@ -47,11 +50,11 @@ public class ProfileChangeRequest implements Cloneable {
return profile;
}
- public Map getProfileProperties() {
- Map result = new HashMap(profile.getProperties());
+ public Map<String, String> getProfileProperties() {
+ Map<String, String> result = new HashMap<String, String>(profile.getProperties());
if (propertiesToRemove != null) {
- for (Iterator it = propertiesToRemove.iterator(); it.hasNext();) {
- result.remove(it.next());
+ for (String key : propertiesToRemove) {
+ result.remove(key);
}
}
if (propertiesToAdd != null)
@@ -60,38 +63,66 @@ public class ProfileChangeRequest implements Cloneable {
return result;
}
- public void addInstallableUnits(IInstallableUnit[] toInstall) {
+ private void addInstallableUnit(IInstallableUnit toInstall) {
if (iusToAdd == null)
- iusToAdd = new ArrayList(toInstall.length);
+ iusToAdd = new ArrayList<IInstallableUnit>();
+ iusToAdd.add(toInstall);
+ }
+
+ public void addInstallableUnits(Collection<IInstallableUnit> toInstall) {
+ for (IInstallableUnit iu : toInstall)
+ addInstallableUnit(iu);
+ }
+
+ public void addInstallableUnits(IQueryResult<IInstallableUnit> toInstall) {
+ for (Iterator<IInstallableUnit> itor = toInstall.iterator(); itor.hasNext();)
+ addInstallableUnit(itor.next());
+ }
+
+ public void addInstallableUnits(IInstallableUnit... toInstall) {
for (int i = 0; i < toInstall.length; i++)
- iusToAdd.add(toInstall[i]);
+ addInstallableUnit(toInstall[i]);
}
- public void removeInstallableUnits(IInstallableUnit[] toUninstall) {
+ public void removeInstallableUnit(IInstallableUnit toUninstall) {
if (iusToRemove == null)
- iusToRemove = new ArrayList(toUninstall.length);
+ iusToRemove = new ArrayList<IInstallableUnit>();
+ iusToRemove.add(toUninstall);
+ }
+
+ public void removeInstallableUnits(IInstallableUnit[] toUninstall) {
for (int i = 0; i < toUninstall.length; i++)
- iusToRemove.add(toUninstall[i]);
+ removeInstallableUnit(toUninstall[i]);
+ }
+
+ public void removeInstallableUnits(Collection<IInstallableUnit> toUninstall) {
+ for (IInstallableUnit iu : toUninstall)
+ removeInstallableUnit(iu);
}
- public void setProfileProperty(String key, Object value) {
+ public void removeInstallableUnits(IQueryResult<IInstallableUnit> toUninstall) {
+ for (Iterator<IInstallableUnit> itor = toUninstall.iterator(); itor.hasNext();)
+ removeInstallableUnit(itor.next());
+ }
+
+ public void setProfileProperty(String key, String value) {
if (propertiesToAdd == null)
- propertiesToAdd = new HashMap();
+ propertiesToAdd = new HashMap<String, String>();
propertiesToAdd.put(key, value);
}
public void removeProfileProperty(String key) {
if (propertiesToRemove == null)
- propertiesToRemove = new ArrayList(1);
+ propertiesToRemove = new ArrayList<String>(1);
propertiesToRemove.add(key);
}
- public void setInstallableUnitProfileProperty(IInstallableUnit iu, String key, Object value) {
+ public void setInstallableUnitProfileProperty(IInstallableUnit iu, String key, String value) {
if (iuPropertiesToAdd == null)
- iuPropertiesToAdd = new HashMap();
- Map properties = (Map) iuPropertiesToAdd.get(iu);
+ iuPropertiesToAdd = new HashMap<IInstallableUnit, Map<String, String>>();
+ Map<String, String> properties = iuPropertiesToAdd.get(iu);
if (properties == null) {
- properties = new HashMap();
+ properties = new HashMap<String, String>();
iuPropertiesToAdd.put(iu, properties);
}
properties.put(key, value);
@@ -99,10 +130,10 @@ public class ProfileChangeRequest implements Cloneable {
public void removeInstallableUnitProfileProperty(IInstallableUnit iu, String key) {
if (iuPropertiesToRemove == null)
- iuPropertiesToRemove = new HashMap();
- List keys = (List) iuPropertiesToRemove.get(iu);
+ iuPropertiesToRemove = new HashMap<IInstallableUnit, List<String>>();
+ List<String> keys = iuPropertiesToRemove.get(iu);
if (keys == null) {
- keys = new ArrayList();
+ keys = new ArrayList<String>();
iuPropertiesToRemove.put(iu, keys);
}
keys.add(key);
@@ -111,74 +142,91 @@ public class ProfileChangeRequest implements Cloneable {
public IInstallableUnit[] getRemovedInstallableUnits() {
if (iusToRemove == null)
return new IInstallableUnit[0];
- return (IInstallableUnit[]) iusToRemove.toArray(new IInstallableUnit[iusToRemove.size()]);
+ return iusToRemove.toArray(new IInstallableUnit[iusToRemove.size()]);
}
public IInstallableUnit[] getAddedInstallableUnits() {
if (iusToAdd == null)
return new IInstallableUnit[0];
- return (IInstallableUnit[]) iusToAdd.toArray(new IInstallableUnit[iusToAdd.size()]);
+ return iusToAdd.toArray(new IInstallableUnit[iusToAdd.size()]);
}
// String [key, key, key] names of properties to remove
public String[] getPropertiesToRemove() {
if (propertiesToRemove == null)
return new String[0];
- return (String[]) propertiesToRemove.toArray(new String[propertiesToRemove.size()]);
+ return propertiesToRemove.toArray(new String[propertiesToRemove.size()]);
}
// map of key value pairs
- public Map getPropertiesToAdd() {
+ public Map<String, String> getPropertiesToAdd() {
if (propertiesToAdd == null)
- return Collections.EMPTY_MAP;
+ return CollectionUtils.emptyMap();
return propertiesToAdd;
}
// map of iu->list of property keys to be removed for an iu
- public Map getInstallableUnitProfilePropertiesToRemove() {
+ public Map<IInstallableUnit, List<String>> getInstallableUnitProfilePropertiesToRemove() {
if (iuPropertiesToRemove == null)
- return Collections.EMPTY_MAP;
+ return CollectionUtils.emptyMap();
return iuPropertiesToRemove;
}
// TODO This can be represented and returned in whatever way makes most sense for planner/engine
// map iu->map of key->value pairs for properties to be added for an iu
- public Map getInstallableUnitProfilePropertiesToAdd() {
+ public Map<IInstallableUnit, Map<String, String>> getInstallableUnitProfilePropertiesToAdd() {
if (iuPropertiesToAdd == null)
- return Collections.EMPTY_MAP;
+ return CollectionUtils.emptyMap();
return iuPropertiesToAdd;
}
public void setInstallableUnitInclusionRules(IInstallableUnit iu, String value) {
- if (iuPropertiesToAdd == null)
- iuPropertiesToAdd = new HashMap();
- Map properties = (Map) iuPropertiesToAdd.get(iu);
- if (properties == null) {
- properties = new HashMap();
- iuPropertiesToAdd.put(iu, properties);
- }
- properties.put(SimplePlanner.INCLUSION_RULES, value);
+ setInstallableUnitProfileProperty(iu, SimplePlanner.INCLUSION_RULES, value);
}
public void removeInstallableUnitInclusionRules(IInstallableUnit iu) {
- if (iuPropertiesToRemove == null)
- iuPropertiesToRemove = new HashMap();
- List keys = (List) iuPropertiesToRemove.get(iu);
- if (keys == null) {
- keys = new ArrayList();
- iuPropertiesToRemove.put(iu, keys);
- }
- keys.add(SimplePlanner.INCLUSION_RULES);
+ removeInstallableUnitProfileProperty(iu, SimplePlanner.INCLUSION_RULES);
}
+ public void setAbsoluteMode(boolean absolute) {
+ isAbsolute = absolute;
+ }
+
+ public boolean getAbsolute() {
+ return isAbsolute;
+ }
+
+ @SuppressWarnings("unchecked")
public Object clone() {
ProfileChangeRequest result = new ProfileChangeRequest(profile);
- result.iusToRemove = iusToRemove == null ? null : (ArrayList) iusToRemove.clone();
- result.iusToAdd = iusToAdd == null ? null : (ArrayList) iusToAdd.clone();
- result.propertiesToRemove = propertiesToRemove == null ? null : (ArrayList) propertiesToRemove.clone();
- result.propertiesToAdd = propertiesToAdd == null ? null : (HashMap) propertiesToAdd.clone();
- result.iuPropertiesToAdd = iuPropertiesToAdd == null ? null : (HashMap) iuPropertiesToAdd.clone();
- result.iuPropertiesToRemove = iuPropertiesToRemove == null ? null : (HashMap) iuPropertiesToRemove.clone();
+ result.iusToRemove = iusToRemove == null ? null : (ArrayList<IInstallableUnit>) iusToRemove.clone();
+ result.iusToAdd = iusToAdd == null ? null : (ArrayList<IInstallableUnit>) iusToAdd.clone();
+ result.propertiesToRemove = propertiesToRemove == null ? null : (ArrayList<String>) propertiesToRemove.clone();
+ result.propertiesToAdd = propertiesToAdd == null ? null : (HashMap<String, String>) propertiesToAdd.clone();
+ result.iuPropertiesToAdd = iuPropertiesToAdd == null ? null : (HashMap<IInstallableUnit, Map<String, String>>) iuPropertiesToAdd.clone();
+ result.iuPropertiesToRemove = iuPropertiesToRemove == null ? null : (HashMap<IInstallableUnit, List<String>>) iuPropertiesToRemove.clone();
return result;
}
+
+ public String toString() {
+ StringBuffer result = new StringBuffer(1000);
+ result.append("==Profile change request for "); //$NON-NLS-1$
+ result.append(profile.getProfileId());
+ result.append('\n');
+ result.append("==Additions=="); //$NON-NLS-1$
+ result.append('\n');
+ for (IInstallableUnit iu : iusToAdd) {
+ result.append('\t');
+ result.append(iu);
+ result.append('\n');
+ }
+ result.append("==Removals=="); //$NON-NLS-1$
+ result.append('\n');
+ for (IInstallableUnit iu : iusToRemove) {
+ result.append('\t');
+ result.append(iu);
+ result.append('\n');
+ }
+ return result.toString();
+ }
}
diff --git a/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/provisional/p2/director/ProvisioningPlan.java b/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/provisional/p2/director/ProvisioningPlan.java
deleted file mode 100644
index e231b38b2..000000000
--- a/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/provisional/p2/director/ProvisioningPlan.java
+++ /dev/null
@@ -1,130 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007, 2009 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.equinox.internal.provisional.p2.director;
-
-import java.util.*;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.equinox.internal.p2.director.QueryableArray;
-import org.eclipse.equinox.internal.provisional.p2.engine.InstallableUnitOperand;
-import org.eclipse.equinox.internal.provisional.p2.engine.Operand;
-import org.eclipse.equinox.internal.provisional.p2.metadata.IInstallableUnit;
-import org.eclipse.equinox.internal.provisional.p2.metadata.query.*;
-
-public class ProvisioningPlan {
- IStatus status;
- Operand[] operands;
- Map actualChangeRequest;
- Map sideEffectChanges;
- ProvisioningPlan installerPlan;
- RequestStatus globalRequestStatus;
- ProfileChangeRequest originalChangeRequest;
- IQueryable completeState;
-
- public ProvisioningPlan(IStatus status, ProfileChangeRequest originalRequest, ProvisioningPlan installerPlan) {
- this(status, new Operand[0], null, null, installerPlan, originalRequest, null);
- }
-
- public ProvisioningPlan(IStatus status, Operand[] operands, Map[] actualChangeRequest, RequestStatus globalStatus, ProvisioningPlan installerPlan, ProfileChangeRequest originalRequest, IQueryable futureState) {
- this.status = status;
- this.operands = operands;
- if (actualChangeRequest != null) {
- this.actualChangeRequest = actualChangeRequest[0];
- this.sideEffectChanges = actualChangeRequest[1];
- }
- this.globalRequestStatus = globalStatus;
- this.installerPlan = installerPlan;
- originalChangeRequest = originalRequest;
- if (futureState == null)
- futureState = new QueryableArray(new IInstallableUnit[0]);
- completeState = futureState;
- }
-
- public IStatus getStatus() {
- return status;
- }
-
- public ProfileChangeRequest getProfileChangeRequest() {
- return originalChangeRequest;
- }
-
- /**
- * The operands to pass to the engine.
- * @return the operands to be executed. This may be an empty array if the
- * plan has errors or if there is nothing to do.
- */
- public Operand[] getOperands() {
- return operands;
- }
-
- public IQueryable getRemovals() {
- return new QueryablePlan(false);
- }
-
- public IQueryable getAdditions() {
- return new QueryablePlan(true);
- }
-
- public RequestStatus getRequestStatus(IInstallableUnit iu) {
- if (actualChangeRequest == null)
- return null;
- return (RequestStatus) actualChangeRequest.get(iu);
- }
-
- public RequestStatus getRequestStatus() {
- return globalRequestStatus;
- }
-
- public Map getSideEffectChanges() {
- if (sideEffectChanges == null)
- return Collections.EMPTY_MAP;
- return sideEffectChanges;
- }
-
- private class QueryablePlan implements IQueryable {
- private boolean addition;
-
- public QueryablePlan(boolean add) {
- this.addition = add;
- }
-
- public Collector query(Query query, Collector collector, IProgressMonitor monitor) {
- if (operands == null || status.getSeverity() == IStatus.ERROR)
- return collector;
- Collection list = new ArrayList();
- for (int i = 0; i < operands.length; i++) {
- if (!(operands[i] instanceof InstallableUnitOperand))
- continue;
- InstallableUnitOperand op = ((InstallableUnitOperand) operands[i]);
- IInstallableUnit iu = addition ? op.second() : op.first();
- if (iu != null)
- list.add(iu);
- }
- return query.perform(list.iterator(), collector);
- }
- }
-
- public ProvisioningPlan getInstallerPlan() {
- return installerPlan;
- }
-
- public void setInstallerPlan(ProvisioningPlan p) {
- installerPlan = p;
- }
-
- public IQueryable getCompleteState() {
- return completeState;
- }
-
- protected void setCompleteState(IQueryable state) {
- completeState = state;
- }
-}
diff --git a/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/provisional/p2/director/RequestStatus.java b/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/provisional/p2/director/RequestStatus.java
index 42e502653..b1f6796b7 100644
--- a/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/provisional/p2/director/RequestStatus.java
+++ b/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/provisional/p2/director/RequestStatus.java
@@ -10,33 +10,34 @@
package org.eclipse.equinox.internal.provisional.p2.director;
import java.util.*;
-import org.eclipse.equinox.internal.p2.director.Explanation;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.equinox.internal.p2.director.*;
import org.eclipse.equinox.internal.p2.director.Explanation.IUInstalled;
import org.eclipse.equinox.internal.p2.director.Explanation.IUToInstall;
-import org.eclipse.equinox.internal.provisional.p2.metadata.IInstallableUnit;
+import org.eclipse.equinox.p2.metadata.IInstallableUnit;
+import org.eclipse.osgi.util.NLS;
-public class RequestStatus {
+public class RequestStatus extends Status {
public static final byte ADDED = 0;
public static final byte REMOVED = 1;
private byte initialRequestType;
private IInstallableUnit iu;
- private int severity;
- private Set explanation;
+ private Set<Explanation> explanation;
private Explanation detailedExplanation;
- private Set conflictingRootIUs;
- private Set conflictingInstalledIUs;
+ private Set<IInstallableUnit> conflictingRootIUs;
+ private Set<IInstallableUnit> conflictingInstalledIUs;
- public RequestStatus(IInstallableUnit iu, byte initialRequesType, int severity, Set explanation) {
+ public RequestStatus(IInstallableUnit iu, byte initialRequesType, int severity, Set<Explanation> explanation) {
+ super(severity, DirectorActivator.PI_DIRECTOR, NLS.bind(Messages.RequestStatus_message, iu));
this.iu = iu;
- this.severity = severity;
this.initialRequestType = initialRequesType;
this.explanation = explanation;
- conflictingRootIUs = new HashSet();
- conflictingInstalledIUs = new HashSet();
+ conflictingRootIUs = new HashSet<IInstallableUnit>();
+ conflictingInstalledIUs = new HashSet<IInstallableUnit>();
if (explanation != null) {
- Iterator iterator = explanation.iterator();
- Object o = null;
+ Iterator<Explanation> iterator = explanation.iterator();
+ Explanation o = null;
while (iterator.hasNext() && ((o = iterator.next()) instanceof Explanation.IUToInstall)) {
conflictingRootIUs.add(((IUToInstall) o).iu);
}
@@ -46,7 +47,7 @@ public class RequestStatus {
conflictingInstalledIUs.add(((IUInstalled) o).iu);
}
}
- detailedExplanation = (Explanation) o;
+ detailedExplanation = o;
}
}
@@ -58,24 +59,20 @@ public class RequestStatus {
return iu;
}
- public int getSeverity() {
- return severity;
- }
-
//Return the already installed roots with which this IU is in conflict
//Return an empty set if there is no conflict
- public Set getConflictsWithInstalledRoots() {
+ public Set<IInstallableUnit> getConflictsWithInstalledRoots() {
return conflictingRootIUs;
}
//Return the already installed roots with which this IU is in conflict
//Return an empty set if there is no conflict
- public Set getConflictsWithAnyRoots() {
+ public Set<IInstallableUnit> getConflictsWithAnyRoots() {
return conflictingInstalledIUs;
}
//Return an explanation as to why this IU can not be resolved.
- public Set getExplanations() {
+ public Set<Explanation> getExplanations() {
//To start with, this does not have to return the most specific explanation. If it simply returns an global explanation it is good enough.
return explanation;
}

Back to the top