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;
    }
 @Override
 public String toString() {
   return String.format(
       "%s -> %s(%s)",
       from.toString(),
       dependencyMetaData.getRequested(),
       Joiner.on(',').join(dependencyMetaData.getModuleConfigurations()));
 }
 public void resolve(DependencyMetaData dependency, BuildableComponentIdResolveResult result) {
   if (dependency.getSelector() instanceof ProjectComponentSelector) {
     ProjectComponentSelector selector = (ProjectComponentSelector) dependency.getSelector();
     LocalComponentMetaData componentMetaData =
         projectComponentRegistry.getProject(selector.getProjectPath());
     result.resolved(componentMetaData.toResolveMetaData());
   } else {
     delegate.resolve(dependency, result);
   }
 }
 public void resolve(DependencyMetaData dependency, BuildableComponentIdResolveResult result) {
   if (dependency.getSelector() instanceof ProjectComponentSelector) {
     ProjectComponentSelector selector = (ProjectComponentSelector) dependency.getSelector();
     String projectPath = selector.getProjectPath();
     LocalComponentMetaData componentMetaData = projectComponentRegistry.getProject(projectPath);
     if (componentMetaData == null) {
       result.failed(
           new ModuleVersionResolveException(
               selector, "project '" + projectPath + "' not found."));
     } else {
       result.resolved(componentMetaData.toResolveMetaData());
     }
   }
 }
 public void resolve(DependencyMetaData dependency, BuildableComponentIdResolveResult result) {
   ModuleVersionSelector module = dependency.getRequested();
   DefaultDependencyResolveDetails details = new DefaultDependencyResolveDetails(module);
   try {
     rule.execute(details);
   } catch (Throwable e) {
     result.failed(new ModuleVersionResolveException(module, e));
     return;
   }
   if (details.isUpdated()) {
     DependencyMetaData substitutedDependency =
         dependency.withRequestedVersion(details.getTarget());
     resolver.resolve(substitutedDependency, result);
     result.setSelectionReason(details.getSelectionReason());
     return;
   }
   resolver.resolve(dependency, result);
 }
 public ModuleVersionSelectorResolveState getSelector(DependencyMetaData dependencyMetaData) {
   ModuleVersionSelector requested = dependencyMetaData.getRequested();
   ModuleVersionSelectorResolveState resolveState = selectors.get(requested);
   if (resolveState == null) {
     resolveState = new ModuleVersionSelectorResolveState(dependencyMetaData, idResolver, this);
     selectors.put(requested, resolveState);
   }
   return resolveState;
 }
 private ModuleVersionSelectorResolveState(
     DependencyMetaData dependencyMetaData,
     DependencyToComponentIdResolver resolver,
     ResolveState resolveState) {
   this.dependencyMetaData = dependencyMetaData;
   this.resolver = resolver;
   this.resolveState = resolveState;
   targetModule =
       resolveState.getModule(
           new DefaultModuleIdentifier(
               dependencyMetaData.getRequested().getGroup(),
               dependencyMetaData.getRequested().getName()));
 }
  public void resolve(DependencyMetaData dependency, BuildableComponentResolveResult result) {
    ModuleVersionSelector requested = dependency.getRequested();
    LOGGER.debug("Attempting to resolve {} using repositories {}", requested, repositoryNames);
    ModuleComponentIdentifier moduleComponentIdentifier =
        new DefaultModuleComponentIdentifier(
            requested.getGroup(), requested.getName(), requested.getVersion());
    ModuleVersionIdentifier moduleVersionIdentifier =
        new DefaultModuleVersionIdentifier(
            requested.getGroup(), requested.getName(), requested.getVersion());

    List<Throwable> errors = new ArrayList<Throwable>();

    List<ComponentMetaDataResolveState> resolveStates =
        new ArrayList<ComponentMetaDataResolveState>();
    for (ModuleComponentRepository repository : repositories) {
      resolveStates.add(
          new ComponentMetaDataResolveState(
              dependency, moduleComponentIdentifier, repository, componentChooser));
    }

    final RepositoryChainModuleResolution latestResolved = findBestMatch(resolveStates, errors);
    if (latestResolved != null) {
      LOGGER.debug("Using {} from {}", latestResolved.module.getId(), latestResolved.repository);
      for (Throwable error : errors) {
        LOGGER.debug("Discarding resolve failure.", error);
      }

      result.resolved(metaDataFactory.transform(latestResolved));
      return;
    }
    if (!errors.isEmpty()) {
      result.failed(new ModuleVersionResolveException(moduleComponentIdentifier, errors));
    } else {
      for (ComponentMetaDataResolveState resolveState : resolveStates) {
        resolveState.applyTo(result);
      }
      result.notFound(moduleVersionIdentifier);
    }
  }
 @Override
 public String toString() {
   return dependencyMetaData.toString();
 }
 public Set<ComponentArtifactMetaData> getArtifacts(ConfigurationMetaData metaData1) {
   return dependencyMetaData.getArtifacts(from.metaData, metaData1);
 }
 // TODO This should be replaced by getRequested()
 public ModuleVersionSelector getRequestedModuleVersion() {
   return dependencyMetaData.getRequested();
 }
 public ComponentSelector getRequested() {
   return dependencyMetaData.getSelector();
 }
 public ModuleResolutionFilter getSelector() {
   Set<String> hierarchy = from.metaData.getHierarchy();
   ModuleResolutionFilter selector =
       DefaultModuleResolutionFilter.excludeAny(dependencyMetaData.getExcludeRules(hierarchy));
   return selector.intersect(resolutionFilter);
 }
 public boolean isTransitive() {
   return from.isTransitive() && dependencyMetaData.isTransitive();
 }