Search in sources :

Example 11 with RepositorySystem

use of org.eclipse.aether.RepositorySystem in project revapi by revapi.

the class Main method convertGavs.

private static ArchivesAndSupplementaryArchives convertGavs(String[] gavs, String errorMessagePrefix, File localRepo) {
    RepositorySystem repositorySystem = MavenBootstrap.newRepositorySystem();
    DefaultRepositorySystemSession session = MavenBootstrap.newRepositorySystemSession(repositorySystem, localRepo);
    session.setDependencySelector(new ScopeDependencySelector("compile", "provided"));
    session.setDependencyTraverser(new ScopeDependencyTraverser("compile", "provided"));
    RemoteRepository mavenCentral = new RemoteRepository.Builder("@@forced-maven-central@@", "default", "http://repo.maven.apache.org/maven2/").build();
    List<RemoteRepository> remoteRepositories = singletonList(mavenCentral);
    ArtifactResolver resolver = new ArtifactResolver(repositorySystem, session, remoteRepositories);
    List<FileArchive> archives = new ArrayList<>();
    List<FileArchive> supplementaryArchives = new ArrayList<>();
    for (String gav : gavs) {
        try {
            archives.add(new FileArchive(resolver.resolveArtifact(gav).getFile()));
            ArtifactResolver.CollectionResult res = resolver.collectTransitiveDeps(gav);
            res.getResolvedArtifacts().forEach(a -> supplementaryArchives.add(new FileArchive(a.getFile())));
            if (!res.getFailures().isEmpty()) {
                LOG.warn("Failed to resolve some transitive dependencies: " + res.getFailures().toString());
            }
        } catch (RepositoryException e) {
            throw new IllegalArgumentException(errorMessagePrefix + " " + e.getMessage());
        }
    }
    return new ArchivesAndSupplementaryArchives(archives, supplementaryArchives);
}
Also used : ArrayList(java.util.ArrayList) RemoteRepository(org.eclipse.aether.repository.RemoteRepository) RepositoryException(org.eclipse.aether.RepositoryException) ArtifactResolver(org.revapi.maven.utils.ArtifactResolver) ScopeDependencyTraverser(org.revapi.maven.utils.ScopeDependencyTraverser) RepositorySystem(org.eclipse.aether.RepositorySystem) DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession) FileArchive(org.revapi.simple.FileArchive) ScopeDependencySelector(org.revapi.maven.utils.ScopeDependencySelector)

Example 12 with RepositorySystem

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

the class MavenResolverGrapeEngineFactory method create.

public static MavenResolverGrapeEngine create(GroovyClassLoader classLoader, List<RepositoryConfiguration> repositoryConfigurations, DependencyResolutionContext dependencyResolutionContext, boolean quiet) {
    RepositorySystem repositorySystem = createServiceLocator().getService(RepositorySystem.class);
    DefaultRepositorySystemSession repositorySystemSession = MavenRepositorySystemUtils.newSession();
    ServiceLoader<RepositorySystemSessionAutoConfiguration> autoConfigurations = ServiceLoader.load(RepositorySystemSessionAutoConfiguration.class);
    for (RepositorySystemSessionAutoConfiguration autoConfiguration : autoConfigurations) {
        autoConfiguration.apply(repositorySystemSession, repositorySystem);
    }
    new DefaultRepositorySystemSessionAutoConfiguration().apply(repositorySystemSession, repositorySystem);
    return new MavenResolverGrapeEngine(classLoader, repositorySystem, repositorySystemSession, createRepositories(repositoryConfigurations), dependencyResolutionContext, quiet);
}
Also used : DefaultRepositorySystem(org.eclipse.aether.internal.impl.DefaultRepositorySystem) RepositorySystem(org.eclipse.aether.RepositorySystem) DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession)

Example 13 with RepositorySystem

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

the class ModifiedClassPathClassLoader method resolveCoordinates.

private static List<URL> resolveCoordinates(String[] coordinates) {
    Exception latestFailure = null;
    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");
    RemoteRepository remoteRepository = new RemoteRepository.Builder("central", "default", "https://repo.maven.apache.org/maven2").build();
    session.setLocalRepositoryManager(repositorySystem.newLocalRepositoryManager(session, localRepository));
    for (int i = 0; i < MAX_RESOLUTION_ATTEMPTS; i++) {
        CollectRequest collectRequest = new CollectRequest(null, Arrays.asList(remoteRepository));
        collectRequest.setDependencies(createDependencies(coordinates));
        DependencyRequest dependencyRequest = new DependencyRequest(collectRequest, null);
        try {
            DependencyResult result = repositorySystem.resolveDependencies(session, dependencyRequest);
            List<URL> resolvedArtifacts = new ArrayList<>();
            for (ArtifactResult artifact : result.getArtifactResults()) {
                resolvedArtifacts.add(artifact.getArtifact().getFile().toURI().toURL());
            }
            return resolvedArtifacts;
        } catch (Exception ex) {
            latestFailure = ex;
        }
    }
    throw new IllegalStateException("Resolution failed after " + MAX_RESOLUTION_ATTEMPTS + " attempts", latestFailure);
}
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) URISyntaxException(java.net.URISyntaxException) 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 14 with RepositorySystem

use of org.eclipse.aether.RepositorySystem in project buck by facebook.

the class Publisher method publish.

/**
   * @param toPublish each {@link Artifact} must contain a file, that will be published under maven
   *                  coordinates in the corresponding {@link Artifact}.
   * @see Artifact#setFile
   */
public DeployResult publish(List<Artifact> toPublish) throws DeploymentException {
    RepositorySystem repoSys = Preconditions.checkNotNull(locator.getService(RepositorySystem.class));
    DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();
    session.setLocalRepositoryManager(repoSys.newLocalRepositoryManager(session, localRepo));
    session.setReadOnly();
    DeployRequest deployRequest = createDeployRequest(toPublish);
    if (dryRun) {
        return new DeployResult(deployRequest).setArtifacts(toPublish).setMetadata(deployRequest.getMetadata());
    } else {
        return repoSys.deploy(session, deployRequest);
    }
}
Also used : RepositorySystem(org.eclipse.aether.RepositorySystem) DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession) DeployResult(org.eclipse.aether.deployment.DeployResult) DeployRequest(org.eclipse.aether.deployment.DeployRequest)

Example 15 with RepositorySystem

use of org.eclipse.aether.RepositorySystem in project camel by apache.

the class BOMResolver method newRepositorySystem.

private RepositorySystem newRepositorySystem() {
    DefaultServiceLocator locator = MavenRepositorySystemUtils.newServiceLocator();
    locator.addService(RepositoryConnectorFactory.class, BasicRepositoryConnectorFactory.class);
    locator.addService(TransporterFactory.class, FileTransporterFactory.class);
    locator.addService(TransporterFactory.class, HttpTransporterFactory.class);
    RepositorySystem system = locator.getService(RepositorySystem.class);
    return system;
}
Also used : RepositorySystem(org.eclipse.aether.RepositorySystem) DefaultServiceLocator(org.eclipse.aether.impl.DefaultServiceLocator)

Aggregations

RepositorySystem (org.eclipse.aether.RepositorySystem)27 DefaultRepositorySystemSession (org.eclipse.aether.DefaultRepositorySystemSession)18 RepositorySystemSession (org.eclipse.aether.RepositorySystemSession)12 RemoteRepository (org.eclipse.aether.repository.RemoteRepository)9 Artifact (org.eclipse.aether.artifact.Artifact)8 DefaultArtifact (org.eclipse.aether.artifact.DefaultArtifact)8 ArtifactResult (org.eclipse.aether.resolution.ArtifactResult)7 DefaultServiceLocator (org.eclipse.aether.impl.DefaultServiceLocator)6 File (java.io.File)5 ArrayList (java.util.ArrayList)5 LocalRepository (org.eclipse.aether.repository.LocalRepository)5 ArtifactRequest (org.eclipse.aether.resolution.ArtifactRequest)4 IOException (java.io.IOException)3 CollectRequest (org.eclipse.aether.collection.CollectRequest)3 Dependency (org.eclipse.aether.graph.Dependency)3 ArtifactResolutionException (org.eclipse.aether.resolution.ArtifactResolutionException)3 DependencyRequest (org.eclipse.aether.resolution.DependencyRequest)3 URL (java.net.URL)2 Path (java.nio.file.Path)2 List (java.util.List)2