Search in sources :

Example 11 with ArtifactRequest

use of org.eclipse.aether.resolution.ArtifactRequest in project spf4j by zolyfarkas.

the class MavenRepositoryUtils method resolveArtifact.

public static File resolveArtifact(final String groupId, final String artifactId, final String classifier, final String extension, final String versionExpr, final List<RemoteRepository> repos, final RepositorySystem repositorySystem, final RepositorySystemSession session) throws ArtifactResolutionException {
    Artifact artifact = new DefaultArtifact(groupId, artifactId, classifier, extension, versionExpr);
    ArtifactRequest artifactRequest = new ArtifactRequest();
    artifactRequest.setArtifact(artifact);
    artifactRequest.setRepositories(repos);
    ArtifactResult artifactResult = repositorySystem.resolveArtifact(session, artifactRequest);
    artifact = artifactResult.getArtifact();
    return artifact.getFile();
}
Also used : 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 12 with ArtifactRequest

use of org.eclipse.aether.resolution.ArtifactRequest in project gate-core by GateNLP.

the class SimpleMavenCache method cacheParents.

private void cacheParents(File pom, RepositorySystem repoSystem, RepositorySystemSession repoSession, List<RemoteRepository> repos) throws ModelBuildingException, IOException, ArtifactResolutionException {
    ModelBuildingRequest req = new DefaultModelBuildingRequest();
    req.setProcessPlugins(false);
    req.setPomFile(pom);
    req.setModelResolver(new SimpleModelResolver(repoSystem, repoSession, repos));
    req.setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL);
    ModelBuilder modelBuilder = new DefaultModelBuilderFactory().newInstance();
    Model model = modelBuilder.build(req).getEffectiveModel();
    Parent parent = model.getParent();
    if (parent == null)
        return;
    Artifact pomArtifact = new DefaultArtifact(parent.getGroupId(), parent.getArtifactId(), "pom", parent.getVersion());
    ArtifactRequest artifactRequest = new ArtifactRequest(pomArtifact, repos, null);
    ArtifactResult artifactResult = repoSystem.resolveArtifact(repoSession, artifactRequest);
    // but copy it to a file named for the original requested version number
    File file = getArtifactFile(artifactRequest.getArtifact());
    FileUtils.copyFile(artifactResult.getArtifact().getFile(), file);
    cacheParents(artifactResult.getArtifact().getFile(), repoSystem, repoSession, repos);
}
Also used : DefaultModelBuilderFactory(org.apache.maven.model.building.DefaultModelBuilderFactory) ModelBuildingRequest(org.apache.maven.model.building.ModelBuildingRequest) DefaultModelBuildingRequest(org.apache.maven.model.building.DefaultModelBuildingRequest) ModelBuilder(org.apache.maven.model.building.ModelBuilder) ArtifactRequest(org.eclipse.aether.resolution.ArtifactRequest) Parent(org.apache.maven.model.Parent) DefaultModelBuildingRequest(org.apache.maven.model.building.DefaultModelBuildingRequest) Model(org.apache.maven.model.Model) File(java.io.File) SubArtifact(org.eclipse.aether.util.artifact.SubArtifact) 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 13 with ArtifactRequest

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

the class MavenArtifactResolver method resolve.

/**
 * Resolve an artifact and return its location in the local repository. Aether performs the normal
 * Maven resolution process ensuring that the latest update is cached to the local repository.
 * In addition, if the {@link MavenProperties#resolvePom} flag is <code>true</code>,
 * the POM is also resolved and cached.
 * @param resource the {@link MavenResource} representing the artifact
 * @return a {@link FileSystemResource} representing the resolved artifact in the local repository
 * @throws IllegalStateException if the artifact does not exist or the resolution fails
 */
Resource resolve(MavenResource resource) {
    Assert.notNull(resource, "MavenResource must not be null");
    validateCoordinates(resource);
    RepositorySystemSession session = newRepositorySystemSession(this.repositorySystem, this.properties.getLocalRepository());
    ArtifactResult resolvedArtifact;
    try {
        List<ArtifactRequest> artifactRequests = new ArrayList<>(2);
        if (properties.isResolvePom()) {
            artifactRequests.add(new ArtifactRequest(toPomArtifact(resource), this.remoteRepositories, JavaScopes.RUNTIME));
        }
        artifactRequests.add(new ArtifactRequest(toJarArtifact(resource), this.remoteRepositories, JavaScopes.RUNTIME));
        List<ArtifactResult> results = this.repositorySystem.resolveArtifacts(session, artifactRequests);
        resolvedArtifact = results.get(results.size() - 1);
    } catch (ArtifactResolutionException e) {
        ChoiceFormat pluralizer = new ChoiceFormat(new double[] { 0d, 1d, ChoiceFormat.nextDouble(1d) }, new String[] { "repositories: ", "repository: ", "repositories: " });
        MessageFormat messageFormat = new MessageFormat("Failed to resolve MavenResource: {0}. Configured remote {1}: {2}");
        messageFormat.setFormat(1, pluralizer);
        String repos = properties.getRemoteRepositories().isEmpty() ? "none" : StringUtils.collectionToDelimitedString(properties.getRemoteRepositories().keySet(), ",", "[", "]");
        throw new IllegalStateException(messageFormat.format(new Object[] { resource, properties.getRemoteRepositories().size(), repos }), e);
    }
    return toResource(resolvedArtifact);
}
Also used : RepositorySystemSession(org.eclipse.aether.RepositorySystemSession) DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) ArtifactRequest(org.eclipse.aether.resolution.ArtifactRequest) MessageFormat(java.text.MessageFormat) ChoiceFormat(java.text.ChoiceFormat) ArrayList(java.util.ArrayList) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult)

Example 14 with ArtifactRequest

use of org.eclipse.aether.resolution.ArtifactRequest in project mule by mulesoft.

the class DefaultRepositoryService method lookupBundle.

@Override
public File lookupBundle(BundleDependency bundleDependency) {
    try {
        if (remoteRepositories.isEmpty()) {
            throw new RepositoryServiceDisabledException("Repository service has not been configured so it's disabled. " + "To enable it you must configure the set of repositories to use using the system property: " + MULE_REMOTE_REPOSITORIES_PROPERTY);
        }
        DefaultArtifact artifact = toArtifact(bundleDependency);
        ArtifactRequest getArtifactRequest = new ArtifactRequest();
        getArtifactRequest.setRepositories(remoteRepositories);
        getArtifactRequest.setArtifact(artifact);
        ArtifactResult artifactResult = repositorySystem.resolveArtifact(repositorySystemSession, getArtifactRequest);
        return artifactResult.getArtifact().getFile();
    } catch (ArtifactResolutionException e) {
        if (e.getCause() instanceof ArtifactNotFoundException) {
            throw new BundleNotFoundException(e);
        } else {
            throw new RepositoryConnectionException("There was a problem connecting to one of the repositories", e);
        }
    }
}
Also used : RepositoryConnectionException(org.mule.runtime.module.repository.api.RepositoryConnectionException) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) ArtifactRequest(org.eclipse.aether.resolution.ArtifactRequest) RepositoryServiceDisabledException(org.mule.runtime.module.repository.api.RepositoryServiceDisabledException) ArtifactNotFoundException(org.eclipse.aether.transfer.ArtifactNotFoundException) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult) BundleNotFoundException(org.mule.runtime.module.repository.api.BundleNotFoundException)

Example 15 with ArtifactRequest

use of org.eclipse.aether.resolution.ArtifactRequest in project mule by mulesoft.

the class DependencyResolver method resolveArtifact.

/**
 * Resolves the path for an artifact.
 *
 * @param artifact the {@link Artifact} requested, must not be {@code null}
 * @return The resolution result, never {@code null}.
 * @throws {@link ArtifactResolutionException} if the artifact could not be resolved.
 */
public ArtifactResult resolveArtifact(Artifact artifact) throws ArtifactResolutionException {
    checkNotNull(artifact, "artifact cannot be null");
    final ArtifactRequest request = new ArtifactRequest(artifact, resolutionContext.getRemoteRepositories(), null);
    return repositoryState.getSystem().resolveArtifact(repositoryState.getSession(), request);
}
Also used : ArtifactRequest(org.eclipse.aether.resolution.ArtifactRequest)

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