Search in sources :

Example 56 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 57 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 58 with ArtifactRequest

use of org.eclipse.aether.resolution.ArtifactRequest in project karaf by apache.

the class Dependency31Helper method resolveArtifact.

private ArtifactResult resolveArtifact(Artifact artifact) throws ArtifactResolutionException {
    ArtifactResult result = artifactCache.get(artifact);
    if (result != null) {
        return result;
    }
    ArtifactRequest request = new ArtifactRequest();
    request.setArtifact(artifact);
    request.setRepositories(projectRepositories);
    result = repositorySystem.resolveArtifact(repositorySystemSession, request);
    if (result != null) {
        artifactCache.put(artifact, result);
    }
    return result;
}
Also used : ArtifactRequest(org.eclipse.aether.resolution.ArtifactRequest) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult)

Aggregations

ArtifactRequest (org.eclipse.aether.resolution.ArtifactRequest)58 ArtifactResult (org.eclipse.aether.resolution.ArtifactResult)52 DefaultArtifact (org.eclipse.aether.artifact.DefaultArtifact)36 ArtifactResolutionException (org.eclipse.aether.resolution.ArtifactResolutionException)34 Artifact (org.eclipse.aether.artifact.Artifact)28 File (java.io.File)22 IOException (java.io.IOException)12 RepositorySystemSession (org.eclipse.aether.RepositorySystemSession)11 DefaultRepositorySystemSession (org.eclipse.aether.DefaultRepositorySystemSession)10 RemoteRepository (org.eclipse.aether.repository.RemoteRepository)10 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)9 FileNotFoundException (java.io.FileNotFoundException)7 ArrayList (java.util.ArrayList)7 XmlPullParserException (org.codehaus.plexus.util.xml.pull.XmlPullParserException)6 ArtifactDescriptorResult (org.eclipse.aether.resolution.ArtifactDescriptorResult)6 Model (org.apache.maven.model.Model)5 ArtifactDescriptorException (org.eclipse.aether.resolution.ArtifactDescriptorException)5 ArtifactDescriptorRequest (org.eclipse.aether.resolution.ArtifactDescriptorRequest)5 FileReader (java.io.FileReader)4 Dependency (org.eclipse.aether.graph.Dependency)4