Search in sources :

Example 1 with DefaultArtifactResolver

use of org.eclipse.aether.internal.impl.DefaultArtifactResolver in project che by eclipse.

the class MavenServerImpl method resolveArtifact.

@Override
public MavenArtifact resolveArtifact(MavenArtifactKey artifactKey, List<MavenRemoteRepository> repositories) throws RemoteException {
    Artifact artifact = getMavenComponent(ArtifactFactory.class).createArtifactWithClassifier(artifactKey.getGroupId(), artifactKey.getArtifactId(), artifactKey.getVersion(), artifactKey.getPackaging(), artifactKey.getClassifier());
    List<ArtifactRepository> repos = new ArrayList<>();
    ArtifactRepositoryFactory factory = getMavenComponent(ArtifactRepositoryFactory.class);
    for (MavenRemoteRepository repository : repositories) {
        try {
            ArtifactRepository artifactRepository = ProjectUtils.buildArtifactRepository(MavenModelUtil.convertToMavenRepository(repository), factory, container);
            repos.add(artifactRepository);
        } catch (InvalidRepositoryException e) {
            MavenServerContext.getLogger().error(e);
        }
    }
    MavenExecutionRequest request = newMavenRequest(null, Collections.emptyList(), Collections.emptyList(), Collections.emptyList());
    repos.forEach(request::addRemoteRepository);
    DefaultMaven maven = (DefaultMaven) getMavenComponent(Maven.class);
    RepositorySystemSession repositorySystemSession = maven.newRepositorySession(request);
    org.eclipse.aether.impl.ArtifactResolver artifactResolver = getMavenComponent(org.eclipse.aether.impl.ArtifactResolver.class);
    InternalLoggerFactory loggerFactory = new InternalLoggerFactory();
    if (artifactResolver instanceof DefaultArtifactResolver) {
        ((DefaultArtifactResolver) artifactResolver).setLoggerFactory(loggerFactory);
    }
    org.eclipse.aether.RepositorySystem repositorySystem = getMavenComponent(org.eclipse.aether.RepositorySystem.class);
    if (repositorySystem instanceof DefaultRepositorySystem) {
        ((DefaultRepositorySystem) repositorySystem).setLoggerFactory(loggerFactory);
    }
    List<RemoteRepository> remoteRepositories = RepositoryUtils.toRepos(request.getRemoteRepositories());
    remoteRepositories = repositorySystem.newResolutionRepositories(repositorySystemSession, remoteRepositories);
    try {
        ArtifactResult artifactResult = repositorySystem.resolveArtifact(repositorySystemSession, new ArtifactRequest(RepositoryUtils.toArtifact(artifact), remoteRepositories, null));
        return MavenModelUtil.convertArtifact(RepositoryUtils.toArtifact(artifactResult.getArtifact()), localRepository);
    } catch (ArtifactResolutionException e) {
        MavenServerContext.getLogger().info(e);
    }
    return MavenModelUtil.convertArtifact(artifact, localRepository);
}
Also used : DefaultMaven(org.apache.maven.DefaultMaven) Maven(org.apache.maven.Maven) InvalidRepositoryException(org.apache.maven.artifact.InvalidRepositoryException) DefaultRepositorySystem(org.eclipse.aether.internal.impl.DefaultRepositorySystem) MavenExecutionRequest(org.apache.maven.execution.MavenExecutionRequest) DefaultMavenExecutionRequest(org.apache.maven.execution.DefaultMavenExecutionRequest) ArrayList(java.util.ArrayList) MavenRemoteRepository(org.eclipse.che.maven.data.MavenRemoteRepository) RemoteRepository(org.eclipse.aether.repository.RemoteRepository) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) ArtifactRequest(org.eclipse.aether.resolution.ArtifactRequest) DefaultArtifactResolver(org.eclipse.aether.internal.impl.DefaultArtifactResolver) RepositorySystemSession(org.eclipse.aether.RepositorySystemSession) DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession) ArtifactRepositoryFactory(org.apache.maven.artifact.repository.ArtifactRepositoryFactory) DefaultMaven(org.apache.maven.DefaultMaven) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) MavenArtifact(org.eclipse.che.maven.data.MavenArtifact) Artifact(org.apache.maven.artifact.Artifact) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult) ArtifactFactory(org.apache.maven.artifact.factory.ArtifactFactory) MavenRemoteRepository(org.eclipse.che.maven.data.MavenRemoteRepository)

Example 2 with DefaultArtifactResolver

use of org.eclipse.aether.internal.impl.DefaultArtifactResolver in project intellij-community by JetBrains.

the class Maven3ServerEmbedderImpl method resolve.

private Artifact resolve(@NotNull final Artifact artifact, @NotNull final List<ArtifactRepository> repos) throws ArtifactResolutionException, ArtifactNotFoundException, RemoteException, org.eclipse.aether.resolution.ArtifactResolutionException {
    final String mavenVersion = getMavenVersion();
    // see https://youtrack.jetbrains.com/issue/IDEA-140208 for details
    if (USE_MVN2_COMPATIBLE_DEPENDENCY_RESOLVING || StringUtil.compareVersionNumbers(mavenVersion, "3.2.5") < 0) {
        MavenExecutionRequest request = new DefaultMavenExecutionRequest();
        request.setRemoteRepositories(repos);
        try {
            getComponent(MavenExecutionRequestPopulator.class).populateFromSettings(request, myMavenSettings);
            getComponent(MavenExecutionRequestPopulator.class).populateDefaults(request);
        } catch (MavenExecutionRequestPopulationException e) {
            throw new RuntimeException(e);
        }
        getComponent(ArtifactResolver.class).resolve(artifact, request.getRemoteRepositories(), myLocalRepository);
        return artifact;
    } else {
        final MavenExecutionRequest request = createRequest(null, Collections.<String>emptyList(), Collections.<String>emptyList(), Collections.<String>emptyList());
        for (ArtifactRepository artifactRepository : repos) {
            request.addRemoteRepository(artifactRepository);
        }
        DefaultMaven maven = (DefaultMaven) getComponent(Maven.class);
        RepositorySystemSession repositorySystemSession = maven.newRepositorySession(request);
        final org.eclipse.aether.impl.ArtifactResolver artifactResolver = getComponent(org.eclipse.aether.impl.ArtifactResolver.class);
        final MyLoggerFactory loggerFactory = new MyLoggerFactory();
        if (artifactResolver instanceof DefaultArtifactResolver) {
            ((DefaultArtifactResolver) artifactResolver).setLoggerFactory(loggerFactory);
        }
        final org.eclipse.aether.RepositorySystem repositorySystem = getComponent(org.eclipse.aether.RepositorySystem.class);
        if (repositorySystem instanceof DefaultRepositorySystem) {
            ((DefaultRepositorySystem) repositorySystem).setLoggerFactory(loggerFactory);
        }
        List<RemoteRepository> repositories = RepositoryUtils.toRepos(request.getRemoteRepositories());
        repositories = repositorySystem.newResolutionRepositories(repositorySystemSession, repositories);
        final ArtifactResult artifactResult = repositorySystem.resolveArtifact(repositorySystemSession, new ArtifactRequest(RepositoryUtils.toArtifact(artifact), repositories, null));
        return RepositoryUtils.toArtifact(artifactResult.getArtifact());
    }
}
Also used : RepositorySystemSession(org.eclipse.aether.RepositorySystemSession) DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession) DefaultRepositorySystem(org.eclipse.aether.internal.impl.DefaultRepositorySystem) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) RemoteRepository(org.eclipse.aether.repository.RemoteRepository) ArtifactResolver(org.apache.maven.artifact.resolver.ArtifactResolver) DefaultArtifactResolver(org.eclipse.aether.internal.impl.DefaultArtifactResolver) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult) ArtifactRequest(org.eclipse.aether.resolution.ArtifactRequest) DefaultArtifactResolver(org.eclipse.aether.internal.impl.DefaultArtifactResolver)

Aggregations

ArtifactRepository (org.apache.maven.artifact.repository.ArtifactRepository)2 DefaultRepositorySystemSession (org.eclipse.aether.DefaultRepositorySystemSession)2 RepositorySystemSession (org.eclipse.aether.RepositorySystemSession)2 DefaultArtifactResolver (org.eclipse.aether.internal.impl.DefaultArtifactResolver)2 DefaultRepositorySystem (org.eclipse.aether.internal.impl.DefaultRepositorySystem)2 RemoteRepository (org.eclipse.aether.repository.RemoteRepository)2 ArtifactRequest (org.eclipse.aether.resolution.ArtifactRequest)2 ArtifactResult (org.eclipse.aether.resolution.ArtifactResult)2 ArrayList (java.util.ArrayList)1 DefaultMaven (org.apache.maven.DefaultMaven)1 Maven (org.apache.maven.Maven)1 Artifact (org.apache.maven.artifact.Artifact)1 InvalidRepositoryException (org.apache.maven.artifact.InvalidRepositoryException)1 ArtifactFactory (org.apache.maven.artifact.factory.ArtifactFactory)1 ArtifactRepositoryFactory (org.apache.maven.artifact.repository.ArtifactRepositoryFactory)1 ArtifactResolver (org.apache.maven.artifact.resolver.ArtifactResolver)1 DefaultMavenExecutionRequest (org.apache.maven.execution.DefaultMavenExecutionRequest)1 MavenExecutionRequest (org.apache.maven.execution.MavenExecutionRequest)1 ArtifactResolutionException (org.eclipse.aether.resolution.ArtifactResolutionException)1 MavenArtifact (org.eclipse.che.maven.data.MavenArtifact)1