Java Code Examples for org.eclipse.aether.RepositorySystem#collectDependencies()

The following examples show how to use org.eclipse.aether.RepositorySystem#collectDependencies() . 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: 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 2
Source File: Maven3DependencyTreeBuilder.java    From archiva with Apache License 2.0 5 votes vote down vote up
private void resolve( ResolveRequest resolveRequest )
{

    RepositorySystem system = mavenSystemManager.getRepositorySystem();
    RepositorySystemSession session = MavenSystemManager.newRepositorySystemSession( resolveRequest.localRepoDir );

    org.eclipse.aether.artifact.Artifact artifact = new DefaultArtifact(
        resolveRequest.groupId + ":" + resolveRequest.artifactId + ":" + resolveRequest.version );

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

    // add remote repositories
    for ( RemoteRepository remoteRepository : resolveRequest.remoteRepositories )
    {
        org.eclipse.aether.repository.RemoteRepository repo = new org.eclipse.aether.repository.RemoteRepository.Builder( remoteRepository.getId( ), "default", remoteRepository.getLocation( ).toString() ).build( );
        collectRequest.addRepository(repo);
    }
    collectRequest.setRequestContext( "project" );

    //collectRequest.addRepository( repo );

    try
    {
        CollectResult collectResult = system.collectDependencies( session, collectRequest );
        collectResult.getRoot().accept( resolveRequest.dependencyVisitor );
        log.debug("Collected dependency results for resolve");
    }
    catch ( DependencyCollectionException e )
    {
        log.error( "Error while collecting dependencies (resolve): {}", e.getMessage(), e );
    }



}
 
Example 3
Source File: MavenAddonDependencyResolver.java    From furnace with Eclipse Public License 1.0 4 votes vote down vote up
private Response<String> resolveAPIVersion(AddonId addonId, RepositorySystem system, Settings settings,
         DefaultRepositorySystemSession session)
{
   List<RemoteRepository> repositories = MavenRepositories.getRemoteRepositories(container, settings);
   String mavenCoords = toMavenCoords(addonId);
   Artifact queryArtifact = new DefaultArtifact(mavenCoords);

   session.setDependencyTraverser(new AddonDependencyTraverser(classifier));
   session.setDependencySelector(new DependencySelector()
   {

      @Override
      public boolean selectDependency(Dependency dependency)
      {
         Artifact artifact = dependency.getArtifact();
         if (isAddon(artifact))
         {
            return true;
         }
         return isFurnaceAPI(artifact);
      }

      @Override
      public DependencySelector deriveChildSelector(DependencyCollectionContext context)
      {
         return this;
      }
   });
   CollectRequest request = new CollectRequest(new Dependency(queryArtifact, null), repositories);
   CollectResult result;
   try
   {
      result = system.collectDependencies(session, request);
   }
   catch (DependencyCollectionException e)
   {
      throw new RuntimeException(e);
   }
   List<Exception> exceptions = result.getExceptions();
   String apiVersion = findVersion(result.getRoot().getChildren(), FURNACE_API_GROUP_ID, FURNACE_API_ARTIFACT_ID);
   return new MavenResponseBuilder<String>(apiVersion).setExceptions(exceptions);
}