Search in sources :

Example 1 with CollectRequest

use of org.eclipse.aether.collection.CollectRequest in project druid by druid-io.

the class PullDependencies method downloadExtension.

/**
   * Download the extension given its maven coordinate
   *
   * @param versionedArtifact The maven artifact of the extension
   * @param toLocation        The location where this extension will be downloaded to
   */
private void downloadExtension(Artifact versionedArtifact, File toLocation) {
    final CollectRequest collectRequest = new CollectRequest();
    collectRequest.setRoot(new Dependency(versionedArtifact, JavaScopes.RUNTIME));
    final DependencyRequest dependencyRequest = new DependencyRequest(collectRequest, DependencyFilterUtils.andFilter(DependencyFilterUtils.classpathFilter(JavaScopes.RUNTIME), new DependencyFilter() {

        @Override
        public boolean accept(DependencyNode node, List<DependencyNode> parents) {
            String scope = node.getDependency().getScope();
            if (scope != null) {
                scope = scope.toLowerCase();
                if (scope.equals("provided")) {
                    return false;
                }
                if (scope.equals("test")) {
                    return false;
                }
                if (scope.equals("system")) {
                    return false;
                }
            }
            if (accept(node.getArtifact())) {
                return false;
            }
            for (DependencyNode parent : parents) {
                if (accept(parent.getArtifact())) {
                    return false;
                }
            }
            return true;
        }

        private boolean accept(final Artifact artifact) {
            return exclusions.contains(artifact.getGroupId());
        }
    }));
    try {
        log.info("Start downloading extension [%s]", versionedArtifact);
        final List<Artifact> artifacts = aether.resolveArtifacts(dependencyRequest);
        for (Artifact artifact : artifacts) {
            if (!exclusions.contains(artifact.getGroupId())) {
                log.info("Adding file [%s] at [%s]", artifact.getFile().getName(), toLocation.getAbsolutePath());
                FileUtils.copyFileToDirectory(artifact.getFile(), toLocation);
            } else {
                log.debug("Skipped Artifact[%s]", artifact);
            }
        }
    } catch (Exception e) {
        log.error(e, "Unable to resolve artifacts for [%s].", dependencyRequest);
        throw Throwables.propagate(e);
    }
    log.info("Finish downloading extension [%s]", versionedArtifact);
}
Also used : DependencyRequest(org.eclipse.aether.resolution.DependencyRequest) DependencyNode(org.eclipse.aether.graph.DependencyNode) DependencyFilter(org.eclipse.aether.graph.DependencyFilter) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) Dependency(org.eclipse.aether.graph.Dependency) CollectRequest(org.eclipse.aether.collection.CollectRequest) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 2 with CollectRequest

use of org.eclipse.aether.collection.CollectRequest in project buck by facebook.

the class Resolver method getRunTimeTransitiveDeps.

private ImmutableMap<String, Artifact> getRunTimeTransitiveDeps(Iterable<Dependency> mavenCoords) throws RepositoryException {
    CollectRequest collectRequest = new CollectRequest();
    collectRequest.setRequestContext(JavaScopes.RUNTIME);
    collectRequest.setRepositories(repos);
    for (Dependency dep : mavenCoords) {
        collectRequest.addDependency(dep);
    }
    DependencyFilter filter = DependencyFilterUtils.classpathFilter(JavaScopes.RUNTIME);
    DependencyRequest dependencyRequest = new DependencyRequest(collectRequest, filter);
    DependencyResult dependencyResult = repoSys.resolveDependencies(session, dependencyRequest);
    ImmutableSortedMap.Builder<String, Artifact> knownDeps = ImmutableSortedMap.naturalOrder();
    for (ArtifactResult artifactResult : dependencyResult.getArtifactResults()) {
        Artifact node = artifactResult.getArtifact();
        knownDeps.put(buildKey(node), node);
    }
    return knownDeps.build();
}
Also used : DependencyRequest(org.eclipse.aether.resolution.DependencyRequest) DependencyResult(org.eclipse.aether.resolution.DependencyResult) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) DependencyFilter(org.eclipse.aether.graph.DependencyFilter) Dependency(org.eclipse.aether.graph.Dependency) STGroupString(org.stringtemplate.v4.STGroupString) CollectRequest(org.eclipse.aether.collection.CollectRequest) SubArtifact(org.eclipse.aether.util.artifact.SubArtifact) Artifact(org.eclipse.aether.artifact.Artifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult)

Example 3 with CollectRequest

use of org.eclipse.aether.collection.CollectRequest in project byte-buddy by raphw.

the class ClassLoaderResolverTest method setUp.

@Before
public void setUp() throws Exception {
    classLoaderResolver = new ClassLoaderResolver(log, repositorySystem, repositorySystemSession, Collections.<RemoteRepository>emptyList());
    when(repositorySystem.collectDependencies(eq(repositorySystemSession), any(CollectRequest.class))).thenReturn(new CollectResult(new CollectRequest()).setRoot(root));
    when(child.getDependency()).thenReturn(new Dependency(new DefaultArtifact(FOO, BAR, QUX, BAZ, FOO + BAR, Collections.<String, String>emptyMap(), new File(FOO + "/" + BAR)), QUX + BAZ));
    when(root.accept(any(DependencyVisitor.class))).then(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocationOnMock) throws Throwable {
            DependencyVisitor dependencyVisitor = invocationOnMock.getArgumentAt(0, DependencyVisitor.class);
            dependencyVisitor.visitEnter(child);
            dependencyVisitor.visitLeave(child);
            return null;
        }
    });
}
Also used : CollectResult(org.eclipse.aether.collection.CollectResult) RemoteRepository(org.eclipse.aether.repository.RemoteRepository) Dependency(org.eclipse.aether.graph.Dependency) CollectRequest(org.eclipse.aether.collection.CollectRequest) InvocationOnMock(org.mockito.invocation.InvocationOnMock) DependencyVisitor(org.eclipse.aether.graph.DependencyVisitor) File(java.io.File) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Before(org.junit.Before)

Example 4 with CollectRequest

use of org.eclipse.aether.collection.CollectRequest in project byte-buddy by raphw.

the class ClassLoaderResolverTest method testCollectionFailure.

@Test(expected = MojoExecutionException.class)
public void testCollectionFailure() throws Exception {
    when(repositorySystem.collectDependencies(eq(repositorySystemSession), any(CollectRequest.class))).thenThrow(new DependencyCollectionException(new CollectResult(new CollectRequest())));
    classLoaderResolver.resolve(new MavenCoordinate(FOO, BAR, QUX));
}
Also used : DependencyCollectionException(org.eclipse.aether.collection.DependencyCollectionException) CollectResult(org.eclipse.aether.collection.CollectResult) CollectRequest(org.eclipse.aether.collection.CollectRequest) Test(org.junit.Test)

Example 5 with CollectRequest

use of org.eclipse.aether.collection.CollectRequest in project spring-boot by spring-projects.

the class AetherGrapeEngine method resolve.

private List<File> resolve(List<Dependency> dependencies) throws ArtifactResolutionException {
    try {
        CollectRequest collectRequest = getCollectRequest(dependencies);
        DependencyRequest dependencyRequest = getDependencyRequest(collectRequest);
        DependencyResult result = this.repositorySystem.resolveDependencies(this.session, dependencyRequest);
        addManagedDependencies(result);
        return getFiles(result);
    } catch (Exception ex) {
        throw new DependencyResolutionFailedException(ex);
    } finally {
        this.progressReporter.finished();
    }
}
Also used : DependencyRequest(org.eclipse.aether.resolution.DependencyRequest) DependencyResult(org.eclipse.aether.resolution.DependencyResult) CollectRequest(org.eclipse.aether.collection.CollectRequest) MalformedURLException(java.net.MalformedURLException) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException)

Aggregations

CollectRequest (org.eclipse.aether.collection.CollectRequest)10 DependencyRequest (org.eclipse.aether.resolution.DependencyRequest)6 Dependency (org.eclipse.aether.graph.Dependency)5 Artifact (org.eclipse.aether.artifact.Artifact)4 DefaultArtifact (org.eclipse.aether.artifact.DefaultArtifact)4 DependencyResult (org.eclipse.aether.resolution.DependencyResult)4 ArrayList (java.util.ArrayList)3 CollectResult (org.eclipse.aether.collection.CollectResult)3 DependencyFilter (org.eclipse.aether.graph.DependencyFilter)3 ArtifactResult (org.eclipse.aether.resolution.ArtifactResult)3 File (java.io.File)2 MalformedURLException (java.net.MalformedURLException)2 URL (java.net.URL)2 DependencyCollectionException (org.eclipse.aether.collection.DependencyCollectionException)2 DependencyNode (org.eclipse.aether.graph.DependencyNode)2 RemoteRepository (org.eclipse.aether.repository.RemoteRepository)2 Before (org.junit.Before)2 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableSortedMap (com.google.common.collect.ImmutableSortedMap)1 IOException (java.io.IOException)1