1 11 12 package org.eclipse.osgi.internal.resolver; 13 14 import java.util.*; 15 import org.eclipse.core.internal.dependencies.*; 16 17 public class Eclipse21SelectionPolicy implements ISelectionPolicy { 18 public Set selectMultiple(ElementSet elementSet) { 19 Set selected = new HashSet(); 20 for (Iterator requiringIter = elementSet.getRequiring().iterator(); requiringIter.hasNext();) { 21 ElementSet requiringNode = (ElementSet) requiringIter.next(); 22 Collection requiringNodeSelectedVersions = requiringNode.getSelected(); 23 for (Iterator requiringVersionsIter = requiringNodeSelectedVersions.iterator(); requiringVersionsIter.hasNext();) { 25 Element requiringSelectedVersion = (Element) requiringVersionsIter.next(); 26 Dependency requiringSelectedVersionDependency = requiringSelectedVersion.getDependency(elementSet.getId()); 28 if (requiringSelectedVersionDependency == null) 29 continue; 30 Element bestVersion = null; 32 for (Iterator satisfiedIter = elementSet.getSatisfied().iterator(); satisfiedIter.hasNext();) { 33 Element satisfiedVersion = (Element) satisfiedIter.next(); 34 boolean satisfiesDependency = requiringSelectedVersionDependency.getMatchRule().isSatisfied(requiringSelectedVersionDependency.getUserObject(), satisfiedVersion.getVersionId()); 35 if (satisfiesDependency) { 36 boolean betterThanBest = bestVersion == null || elementSet.getSystem().compare(satisfiedVersion.getVersionId(), bestVersion.getVersionId()) > 0; 37 if (betterThanBest) 38 bestVersion = satisfiedVersion; 39 } 40 } 41 if (bestVersion != null) 42 selected.add(bestVersion); 43 } 44 } 45 if (selected.isEmpty()) { 47 Element bestVersion = null; 48 for (Iterator satisfiedIter = elementSet.getSatisfied().iterator(); satisfiedIter.hasNext();) { 49 Element satisfiedVersion = (Element) satisfiedIter.next(); 50 boolean betterThanBest = bestVersion == null || elementSet.getSystem().compare(satisfiedVersion.getVersionId(), bestVersion.getVersionId()) > 0; 51 if (betterThanBest) 52 bestVersion = satisfiedVersion; 53 } 54 selected = Collections.singleton(bestVersion); 55 } 56 return selected; 57 } 58 59 public Element selectSingle(ElementSet elementSet) { 60 if (elementSet.getRequiring().isEmpty()) { 62 Element highest = null; 64 for (Iterator satisfiedIter = elementSet.getSatisfied().iterator(); satisfiedIter.hasNext();) { 65 Element satisfiedVersion = (Element) satisfiedIter.next(); 66 if (highest == null || elementSet.getSystem().compare(satisfiedVersion.getVersionId(), highest.getVersionId()) > 0) 67 highest = satisfiedVersion; 68 } 69 return highest; 70 } 71 72 Element highest = null; 74 int highestStatus = 0; for (Iterator satisfiedIter = elementSet.getSatisfied().iterator(); satisfiedIter.hasNext();) { 76 boolean satisfiesAllMandatory = true; 77 boolean satisfiesAll = true; 78 boolean isRequired = false; 79 Element satisfiedVersion = (Element) satisfiedIter.next(); 80 for (Iterator requiringIter = elementSet.getRequiring().iterator(); requiringIter.hasNext();) { 81 ElementSet requiringNode = (ElementSet) requiringIter.next(); 82 Collection requiringNodeSelectedVersions = requiringNode.getSelected(); 83 for (Iterator requiringVersionsIter = requiringNodeSelectedVersions.iterator(); requiringVersionsIter.hasNext();) { 85 Element requiringSelectedVersion = (Element) requiringVersionsIter.next(); 86 Dependency requiringSelectedVersionDep = requiringSelectedVersion.getDependency(elementSet.getId()); 88 if (requiringSelectedVersionDep != null) { 89 boolean satisfiesDependency = requiringSelectedVersionDep.getMatchRule().isSatisfied(requiringSelectedVersionDep.getUserObject(), satisfiedVersion.getVersionId()); 90 isRequired |= satisfiesDependency; 91 satisfiesAll &= satisfiesDependency; 92 satisfiesAllMandatory &= (satisfiesDependency | requiringSelectedVersionDep.isOptional()); 93 } 94 } 95 } 96 int status = satisfiesAll ? 3 : (satisfiesAllMandatory ? 2 : (isRequired ? 1 : 0)); 97 boolean higherThanHighest = highest == null || elementSet.getSystem().compare(satisfiedVersion.getVersionId(), highest.getVersionId()) > 0; 98 if (status > highestStatus || (status == highestStatus && higherThanHighest)) { 99 highest = satisfiedVersion; 100 highestStatus = status; 101 } 102 } 103 return highest; 104 } 105 106 } | Popular Tags |