Search in sources :

Example 1 with ArtifactResolutionRequest

use of org.apache.maven.artifact.resolver.ArtifactResolutionRequest in project che by eclipse.

the class CheArtifactResolver method resolve.

// ------------------------------------------------------------------------
//
// ------------------------------------------------------------------------
public ArtifactResolutionResult resolve(ArtifactResolutionRequest request) {
    Artifact rootArtifact = request.getArtifact();
    Set<Artifact> artifacts = request.getArtifactDependencies();
    Map<String, Artifact> managedVersions = request.getManagedVersionMap();
    List<ResolutionListener> listeners = request.getListeners();
    ArtifactFilter collectionFilter = request.getCollectionFilter();
    ArtifactFilter resolutionFilter = request.getResolutionFilter();
    RepositorySystemSession session = getSession(request.getLocalRepository());
    //TODO: hack because metadata isn't generated in m2e correctly and i want to run the maven i have in the workspace
    if (source == null) {
        try {
            source = container.lookup(ArtifactMetadataSource.class);
        } catch (ComponentLookupException e) {
        // won't happen
        }
    }
    if (listeners == null) {
        listeners = new ArrayList<ResolutionListener>();
        if (logger.isDebugEnabled()) {
            listeners.add(new DebugResolutionListener(logger));
        }
        listeners.add(new WarningResolutionListener(logger));
    }
    ArtifactResolutionResult result = new ArtifactResolutionResult();
    if (request.isResolveRoot()) /* && rootArtifact.getFile() == null */
    {
        try {
            resolve(rootArtifact, request.getRemoteRepositories(), session);
        } catch (ArtifactResolutionException e) {
            result.addErrorArtifactException(e);
            return result;
        } catch (ArtifactNotFoundException e) {
            result.addMissingArtifact(request.getArtifact());
            return result;
        }
    }
    ArtifactResolutionRequest collectionRequest = request;
    if (request.isResolveTransitively()) {
        MetadataResolutionRequest metadataRequest = new DefaultMetadataResolutionRequest(request);
        metadataRequest.setArtifact(rootArtifact);
        metadataRequest.setResolveManagedVersions(managedVersions == null);
        try {
            ResolutionGroup resolutionGroup = source.retrieve(metadataRequest);
            if (managedVersions == null) {
                managedVersions = resolutionGroup.getManagedVersions();
            }
            Set<Artifact> directArtifacts = resolutionGroup.getArtifacts();
            if (artifacts == null || artifacts.isEmpty()) {
                artifacts = directArtifacts;
            } else {
                List<Artifact> allArtifacts = new ArrayList<Artifact>();
                allArtifacts.addAll(artifacts);
                allArtifacts.addAll(directArtifacts);
                Map<String, Artifact> mergedArtifacts = new LinkedHashMap<String, Artifact>();
                for (Artifact artifact : allArtifacts) {
                    String conflictId = artifact.getDependencyConflictId();
                    if (!mergedArtifacts.containsKey(conflictId)) {
                        mergedArtifacts.put(conflictId, artifact);
                    }
                }
                artifacts = new LinkedHashSet<Artifact>(mergedArtifacts.values());
            }
            collectionRequest = new ArtifactResolutionRequest(request);
            collectionRequest.setServers(request.getServers());
            collectionRequest.setMirrors(request.getMirrors());
            collectionRequest.setProxies(request.getProxies());
            collectionRequest.setRemoteRepositories(resolutionGroup.getResolutionRepositories());
        } catch (ArtifactMetadataRetrievalException e) {
            ArtifactResolutionException are = new ArtifactResolutionException("Unable to get dependency information for " + rootArtifact.getId() + ": " + e.getMessage(), rootArtifact, metadataRequest.getRemoteRepositories(), e);
            result.addMetadataResolutionException(are);
            return result;
        }
    }
    if (artifacts == null || artifacts.isEmpty()) {
        if (request.isResolveRoot()) {
            result.addArtifact(rootArtifact);
        }
        return result;
    }
    // After the collection we will have the artifact object in the result but they will not be resolved yet.
    result = artifactCollector.collect(artifacts, rootArtifact, managedVersions, collectionRequest, source, collectionFilter, listeners, null);
    if (result.hasMetadataResolutionExceptions() || result.hasVersionRangeViolations() || result.hasCircularDependencyExceptions()) {
        return result;
    }
    if (result.getArtifactResolutionNodes() != null) {
        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
        CountDownLatch latch = new CountDownLatch(result.getArtifactResolutionNodes().size());
        for (ResolutionNode node : result.getArtifactResolutionNodes()) {
            Artifact artifact = node.getArtifact();
            if (resolutionFilter == null || resolutionFilter.include(artifact)) {
                executor.execute(new ResolveTask(classLoader, latch, artifact, session, node.getRemoteRepositories(), result));
            } else {
                latch.countDown();
            }
        }
        try {
            latch.await();
        } catch (InterruptedException e) {
            result.addErrorArtifactException(new ArtifactResolutionException("Resolution interrupted", rootArtifact, e));
        }
    }
    // have been resolved.
    if (request.isResolveRoot()) {
        // Add the root artifact (as the first artifact to retain logical order of class path!)
        Set<Artifact> allArtifacts = new LinkedHashSet<Artifact>();
        allArtifacts.add(rootArtifact);
        allArtifacts.addAll(result.getArtifacts());
        result.setArtifacts(allArtifacts);
    }
    return result;
}
Also used : DefaultMetadataResolutionRequest(org.apache.maven.repository.legacy.metadata.DefaultMetadataResolutionRequest) MetadataResolutionRequest(org.apache.maven.repository.legacy.metadata.MetadataResolutionRequest) LinkedHashSet(java.util.LinkedHashSet) ArtifactMetadataRetrievalException(org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException) ArrayList(java.util.ArrayList) ComponentLookupException(org.codehaus.plexus.component.repository.exception.ComponentLookupException) LinkedHashMap(java.util.LinkedHashMap) DefaultMetadataResolutionRequest(org.apache.maven.repository.legacy.metadata.DefaultMetadataResolutionRequest) AbstractArtifactResolutionException(org.apache.maven.artifact.resolver.AbstractArtifactResolutionException) ArtifactResolutionException(org.apache.maven.artifact.resolver.ArtifactResolutionException) DebugResolutionListener(org.apache.maven.artifact.resolver.DebugResolutionListener) ArtifactResolutionRequest(org.apache.maven.artifact.resolver.ArtifactResolutionRequest) ArtifactNotFoundException(org.apache.maven.artifact.resolver.ArtifactNotFoundException) ResolutionListener(org.apache.maven.artifact.resolver.ResolutionListener) DebugResolutionListener(org.apache.maven.artifact.resolver.DebugResolutionListener) WarningResolutionListener(org.apache.maven.artifact.resolver.WarningResolutionListener) RepositorySystemSession(org.eclipse.aether.RepositorySystemSession) ResolutionNode(org.apache.maven.artifact.resolver.ResolutionNode) ResolutionGroup(org.apache.maven.artifact.metadata.ResolutionGroup) CountDownLatch(java.util.concurrent.CountDownLatch) Artifact(org.apache.maven.artifact.Artifact) ArtifactFilter(org.apache.maven.artifact.resolver.filter.ArtifactFilter) ArtifactResolutionResult(org.apache.maven.artifact.resolver.ArtifactResolutionResult) WarningResolutionListener(org.apache.maven.artifact.resolver.WarningResolutionListener) ArtifactMetadataSource(org.apache.maven.artifact.metadata.ArtifactMetadataSource)

Example 2 with ArtifactResolutionRequest

use of org.apache.maven.artifact.resolver.ArtifactResolutionRequest in project che by eclipse.

the class CheArtifactResolver method resolveTransitively.

public ArtifactResolutionResult resolveTransitively(Set<Artifact> artifacts, Artifact originatingArtifact, Map managedVersions, ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories, ArtifactMetadataSource source, ArtifactFilter filter, List<ResolutionListener> listeners, List<ConflictResolver> conflictResolvers) throws ArtifactResolutionException, ArtifactNotFoundException {
    ArtifactResolutionRequest request = new ArtifactResolutionRequest().setArtifact(originatingArtifact).setResolveRoot(false).setArtifactDependencies(artifacts).setManagedVersionMap(managedVersions).setLocalRepository(localRepository).setRemoteRepositories(remoteRepositories).setCollectionFilter(filter).setListeners(listeners);
    injectSession2(request, legacySupport.getSession());
    return resolveWithExceptions(request);
}
Also used : ArtifactResolutionRequest(org.apache.maven.artifact.resolver.ArtifactResolutionRequest)

Example 3 with ArtifactResolutionRequest

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

the class Maven3ServerEmbedder method addMvn2CompatResults.

protected void addMvn2CompatResults(MavenProject project, List<Exception> exceptions, List<ResolutionListener> listeners, ArtifactRepository localRepository, Collection<MavenExecutionResult> executionResults) {
    ArtifactResolutionRequest resolutionRequest = new ArtifactResolutionRequest();
    resolutionRequest.setArtifactDependencies(project.getDependencyArtifacts());
    resolutionRequest.setArtifact(project.getArtifact());
    resolutionRequest.setManagedVersionMap(project.getManagedVersionMap());
    resolutionRequest.setLocalRepository(localRepository);
    resolutionRequest.setRemoteRepositories(project.getRemoteArtifactRepositories());
    resolutionRequest.setListeners(listeners);
    resolutionRequest.setResolveRoot(false);
    resolutionRequest.setResolveTransitively(true);
    ArtifactResolver resolver = getComponent(ArtifactResolver.class);
    ArtifactResolutionResult result = resolver.resolve(resolutionRequest);
    project.setArtifacts(result.getArtifacts());
    executionResults.add(new MavenExecutionResult(project, exceptions));
}
Also used : ArtifactResolutionRequest(org.apache.maven.artifact.resolver.ArtifactResolutionRequest) MavenExecutionResult(org.jetbrains.idea.maven.server.embedder.MavenExecutionResult) ArtifactResolutionResult(org.apache.maven.artifact.resolver.ArtifactResolutionResult) ArtifactResolver(org.apache.maven.artifact.resolver.ArtifactResolver)

Example 4 with ArtifactResolutionRequest

use of org.apache.maven.artifact.resolver.ArtifactResolutionRequest in project kotlin by JetBrains.

the class KotlinCompileMojoBase method getCompilerPluginClassPaths.

private List<String> getCompilerPluginClassPaths() {
    ArrayList<String> result = new ArrayList<String>();
    List<File> files = new ArrayList<File>();
    for (Dependency dependency : mojoExecution.getPlugin().getDependencies()) {
        Artifact artifact = system.createDependencyArtifact(dependency);
        ArtifactResolutionResult resolved = system.resolve(new ArtifactResolutionRequest().setArtifact(artifact));
        for (Artifact resolvedArtifact : resolved.getArtifacts()) {
            File file = resolvedArtifact.getFile();
            if (file != null && file.exists()) {
                files.add(file);
            }
        }
    }
    for (File file : files) {
        result.add(file.getAbsolutePath());
    }
    return result;
}
Also used : ArtifactResolutionRequest(org.apache.maven.artifact.resolver.ArtifactResolutionRequest) ArtifactResolutionResult(org.apache.maven.artifact.resolver.ArtifactResolutionResult) Dependency(org.apache.maven.model.Dependency) File(java.io.File) Artifact(org.apache.maven.artifact.Artifact)

Example 5 with ArtifactResolutionRequest

use of org.apache.maven.artifact.resolver.ArtifactResolutionRequest in project maven-plugins by apache.

the class DefaultDependencyResolver method resolveTransitively.

private Set<Artifact> resolveTransitively(final Set<Artifact> dependencyArtifacts, final List<ArtifactRepository> repos, final ArtifactFilter filter, final AssemblerConfigurationSource configSource) throws DependencyResolutionException {
    final MavenProject project = configSource.getProject();
    ArtifactResolutionRequest req = new ArtifactResolutionRequest();
    req.setLocalRepository(configSource.getLocalRepository());
    req.setResolveRoot(false);
    req.setRemoteRepositories(repos);
    req.setResolveTransitively(true);
    req.setArtifact(project.getArtifact());
    req.setArtifactDependencies(dependencyArtifacts);
    req.setManagedVersionMap(project.getManagedVersionMap());
    req.setCollectionFilter(filter);
    req.setOffline(configSource.getMavenSession().isOffline());
    req.setForceUpdate(configSource.getMavenSession().getRequest().isUpdateSnapshots());
    req.setServers(configSource.getMavenSession().getRequest().getServers());
    req.setMirrors(configSource.getMavenSession().getRequest().getMirrors());
    req.setProxies(configSource.getMavenSession().getRequest().getProxies());
    ArtifactResolutionResult result;
    result = resolver.resolve(req);
    if (result.hasExceptions()) {
        throw new DependencyResolutionException("Failed to resolve dependencies for assembly: ", result.getExceptions().get(0));
    }
    getLogger().debug("While resolving dependencies of " + project.getId() + ":");
    FilterUtils.reportFilteringStatistics(Collections.singleton(filter), getLogger());
    return result.getArtifacts();
}
Also used : MavenProject(org.apache.maven.project.MavenProject) ArtifactResolutionRequest(org.apache.maven.artifact.resolver.ArtifactResolutionRequest) ArtifactResolutionResult(org.apache.maven.artifact.resolver.ArtifactResolutionResult)

Aggregations

ArtifactResolutionRequest (org.apache.maven.artifact.resolver.ArtifactResolutionRequest)12 ArtifactResolutionResult (org.apache.maven.artifact.resolver.ArtifactResolutionResult)9 Artifact (org.apache.maven.artifact.Artifact)6 ArrayList (java.util.ArrayList)4 LinkedHashSet (java.util.LinkedHashSet)3 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)3 MavenProject (org.apache.maven.project.MavenProject)3 File (java.io.File)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 ArtifactResolver (org.apache.maven.artifact.resolver.ArtifactResolver)2 ComponentLookupException (org.codehaus.plexus.component.repository.exception.ComponentLookupException)2 RepositorySystemSession (org.eclipse.aether.RepositorySystemSession)2 IOException (java.io.IOException)1 RemoteException (java.rmi.RemoteException)1 LinkedHashMap (java.util.LinkedHashMap)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 LicensedProjects (org.apache.hyracks.maven.license.project.LicensedProjects)1 MavenExecutionException (org.apache.maven.MavenExecutionException)1 DefaultArtifact (org.apache.maven.artifact.DefaultArtifact)1