org.eclipse.aether.graph.DependencyNode Java Examples

The following examples show how to use org.eclipse.aether.graph.DependencyNode. 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: 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 #2
Source File: SerializeGraphTest.java    From cloud-opensource-java with Apache License 2.0 6 votes vote down vote up
@Test
public void testTreeWithScopeConflict() throws IOException
{
    DependencyNode root = new DefaultDependencyNode(
            new Dependency( new DefaultArtifact( "com.google", "rootArtifact", "jar", "1.0.0" ), "compile" )
    );
    DependencyNode left = new DefaultDependencyNode(
            new Dependency( new DefaultArtifact( "org.apache", "left", "xml", "0.1-SNAPSHOT" ), "test", true )
    );
    DependencyNode right = new DefaultDependencyNode(
            new Dependency( new DefaultArtifact( "com.google", "rootArtifact", "jar", "1.0.0" ), "test" )
    );

    root.setChildren( Arrays.asList( left, right ) );

    String actual = serializer.serialize( root );
    File file = new File(getBasedir(), "/target/test-classes/SerializerTests/ScopeConflict.txt");
    String expected = FileUtils.readFileToString(file);

    Assert.assertEquals(expected, actual);
}
 
Example #3
Source File: SerializeGraphTest.java    From cloud-opensource-java with Apache License 2.0 6 votes vote down vote up
@Test
public void testTreeWithOptional() throws IOException
{
    DependencyNode root = new DefaultDependencyNode(
            new Dependency( new DefaultArtifact( "com.google", "rootArtifact", "jar", "1.0.0" ), "")
    );
    DependencyNode left = new DefaultDependencyNode(
            new Dependency( new DefaultArtifact( "org.apache", "left", "xml", "0.1-SNAPSHOT" ), "test", true )
    );
    DependencyNode right = new DefaultDependencyNode(
            new Dependency( new DefaultArtifact( "org.xyz", "right", "zip", "1" ), "provided" )
    );

    root.setChildren( Arrays.asList( left, right ) );

    String actual = serializer.serialize( root );
    File file = new File(getBasedir(), "/target/test-classes/SerializerTests/OptionalDependency.txt");
    String expected = FileUtils.readFileToString(file);

    Assert.assertEquals(expected, actual);
}
 
Example #4
Source File: SerializeGraphTest.java    From cloud-opensource-java with Apache License 2.0 6 votes vote down vote up
@Test
public void testBasicTree() throws IOException
{
    DependencyNode root = new DefaultDependencyNode(
            new Dependency( new DefaultArtifact( "com.google", "rootArtifact", "jar", "1.0.0" ), null)
    );
    DependencyNode left = new DefaultDependencyNode(
            new Dependency( new DefaultArtifact( "org.apache", "left", "xml", "0.1-SNAPSHOT" ), "test" )
    );
    DependencyNode right = new DefaultDependencyNode(
            new Dependency( new DefaultArtifact( "org.xyz", "right", "zip", "1" ), "provided" )
    );

    root.setChildren( Arrays.asList( left, right ) );

    String actual = serializer.serialize( root );
    File file = new File(getBasedir(), "/target/test-classes/SerializerTests/BasicTree.txt");
    String expected = FileUtils.readFileToString( file );

    Assert.assertEquals(expected, actual);
}
 
Example #5
Source File: SerializeGraphTest.java    From cloud-opensource-java with Apache License 2.0 6 votes vote down vote up
@Test
public void testTreeWithVersionConflict() throws IOException
{
    DependencyNode root = new DefaultDependencyNode(
            new Dependency( new DefaultArtifact( "com.google", "rootArtifact", "jar", "1.0.0" ), "compile" )
    );
    DependencyNode left = new DefaultDependencyNode(
            new Dependency( new DefaultArtifact( "org.apache", "left", "xml", "0.1-SNAPSHOT" ), "test", true )
    );
    DependencyNode right = new DefaultDependencyNode(
            new Dependency( new DefaultArtifact( "com.google", "rootArtifact", "jar", "2.0.0" ), "test" )
    );

    root.setChildren( Arrays.asList( left, right ) );

    String actual = serializer.serialize( root );
    File file = new File(getBasedir(), "/target/test-classes/SerializerTests/VersionConflict.txt");
    String expected = FileUtils.readFileToString(file);

    Assert.assertEquals(expected, actual);
}
 
Example #6
Source File: ExtraArtifactsHandlerTest.java    From thorntail with Apache License 2.0 6 votes vote down vote up
private void shouldGetWithClassifierAndExtension(String classifier, String extension) {
    DependencyNode dependency = dependencyNode();
    List<DependencyNode> extraDependencies =
            ExtraArtifactsHandler.getExtraDependencies(Collections.singletonList(dependency));

    assertThat(extraDependencies).hasSize(1);

    DependencyNode extraDependency = extraDependencies.get(0);
    Artifact artifact = extraDependency.getDependency().getArtifact();
    assertThat(artifact.getGroupId()).isEqualTo(GROUP_ID);
    assertThat(artifact.getArtifactId()).isEqualTo(ARTIFACT_ID);
    assertThat(artifact.getVersion()).isEqualTo(VERSION);

    assertThat(artifact.getClassifier()).isEqualTo(classifier);
    assertThat(artifact.getExtension()).isEqualTo(extension);
}
 
Example #7
Source File: LinkageCheckerRuleTest.java    From cloud-opensource-java with Apache License 2.0 6 votes vote down vote up
/**
 * Returns a dependency graph node resolved from {@code coordinates}.
 */
private DependencyNode createResolvedDependencyGraph(String... coordinates)
    throws RepositoryException {
  CollectRequest collectRequest = new CollectRequest();
  collectRequest.setRootArtifact(dummyArtifactWithFile);
  collectRequest.setRepositories(ImmutableList.of(RepositoryUtility.CENTRAL));
  collectRequest.setDependencies(
      Arrays.stream(coordinates)
          .map(DefaultArtifact::new)
          .map(artifact -> new Dependency(artifact, "compile"))
          .collect(toImmutableList()));
  DependencyNode dependencyNode =
      repositorySystem.collectDependencies(repositorySystemSession, collectRequest).getRoot();

  DependencyRequest dependencyRequest = new DependencyRequest();
  dependencyRequest.setRoot(dependencyNode);
  DependencyResult dependencyResult =
      repositorySystem.resolveDependencies(repositorySystemSession, dependencyRequest);

  return dependencyResult.getRoot();
}
 
Example #8
Source File: LinkageCheckerRuleTest.java    From cloud-opensource-java with Apache License 2.0 6 votes vote down vote up
private void setupMockDependencyResolution(String... coordinates) throws RepositoryException {
  // The root node is Maven artifact "a:b:0.1" that has dependencies specified as `coordinates`.
  DependencyNode rootNode = createResolvedDependencyGraph(coordinates);
  Traverser<DependencyNode> traverser = Traverser.forGraph(node -> node.getChildren());

  // DependencyResolutionResult.getDependencies returns depth-first order
  ImmutableList<Dependency> dummyDependencies =
      ImmutableList.copyOf(traverser.depthFirstPreOrder(rootNode)).stream()
          .map(DependencyNode::getDependency)
          .filter(Objects::nonNull)
          .collect(toImmutableList());
  when(mockDependencyResolutionResult.getDependencies()).thenReturn(dummyDependencies);
  when(mockDependencyResolutionResult.getResolvedDependencies())
      .thenReturn(
          ImmutableList.copyOf(traverser.breadthFirst(rootNode.getChildren())).stream()
              .map(DependencyNode::getDependency)
              .filter(Objects::nonNull)
              .collect(toImmutableList()));
  when(mockDependencyResolutionResult.getDependencyGraph()).thenReturn(rootNode);
  when(mockProject.getDependencies())
      .thenReturn(
          dummyDependencies.subList(0, coordinates.length).stream()
              .map(LinkageCheckerRuleTest::toDependency)
              .collect(Collectors.toList()));
}
 
Example #9
Source File: TreeDependencyNodeVisitor.java    From archiva with Apache License 2.0 6 votes vote down vote up
@Override
public boolean visitEnter( DependencyNode dependencyNode )
{
    TreeEntry entry =
        new TreeEntry( getModelMapper().map( dependencyNode.getDependency().getArtifact(), Artifact.class ) );
    entry.getArtifact().setFileExtension( dependencyNode.getDependency().getArtifact().getExtension() );
    entry.getArtifact().setScope( dependencyNode.getDependency().getScope() );
    entry.setParent( currentEntry );
    currentEntry = entry;

    if ( firstDependencyNode == null )
    {
        firstDependencyNode = dependencyNode;
        treeEntries.add( currentEntry );
    }
    else
    {
        currentEntry.getParent().getChilds().add( currentEntry );
    }
    return true;
}
 
Example #10
Source File: AetherGraphTraverserTest.java    From migration-tooling with Apache License 2.0 6 votes vote down vote up
@Test
public void testBasicGraphConstruction() {
  DependencyNode root = dependencyNode("root:root:1");
  DependencyNode depA = dependencyNode("a:a:1");
  DependencyNode depB = dependencyNode("b:b:1");

  root.setChildren(ImmutableList.of(depA, depB));

  MavenJarRule rootRule = new MavenJarRule(root);
  MavenJarRule aRule = new MavenJarRule(depA);
  MavenJarRule bRule = new MavenJarRule(depB);

  MutableGraph<MavenJarRule> expected = newGraph();
  addEdge(expected, rootRule, aRule);
  addEdge(expected, rootRule, bRule);

  // Construct the graph
  MutableGraph<MavenJarRule> actual = newGraph();
  AetherGraphTraverser visitor = new AetherGraphTraverser(actual);
  root.accept(visitor);

  assertThatGraphsEqual(actual, expected);
}
 
Example #11
Source File: GraphSerializerTest.java    From migration-tooling with Apache License 2.0 6 votes vote down vote up
@Test
public void testSharedChild() {
  DependencyNode sentinel = dependencyNode("dummy:dummy:0");
  DependencyNode nodeA = dependencyNode("a:a:1");
  DependencyNode nodeB = dependencyNode("b:b:1");
  DependencyNode child = dependencyNode("child:child:1");

  sentinel.setChildren(ImmutableList.of(nodeA, nodeB));
  nodeA.setChildren(ImmutableList.of(child));
  nodeB.setChildren(ImmutableList.of(child));

  Set<MavenJarRule> rules = GraphSerializer.generateBuildRules(sentinel);

  MavenJarRule ruleA = new MavenJarRule(nodeA);
  MavenJarRule ruleB = new MavenJarRule(nodeB);
  MavenJarRule childRule = new MavenJarRule(child);
  addDependency(ruleA, childRule);
  addDependency(ruleB, childRule);

  assertRuleSetContainsExactly(rules, ruleA, ruleB, childRule);

}
 
Example #12
Source File: GraphSerializerTest.java    From migration-tooling with Apache License 2.0 6 votes vote down vote up
@Test
public void testMultipleDirectDependencies() {
  DependencyNode sentinel = dependencyNode("dummy:dummy:0");
  DependencyNode nodeA = dependencyNode("a:a:1");
  DependencyNode nodeA1 = dependencyNode("a:1:1");
  DependencyNode nodeB = dependencyNode("b:b:1");
  DependencyNode nodeC = dependencyNode("c:c:1");

  sentinel.setChildren(ImmutableList.of(nodeA, nodeB, nodeC));
  nodeA.setChildren(ImmutableList.of(nodeA1));

  Set<MavenJarRule> rules = GraphSerializer.generateBuildRules(sentinel);

  MavenJarRule ruleA = new MavenJarRule(nodeA);
  MavenJarRule ruleA1 = new MavenJarRule(nodeA1);
  MavenJarRule ruleB = new MavenJarRule(nodeB);
  MavenJarRule ruleC = new MavenJarRule(nodeC);
  addDependency(ruleA, ruleA1);

  assertRuleSetContainsExactly(rules, ruleA, ruleA1, ruleB, ruleC);
}
 
Example #13
Source File: ArtifactResolver.java    From migration-tooling with Apache License 2.0 6 votes vote down vote up
/**
 * Given a set of coordinates, resolves the transitive dependencies, and then returns the root
 * node to the resolved dependency graph. The root node is a sentinel node with direct edges
 * on the artifacts users declared explicit on.
 */
public DependencyNode resolveArtifacts(List<String> artifactCoords) {
  List<Dependency> directDependencies = createDirectDependencyList(artifactCoords);
  CollectRequest collectRequest =
      aether.createCollectRequest(directDependencies, managedDependencies);

  DependencyRequest dependencyRequest = aether.createDependencyRequest(collectRequest);
  DependencyResult dependencyResult;
  try {
    dependencyResult = aether.requestDependencyResolution(dependencyRequest);
  } catch (DependencyResolutionException e) {
    //FIXME(petros): This is very fragile. If one artifact doesn't resolve, no artifacts resolve.
    logger.warning("Unable to resolve transitive dependencies: " + e.getMessage());
    return null;
  }
  // root is a sentinel node whose direct children are the requested artifacts.
  return dependencyResult.getRoot();
}
 
Example #14
Source File: ArtifactProblem.java    From cloud-opensource-java with Apache License 2.0 6 votes vote down vote up
private static boolean equalsOnDependencies(
    List<DependencyNode> listA, List<DependencyNode> listB) {
  int size = listA.size();
  if (listB.size() != size) {
    return false;
  }

  for (int i = 0; i < size; i++) {
    DependencyNode nodeA = listA.get(i);
    DependencyNode nodeB = listB.get(i);
    Dependency dependencyA = nodeA.getDependency();
    Dependency dependencyB = nodeB.getDependency();
    if (!Objects.equals(dependencyA, dependencyB)) {
      return false;
    }
  }
  return true;
}
 
Example #15
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 #16
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 #17
Source File: BuildDependencyGraphVisitor.java    From quarkus with Apache License 2.0 6 votes vote down vote up
private void visitLeave(DependencyNode node) {
    final Dependency dep = node.getDependency();
    if (dep == null) {
        return;
    }
    final Artifact artifact = dep.getArtifact();
    if (artifact.getFile() == null) {
        requests.add(new ArtifactRequest(node));
    }
    if (deploymentNode != null) {
        if (runtimeNode == null && !appDeps.contains(new AppArtifactKey(artifact.getGroupId(),
                artifact.getArtifactId(), artifact.getClassifier(), artifact.getExtension()))) {
            //we never want optional deps on the deployment CP
            if (!node.getDependency().isOptional()) {
                deploymentDepNodes.add(node);
            }
        } else if (runtimeNode == node) {
            runtimeNode = null;
            runtimeArtifact = null;
        }
        if (deploymentNode == node) {
            deploymentNode = null;
        }
    }
}
 
Example #18
Source File: ArtifactProblemTest.java    From cloud-opensource-java with Apache License 2.0 6 votes vote down vote up
@Test
public void testEquality() {
  UnresolvableArtifactProblem problemA = new UnresolvableArtifactProblem(ImmutableList.of(nodeA));

  Artifact artifactACopy = new DefaultArtifact("foo:a:1.0.0");
  DependencyNode nodeACopy = new DefaultDependencyNode(new Dependency(artifactACopy, "compile"));
  UnresolvableArtifactProblem problemACopy =
      new UnresolvableArtifactProblem(ImmutableList.of(nodeACopy));

  DependencyNode nodeAWithProvidedScope =
      new DefaultDependencyNode(new Dependency(artifactACopy, "provided"));
  UnresolvableArtifactProblem problemAWithProvidedScope =
      new UnresolvableArtifactProblem(ImmutableList.of(nodeAWithProvidedScope));

  UnresolvableArtifactProblem problemB = new UnresolvableArtifactProblem(ImmutableList.of(nodeB));

  new EqualsTester()
      .addEqualityGroup(problemA, problemACopy)
      .addEqualityGroup(problemB)
      .addEqualityGroup(problemAWithProvidedScope)
      .testEquals();
}
 
Example #19
Source File: DependencyGraphBuilder.java    From cloud-opensource-java with Apache License 2.0 6 votes vote down vote up
private DependencyGraph buildDependencyGraph(
    List<DependencyNode> dependencyNodes, DefaultRepositorySystemSession session) {
   
  try {
    DependencyNode node = resolveCompileTimeDependencies(dependencyNodes, session);
    return DependencyGraph.from(node);
  } catch (DependencyResolutionException ex) {
    DependencyResult result = ex.getResult();
    DependencyGraph graph = DependencyGraph.from(result.getRoot());

    for (ArtifactResult artifactResult : result.getArtifactResults()) {
      Artifact resolvedArtifact = artifactResult.getArtifact();

      if (resolvedArtifact == null) {
        Artifact requestedArtifact = artifactResult.getRequest().getArtifact();
        graph.addUnresolvableArtifactProblem(requestedArtifact);
      }
    }
    
    return graph;
  }
}
 
Example #20
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 #21
Source File: Maven.java    From bazel-deps with MIT License 6 votes vote down vote up
public static Set<Artifact> transitiveDependencies(Artifact artifact) {

    RepositorySystem system = newRepositorySystem();

    RepositorySystemSession session = newRepositorySystemSession(system);

    CollectRequest collectRequest = new CollectRequest();
    collectRequest.setRoot(new Dependency(artifact, ""));
    collectRequest.setRepositories(repositories());

    CollectResult collectResult = null;
    try {
      collectResult = system.collectDependencies(session, collectRequest);
    } catch (DependencyCollectionException e) {
      throw new RuntimeException(e);
    }

    PreorderNodeListGenerator visitor = new PreorderNodeListGenerator();
    collectResult.getRoot().accept(visitor);

    return ImmutableSet.copyOf(
      visitor.getNodes().stream()
        .filter(d -> !d.getDependency().isOptional())
        .map(DependencyNode::getArtifact)
        .collect(Collectors.toList()));
  }
 
Example #22
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 #23
Source File: GraphSerializerTest.java    From migration-tooling with Apache License 2.0 6 votes vote down vote up
/**
 * Ensures that the generated rules preserve dependency relations
 * (i.e. parent, child sets). This will be used to generate the deps field.
 */
@Test
public void testBasicParentChildRelations() {
  DependencyNode sentinel = dependencyNode("dummy:dummy:0");
  DependencyNode parentNode = dependencyNode("a:a:1");
  DependencyNode childNode = dependencyNode("a:2:1");

  sentinel.setChildren(ImmutableList.of(parentNode));
  parentNode.setChildren(ImmutableList.of(childNode));

  MavenJarRule parent = new MavenJarRule(parentNode);
  MavenJarRule child = new MavenJarRule(childNode);
  addDependency(parent, child);

  Set<MavenJarRule> actual = GraphSerializer.generateBuildRules(sentinel);

  assertRuleSetContainsExactly(actual, parent, child);
}
 
Example #24
Source File: UniquePathRecordingDependencyVisitor.java    From cloud-opensource-java with Apache License 2.0 5 votes vote down vote up
public boolean visitEnter(DependencyNode node) {
  parents.add(node);

  if (filter.accept(node, parents)) {
    paths.add(new ArrayList<>(parents));

    visited.add(node);
    return false;
  }

  // Returning true if this node has not been visited
  return visited.add(node);
}
 
Example #25
Source File: BootstrapAppModelResolver.java    From quarkus with Apache License 2.0 5 votes vote down vote up
private static void collect(List<DependencyNode> nodes, List<AppDependency> appDeps) {
    for (DependencyNode node : nodes) {
        collect(node.getChildren(), appDeps);
        final Dependency dep = node.getDependency();
        appDeps.add(new AppDependency(toAppArtifact(node.getArtifact()), dep.getScope(), dep.isOptional()));
    }
}
 
Example #26
Source File: DependencyDownloader.java    From go-offline-maven-plugin with Apache License 2.0 5 votes vote down vote up
@Override
public boolean visitEnter(DependencyNode node) {
    if (root) {
        root = false;
        return true;
    }
    return artifacts.add(node.getArtifact());
}
 
Example #27
Source File: SerializeGraph.java    From cloud-opensource-java with Apache License 2.0 5 votes vote down vote up
private String VersionConflict( DependencyNode node )
{
    if( coordinateVersionMap.containsKey( getVersionlessCoordinate( node ) ) )
    {
        return coordinateVersionMap.get( getVersionlessCoordinate( node ) );
    }
    return null;
}
 
Example #28
Source File: CycleBreakerGraphTransformerTest.java    From cloud-opensource-java with Apache License 2.0 5 votes vote down vote up
@Test
public void testShouldVisitChildren() {
  CycleBreakerGraphTransformer transformer = new CycleBreakerGraphTransformer();
  Artifact artifact = new DefaultArtifact("g:a:1");
  DependencyNode node1 = new DefaultDependencyNode(artifact);
  DependencyNode node2 = new DefaultDependencyNode(artifact);

  assertTrue(transformer.shouldVisitChildren(node1));
  assertFalse(transformer.shouldVisitChildren(node1));
  assertTrue(transformer.shouldVisitChildren(node2));
}
 
Example #29
Source File: SimpleMavenCache.java    From gate-core with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void cacheArtifact(Artifact artifact)
    throws IOException, SettingsBuildingException,
    DependencyCollectionException, DependencyResolutionException,
    ArtifactResolutionException, ModelBuildingException {

  // setup a maven resolution hierarchy that uses the main local repo as
  // a remote repo and then cache into a new local repo
  List<RemoteRepository> repos = Utils.getRepositoryList();
  RepositorySystem repoSystem = Utils.getRepositorySystem();
  DefaultRepositorySystemSession repoSession =
      Utils.getRepositorySession(repoSystem, null);

  // treat the usual local repository as if it were a remote, ignoring checksum
  // failures as the local repo doesn't have checksums as a rule
  RemoteRepository localAsRemote =
      new RemoteRepository.Builder("localAsRemote", "default",
          repoSession.getLocalRepository().getBasedir().toURI().toString())
              .setPolicy(new RepositoryPolicy(true,
                      RepositoryPolicy.UPDATE_POLICY_NEVER,
                      RepositoryPolicy.CHECKSUM_POLICY_IGNORE))
              .build();

  repos.add(0, localAsRemote);

  repoSession.setLocalRepositoryManager(repoSystem.newLocalRepositoryManager(
      repoSession, new LocalRepository(head.getAbsolutePath())));

  Dependency dependency = new Dependency(artifact, "runtime");

  CollectRequest collectRequest = new CollectRequest(dependency, repos);

  DependencyNode node =
      repoSystem.collectDependencies(repoSession, collectRequest).getRoot();

  DependencyRequest dependencyRequest = new DependencyRequest();
  dependencyRequest.setRoot(node);

  repoSystem.resolveDependencies(repoSession, dependencyRequest);

}
 
Example #30
Source File: UniquePathRecordingDependencyVisitorTest.java    From cloud-opensource-java with Apache License 2.0 5 votes vote down vote up
@Test
public void testVisitingUniqueNodes() {
  // This setup creates a dependency graph like below. There are two paths from the root to node
  // 'y'. UniquePathRecordingDependencyVisitor does not record paths that have the same
  // intermediate node.
  //
  //    root
  //   /   \
  //  a     b
  //   \   /
  //     x
  //     |
  //     y

  DefaultDependencyNode root = new DefaultDependencyNode(new DefaultArtifact("g:r:1"));
  DefaultDependencyNode a = new DefaultDependencyNode(new DefaultArtifact("g:a:1"));
  DefaultDependencyNode b = new DefaultDependencyNode(new DefaultArtifact("g:b:1"));
  DefaultDependencyNode x = new DefaultDependencyNode(new DefaultArtifact("g:x:1"));
  DefaultDependencyNode y = new DefaultDependencyNode(new DefaultArtifact("g:y:1"));

  root.setChildren(ImmutableList.of(a, b));
  a.setChildren(ImmutableList.of(x));
  b.setChildren(ImmutableList.of(x));
  x.setChildren(ImmutableList.of(y));

  UniquePathRecordingDependencyVisitor visitor =
      new UniquePathRecordingDependencyVisitor(
          (DependencyNode node, List<DependencyNode> parents) ->
              node.getArtifact().getArtifactId().equals("y"));

  root.accept(visitor);

  ImmutableList<List<DependencyNode>> paths = visitor.getPaths();
  Truth.assertThat(paths).hasSize(1);
  assertSame(root, paths.get(0).get(0));
  assertSame(a, paths.get(0).get(1));
  assertSame(x, paths.get(0).get(2));
  assertSame(y, paths.get(0).get(3));
}