Java Code Examples for org.gradle.api.artifacts.result.ResolvedComponentResult#getDependencies()

The following examples show how to use org.gradle.api.artifacts.result.ResolvedComponentResult#getDependencies() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DependencyOrder.java    From pygradle with Apache License 2.0 6 votes vote down vote up
/**
 * Traverses the dependency tree post-order and collects dependencies.
 * <p>
 * The recursive post-order traversal returns the root of the (sub)tree.
 * This allows the post-order adding into the set of dependencies as we
 * return from the recursive calls. The set of seen dependencies ensures
 * ensures that the cycles in Ivy metadata do not cause cycles in our
 * recursive calls.
 *
 * @param root         the root of the dependency (sub)tree
 * @param seen         the input set of already seen dependencies
 * @param dependencies the output set of dependencies in post-order
 * @return the root itself
 */
public static ResolvedComponentResult postOrderDependencies(
    ResolvedComponentResult root,
    Set<ComponentIdentifier> seen,
    Set<ResolvedComponentResult> dependencies) {
    for (DependencyResult d : root.getDependencies()) {
        if (!(d instanceof ResolvedDependencyResult)) {
            throw new GradleException("Unresolved dependency found for " + d.toString());
        }

        ResolvedComponentResult component = ((ResolvedDependencyResult) d).getSelected();
        ComponentIdentifier id = component.getId();

        if (!seen.contains(id)) {
            seen.add(id);
            dependencies.add(postOrderDependencies(component, seen, dependencies));
        }
    }

    return root;
}
 
Example 2
Source File: DefaultResolutionResult.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void eachElement(ResolvedComponentResult node,
                         Action<? super ResolvedComponentResult> moduleAction, Action<? super DependencyResult> dependencyAction,
                         Set<ResolvedComponentResult> visited) {
    if (!visited.add(node)) {
        return;
    }
    moduleAction.execute(node);
    for (DependencyResult d : node.getDependencies()) {
        dependencyAction.execute(d);
        if (d instanceof ResolvedDependencyResult) {
            eachElement(((ResolvedDependencyResult) d).getSelected(), moduleAction, dependencyAction, visited);
        }
    }
}
 
Example 3
Source File: DefaultResolutionResult.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void eachElement(ResolvedComponentResult node,
                         Action<? super ResolvedComponentResult> moduleAction, Action<? super DependencyResult> dependencyAction,
                         Set<ResolvedComponentResult> visited) {
    if (!visited.add(node)) {
        return;
    }
    moduleAction.execute(node);
    for (DependencyResult d : node.getDependencies()) {
        dependencyAction.execute(d);
        if (d instanceof ResolvedDependencyResult) {
            eachElement(((ResolvedDependencyResult) d).getSelected(), moduleAction, dependencyAction, visited);
        }
    }
}
 
Example 4
Source File: LinkageCheckTask.java    From cloud-opensource-java with Apache License 2.0 5 votes vote down vote up
private void recordDependencyPaths(
    ImmutableListMultimap.Builder<String, String> output,
    ArrayDeque<ResolvedComponentResult> stack,
    ImmutableSet<String> targetCoordinates) {
  ResolvedComponentResult item = stack.getLast();
  ModuleVersionIdentifier identifier = item.getModuleVersion();
  String coordinates =
      String.format(
          "%s:%s:%s", identifier.getGroup(), identifier.getName(), identifier.getVersion());
  if (targetCoordinates.contains(coordinates)) {
    String dependencyPath =
        stack.stream().map(this::formatComponentResult).collect(Collectors.joining(" / "));
    output.put(coordinates, dependencyPath);
  }

  for (DependencyResult dependencyResult : item.getDependencies()) {
    if (dependencyResult instanceof ResolvedDependencyResult) {
      ResolvedDependencyResult resolvedDependencyResult =
          (ResolvedDependencyResult) dependencyResult;
      ResolvedComponentResult child = resolvedDependencyResult.getSelected();
      stack.add(child);
      recordDependencyPaths(output, stack, targetCoordinates);
    } else if (dependencyResult instanceof UnresolvedDependencyResult) {
      UnresolvedDependencyResult unresolvedResult = (UnresolvedDependencyResult) dependencyResult;
      getLogger()
          .error(
              "Could not resolve dependency: "
                  + unresolvedResult.getAttempted().getDisplayName());
    } else {
      throw new IllegalStateException("Unexpected dependency result type: " + dependencyResult);
    }
  }

  stack.removeLast();
}
 
Example 5
Source File: DefaultResolutionResult.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void eachElement(ResolvedComponentResult node,
                         Action<? super ResolvedComponentResult> moduleAction, Action<? super DependencyResult> dependencyAction,
                         Set<ResolvedComponentResult> visited) {
    if (!visited.add(node)) {
        return;
    }
    moduleAction.execute(node);
    for (DependencyResult d : node.getDependencies()) {
        dependencyAction.execute(d);
        if (d instanceof ResolvedDependencyResult) {
            eachElement(((ResolvedDependencyResult) d).getSelected(), moduleAction, dependencyAction, visited);
        }
    }
}
 
Example 6
Source File: DefaultResolutionResult.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void eachElement(ResolvedComponentResult node,
                         Action<? super ResolvedComponentResult> moduleAction, Action<? super DependencyResult> dependencyAction,
                         Set<ResolvedComponentResult> visited) {
    if (!visited.add(node)) {
        return;
    }
    moduleAction.execute(node);
    for (DependencyResult d : node.getDependencies()) {
        dependencyAction.execute(d);
        if (d instanceof ResolvedDependencyResult) {
            eachElement(((ResolvedDependencyResult) d).getSelected(), moduleAction, dependencyAction, visited);
        }
    }
}