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

The following examples show how to use org.eclipse.aether.graph.DependencyNode#getArtifact() . 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: SerializeGraph.java    From cloud-opensource-java with Apache License 2.0 6 votes vote down vote up
private String ScopeConflict( DependencyNode node )
{
    Artifact artifact = node.getArtifact();
    List<String> scopes = Arrays.asList( "compile", "provided", "runtime", "test", "system" );

    for( String scope:scopes )
    {
        String coordinate = artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" +
                artifact.getExtension() + ":" + artifact.getVersion() + ":" + scope;
        if( coordinateStrings.contains( coordinate ) )
        {
            return scope;
        }
    }
    // check for scopeless, this probably can't happen
    return null;
}
 
Example 2
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 3
Source File: DeploymentInjectingDependencyVisitor.java    From quarkus with Apache License 2.0 6 votes vote down vote up
private void collectRuntimeExtensions(DependencyNode node) {
    final Artifact artifact = node.getArtifact();
    if (!artifact.getExtension().equals("jar")) {
        return;
    }
    final Path path = resolve(artifact);
    try {
        if (Files.isDirectory(path)) {
            processMetaInfDir(node, path.resolve(BootstrapConstants.META_INF));
        } else {
            try (FileSystem artifactFs = ZipUtils.newFileSystem(path)) {
                processMetaInfDir(node, artifactFs.getPath(BootstrapConstants.META_INF));
            }
        }
    } catch (Exception t) {
        throw new DeploymentInjectionException("Failed to inject extension deplpyment dependencies", t);
    }
    collectRuntimeExtensions(node.getChildren());
}
 
Example 4
Source File: DeploymentInjectingDependencyVisitor.java    From quarkus with Apache License 2.0 6 votes vote down vote up
private void processPlatformArtifact(DependencyNode node, Path descriptor) throws BootstrapDependencyProcessingException {
    final Properties rtProps = resolveDescriptor(descriptor);
    if (rtProps == null) {
        return;
    }
    final String value = rtProps.getProperty(BootstrapConstants.PROP_DEPLOYMENT_ARTIFACT);
    appBuilder.handleExtensionProperties(rtProps, node.getArtifact().toString());
    if (value == null) {
        return;
    }
    Artifact deploymentArtifact = toArtifact(value);
    if (deploymentArtifact.getVersion() == null || deploymentArtifact.getVersion().isEmpty()) {
        deploymentArtifact = deploymentArtifact.setVersion(node.getArtifact().getVersion());
    }
    node.setData(QUARKUS_DEPLOYMENT_ARTIFACT, deploymentArtifact);
    runtimeNodes.add(node);
    Dependency dependency = new Dependency(node.getArtifact(), JavaScopes.COMPILE);
    runtimeExtensionDeps.add(dependency);
    managedDeps.add(new Dependency(deploymentArtifact, JavaScopes.COMPILE));
}
 
Example 5
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 6
Source File: MavenAddonDependencyResolver.java    From furnace with Eclipse Public License 1.0 6 votes vote down vote up
private String findVersion(List<DependencyNode> dependencies, String groupId, String artifactId)
{
   for (DependencyNode child : dependencies)
   {
      Artifact childArtifact = child.getArtifact();

      if (groupId.equals(childArtifact.getGroupId())
               && artifactId.equals(childArtifact.getArtifactId()))
      {
         return childArtifact.getBaseVersion();
      }
      else
      {
         String version = findVersion(child.getChildren(), groupId, artifactId);
         if (version != null)
         {
            return version;
         }
      }
   }
   return null;
}
 
Example 7
Source File: SerializeGraph.java    From cloud-opensource-java with Apache License 2.0 5 votes vote down vote up
private static String getDependencyCoordinate( DependencyNode node )
{
    Artifact artifact = node.getArtifact();
    String scope = node.getDependency().getScope();
    String coords = artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" +
            artifact.getExtension() + ":" + artifact.getVersion();

    if( scope != null && !scope.isEmpty() )
    {
        coords = coords.concat( ":" + scope );
    }
    return coords;
}
 
Example 8
Source File: SerializeGraph.java    From cloud-opensource-java with Apache License 2.0 5 votes vote down vote up
private static String getVersionlessCoordinate( DependencyNode node )
{
    Artifact artifact = node.getArtifact();

    // scope not included because we check for scope conflicts separately
    return artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + artifact.getExtension();
}
 
Example 9
Source File: ExtraArtifactsHandler.java    From thorntail with Apache License 2.0 5 votes vote down vote up
private DependencyNode createNode(DependencyNode n, Optional<String> extension, Optional<String> classifier) {
    Artifact original = n.getArtifact();
    Artifact withExtension =
            new DefaultArtifact(original.getGroupId(),
                    original.getArtifactId(),
                    classifier.orElse(original.getClassifier()),
                    extension.orElse(original.getExtension()),
                    original.getVersion(),
                    original.getProperties(),
                    (File) null);

    DefaultDependencyNode nodeWithClassifier = new DefaultDependencyNode(new Dependency(withExtension, "system"));

    return nodeWithClassifier;
}
 
Example 10
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));
    }
  }
}