Java Code Examples for org.eclipse.aether.graph.DependencyNode#getChildren()

The following examples show how to use org.eclipse.aether.graph.DependencyNode#getChildren() . 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: CycleBreakerGraphTransformer.java    From cloud-opensource-java with Apache License 2.0 6 votes vote down vote up
private void removeCycle(DependencyNode parent, DependencyNode node, Set<Artifact> ancestors) {
  Artifact artifact = node.getArtifact();

  if (ancestors.contains(artifact)) { // Set (rather than List) gives O(1) lookup here
    // parent is not null when ancestors is not empty
    removeChildFromParent(node, parent);
    return;
  }

  if (shouldVisitChildren(node)) {
    ancestors.add(artifact);
    for (DependencyNode child : node.getChildren()) {
      removeCycle(node, child, ancestors);
    }
    ancestors.remove(artifact);
  }
}
 
Example 2
Source File: DeploymentInjectingDependencyVisitor.java    From quarkus with Apache License 2.0 6 votes vote down vote up
private void replaceWith(DependencyNode originalNode, DependencyNode newNode)
        throws BootstrapDependencyProcessingException {
    List<DependencyNode> children = newNode.getChildren();
    if (children.isEmpty()) {
        throw new BootstrapDependencyProcessingException(
                "No dependencies collected for Quarkus extension deployment artifact " + newNode.getArtifact()
                        + " while at least the corresponding runtime artifact " + originalNode.getArtifact()
                        + " is expected");
    }
    log.debugf("Injecting deployment dependency %s", newNode);

    originalNode.setData(QUARKUS_RUNTIME_ARTIFACT, originalNode.getArtifact());
    originalNode.setArtifact(newNode.getArtifact());
    originalNode.getDependency().setArtifact(newNode.getArtifact());
    originalNode.setChildren(children);
    injectedDeps = true;
}
 
Example 3
Source File: GraphSerializer.java    From migration-tooling with Apache License 2.0 6 votes vote down vote up
@Override
public boolean visitEnter(DependencyNode dependencyNode) {
  if (dependencyNode == null || dependencyNode.getDependency().isOptional()) {
    return false;
  }
  MavenJarRule rule = getRule(dependencyNode);
  boolean isFirstVisit = visited.add(rule);
  if (!isFirstVisit) {
    return false;
  }
  for (DependencyNode child : dependencyNode.getChildren()) {
    MavenJarRule childRule = getRule(child);
    ruleGraph.putEdge(rule, childRule);
  }
  return true;
}
 
Example 4
Source File: BootstrapAppModelResolver.java    From quarkus with Apache License 2.0 5 votes vote down vote up
static List<AppDependency> toAppDepList(DependencyNode rootNode) {
    final List<DependencyNode> depNodes = rootNode.getChildren();
    if (depNodes.isEmpty()) {
        return Collections.emptyList();
    }
    final List<AppDependency> appDeps = new ArrayList<>();
    collect(depNodes, appDeps);
    return appDeps;
}
 
Example 5
Source File: DependencyGraph.java    From cloud-opensource-java with Apache License 2.0 4 votes vote down vote up
private static void levelOrder(DependencyGraph graph) {
  Queue<DependencyGraph.LevelOrderQueueItem> queue = new ArrayDeque<>();
  queue.add(new DependencyGraph.LevelOrderQueueItem(graph.root, null));

  while (!queue.isEmpty()) {
    DependencyGraph.LevelOrderQueueItem item = queue.poll();
    DependencyNode dependencyNode = item.dependencyNode;

    DependencyPath parentPath = item.parentPath;
    Artifact artifact = dependencyNode.getArtifact();
    if (artifact != null && parentPath != null) {
      // When requesting dependencies of 2 or more artifacts, root DependencyNode's artifact is
      // set to null

      // When there's an ancestor dependency node with the same groupId and artifactId as
      // the dependency, Maven will not pick up the dependency. For example, if there's a
      // dependency path "g1:a1:2.0 / ... / g1:a1:1.0" (the leftmost node as root), then Maven's
      // dependency mediation always picks g1:a1:2.0 over g1:a1:1.0.
      
      // TODO This comment doesn't seem right. That's true for the root,
      // but not for non-root nodes. A node elsewhere in the tree could cause the 
      // descendant to be selected. 
      
      String groupIdAndArtifactId = Artifacts.makeKey(artifact);
      boolean ancestorHasSameKey =
          parentPath.getArtifacts().stream()
              .map(Artifacts::makeKey)
              .anyMatch(key -> key.equals(groupIdAndArtifactId));
      if (ancestorHasSameKey) {
        continue;
      }
    }

    // parentPath is null for the first item
    DependencyPath path =
        parentPath == null
            ? new DependencyPath(artifact)
            : parentPath.append(dependencyNode.getDependency());
    graph.addPath(path);

    graph.parentToChildren.put(parentPath, path);

    for (DependencyNode child : dependencyNode.getChildren()) {
      queue.add(new DependencyGraph.LevelOrderQueueItem(child, path));
    }
  }
}