Search in sources :

Example 1 with DependencyResult

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

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

Example 3 with DependencyResult

use of org.eclipse.aether.resolution.DependencyResult in project spring-boot by spring-projects.

the class ModifiedClassPathRunner method resolveCoordinates.

private List<URL> resolveCoordinates(String[] coordinates) throws Exception {
    DefaultServiceLocator serviceLocator = MavenRepositorySystemUtils.newServiceLocator();
    serviceLocator.addService(RepositoryConnectorFactory.class, BasicRepositoryConnectorFactory.class);
    serviceLocator.addService(TransporterFactory.class, HttpTransporterFactory.class);
    RepositorySystem repositorySystem = serviceLocator.getService(RepositorySystem.class);
    DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();
    LocalRepository localRepository = new LocalRepository(System.getProperty("user.home") + "/.m2/repository");
    session.setLocalRepositoryManager(repositorySystem.newLocalRepositoryManager(session, localRepository));
    CollectRequest collectRequest = new CollectRequest(null, Arrays.asList(new RemoteRepository.Builder("central", "default", "http://central.maven.org/maven2").build()));
    collectRequest.setDependencies(createDependencies(coordinates));
    DependencyRequest dependencyRequest = new DependencyRequest(collectRequest, null);
    DependencyResult result = repositorySystem.resolveDependencies(session, dependencyRequest);
    List<URL> resolvedArtifacts = new ArrayList<URL>();
    for (ArtifactResult artifact : result.getArtifactResults()) {
        resolvedArtifacts.add(artifact.getArtifact().getFile().toURI().toURL());
    }
    return resolvedArtifacts;
}
Also used : DependencyResult(org.eclipse.aether.resolution.DependencyResult) LocalRepository(org.eclipse.aether.repository.LocalRepository) ArrayList(java.util.ArrayList) RemoteRepository(org.eclipse.aether.repository.RemoteRepository) DefaultServiceLocator(org.eclipse.aether.impl.DefaultServiceLocator) CollectRequest(org.eclipse.aether.collection.CollectRequest) URL(java.net.URL) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult) RepositorySystem(org.eclipse.aether.RepositorySystem) DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession) DependencyRequest(org.eclipse.aether.resolution.DependencyRequest)

Example 4 with DependencyResult

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

use of org.eclipse.aether.resolution.DependencyResult in project atlasmap by atlasmap.

the class GenerateInspectionsMojo method resolveClasspath.

private List<URL> resolveClasspath(List<String> artifacts) throws MojoFailureException {
    final List<URL> urls = new ArrayList<>();
    try {
        for (String gav : artifacts) {
            Artifact artifact = new DefaultArtifact(gav);
            getLog().debug("Resolving dependencies for artifact: " + artifact);
            CollectRequest collectRequest = new CollectRequest();
            collectRequest.setRoot(new Dependency(artifact, ""));
            collectRequest.setRepositories(remoteRepos);
            DependencyRequest dependencyRequest = new DependencyRequest();
            dependencyRequest.setCollectRequest(collectRequest);
            DependencyResult dependencyResult = system.resolveDependencies(repoSession, dependencyRequest);
            PreorderNodeListGenerator nlg = new PreorderNodeListGenerator();
            dependencyResult.getRoot().accept(nlg);
            Iterator<DependencyNode> it = nlg.getNodes().iterator();
            while (it.hasNext()) {
                DependencyNode node = it.next();
                if (node.getDependency() != null) {
                    Artifact x = node.getDependency().getArtifact();
                    if (x.getFile() != null) {
                        getLog().debug("Found dependency: " + x + " for artifact: " + artifact);
                        urls.add(x.getFile().toURI().toURL());
                    }
                }
            }
        }
    } catch (IllegalArgumentException e) {
        throw new MojoFailureException(e.getMessage(), e);
    } catch (DependencyResolutionException e) {
        throw new MojoFailureException(e.getMessage(), e);
    } catch (MalformedURLException e) {
        throw new MojoFailureException(e.getMessage(), e);
    }
    return urls;
}
Also used : MalformedURLException(java.net.MalformedURLException) DependencyResult(org.eclipse.aether.resolution.DependencyResult) ArrayList(java.util.ArrayList) MojoFailureException(org.apache.maven.plugin.MojoFailureException) Dependency(org.eclipse.aether.graph.Dependency) CollectRequest(org.eclipse.aether.collection.CollectRequest) PreorderNodeListGenerator(org.eclipse.aether.util.graph.visitor.PreorderNodeListGenerator) URL(java.net.URL) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact) DependencyRequest(org.eclipse.aether.resolution.DependencyRequest) DependencyNode(org.eclipse.aether.graph.DependencyNode) DependencyResolutionException(org.eclipse.aether.resolution.DependencyResolutionException) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact)

Aggregations

DependencyResult (org.eclipse.aether.resolution.DependencyResult)15 DependencyRequest (org.eclipse.aether.resolution.DependencyRequest)13 CollectRequest (org.eclipse.aether.collection.CollectRequest)11 Dependency (org.eclipse.aether.graph.Dependency)8 Artifact (org.eclipse.aether.artifact.Artifact)7 DefaultArtifact (org.eclipse.aether.artifact.DefaultArtifact)7 ArtifactResult (org.eclipse.aether.resolution.ArtifactResult)7 ArrayList (java.util.ArrayList)6 File (java.io.File)4 MalformedURLException (java.net.MalformedURLException)4 URL (java.net.URL)4 DependencyFilter (org.eclipse.aether.graph.DependencyFilter)4 DependencyNode (org.eclipse.aether.graph.DependencyNode)4 DependencyResolutionException (org.eclipse.aether.resolution.DependencyResolutionException)4 RepositorySystem (org.eclipse.aether.RepositorySystem)3 RemoteRepository (org.eclipse.aether.repository.RemoteRepository)3 MojoFailureException (org.apache.maven.plugin.MojoFailureException)2 DefaultRepositorySystemSession (org.eclipse.aether.DefaultRepositorySystemSession)2 DefaultServiceLocator (org.eclipse.aether.impl.DefaultServiceLocator)2 LocalRepository (org.eclipse.aether.repository.LocalRepository)2