1 11 12 package org.eclipse.core.internal.dependencies; 13 14 import java.util.*; 15 16 public class ResolutionVisitor implements IElementSetVisitor { 17 private int order; 18 19 public ResolutionVisitor(int order) { 20 this.order = order; 21 } 22 23 public Collection getAncestors(ElementSet elementSet) { 24 return elementSet.getRequired(); 25 } 26 27 public Collection getDescendants(ElementSet elementSet) { 28 return elementSet.getRequiring(); 29 } 30 31 public int getOrder() { 32 return order; 33 } 34 35 public void update(ElementSet elementSet) { 36 if (elementSet.getRequired().isEmpty()) { 38 elementSet.setResolved(elementSet.getSelected()); 39 return; 40 } 41 Set resolved = new HashSet(); 42 43 for (Iterator elementsIter = elementSet.getSelected().iterator(); elementsIter.hasNext();) { 44 Element element = (Element) elementsIter.next(); 45 Dependency[] dependencies = element.getDependencies(); 46 boolean versionResolved = true; 47 for (int i = 0; i < dependencies.length; i++) { 48 ElementSet requiredNode = elementSet.getSystem().getElementSet(dependencies[i].getRequiredObjectId()); 49 List requiredNodeResolvedVersions = new ArrayList(requiredNode.getResolved()); 50 Object highestRequiredVersionId = null; 51 for (Iterator requiredNodeResolvedVersionsIter = requiredNodeResolvedVersions.iterator(); requiredNodeResolvedVersionsIter.hasNext();) { 52 Element requiredResolvedVersion = (Element) requiredNodeResolvedVersionsIter.next(); 53 if (dependencies[i].getMatchRule().isSatisfied(dependencies[i].getUserObject(), requiredResolvedVersion.getVersionId())) 54 if (highestRequiredVersionId == null || elementSet.getSystem().compare(requiredResolvedVersion.getVersionId(), highestRequiredVersionId) > 0) 55 highestRequiredVersionId = requiredResolvedVersion.getVersionId(); 56 } 57 if (highestRequiredVersionId == null && !dependencies[i].isOptional()) { 58 versionResolved = false; 59 break; 60 } 61 elementSet.resolveDependency(dependencies[i], highestRequiredVersionId); 63 } 64 if (versionResolved) 65 resolved.add(element); 66 } 67 elementSet.setResolved(resolved); 68 } 69 } | Popular Tags |