Search in sources :

Example 6 with CollectRequest

use of org.eclipse.aether.collection.CollectRequest 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 7 with CollectRequest

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

the class ClassLoaderResolver method doResolve.

/**
     * Resolves a Maven coordinate to a class loader that can load all of the coordinates classes.
     *
     * @param mavenCoordinate The Maven coordinate to resolve.
     * @return A class loader that references all of the class loader's dependencies and which is a child of this class's class loader.
     * @throws MojoExecutionException If the user configuration results in an error.
     * @throws MojoFailureException   If the plugin application raises an error.
     */
private ClassLoader doResolve(MavenCoordinate mavenCoordinate) throws MojoExecutionException, MojoFailureException {
    List<URL> urls = new ArrayList<URL>();
    log.info("Resolving transformer dependency: " + mavenCoordinate);
    try {
        DependencyNode root = repositorySystem.collectDependencies(repositorySystemSession, new CollectRequest(new Dependency(mavenCoordinate.asArtifact(), "runtime"), remoteRepositories)).getRoot();
        repositorySystem.resolveDependencies(repositorySystemSession, new DependencyRequest().setRoot(root));
        PreorderNodeListGenerator preorderNodeListGenerator = new PreorderNodeListGenerator();
        root.accept(preorderNodeListGenerator);
        for (Artifact artifact : preorderNodeListGenerator.getArtifacts(false)) {
            urls.add(artifact.getFile().toURI().toURL());
        }
    } catch (DependencyCollectionException exception) {
        throw new MojoExecutionException("Could not collect dependencies for " + mavenCoordinate, exception);
    } catch (DependencyResolutionException exception) {
        throw new MojoExecutionException("Could not resolve dependencies for " + mavenCoordinate, exception);
    } catch (MalformedURLException exception) {
        throw new MojoFailureException("Could not resolve file as URL for " + mavenCoordinate, exception);
    }
    return new URLClassLoader(urls.toArray(new URL[urls.size()]), ByteBuddy.class.getClassLoader());
}
Also used : DependencyCollectionException(org.eclipse.aether.collection.DependencyCollectionException) MalformedURLException(java.net.MalformedURLException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArrayList(java.util.ArrayList) MojoFailureException(org.apache.maven.plugin.MojoFailureException) ByteBuddy(net.bytebuddy.ByteBuddy) Dependency(org.eclipse.aether.graph.Dependency) CollectRequest(org.eclipse.aether.collection.CollectRequest) PreorderNodeListGenerator(org.eclipse.aether.util.graph.visitor.PreorderNodeListGenerator) URL(java.net.URL) Artifact(org.eclipse.aether.artifact.Artifact) DependencyRequest(org.eclipse.aether.resolution.DependencyRequest) DependencyNode(org.eclipse.aether.graph.DependencyNode) URLClassLoader(java.net.URLClassLoader) DependencyResolutionException(org.eclipse.aether.resolution.DependencyResolutionException)

Example 8 with CollectRequest

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

the class ByteBuddyMojoTest method setUp.

@Before
public void setUp() throws Exception {
    when(repositorySystem.collectDependencies(any(RepositorySystemSession.class), any(CollectRequest.class))).thenReturn(new CollectResult(new CollectRequest()).setRoot(root));
    project = File.createTempFile(FOO, TEMP);
    assertThat(project.delete(), is(true));
    assertThat(project.mkdir(), is(true));
}
Also used : RepositorySystemSession(org.eclipse.aether.RepositorySystemSession) CollectResult(org.eclipse.aether.collection.CollectResult) CollectRequest(org.eclipse.aether.collection.CollectRequest) Before(org.junit.Before)

Example 9 with CollectRequest

use of org.eclipse.aether.collection.CollectRequest in project pinpoint by naver.

the class DependencyResolver method resolveArtifactsAndDependencies.

public List<File> resolveArtifactsAndDependencies(List<Artifact> artifacts) throws ArtifactResolutionException, DependencyResolutionException {
    List<Dependency> dependencies = new ArrayList<Dependency>();
    for (Artifact artifact : artifacts) {
        dependencies.add(new Dependency(artifact, JavaScopes.RUNTIME));
    }
    CollectRequest collectRequest = new CollectRequest((Dependency) null, dependencies, repositories);
    DependencyFilter classpathFilter = DependencyFilterUtils.classpathFilter(JavaScopes.RUNTIME);
    DependencyRequest dependencyRequest = new DependencyRequest(collectRequest, classpathFilter);
    DependencyResult result = system.resolveDependencies(session, dependencyRequest);
    List<File> files = new ArrayList<File>();
    for (ArtifactResult artifactResult : result.getArtifactResults()) {
        files.add(artifactResult.getArtifact().getFile());
    }
    return files;
}
Also used : DependencyRequest(org.eclipse.aether.resolution.DependencyRequest) DependencyResult(org.eclipse.aether.resolution.DependencyResult) ArrayList(java.util.ArrayList) DependencyFilter(org.eclipse.aether.graph.DependencyFilter) Dependency(org.eclipse.aether.graph.Dependency) CollectRequest(org.eclipse.aether.collection.CollectRequest) File(java.io.File) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult)

Example 10 with CollectRequest

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

the class AetherGrapeEngine method getCollectRequest.

private CollectRequest getCollectRequest(List<Dependency> dependencies) {
    CollectRequest collectRequest = new CollectRequest((Dependency) null, dependencies, new ArrayList<>(this.repositories));
    collectRequest.setManagedDependencies(this.resolutionContext.getManagedDependencies());
    return collectRequest;
}
Also used : CollectRequest(org.eclipse.aether.collection.CollectRequest)

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