Search in sources :

Example 16 with ArtifactResolutionResult

use of org.apache.maven.artifact.resolver.ArtifactResolutionResult in project cxf by apache.

the class AbstractCodegenMojo method resolveArbitraryWsdl.

private Artifact resolveArbitraryWsdl(Artifact artifact) {
    ArtifactResolutionRequest request = new ArtifactResolutionRequest();
    request.setArtifact(artifact);
    request.setResolveRoot(true).setResolveTransitively(false);
    request.setServers(mavenSession.getRequest().getServers());
    request.setMirrors(mavenSession.getRequest().getMirrors());
    request.setProxies(mavenSession.getRequest().getProxies());
    request.setLocalRepository(mavenSession.getLocalRepository());
    request.setRemoteRepositories(mavenSession.getRequest().getRemoteRepositories());
    ArtifactResolutionResult result = repositorySystem.resolve(request);
    Artifact resolvedArtifact = result.getOriginatingArtifact();
    if (resolvedArtifact == null && !CollectionUtils.isEmpty(result.getArtifacts())) {
        resolvedArtifact = result.getArtifacts().iterator().next();
    }
    return resolvedArtifact;
}
Also used : ArtifactResolutionRequest(org.apache.maven.artifact.resolver.ArtifactResolutionRequest) ArtifactResolutionResult(org.apache.maven.artifact.resolver.ArtifactResolutionResult) Artifact(org.apache.maven.artifact.Artifact)

Example 17 with ArtifactResolutionResult

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

the class MavenServerImpl method internalResolveProject.

private MavenResult internalResolveProject(File pom, List<String> activeProfiles, List<String> inactiveProfiles, List<ResolutionListener> dependencyTreeResolutionListeners) {
    MavenExecutionRequest request = newMavenRequest(pom, activeProfiles, inactiveProfiles, Collections.emptyList());
    request.setUpdateSnapshots(updateSnapshots);
    AtomicReference<MavenResult> reference = new AtomicReference<>();
    runMavenRequest(request, () -> {
        try {
            ProjectBuilder builder = getMavenComponent(ProjectBuilder.class);
            List<ProjectBuildingResult> resultList = builder.build(Collections.singletonList(pom), false, request.getProjectBuildingRequest());
            ProjectBuildingResult result = resultList.get(0);
            MavenProject mavenProject = result.getProject();
            RepositorySystemSession repositorySession = getMavenComponent(LegacySupport.class).getRepositorySession();
            if (repositorySession instanceof DefaultRepositorySystemSession) {
                ((DefaultRepositorySystemSession) repositorySession).setTransferListener(new ArtifactTransferListener(mavenProgressNotifier));
                if (workspaceCache != null) {
                    ((DefaultRepositorySystemSession) repositorySession).setWorkspaceReader(new MavenWorkspaceReader(workspaceCache));
                }
            }
            List<Exception> exceptions = new ArrayList<>();
            loadExtensions(mavenProject, exceptions);
            mavenProject.setDependencyArtifacts(mavenProject.createArtifacts(getMavenComponent(ArtifactFactory.class), null, null));
            ArtifactResolutionRequest resolutionRequest = new ArtifactResolutionRequest();
            resolutionRequest.setArtifact(mavenProject.getArtifact());
            resolutionRequest.setRemoteRepositories(mavenProject.getRemoteArtifactRepositories());
            resolutionRequest.setArtifactDependencies(mavenProject.getDependencyArtifacts());
            resolutionRequest.setListeners(dependencyTreeResolutionListeners);
            resolutionRequest.setLocalRepository(localRepo);
            resolutionRequest.setManagedVersionMap(mavenProject.getManagedVersionMap());
            resolutionRequest.setResolveTransitively(true);
            resolutionRequest.setResolveRoot(false);
            ArtifactResolver resolver = getMavenComponent(ArtifactResolver.class);
            ArtifactResolutionResult resolve = resolver.resolve(resolutionRequest);
            mavenProject.setArtifacts(resolve.getArtifacts());
            reference.set(new MavenResult(mavenProject, exceptions));
        } catch (Exception e) {
            reference.set(new MavenResult(null, null, Collections.singletonList(e)));
        }
    });
    return reference.get();
}
Also used : RepositorySystemSession(org.eclipse.aether.RepositorySystemSession) DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession) LegacySupport(org.apache.maven.plugin.LegacySupport) MavenExecutionRequest(org.apache.maven.execution.MavenExecutionRequest) DefaultMavenExecutionRequest(org.apache.maven.execution.DefaultMavenExecutionRequest) ArrayList(java.util.ArrayList) AtomicReference(java.util.concurrent.atomic.AtomicReference) ProjectBuildingException(org.apache.maven.project.ProjectBuildingException) InitializationException(org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException) ModelInterpolationException(org.apache.maven.project.interpolation.ModelInterpolationException) InvocationTargetException(java.lang.reflect.InvocationTargetException) RemoteException(java.rmi.RemoteException) InvalidProjectModelException(org.apache.maven.project.InvalidProjectModelException) SettingsBuildingException(org.apache.maven.settings.building.SettingsBuildingException) ComponentLookupException(org.codehaus.plexus.component.repository.exception.ComponentLookupException) MavenExecutionException(org.apache.maven.MavenExecutionException) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) InvalidRepositoryException(org.apache.maven.artifact.InvalidRepositoryException) MavenExecutionRequestPopulationException(org.apache.maven.execution.MavenExecutionRequestPopulationException) ArtifactResolver(org.apache.maven.artifact.resolver.ArtifactResolver) CheArtifactResolver(org.eclipse.che.maven.CheArtifactResolver) DefaultArtifactResolver(org.eclipse.aether.internal.impl.DefaultArtifactResolver) ProjectBuilder(org.apache.maven.project.ProjectBuilder) MavenProject(org.apache.maven.project.MavenProject) DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession) ProjectBuildingResult(org.apache.maven.project.ProjectBuildingResult) ArtifactResolutionRequest(org.apache.maven.artifact.resolver.ArtifactResolutionRequest) ArtifactResolutionResult(org.apache.maven.artifact.resolver.ArtifactResolutionResult)

Example 18 with ArtifactResolutionResult

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

the class CheArtifactResolver method resolveWithExceptions.

public ArtifactResolutionResult resolveWithExceptions(ArtifactResolutionRequest request) throws ArtifactResolutionException, ArtifactNotFoundException {
    ArtifactResolutionResult result = resolve(request);
    // We have collected all the problems so let's mimic the way the old code worked and just blow up right here.
    // That's right lets just let it rip right here and send a big incomprehensible blob of text at unsuspecting
    // users. Bad dog!
    resolutionErrorHandler.throwErrors(request, result);
    return result;
}
Also used : ArtifactResolutionResult(org.apache.maven.artifact.resolver.ArtifactResolutionResult)

Example 19 with ArtifactResolutionResult

use of org.apache.maven.artifact.resolver.ArtifactResolutionResult in project camel by apache.

the class RunMojo method resolveExecutableDependencies.

private Set<Artifact> resolveExecutableDependencies(Artifact executablePomArtifact) throws MojoExecutionException {
    Set<Artifact> executableDependencies;
    try {
        MavenProject executableProject = this.projectBuilder.buildFromRepository(executablePomArtifact, this.remoteRepositories, this.localRepository);
        // get all of the dependencies for the executable project
        List<Artifact> dependencies = CastUtils.cast(executableProject.getDependencies());
        // make Artifacts of all the dependencies
        Set<Artifact> dependencyArtifacts = CastUtils.cast(MavenMetadataSource.createArtifacts(this.artifactFactory, dependencies, null, null, null));
        // not forgetting the Artifact of the project itself
        dependencyArtifacts.add(executableProject.getArtifact());
        // resolve all dependencies transitively to obtain a comprehensive
        // list of assemblies
        ArtifactResolutionResult result = artifactResolver.resolveTransitively(dependencyArtifacts, executablePomArtifact, Collections.emptyMap(), this.localRepository, this.remoteRepositories, metadataSource, null, Collections.emptyList());
        executableDependencies = CastUtils.cast(result.getArtifacts());
    } catch (Exception ex) {
        throw new MojoExecutionException("Encountered problems resolving dependencies of the executable " + "in preparation for its execution.", ex);
    }
    return executableDependencies;
}
Also used : MavenProject(org.apache.maven.project.MavenProject) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArtifactResolutionResult(org.apache.maven.artifact.resolver.ArtifactResolutionResult) Artifact(org.apache.maven.artifact.Artifact) InvalidVersionSpecificationException(org.apache.maven.artifact.versioning.InvalidVersionSpecificationException) MalformedURLException(java.net.MalformedURLException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException)

Example 20 with ArtifactResolutionResult

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

the class AbstractJavadocMojo method getClasspath.

/**
     * Method that sets the classpath elements that will be specified in the javadoc <code>-classpath</code>
     * parameter. Since we have all the sources of the current reactor, it is sufficient to consider the
     * dependencies of the reactor modules, excluding the module artifacts which may not yet be available
     * when the reactor project is built for the first time.
     *
     * @return a String that contains the concatenated classpath elements, separated by the System pathSeparator
     *         string (colon (<code>:</code>) on Solaris or semi-colon (<code>;</code>) on Windows).
     * @throws MavenReportException if any.
     * @see File#pathSeparator
     */
private String getClasspath() throws MavenReportException {
    List<String> classpathElements = new ArrayList<String>();
    Map<String, Artifact> compileArtifactMap = new HashMap<String, Artifact>();
    if (isTest()) {
        classpathElements.addAll(getProjectBuildOutputDirs(project));
    }
    populateCompileArtifactMap(compileArtifactMap, getProjectArtifacts(project));
    if (isAggregator() && project.isExecutionRoot()) {
        List<Artifact> reactorArtifacts = new ArrayList<Artifact>();
        for (MavenProject p : reactorProjects) {
            reactorArtifacts.add(p.getArtifact());
        }
        try {
            for (MavenProject subProject : reactorProjects) {
                if (subProject != project) {
                    classpathElements.addAll(getProjectBuildOutputDirs(subProject));
                    Set<Artifact> dependencyArtifacts = subProject.createArtifacts(factory, null, null);
                    // do not attempt to resolve artifacts of the current reactor which may not exist yet
                    dependencyArtifacts.removeAll(reactorArtifacts);
                    if (!dependencyArtifacts.isEmpty()) {
                        ArtifactResolutionResult result = null;
                        try {
                            result = resolver.resolveTransitively(dependencyArtifacts, subProject.getArtifact(), subProject.getManagedVersionMap(), localRepository, subProject.getRemoteArtifactRepositories(), artifactMetadataSource);
                        } catch (ArtifactNotFoundException e) {
                            throw new MavenReportException(e.getMessage(), e);
                        } catch (ArtifactResolutionException e) {
                            throw new MavenReportException(e.getMessage(), e);
                        }
                        if (result == null) {
                            continue;
                        }
                        populateCompileArtifactMap(compileArtifactMap, getCompileArtifacts(result.getArtifacts()));
                        if (getLog().isDebugEnabled()) {
                            StringBuilder sb = new StringBuilder();
                            sb.append("Compiled artifacts for ");
                            sb.append(subProject.getGroupId()).append(":");
                            sb.append(subProject.getArtifactId()).append(":");
                            sb.append(subProject.getVersion()).append('\n');
                            for (Artifact a : compileArtifactMap.values()) {
                                sb.append(a.getFile()).append('\n');
                            }
                            getLog().debug(sb.toString());
                        }
                    }
                }
            }
        } catch (InvalidDependencyVersionException e) {
            throw new MavenReportException(e.getMessage(), e);
        }
    }
    for (Artifact a : compileArtifactMap.values()) {
        classpathElements.add(a.getFile().toString());
    }
    if (additionalDependencies != null) {
        for (Dependency dependency : additionalDependencies) {
            Artifact artifact = resolveDependency(dependency);
            String path = artifact.getFile().toString();
            getLog().debug("add additional artifact with path " + path);
            classpathElements.add(path);
        }
    }
    return StringUtils.join(classpathElements.iterator(), File.pathSeparator);
}
Also used : HashMap(java.util.HashMap) InvalidDependencyVersionException(org.apache.maven.project.artifact.InvalidDependencyVersionException) ArrayList(java.util.ArrayList) Dependency(org.apache.maven.model.Dependency) JavadocPathArtifact(org.apache.maven.plugin.javadoc.options.JavadocPathArtifact) Artifact(org.apache.maven.artifact.Artifact) DocletArtifact(org.apache.maven.plugin.javadoc.options.DocletArtifact) BootclasspathArtifact(org.apache.maven.plugin.javadoc.options.BootclasspathArtifact) ResourcesArtifact(org.apache.maven.plugin.javadoc.options.ResourcesArtifact) TagletArtifact(org.apache.maven.plugin.javadoc.options.TagletArtifact) ArtifactResolutionException(org.apache.maven.artifact.resolver.ArtifactResolutionException) MavenProject(org.apache.maven.project.MavenProject) ArtifactResolutionResult(org.apache.maven.artifact.resolver.ArtifactResolutionResult) ArtifactNotFoundException(org.apache.maven.artifact.resolver.ArtifactNotFoundException) MavenReportException(org.apache.maven.reporting.MavenReportException)

Aggregations

ArtifactResolutionResult (org.apache.maven.artifact.resolver.ArtifactResolutionResult)26 ArtifactResolutionRequest (org.apache.maven.artifact.resolver.ArtifactResolutionRequest)20 Artifact (org.apache.maven.artifact.Artifact)19 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)9 MavenProject (org.apache.maven.project.MavenProject)9 ArrayList (java.util.ArrayList)8 File (java.io.File)6 ArtifactResolutionException (org.apache.maven.artifact.resolver.ArtifactResolutionException)5 LinkedHashSet (java.util.LinkedHashSet)4 Dependency (org.apache.maven.model.Dependency)4 MojoFailureException (org.apache.maven.plugin.MojoFailureException)4 DefaultArtifact (org.apache.maven.artifact.DefaultArtifact)3 ArtifactRepository (org.apache.maven.artifact.repository.ArtifactRepository)3 IOException (java.io.IOException)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 MalformedURLException (java.net.MalformedURLException)2 MavenExecutionException (org.apache.maven.MavenExecutionException)2 ArtifactNotFoundException (org.apache.maven.artifact.resolver.ArtifactNotFoundException)2 ArtifactResolver (org.apache.maven.artifact.resolver.ArtifactResolver)2 ArtifactFilter (org.apache.maven.artifact.resolver.filter.ArtifactFilter)2