Search in sources :

Example 6 with ArtifactResolutionRequest

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

the class DefaultDependencyResolver method resolveNonTransitively.

Set<Artifact> resolveNonTransitively(final Assembly assembly, final Set<Artifact> dependencyArtifacts, final AssemblerConfigurationSource configSource, final List<ArtifactRepository> repos) throws DependencyResolutionException {
    final List<Artifact> missing = new ArrayList<Artifact>();
    final Set<Artifact> resolved = new LinkedHashSet<Artifact>();
    for (final Artifact depArtifact : dependencyArtifacts) {
        ArtifactResolutionRequest req = new ArtifactResolutionRequest();
        req.setLocalRepository(configSource.getLocalRepository());
        req.setRemoteRepositories(repos);
        req.setArtifact(depArtifact);
        ArtifactResolutionResult resolve = resolver.resolve(req);
        if (resolve.hasExceptions()) {
            if (getLogger().isDebugEnabled()) {
                getLogger().debug("Failed to resolve: " + depArtifact.getId() + " for assembly: " + assembly.getId());
            }
            missing.add(depArtifact);
        } else {
            resolved.add(depArtifact);
        }
    }
    if (!missing.isEmpty()) {
        final MavenProject project = configSource.getProject();
        final Artifact rootArtifact = project.getArtifact();
        final Throwable error = new MultipleArtifactsNotFoundException(rootArtifact, new ArrayList<Artifact>(resolved), missing, repos);
        throw new DependencyResolutionException("Failed to resolve dependencies for: " + assembly.getId(), error);
    }
    return resolved;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) MavenProject(org.apache.maven.project.MavenProject) ArtifactResolutionRequest(org.apache.maven.artifact.resolver.ArtifactResolutionRequest) ArtifactResolutionResult(org.apache.maven.artifact.resolver.ArtifactResolutionResult) ArrayList(java.util.ArrayList) MultipleArtifactsNotFoundException(org.apache.maven.artifact.resolver.MultipleArtifactsNotFoundException) Artifact(org.apache.maven.artifact.Artifact)

Example 7 with ArtifactResolutionRequest

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

the class RepositoryReplicatorMojo method resolveAndCopyArtifact.

private boolean resolveAndCopyArtifact(Artifact artifact) throws MojoExecutionException, IOException {
    if (copiedArtifacts.contains(artifact)) {
        return true;
    }
    copiedArtifacts.add(artifact);
    File artifactFile = artifact.getFile();
    if (artifactFile == null && !artifact.isResolved()) {
        ArtifactResolutionRequest request = new ArtifactResolutionRequest();
        request.setArtifact(artifact);
        request.setLocalRepository(session.getLocalRepository());
        request.setRemoteRepositories(remoteRepositories);
        ArtifactResolutionResult result = repositorySystem.resolve(request);
        artifactFile = artifact.getFile();
        if (!result.isSuccess() && artifactFile == null) {
            if (getLog().isDebugEnabled()) {
                for (Exception e : result.getExceptions()) {
                    getLog().error(e);
                }
            }
            throw new MojoExecutionException("Failed to resolve artifact " + artifact);
        }
    }
    return copyArtifact(artifactFile, artifactFile.getPath().substring(localRepositoryBasedirLength));
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArtifactResolutionRequest(org.apache.maven.artifact.resolver.ArtifactResolutionRequest) ArtifactResolutionResult(org.apache.maven.artifact.resolver.ArtifactResolutionResult) File(java.io.File) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException)

Example 8 with ArtifactResolutionRequest

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

the class FsMountMojo method getArtifactFile.

private File getArtifactFile(Bundle bundle, String type) throws MojoExecutionException {
    Artifact artifactObject = repository.createArtifact(bundle.getGroupId(), bundle.getArtifactId(), bundle.getVersion(), type);
    ArtifactResolutionRequest request = new ArtifactResolutionRequest();
    request.setArtifact(artifactObject);
    request.setLocalRepository(localRepository);
    request.setRemoteRepositories(remoteRepositories);
    ArtifactResolutionResult result = repository.resolve(request);
    if (result.isSuccess()) {
        return artifactObject.getFile();
    } else {
        throw new MojoExecutionException("Unable to download artifact: " + artifactObject.toString());
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArtifactResolutionRequest(org.apache.maven.artifact.resolver.ArtifactResolutionRequest) ArtifactResolutionResult(org.apache.maven.artifact.resolver.ArtifactResolutionResult) Artifact(org.apache.maven.artifact.Artifact)

Example 9 with ArtifactResolutionRequest

use of org.apache.maven.artifact.resolver.ArtifactResolutionRequest 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 10 with ArtifactResolutionRequest

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

the class VersionCheckerMojo method resolve.

private File resolve(String artifactDescriptor) {
    String[] s = artifactDescriptor.split(":");
    String type = (s.length >= 4 ? s[3] : "jar");
    Artifact artifact = repository.createArtifact(s[0], s[1], s[2], type);
    ArtifactResolutionRequest request = new ArtifactResolutionRequest();
    request.setArtifact(artifact);
    request.setResolveRoot(true).setResolveTransitively(false);
    request.setServers(session.getRequest().getServers());
    request.setMirrors(session.getRequest().getMirrors());
    request.setProxies(session.getRequest().getProxies());
    request.setLocalRepository(session.getLocalRepository());
    request.setRemoteRepositories(session.getRequest().getRemoteRepositories());
    repository.resolve(request);
    return artifact.getFile();
}
Also used : ArtifactResolutionRequest(org.apache.maven.artifact.resolver.ArtifactResolutionRequest) Artifact(org.apache.maven.artifact.Artifact)

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