1 11 12 package org.eclipse.osgi.internal.resolver; 13 14 import java.util.*; 15 import org.eclipse.core.internal.dependencies.*; 16 17 21 public class Eclipse30SelectionPolicy implements ISelectionPolicy { 22 public Set selectMultiple(ElementSet elementSet) { 23 Set selected = new HashSet(); 24 Collection previouslyResolvedSet = elementSet.getResolved(); 26 for (Iterator iter = previouslyResolvedSet.iterator(); iter.hasNext();) { 27 Element previouslyResolved = (Element) iter.next(); 28 if (elementSet.getSatisfied().contains(previouslyResolved)) 30 selected.add(previouslyResolved); 31 } 32 for (Iterator requiringIter = elementSet.getRequiring().iterator(); requiringIter.hasNext();) { 34 ElementSet requiringNode = (ElementSet) requiringIter.next(); 35 Collection requiringNodeSelectedVersions = requiringNode.getSelected(); 36 for (Iterator requiringVersionsIter = requiringNodeSelectedVersions.iterator(); requiringVersionsIter.hasNext();) { 38 Element requiringSelectedVersion = (Element) requiringVersionsIter.next(); 39 Dependency requiringSelectedVersionDependency = requiringSelectedVersion.getDependency(elementSet.getId()); 41 if (requiringSelectedVersionDependency == null) 42 continue; 43 Element bestVersion = null; 45 for (Iterator satisfiedIter = elementSet.getSatisfied().iterator(); satisfiedIter.hasNext();) { 46 Element satisfiedVersion = (Element) satisfiedIter.next(); 47 boolean satisfiesDependency = requiringSelectedVersionDependency.getMatchRule().isSatisfied(requiringSelectedVersionDependency.getUserObject(), satisfiedVersion.getVersionId()); 48 if (satisfiesDependency) { 49 boolean betterThanBest = bestVersion == null || elementSet.getSystem().compare(satisfiedVersion.getVersionId(), bestVersion.getVersionId()) > 0; 50 if (betterThanBest) 51 bestVersion = satisfiedVersion; 52 } 53 } 54 if (bestVersion != null) 55 selected.add(bestVersion); 56 } 57 } 58 if (selected.isEmpty()) { 60 Element bestVersion = null; 61 for (Iterator satisfiedIter = elementSet.getSatisfied().iterator(); satisfiedIter.hasNext();) { 62 Element satisfiedVersion = (Element) satisfiedIter.next(); 63 boolean betterThanBest = bestVersion == null || elementSet.getSystem().compare(satisfiedVersion.getVersionId(), bestVersion.getVersionId()) > 0; 64 if (betterThanBest) 65 bestVersion = satisfiedVersion; 66 } 67 selected = Collections.singleton(bestVersion); 68 } 69 return selected; 70 } 71 72 public Element selectSingle(ElementSet elementSet) { 73 Collection previouslyResolvedSet = elementSet.getResolved(); 74 if (!previouslyResolvedSet.isEmpty()) { 76 Element previouslyResolved = (Element) previouslyResolvedSet.iterator().next(); 78 if (elementSet.getSatisfied().contains(previouslyResolved)) 80 return previouslyResolved; 81 } 82 83 if (elementSet.getRequiring().isEmpty()) { 85 Element highest = null; 87 for (Iterator satisfiedIter = elementSet.getSatisfied().iterator(); satisfiedIter.hasNext();) { 88 Element satisfiedVersion = (Element) satisfiedIter.next(); 89 if (highest == null || elementSet.getSystem().compare(satisfiedVersion.getVersionId(), highest.getVersionId()) > 0) 90 highest = satisfiedVersion; 91 } 92 return highest; 93 } 94 95 Element highest = null; 97 int highestStatus = 0; for (Iterator satisfiedIter = elementSet.getSatisfied().iterator(); satisfiedIter.hasNext();) { 99 boolean satisfiesAllMandatory = true; 100 boolean satisfiesAll = true; 101 boolean isRequired = false; 102 Element satisfiedVersion = (Element) satisfiedIter.next(); 103 for (Iterator requiringIter = elementSet.getRequiring().iterator(); requiringIter.hasNext();) { 104 ElementSet requiringNode = (ElementSet) requiringIter.next(); 105 Collection requiringNodeSelectedVersions = requiringNode.getSelected(); 106 for (Iterator requiringVersionsIter = requiringNodeSelectedVersions.iterator(); requiringVersionsIter.hasNext();) { 108 Element requiringSelectedVersion = (Element) requiringVersionsIter.next(); 109 Dependency requiringSelectedVersionDep = requiringSelectedVersion.getDependency(elementSet.getId()); 111 if (requiringSelectedVersionDep != null) { 112 boolean satisfiesDependency = requiringSelectedVersionDep.getMatchRule().isSatisfied(requiringSelectedVersionDep.getUserObject(), satisfiedVersion.getVersionId()); 113 isRequired |= satisfiesDependency; 114 satisfiesAll &= satisfiesDependency; 115 satisfiesAllMandatory &= (satisfiesDependency | requiringSelectedVersionDep.isOptional()); 116 } 117 } 118 } 119 int status = satisfiesAll ? 3 : (satisfiesAllMandatory ? 2 : (isRequired ? 1 : 0)); 120 boolean higherThanHighest = highest == null || elementSet.getSystem().compare(satisfiedVersion.getVersionId(), highest.getVersionId()) > 0; 121 if (status > highestStatus || (status == highestStatus && higherThanHighest)) { 122 highest = satisfiedVersion; 123 highestStatus = status; 124 } 125 } 126 return highest; 127 } 128 129 } | Popular Tags |