Search in sources :

Example 41 with ArtifactRequest

use of org.eclipse.aether.resolution.ArtifactRequest in project spring-cloud-function by spring-cloud.

the class DependencyResolutionModule method getArtifactRequests.

private List<ArtifactRequest> getArtifactRequests(List<Dependency> dependencies) {
    List<ArtifactRequest> list = new ArrayList<>();
    for (Dependency dependency : dependencies) {
        ArtifactRequest request = new ArtifactRequest(dependency.getArtifact(), null, null);
        request.setRepositories(aetherRepositories(new Properties()));
        list.add(request);
    }
    return list;
}
Also used : ArtifactRequest(org.eclipse.aether.resolution.ArtifactRequest) ArrayList(java.util.ArrayList) Dependency(org.eclipse.aether.graph.Dependency) Properties(java.util.Properties)

Example 42 with ArtifactRequest

use of org.eclipse.aether.resolution.ArtifactRequest in project syndesis by syndesisio.

the class RepackageExtensionMojo method downloadAndInstallArtifact.

/*
     * @param artifact The artifact coordinates in the format
     *            {@code <groupId>:<artifactId>[:<extension>[:<classifier>]]:<version>}, must not be {@code null}.
     *
     */
protected ArtifactResult downloadAndInstallArtifact(String artifact) throws MojoExecutionException {
    ArtifactResult result;
    ArtifactRequest request = new ArtifactRequest();
    request.setArtifact(new DefaultArtifact(artifact));
    request.setRepositories(remoteRepos);
    getLog().info("Resolving artifact " + artifact + " from " + remoteRepos);
    try {
        result = repoSystem.resolveArtifact(repoSession, request);
        return result;
    } catch (ArtifactResolutionException e) {
        throw new MojoExecutionException(e.getMessage(), e);
    }
}
Also used : ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) ArtifactRequest(org.eclipse.aether.resolution.ArtifactRequest) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult)

Example 43 with ArtifactRequest

use of org.eclipse.aether.resolution.ArtifactRequest in project sts4 by spring-projects.

the class MavenBridge method resolve.

public Artifact resolve(final Artifact artifact, List<ArtifactRepository> remoteRepositories, MavenExecutionRequest executionRequest) throws MavenException {
    if (remoteRepositories == null) {
        try {
            remoteRepositories = getArtifactRepositories();
        } catch (MavenException e) {
            // we've tried
            remoteRepositories = Collections.emptyList();
        }
    }
    final List<ArtifactRepository> _remoteRepositories = remoteRepositories;
    org.eclipse.aether.RepositorySystem repoSystem = lookup(org.eclipse.aether.RepositorySystem.class);
    ArtifactRequest request = new ArtifactRequest();
    request.setArtifact(RepositoryUtils.toArtifact(artifact));
    request.setRepositories(RepositoryUtils.toRepos(_remoteRepositories));
    ArtifactResult result;
    try {
        result = repoSystem.resolveArtifact(createRepositorySession(executionRequest), request);
    } catch (ArtifactResolutionException ex) {
        result = ex.getResults().get(0);
    }
    setLastUpdated(executionRequest.getLocalRepository(), _remoteRepositories, artifact);
    if (result.isResolved()) {
        artifact.selectVersion(result.getArtifact().getVersion());
        artifact.setFile(result.getArtifact().getFile());
        artifact.setResolved(true);
    } else {
        throw new MavenException(result.getExceptions().toArray(new Exception[result.getExceptions().size()]));
    }
    return artifact;
}
Also used : ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) ArtifactRequest(org.eclipse.aether.resolution.ArtifactRequest) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) PlexusContainerException(org.codehaus.plexus.PlexusContainerException) DuplicateProjectException(org.apache.maven.project.DuplicateProjectException) ProjectBuildingException(org.apache.maven.project.ProjectBuildingException) FileNotFoundException(java.io.FileNotFoundException) ConcurrentModificationException(java.util.ConcurrentModificationException) SettingsBuildingException(org.apache.maven.settings.building.SettingsBuildingException) PluginVersionResolutionException(org.apache.maven.plugin.version.PluginVersionResolutionException) NoSuchRealmException(org.codehaus.plexus.classworlds.realm.NoSuchRealmException) ComponentLookupException(org.codehaus.plexus.component.repository.exception.ComponentLookupException) CycleDetectedException(org.codehaus.plexus.util.dag.CycleDetectedException) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) InvalidRepositoryException(org.apache.maven.artifact.InvalidRepositoryException) IOException(java.io.IOException) MavenExecutionRequestPopulationException(org.apache.maven.execution.MavenExecutionRequestPopulationException) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult)

Example 44 with ArtifactRequest

use of org.eclipse.aether.resolution.ArtifactRequest in project unleash-maven-plugin by shillner.

the class ArtifactCacheLoader method load.

@Override
public Optional<ArtifactResult> load(ArtifactCoordinates coordinates) throws Exception {
    Artifact artifact = new DefaultArtifact(coordinates.toString());
    ArtifactRequest artifactRequest = new ArtifactRequest();
    artifactRequest.setArtifact(artifact);
    artifactRequest.setRepositories(this.remoteProjectRepos);
    ArtifactResult artifactResult;
    try {
        artifactResult = this.repoSystem.resolveArtifact(this.repoSession, artifactRequest);
    } catch (ArtifactResolutionException e) {
        // must not throw the error or log as an error since this is an expected behavior
        artifactResult = null;
    }
    return Optional.fromNullable(artifactResult);
}
Also used : ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) ArtifactRequest(org.eclipse.aether.resolution.ArtifactRequest) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult)

Example 45 with ArtifactRequest

use of org.eclipse.aether.resolution.ArtifactRequest in project grails-maven by grails.

the class AbstractGrailsMojo method resolveArtifactIds.

protected Collection<File> resolveArtifactIds(Collection<String> artifactIds) throws MojoExecutionException {
    Collection<ArtifactRequest> requests = new ArrayList<ArtifactRequest>();
    for (String artifactId : artifactIds) {
        ArtifactRequest request = new ArtifactRequest();
        request.setArtifact(new DefaultArtifact(artifactId));
        request.setRepositories(remoteRepos);
        getLog().debug("Resolving artifact " + artifactId + " from " + remoteRepos);
        requests.add(request);
    }
    Collection<File> files = new ArrayList<File>();
    try {
        List<ArtifactResult> result = repoSystem.resolveArtifacts(repoSession, requests);
        for (ArtifactResult artifactResult : result) {
            File file = artifactResult.getArtifact().getFile();
            files.add(file);
            getLog().debug("Resolved artifact " + artifactResult.getArtifact().getArtifactId() + " to " + file + " from " + artifactResult.getRepository());
        }
    } catch (ArtifactResolutionException e) {
        throw new MojoExecutionException(e.getMessage(), e);
    }
    return files;
}
Also used : ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) ArtifactRequest(org.eclipse.aether.resolution.ArtifactRequest) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) File(java.io.File) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult)

Aggregations

ArtifactRequest (org.eclipse.aether.resolution.ArtifactRequest)45 ArtifactResult (org.eclipse.aether.resolution.ArtifactResult)41 DefaultArtifact (org.eclipse.aether.artifact.DefaultArtifact)27 ArtifactResolutionException (org.eclipse.aether.resolution.ArtifactResolutionException)26 Artifact (org.eclipse.aether.artifact.Artifact)20 File (java.io.File)18 DefaultRepositorySystemSession (org.eclipse.aether.DefaultRepositorySystemSession)9 RemoteRepository (org.eclipse.aether.repository.RemoteRepository)9 IOException (java.io.IOException)8 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)8 ArrayList (java.util.ArrayList)7 RepositorySystemSession (org.eclipse.aether.RepositorySystemSession)7 FileNotFoundException (java.io.FileNotFoundException)5 Model (org.apache.maven.model.Model)4 FileReader (java.io.FileReader)3 ArtifactRepository (org.apache.maven.artifact.repository.ArtifactRepository)3 MavenXpp3Reader (org.apache.maven.model.io.xpp3.MavenXpp3Reader)3 XmlPullParserException (org.codehaus.plexus.util.xml.pull.XmlPullParserException)3 RepositorySystem (org.eclipse.aether.RepositorySystem)3 Dependency (org.eclipse.aether.graph.Dependency)3