From 55cada7d53efae6a965951be458b78536460a672 Mon Sep 17 00:00:00 2001 From: Pascal Rapicault (Ericsson) Date: Fri, 26 Apr 2013 16:39:08 -0400 Subject: Guarantee that we are picking the highest version available --- .../director/UserDefinedOptimizationFunction.java | 53 +++++++++++++++++----- 1 file changed, 41 insertions(+), 12 deletions(-) (limited to 'bundles/org.eclipse.equinox.p2.director/src') diff --git a/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/UserDefinedOptimizationFunction.java b/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/UserDefinedOptimizationFunction.java index 6a8d69cc4..95df3b8e2 100644 --- a/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/UserDefinedOptimizationFunction.java +++ b/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/UserDefinedOptimizationFunction.java @@ -22,9 +22,10 @@ public class UserDefinedOptimizationFunction extends OptimizationFunction { private Collection alreadyExistingRoots; private LexicoHelper dependencyHelper; private IQueryable picker; - private List changeVariables = new ArrayList(); - private List removalVariables = new ArrayList(); - private List newVariables = new ArrayList(); + + // private List changeVariables = new ArrayList(); + // private List removalVariables = new ArrayList(); + // private List newVariables = new ArrayList(); public UserDefinedOptimizationFunction(IQueryable lastState, List abstractVariables, List optionalVariables, IQueryable picker, IInstallableUnit selectionContext, Map> slice, DependencyHelper dependencyHelper, Collection alreadyInstalledIUs) { super(lastState, abstractVariables, optionalVariables, picker, selectionContext, slice); @@ -35,10 +36,10 @@ public class UserDefinedOptimizationFunction extends OptimizationFunction { } public List> createOptimizationFunction(IInstallableUnit metaIu, Collection newRoots) { - List weightedObjects = new ArrayList(); + List> weightedObjects = new ArrayList>(); List objects = new ArrayList(); BigInteger weight = BigInteger.valueOf(slice.size() + 1); - String[] criteria = new String[] {"+new", "-removed", "-changed"}; + String[] criteria = new String[] {"+new", "-changed", "-notuptodate", "-removed"}; BigInteger currentWeight = weight.pow(criteria.length - 1); int formermaxvarid = dependencyHelper.getSolver().nextFreeVarId(false); int newmaxvarid; @@ -53,10 +54,10 @@ public class UserDefinedOptimizationFunction extends OptimizationFunction { weightedObjects.clear(); removedRoots(weightedObjects, criteria[i].startsWith("+") ? currentWeight.negate() : currentWeight, metaIu); currentWeight = currentWeight.divide(weight); - // } else if (criteria[i].endsWith("notuptodate")) { - // weightedObjects.clear(); - // notuptodate(weightedObjects, criteria[i].startsWith("+") ? currentWeight.negate() : currentWeight, metaIu); - // currentWeight = currentWeight.divide(weight); + } else if (criteria[i].endsWith("notuptodate")) { + weightedObjects.clear(); + notuptodate(weightedObjects, criteria[i].startsWith("+") ? currentWeight.negate() : currentWeight, metaIu); + currentWeight = currentWeight.divide(weight); // } else if (criteria[i].endsWith("unsat_recommends")) { // weightedObjects.clear(); // optional(weightedObjects, criteria[i].startsWith("+") ? currentWeight.negate() : currentWeight, metaIu); @@ -107,7 +108,7 @@ public class UserDefinedOptimizationFunction extends OptimizationFunction { } try { Projector.AbstractVariable abs = new Projector.AbstractVariable("CHANGED"); //TODO - changeVariables.add(abs); + // changeVariables.add(abs); // abs <=> iuv1 or not iuv2 or ... or not iuvn dependencyHelper.or(FakeExplanation.getInstance(), abs, changed); weightedObjects.add(WeightedObject.newWO(abs, weight)); @@ -130,7 +131,7 @@ public class UserDefinedOptimizationFunction extends OptimizationFunction { if (!oneInstalled) { try { Projector.AbstractVariable abs = new Projector.AbstractVariable("NEW"); //TODO - newVariables.add(abs); + // newVariables.add(abs); // a <=> iuv1 or ... or iuvn dependencyHelper.or(FakeExplanation.getInstance(), abs, matches.toArray(IInstallableUnit.class)); weightedObjects.add(WeightedObject.newWO(abs, weight)); @@ -157,7 +158,7 @@ public class UserDefinedOptimizationFunction extends OptimizationFunction { if (installed) { try { Projector.AbstractVariable abs = new Projector.AbstractVariable("REMOVED"); //TODO - removalVariables.add(abs); + // removalVariables.add(abs); // abs <=> not iuv1 and ... and not iuvn dependencyHelper.and(FakeExplanation.getInstance(), abs, literals); weightedObjects.add(WeightedObject.newWO(abs, weight)); @@ -169,6 +170,34 @@ public class UserDefinedOptimizationFunction extends OptimizationFunction { } } + protected void notuptodate(List> weightedObjects, BigInteger weight, IInstallableUnit entryPointIU) { + Collection requirements = entryPointIU.getRequirements(); + for (IRequirement req : requirements) { + IQuery query = QueryUtil.createMatchQuery(req.getMatches()); + IQueryResult matches = picker.query(query, null); + List toSort = new ArrayList(matches.toUnmodifiableSet()); + Collections.sort(toSort, Collections.reverseOrder()); + Projector.AbstractVariable abs = new Projector.AbstractVariable(); + Object notlatest = dependencyHelper.not(toSort.get(0)); + try { + // notuptodate <=> not iuvn and (iuv1 or iuv2 or ... iuvn-1) + dependencyHelper.implication(new Object[] {abs}).implies(notlatest).named(FakeExplanation.getInstance()); + Object[] clause = new Object[toSort.size()]; + toSort.toArray(clause); + clause[0] = dependencyHelper.not(abs); + dependencyHelper.clause(FakeExplanation.getInstance(), clause); + for (int i = 1; i < toSort.size(); i++) { + dependencyHelper.implication(new Object[] {notlatest, toSort.get(i)}).implies(abs).named(FakeExplanation.getInstance()); + } + } catch (ContradictionException e) { + // should never happen + e.printStackTrace(); + } + + weightedObjects.add(WeightedObject.newWO(abs, weight)); + } + } + private static class FakeExplanation extends Explanation { private static Explanation singleton = new FakeExplanation(); -- cgit v1.2.3