private ModuleComponentIdentifier chooseBestMatchingDependency(
      ModuleVersionListing versions, ModuleVersionSelector requested) {
    for (Versioned candidate : sortLatestFirst(versions)) {
      // Apply version selection rules
      ModuleComponentIdentifier candidateIdentifier =
          DefaultModuleComponentIdentifier.newId(
              requested.getGroup(), requested.getName(), candidate.getVersion());
      ModuleComponentSelector requestedComponentSelector =
          DefaultModuleComponentSelector.newSelector(requested);
      VersionSelectionInternal selection =
          new DefaultVersionSelection(requestedComponentSelector, candidateIdentifier);
      versionSelectionRules.apply(selection);

      switch (selection.getState()) {
        case ACCEPTED:
          return candidateIdentifier;
        case REJECTED:
          continue;
        default:
          break;
      }

      // Invoke version matcher
      if (versionMatcher.accept(requested.getVersion(), candidate.getVersion())) {
        return candidateIdentifier;
      }
    }
    return null;
  }
 public RenderableUnresolvedDependencyResult(UnresolvedDependencyResult dependency) {
   this.dependency = dependency;
   ModuleVersionSelector attempted = dependency.getAttempted();
   this.actual =
       DefaultModuleVersionIdentifier.newId(
           attempted.getGroup(), attempted.getName(), attempted.getVersion());
 }
 public DependencyMetaData withRequestedVersion(String requestedVersion) {
   if (requestedVersion.equals(requested.getVersion())) {
     return this;
   }
   ModuleVersionSelector newRequested =
       DefaultModuleVersionSelector.newSelector(
           requested.getGroup(), requested.getName(), requestedVersion);
   ComponentSelector newSelector = DefaultModuleComponentSelector.newSelector(newRequested);
   return copyWithTarget(newSelector, newRequested);
 }
 public UnresolvedDependencyEdge(UnresolvedDependencyResult dependency) {
   this.dependency = dependency;
   ModuleComponentSelector moduleComponentSelector = dependency.getAttempted();
   ModuleVersionSelector attempted =
       DefaultModuleVersionSelector.newSelector(
           moduleComponentSelector.getGroup(),
           moduleComponentSelector.getName(),
           moduleComponentSelector.getVersion());
   actual =
       DefaultModuleVersionIdentifier.newId(
           attempted.getGroup(), attempted.getName(), attempted.getVersion());
 }
 private MutableModuleVersionMetaData resolveComponentMetaData(
     DependencyMetaData dependency,
     Versioned candidate,
     ModuleComponentRepositoryAccess moduleAccess) {
   ModuleVersionSelector selector = dependency.getRequested();
   ModuleComponentIdentifier candidateId =
       DefaultModuleComponentIdentifier.newId(
           selector.getGroup(), selector.getName(), candidate.getVersion());
   DependencyMetaData moduleVersionDependency =
       dependency.withRequestedVersion(candidate.getVersion());
   BuildableModuleVersionMetaDataResolveResult descriptorResult =
       new DefaultBuildableModuleVersionMetaDataResolveResult();
   moduleAccess.resolveComponentMetaData(moduleVersionDependency, candidateId, descriptorResult);
   return descriptorResult.getMetaData();
 }
  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);
    }
  }
 /**
  * @param selector the selector to get coordinates from
  * @return the coordinates in the form of "<group>:<name>"
  */
 protected String getCoord(ModuleVersionSelector selector) {
   return selector.getGroup() + ":" + selector.getName();
 }
 /**
  * @param details the details to get coordinates from
  * @return the coordinates in the form of "<group>:<name>", taken from details.requested.
  */
 protected String getCoord(DependencyResolveDetails details) {
   ModuleVersionSelector requested = details.getRequested();
   return requested.getGroup() + ":" + requested.getName();
 }
 public boolean canSelectMultipleComponents(ModuleVersionSelector selector) {
   return versionMatcher.isDynamic(selector.getVersion()) || versionSelectionRules.hasRules();
 }
 public String getDynamicConstraintVersion() {
   return requested.getVersion();
 }