Search in sources :

Example 1 with DefaultRepositorySystem

use of org.eclipse.aether.internal.impl.DefaultRepositorySystem in project intellij-plugins by JetBrains.

the class GeneratorServer method createPlexusContainer.

private static DefaultPlexusContainer createPlexusContainer() throws PlexusContainerException, ComponentLookupException {
    ContainerConfiguration containerConfiguration = new DefaultContainerConfiguration().setClassPathScanning(PlexusConstants.SCANNING_INDEX).setAutoWiring(true).setClassWorld(new ClassWorld("plexus.core", Thread.currentThread().getContextClassLoader())).setName("maven");
    final DefaultPlexusContainer container = new DefaultPlexusContainer(containerConfiguration);
    final List<LocalRepositoryManagerFactory> factoryList = Collections.singletonList(container.lookup(LocalRepositoryManagerFactory.class, "simple"));
    final String mavenVersion = container.lookup(RuntimeInformation.class).getMavenVersion();
    // tracked impl is not suitable for us (our list of remote repo may be not equals - we don't want think about it)
    if (mavenVersion.length() >= 5 && mavenVersion.charAt(2) == '0' && mavenVersion.charAt(4) < '4') {
        final DefaultRepositorySystem repositorySystem = (DefaultRepositorySystem) container.lookup(RepositorySystem.class);
        try {
            repositorySystem.getClass().getMethod("setLocalRepositoryManagerFactories", List.class).invoke(repositorySystem, factoryList);
        } catch (Exception e) {
            container.getLoggerManager().getLoggerForComponent(null).warn("", e);
        }
    } else {
        ((DefaultLocalRepositoryProvider) container.lookup(LocalRepositoryProvider.class)).setLocalRepositoryManagerFactories(factoryList);
    }
    return container;
}
Also used : DefaultLocalRepositoryProvider(org.eclipse.aether.internal.impl.DefaultLocalRepositoryProvider) DefaultRepositorySystem(org.eclipse.aether.internal.impl.DefaultRepositorySystem) ClassWorld(org.codehaus.plexus.classworlds.ClassWorld) SettingsBuildingException(org.apache.maven.settings.building.SettingsBuildingException) ComponentLookupException(org.codehaus.plexus.component.repository.exception.ComponentLookupException) InvalidRepositoryException(org.apache.maven.artifact.InvalidRepositoryException) IOException(java.io.IOException) DefaultRepositorySystem(org.eclipse.aether.internal.impl.DefaultRepositorySystem) RepositorySystem(org.apache.maven.repository.RepositorySystem) LocalRepositoryManagerFactory(org.eclipse.aether.spi.localrepo.LocalRepositoryManagerFactory) DefaultLocalRepositoryProvider(org.eclipse.aether.internal.impl.DefaultLocalRepositoryProvider) LocalRepositoryProvider(org.eclipse.aether.impl.LocalRepositoryProvider) RuntimeInformation(org.apache.maven.rtinfo.RuntimeInformation)

Example 2 with DefaultRepositorySystem

use of org.eclipse.aether.internal.impl.DefaultRepositorySystem 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 3 with DefaultRepositorySystem

use of org.eclipse.aether.internal.impl.DefaultRepositorySystem 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

DefaultRepositorySystem (org.eclipse.aether.internal.impl.DefaultRepositorySystem)3 InvalidRepositoryException (org.apache.maven.artifact.InvalidRepositoryException)2 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 RemoteRepository (org.eclipse.aether.repository.RemoteRepository)2 ArtifactRequest (org.eclipse.aether.resolution.ArtifactRequest)2 ArtifactResult (org.eclipse.aether.resolution.ArtifactResult)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 DefaultMaven (org.apache.maven.DefaultMaven)1 Maven (org.apache.maven.Maven)1 Artifact (org.apache.maven.artifact.Artifact)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 RepositorySystem (org.apache.maven.repository.RepositorySystem)1