Search in sources :

Example 6 with ArtifactResolver

use of org.apache.maven.artifact.resolver.ArtifactResolver 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)

Example 7 with ArtifactResolver

use of org.apache.maven.artifact.resolver.ArtifactResolver in project intellij-community by JetBrains.

the class Maven3ServerEmbedderImpl method reset.

@Override
public void reset() throws RemoteException {
    try {
        setConsoleAndIndicator(null, null);
        final ArtifactFactory artifactFactory = getComponent(ArtifactFactory.class);
        if (artifactFactory instanceof CustomMaven3ArtifactFactory) {
            ((CustomMaven3ArtifactFactory) artifactFactory).reset();
        }
        final ArtifactResolver artifactResolver = getComponent(ArtifactResolver.class);
        if (artifactResolver instanceof CustomMaven3ArtifactResolver) {
            ((CustomMaven3ArtifactResolver) artifactResolver).reset();
        }
        final RepositoryMetadataManager repositoryMetadataManager = getComponent(RepositoryMetadataManager.class);
        if (repositoryMetadataManager instanceof CustomMaven3RepositoryMetadataManager) {
            ((CustomMaven3RepositoryMetadataManager) repositoryMetadataManager).reset();
        }
    //((CustomWagonManager)getComponent(WagonManager.class)).reset();
    } catch (Exception e) {
        throw rethrowException(e);
    }
}
Also used : RepositoryMetadataManager(org.apache.maven.artifact.repository.metadata.RepositoryMetadataManager) ArtifactFactory(org.apache.maven.artifact.factory.ArtifactFactory) ArtifactResolver(org.apache.maven.artifact.resolver.ArtifactResolver) DefaultArtifactResolver(org.eclipse.aether.internal.impl.DefaultArtifactResolver) ArtifactNotFoundException(org.apache.maven.artifact.resolver.ArtifactNotFoundException) InitializationException(org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException) ModelInterpolationException(org.apache.maven.project.interpolation.ModelInterpolationException) RemoteException(java.rmi.RemoteException) ComponentLookupException(org.codehaus.plexus.component.repository.exception.ComponentLookupException) ContextException(org.codehaus.plexus.context.ContextException) ArtifactResolutionException(org.apache.maven.artifact.resolver.ArtifactResolutionException) InvalidRepositoryException(org.apache.maven.artifact.InvalidRepositoryException)

Example 8 with ArtifactResolver

use of org.apache.maven.artifact.resolver.ArtifactResolver in project maven-archetype by apache.

the class ArchetypeTest method getContextClassloader.

// Gets the classloader for this artifact's file.
private ClassLoader getContextClassloader(Artifact archetypeArtifact, ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories) throws Exception {
    ArtifactResolver artifactResolver = (ArtifactResolver) lookup(ArtifactResolver.class.getName());
    try {
        artifactResolver.resolve(archetypeArtifact, remoteRepositories, localRepository);
    } catch (ArtifactResolutionException e) {
        throw new ArchetypeDescriptorException("Error attempting to download archetype: " + e.getMessage(), e);
    } catch (ArtifactNotFoundException e) {
        throw new ArchetypeNotFoundException("OldArchetype does not exist: " + e.getMessage(), e);
    }
    URLClassLoader archetypeJarLoader;
    try {
        URL[] urls = new URL[1];
        urls[0] = archetypeArtifact.getFile().toURI().toURL();
        archetypeJarLoader = new URLClassLoader(urls);
    } catch (IOException e) {
        throw new ArchetypeDescriptorException("Error reading the " + OldArchetype.ARCHETYPE_DESCRIPTOR + " descriptor.", e);
    }
    return archetypeJarLoader;
}
Also used : ArtifactResolutionException(org.apache.maven.artifact.resolver.ArtifactResolutionException) URLClassLoader(java.net.URLClassLoader) IOException(java.io.IOException) ArtifactNotFoundException(org.apache.maven.artifact.resolver.ArtifactNotFoundException) ArtifactResolver(org.apache.maven.artifact.resolver.ArtifactResolver) URL(java.net.URL)

Aggregations

ArtifactResolver (org.apache.maven.artifact.resolver.ArtifactResolver)8 DefaultArtifactResolver (org.eclipse.aether.internal.impl.DefaultArtifactResolver)5 CheArtifactResolver (org.eclipse.che.maven.CheArtifactResolver)3 IOException (java.io.IOException)2 RemoteException (java.rmi.RemoteException)2 InvalidRepositoryException (org.apache.maven.artifact.InvalidRepositoryException)2 ArtifactFactory (org.apache.maven.artifact.factory.ArtifactFactory)2 ArtifactRepository (org.apache.maven.artifact.repository.ArtifactRepository)2 ArtifactNotFoundException (org.apache.maven.artifact.resolver.ArtifactNotFoundException)2 ArtifactResolutionException (org.apache.maven.artifact.resolver.ArtifactResolutionException)2 ArtifactResolutionRequest (org.apache.maven.artifact.resolver.ArtifactResolutionRequest)2 ArtifactResolutionResult (org.apache.maven.artifact.resolver.ArtifactResolutionResult)2 MavenProject (org.apache.maven.project.MavenProject)2 ModelInterpolationException (org.apache.maven.project.interpolation.ModelInterpolationException)2 ComponentLookupException (org.codehaus.plexus.component.repository.exception.ComponentLookupException)2 InitializationException (org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException)2 DefaultRepositorySystemSession (org.eclipse.aether.DefaultRepositorySystemSession)2 RepositorySystemSession (org.eclipse.aether.RepositorySystemSession)2 File (java.io.File)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1