Search in sources :

Example 1 with DependencyRequest

use of org.eclipse.aether.resolution.DependencyRequest 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 DependencyRequest

use of org.eclipse.aether.resolution.DependencyRequest in project druid by druid-io.

the class PullDependenciesTest method setUp.

@Before
public void setUp() throws Exception {
    localRepo = temporaryFolder.newFolder();
    extensionToJars = new HashMap<>();
    extensionToJars.put(extension_A, ImmutableList.of("a.jar", "b.jar", "c.jar"));
    extensionToJars.put(extension_B, ImmutableList.of("d.jar", "e.jar"));
    extensionToJars.put(hadoop_client_2_3_0, ImmutableList.of("f.jar", "g.jar"));
    extensionToJars.put(hadoop_client_2_4_0, ImmutableList.of("h.jar", "i.jar"));
    rootExtensionsDir = new File(temporaryFolder.getRoot(), "extensions");
    rootHadoopDependenciesDir = new File(temporaryFolder.getRoot(), "druid_hadoop_dependencies");
    pullDependencies = new PullDependencies(new DefaultTeslaAether() {

        @Override
        public List<Artifact> resolveArtifacts(DependencyRequest request) throws DependencyResolutionException {
            return getArtifactsForExtension(request.getCollectRequest().getRoot().getArtifact());
        }
    }, new ExtensionsConfig() {

        @Override
        public String getDirectory() {
            return rootExtensionsDir.getAbsolutePath();
        }

        @Override
        public String getHadoopDependenciesDir() {
            return rootHadoopDependenciesDir.getAbsolutePath();
        }
    });
    pullDependencies.coordinates = ImmutableList.of(EXTENSION_A_COORDINATE, EXTENSION_B_COORDINATE);
    pullDependencies.hadoopCoordinates = ImmutableList.of(HADOOP_CLIENT_2_3_0_COORDINATE, HADOOP_CLIENT_2_4_0_COORDINATE);
}
Also used : DependencyRequest(org.eclipse.aether.resolution.DependencyRequest) DefaultTeslaAether(io.tesla.aether.internal.DefaultTeslaAether) ExtensionsConfig(io.druid.guice.ExtensionsConfig) File(java.io.File) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact) Before(org.junit.Before)

Example 3 with DependencyRequest

use of org.eclipse.aether.resolution.DependencyRequest 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 4 with DependencyRequest

use of org.eclipse.aether.resolution.DependencyRequest in project byte-buddy by raphw.

the class ClassLoaderResolverTest method testResolutionFailure.

@Test(expected = MojoExecutionException.class)
public void testResolutionFailure() throws Exception {
    when(repositorySystem.resolveDependencies(eq(repositorySystemSession), any(DependencyRequest.class))).thenThrow(new DependencyResolutionException(new DependencyResult(new DependencyRequest(root, mock(DependencyFilter.class))), new Throwable()));
    classLoaderResolver.resolve(new MavenCoordinate(FOO, BAR, QUX));
}
Also used : DependencyRequest(org.eclipse.aether.resolution.DependencyRequest) DependencyResult(org.eclipse.aether.resolution.DependencyResult) DependencyResolutionException(org.eclipse.aether.resolution.DependencyResolutionException) Test(org.junit.Test)

Example 5 with DependencyRequest

use of org.eclipse.aether.resolution.DependencyRequest 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

DependencyRequest (org.eclipse.aether.resolution.DependencyRequest)9 CollectRequest (org.eclipse.aether.collection.CollectRequest)6 DependencyResult (org.eclipse.aether.resolution.DependencyResult)6 Artifact (org.eclipse.aether.artifact.Artifact)5 ArrayList (java.util.ArrayList)4 DefaultArtifact (org.eclipse.aether.artifact.DefaultArtifact)4 Dependency (org.eclipse.aether.graph.Dependency)4 ArtifactResult (org.eclipse.aether.resolution.ArtifactResult)4 File (java.io.File)3 DependencyFilter (org.eclipse.aether.graph.DependencyFilter)3 MalformedURLException (java.net.MalformedURLException)2 URL (java.net.URL)2 DependencyNode (org.eclipse.aether.graph.DependencyNode)2 DependencyResolutionException (org.eclipse.aether.resolution.DependencyResolutionException)2 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableSortedMap (com.google.common.collect.ImmutableSortedMap)1 ExtensionsConfig (io.druid.guice.ExtensionsConfig)1 DefaultTeslaAether (io.tesla.aether.internal.DefaultTeslaAether)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1