示例#1
1
 private Set<ResolvedArtifact> getArtifacts(ConfigurationNode childConfiguration) {
   String[] targetConfigurations =
       from.metaData.getHierarchy().toArray(new String[from.metaData.getHierarchy().size()]);
   DependencyArtifactDescriptor[] dependencyArtifacts =
       dependencyDescriptor.getDependencyArtifacts(targetConfigurations);
   if (dependencyArtifacts.length == 0) {
     return Collections.emptySet();
   }
   Set<ResolvedArtifact> artifacts = new LinkedHashSet<ResolvedArtifact>();
   for (DependencyArtifactDescriptor artifactDescriptor : dependencyArtifacts) {
     ModuleRevisionId id =
         childConfiguration.moduleRevision.metaData.getDescriptor().getModuleRevisionId();
     Artifact artifact =
         new DefaultArtifact(
             id,
             null,
             artifactDescriptor.getName(),
             artifactDescriptor.getType(),
             artifactDescriptor.getExt(),
             artifactDescriptor.getUrl(),
             artifactDescriptor.getQualifiedExtraAttributes());
     artifacts.add(
         resolveState.builder.newArtifact(
             childConfiguration.getResult(),
             artifact,
             targetModuleRevision.resolve().getArtifactResolver()));
   }
   return artifacts;
 }
    public void visitOutgoingDependencies(Collection<DependencyEdge> target) {
      // If this configuration's version is in conflict, don't do anything
      // If not traversed before, add all selected outgoing edges
      // If traversed before, and the selected modules have changed, remove previous outgoing edges
      // and add outgoing edges again with
      //    the new selections.
      // If traversed before, and the selected modules have not changed, ignore
      // If none of the incoming edges are transitive, then the node has no outgoing edges

      if (moduleRevision.state != ModuleState.Selected) {
        LOGGER.debug("version for {} is not selected. ignoring.", this);
        return;
      }

      List<DependencyEdge> transitiveIncoming = new ArrayList<DependencyEdge>();
      for (DependencyEdge edge : incomingEdges) {
        if (edge.isTransitive()) {
          transitiveIncoming.add(edge);
        }
      }

      if (transitiveIncoming.isEmpty() && this != resolveState.root) {
        if (previousTraversal != null) {
          removeOutgoingEdges();
        }
        if (incomingEdges.isEmpty()) {
          LOGGER.debug("{} has no incoming edges. ignoring.", this);
        } else {
          LOGGER.debug("{} has no transitive incoming edges. ignoring outgoing edges.", this);
        }
        return;
      }

      ModuleResolutionFilter resolutionFilter = getSelector(transitiveIncoming);
      if (previousTraversal != null) {
        if (previousTraversal.acceptsSameModulesAs(resolutionFilter)) {
          LOGGER.debug(
              "Changed edges for {} selects same versions as previous traversal. ignoring", this);
          // Don't need to traverse again, but hang on to the new filter as the set of artifact may
          // have changed
          previousTraversal = resolutionFilter;
          return;
        }
        removeOutgoingEdges();
      }

      for (DependencyMetaData dependency : metaData.getDependencies()) {
        ModuleIdentifier targetModuleId =
            DefaultModuleIdentifier.newId(
                dependency.getRequested().getGroup(), dependency.getRequested().getName());
        if (isExcluded(resolutionFilter, targetModuleId)) {
          continue;
        }
        DependencyEdge dependencyEdge =
            new DependencyEdge(this, dependency, resolutionFilter, resolveState);
        outgoingEdges.add(dependencyEdge);
        target.add(dependencyEdge);
      }
      previousTraversal = resolutionFilter;
    }
    public Set<File> getFiles(Spec<Dependency> dependencySpec) {
      rethrowFailure();
      Set<ModuleDependency> allDependencies =
          configuration.getAllDependencies(ModuleDependency.class);
      Set<ModuleDependency> selectedDependencies =
          Specs.filterIterable(allDependencies, dependencySpec);

      Set<ResolvedArtifact> artifacts = new LinkedHashSet<ResolvedArtifact>();

      for (ModuleDependency moduleDependency : selectedDependencies) {
        Set<ResolvedDependency> resolvedDependencies =
            conversionResult.getFirstLevelResolvedDependencies().get(moduleDependency);
        for (ResolvedDependency resolvedDependency : resolvedDependencies) {
          artifacts.addAll(resolvedDependency.getParentArtifacts(conversionResult.getRoot()));
          walker.add(resolvedDependency);
        }
      }

      artifacts.addAll(walker.findValues());

      Set<File> files = new LinkedHashSet<File>();
      for (ResolvedArtifact artifact : artifacts) {
        File depFile = artifact.getFile();
        if (depFile != null) {
          files.add(depFile);
        } else {
          logger.debug(String.format("Resolved artifact %s contains a null value.", artifact));
        }
      }
      return files;
    }
示例#4
0
    public void visitOutgoingDependencies(Collection<DependencyEdge> target) {
      // If this configuration's version is in conflict, don't do anything
      // If not traversed before, add all selected outgoing edges
      // If traversed before, and the selected modules have changed, remove previous outgoing edges
      // and add outgoing edges again with
      //    the new selections.
      // If traversed before, and the selected modules have not changed, ignore
      // If none of the incoming edges are transitive, then the node has no outgoing edges

      if (moduleRevision.state != ModuleState.Selected) {
        LOGGER.debug("version for {} is not selected. ignoring.", this);
        return;
      }

      List<DependencyEdge> transitiveIncoming = new ArrayList<DependencyEdge>();
      for (DependencyEdge edge : incomingEdges) {
        if (edge.isTransitive()) {
          transitiveIncoming.add(edge);
        }
      }

      if (transitiveIncoming.isEmpty() && this != resolveState.root) {
        if (previousTraversal != null) {
          removeOutgoingEdges();
        }
        if (incomingEdges.isEmpty()) {
          LOGGER.debug("{} has no incoming edges. ignoring.", this);
        } else {
          LOGGER.debug("{} has no transitive incoming edges. ignoring outgoing edges.", this);
        }
        return;
      }

      ModuleVersionSpec selectorSpec = getSelector(transitiveIncoming);
      if (previousTraversal != null) {
        if (previousTraversal.acceptsSameModulesAs(selectorSpec)) {
          LOGGER.debug(
              "Changed edges for {} selects same versions as previous traversal. ignoring", this);
          return;
        }
        removeOutgoingEdges();
      }

      for (DependencyMetaData dependency : metaData.getDependencies()) {
        DependencyDescriptor dependencyDescriptor = dependency.getDescriptor();
        ModuleId targetModuleId = dependencyDescriptor.getDependencyRevisionId().getModuleId();
        if (!selectorSpec.isSatisfiedBy(targetModuleId)) {
          LOGGER.debug("{} is excluded from {}.", targetModuleId, this);
          continue;
        }
        DependencyEdge dependencyEdge =
            new DependencyEdge(this, dependency, selectorSpec, resolveState);
        outgoingEdges.add(dependencyEdge);
        target.add(dependencyEdge);
      }
      previousTraversal = selectorSpec;
    }
示例#5
0
 public void removeOutgoingEdges() {
   for (DependencyEdge outgoingDependency : outgoingEdges) {
     outgoingDependency.removeFromTargetConfigurations();
   }
   outgoingEdges.clear();
   previousTraversal = null;
 }
示例#6
0
 /**
  * Called when a change is made to a configuration node, such that its dependency graph
  * <em>may</em> now be larger than it previously was, and the node should be visited.
  */
 public void onMoreSelected(ConfigurationNode configuration) {
   // Add to the end of the queue, so that we traverse the graph in breadth-wise order to pick up
   // as many conflicts as
   // possible before attempting to resolve them
   if (queued.add(configuration)) {
     queue.addLast(configuration);
   }
 }
 public void removeFromTargetConfigurations() {
   for (ConfigurationNode targetConfiguration : targetConfigurations) {
     targetConfiguration.removeIncomingEdge(this);
   }
   targetConfigurations.clear();
   if (targetModuleRevision != null) {
     selector.getSelectedModule().removeUnattachedDependency(this);
   }
 }
示例#8
0
    public void attachToParents(
        ConfigurationNode childConfiguration, ResolvedConfigurationBuilder result) {
      ResolvedConfigurationIdentifier parent = from.getResult();
      ResolvedConfigurationIdentifier child = childConfiguration.getResult();
      result.addChild(parent, child);

      Set<ResolvedArtifact> artifacts = getArtifacts(childConfiguration);
      if (artifacts.isEmpty()) {
        artifacts = childConfiguration.getArtifacts();
      }
      // TODO SF merge with addChild
      result.addParentSpecificArtifacts(child, parent, artifacts);

      if (parent == resolveState.root.getResult()) {
        EnhancedDependencyDescriptor enhancedDependencyDescriptor =
            (EnhancedDependencyDescriptor) dependencyDescriptor;
        result.addFirstLevelDependency(enhancedDependencyDescriptor.getModuleDependency(), child);
      }
    }
示例#9
0
 public void restart(ModuleVersionResolveState selected) {
   select(selected);
   for (ModuleVersionResolveState version : versions.values()) {
     version.restart(selected);
   }
   for (DependencyEdge dependency : new ArrayList<DependencyEdge>(unattachedDependencies)) {
     dependency.restart(selected);
   }
   unattachedDependencies.clear();
 }
示例#10
0
 public Set<ResolvedArtifact> getArtifacts() {
   if (artifacts == null) {
     artifacts = new LinkedHashSet<ResolvedArtifact>();
     for (Artifact artifact : metaData.getArtifacts()) {
       artifacts.add(
           resolveState.builder.newArtifact(
               getResult(), artifact, moduleRevision.resolve().getArtifactResolver()));
     }
   }
   return artifacts;
 }
示例#11
0
 public void attachToTargetConfigurations() {
   if (targetModuleRevision.state != ModuleState.Selected) {
     return;
   }
   calculateTargetConfigurations();
   for (ConfigurationNode targetConfiguration : targetConfigurations) {
     targetConfiguration.addIncomingEdge(this);
   }
   if (!targetConfigurations.isEmpty()) {
     selector.getSelectedModule().removeUnattachedDependency(this);
   }
 }
示例#12
0
 public void restart(ModuleVersionResolveState selected) {
   // Restarting this configuration after conflict resolution.
   // If this configuration belongs to the select version, queue ourselves up for traversal.
   // If not, then move our incoming edges across to the selected configuration
   if (moduleRevision == selected) {
     resolveState.onMoreSelected(this);
   } else {
     for (DependencyEdge dependency : incomingEdges) {
       dependency.restart(selected);
     }
     incomingEdges.clear();
   }
 }
示例#13
0
    private void calculateTargetConfigurations() {
      targetConfigurations.clear();
      ModuleVersionMetaData targetModuleVersion = targetModuleRevision.getMetaData();
      if (targetModuleVersion == null) {
        // Broken version
        return;
      }

      Set<ConfigurationMetaData> targetConfigurations =
          resolveState.dependencyToConfigurationResolver.resolveTargetConfigurations(
              dependencyMetaData, from.metaData, targetModuleVersion);
      for (ConfigurationMetaData targetConfiguration : targetConfigurations) {
        ConfigurationNode targetConfigurationNode =
            resolveState.getConfigurationNode(targetModuleRevision, targetConfiguration.getName());
        this.targetConfigurations.add(targetConfigurationNode);
      }
    }
示例#14
0
 /**
  * Called when a change is made to a configuration node, such that its dependency graph
  * <em>may</em> now be smaller than it previously was, and the node should be visited.
  */
 public void onFewerSelected(ConfigurationNode configuration) {
   // Add to the front of the queue, to flush out configurations that are no longer required.
   if (queued.add(configuration)) {
     queue.addFirst(configuration);
   }
 }
 public void addSelector(ModuleVersionSelectorResolveState selector) {
   selectors.add(selector);
 }
示例#16
0
  /**
   * Traverses the dependency graph, resolving conflicts and building the paths from the root
   * configuration.
   */
  private void traverseGraph(ResolveState resolveState) {
    Set<ModuleIdentifier> conflicts = new LinkedHashSet<ModuleIdentifier>();

    resolveState.onMoreSelected(resolveState.root);

    List<DependencyEdge> dependencies = new ArrayList<DependencyEdge>();
    while (resolveState.peek() != null || !conflicts.isEmpty()) {
      if (resolveState.peek() != null) {
        ConfigurationNode node = resolveState.pop();
        LOGGER.debug("Visiting configuration {}.", node);

        // Calculate the outgoing edges of this configuration
        dependencies.clear();
        node.visitOutgoingDependencies(dependencies);

        for (DependencyEdge dependency : dependencies) {
          LOGGER.debug("Visiting dependency {}", dependency);

          // Resolve dependency to a particular revision
          ModuleVersionResolveState moduleRevision = dependency.resolveModuleRevisionId();
          if (moduleRevision == null) {
            // Failed to resolve.
            continue;
          }
          ModuleIdentifier moduleId = moduleRevision.id.getModule();

          // Check for a new conflict
          if (moduleRevision.state == ModuleState.New) {
            ModuleResolveState module = resolveState.getModule(moduleId);

            // A new module revision. Check for conflict
            Collection<ModuleVersionResolveState> versions = module.getVersions();
            if (versions.size() == 1) {
              // First version of this module. Select it for now
              LOGGER.debug("Selecting new module version {}", moduleRevision);
              module.select(moduleRevision);
            } else {
              // Not the first version of this module. We have a new conflict
              LOGGER.debug("Found new conflicting module version {}", moduleRevision);
              conflicts.add(moduleId);

              // Deselect the currently selected version, and remove all outgoing edges from the
              // version
              // This will propagate through the graph and prune configurations that are no longer
              // required
              ModuleVersionResolveState previouslySelected = module.clearSelection();
              if (previouslySelected != null) {
                for (ConfigurationNode configuration : previouslySelected.configurations) {
                  configuration.removeOutgoingEdges();
                }
              }
            }
          }

          dependency.attachToTargetConfigurations();
        }
      } else {
        // We have some batched up conflicts. Resolve the first, and continue traversing the graph
        ModuleIdentifier moduleId = conflicts.iterator().next();
        conflicts.remove(moduleId);
        ModuleResolveState module = resolveState.getModule(moduleId);
        ModuleVersionResolveState selected =
            conflictResolver.select(module.getVersions(), resolveState.root.moduleRevision);
        LOGGER.debug("Selected {} from conflicting modules {}.", selected, module.getVersions());

        // Restart each configuration. For the evicted configuration, this means moving incoming
        // dependencies across to the
        // matching selected configuration. For the select configuration, this mean traversing its
        // dependencies.
        module.restart(selected);
      }
    }
  }
示例#17
0
 public void removeIncomingEdge(DependencyEdge dependencyEdge) {
   incomingEdges.remove(dependencyEdge);
   resolveState.onFewerSelected(this);
 }
示例#18
0
 public void addIncomingEdge(DependencyEdge dependencyEdge) {
   incomingEdges.add(dependencyEdge);
   resolveState.onMoreSelected(this);
 }
示例#19
0
    private Collection<List<ModuleVersionIdentifier>> calculatePaths(
        BrokenDependency brokenDependency) {
      // Include the shortest path from each version that has a direct dependency on the broken
      // dependency, back to the root

      Map<ModuleVersionResolveState, List<ModuleVersionIdentifier>> shortestPaths =
          new LinkedHashMap<ModuleVersionResolveState, List<ModuleVersionIdentifier>>();
      List<ModuleVersionIdentifier> rootPath = new ArrayList<ModuleVersionIdentifier>();
      rootPath.add(root.moduleRevision.id);
      shortestPaths.put(root.moduleRevision, rootPath);

      Set<ModuleVersionResolveState> directDependees =
          new LinkedHashSet<ModuleVersionResolveState>();
      for (ConfigurationNode node : brokenDependency.requiredBy) {
        directDependees.add(node.moduleRevision);
      }

      Set<ModuleVersionResolveState> seen = new HashSet<ModuleVersionResolveState>();
      LinkedList<ModuleVersionResolveState> queue = new LinkedList<ModuleVersionResolveState>();
      queue.addAll(directDependees);
      while (!queue.isEmpty()) {
        ModuleVersionResolveState version = queue.getFirst();
        if (version == root.moduleRevision) {
          queue.removeFirst();
        } else if (seen.add(version)) {
          for (ConfigurationNode configuration : version.configurations) {
            for (DependencyEdge dependencyEdge : configuration.incomingEdges) {
              queue.add(0, dependencyEdge.from.moduleRevision);
            }
          }
        } else {
          queue.remove();
          List<ModuleVersionIdentifier> shortest = null;
          for (ConfigurationNode configuration : version.configurations) {
            for (DependencyEdge dependencyEdge : configuration.incomingEdges) {
              List<ModuleVersionIdentifier> candidate =
                  shortestPaths.get(dependencyEdge.from.moduleRevision);
              if (candidate == null) {
                continue;
              }
              if (shortest == null) {
                shortest = candidate;
              } else if (shortest.size() > candidate.size()) {
                shortest = candidate;
              }
            }
          }
          if (shortest == null) {
            continue;
          }
          List<ModuleVersionIdentifier> path = new ArrayList<ModuleVersionIdentifier>();
          path.addAll(shortest);
          path.add(version.id);
          shortestPaths.put(version, path);
        }
      }

      List<List<ModuleVersionIdentifier>> paths = new ArrayList<List<ModuleVersionIdentifier>>();
      for (ModuleVersionResolveState version : directDependees) {
        List<ModuleVersionIdentifier> path = shortestPaths.get(version);
        paths.add(path);
      }
      return paths;
    }
示例#20
0
 public void removeFromTargetConfigurations() {
   for (ConfigurationNode targetConfiguration : targetConfigurations) {
     targetConfiguration.removeIncomingEdge(this);
   }
   targetConfigurations.clear();
 }
示例#21
0
 public void addConfiguration(ConfigurationNode configurationNode) {
   configurations.add(configurationNode);
 }
示例#22
0
 public void removeUnattachedDependency(DependencyEdge edge) {
   unattachedDependencies.remove(edge);
 }
示例#23
0
 public void addUnattachedDependency(DependencyEdge edge) {
   unattachedDependencies.add(edge);
 }
示例#24
0
 public ConfigurationNode pop() {
   ConfigurationNode next = queue.removeFirst();
   queued.remove(next);
   return next;
 }