Search in sources :

Example 56 with ArtifactResult

use of org.eclipse.aether.resolution.ArtifactResult in project revapi by revapi.

the class ArtifactResolver method resolveArtifact.

private Artifact resolveArtifact(Artifact artifact, RepositorySystemSession session) throws ArtifactResolutionException {
    ArtifactRequest request = new ArtifactRequest().setArtifact(artifact).setRepositories(repositories);
    ArtifactResult result = repositorySystem.resolveArtifact(session, request);
    return result.getArtifact();
}
Also used : LocalArtifactRequest(org.eclipse.aether.repository.LocalArtifactRequest) ArtifactRequest(org.eclipse.aether.resolution.ArtifactRequest) LocalArtifactResult(org.eclipse.aether.repository.LocalArtifactResult) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult)

Example 57 with ArtifactResult

use of org.eclipse.aether.resolution.ArtifactResult in project kie-wb-common by kiegroup.

the class MavenArtifactResolverTest method resolveArtifactNotOffline.

@Test
public void resolveArtifactNotOffline() throws Exception {
    final boolean[] executedOffline = { false };
    RepositorySystemSession session = Aether.getAether().getSession();
    assertThat(checksIfArtifactIsPresent(session)).isFalse();
    File file = new File("target/test-classes/fake-uberfire-m2repo-editor-backend-100-SNAPSHOT.jar");
    assertThat(file).exists();
    Artifact artifact = getArtifact();
    artifact = artifact.setFile(file);
    ArtifactRequest artifactRequest = new ArtifactRequest();
    artifactRequest.setArtifact(artifact);
    ArtifactResult result;
    try {
        Aether.getAether().getSystem().resolveArtifact(session, artifactRequest);
    } catch (ArtifactResolutionException ex) {
        assertThat(ex).isNotNull();
    }
    deployTestJar(artifact, session);
    MavenArtifactResolver resolver = new MavenArtifactResolver() {

        public URI resolve(final String groupId, final String artifactId, final String version) throws Exception {
            return internalResolver(false, groupId, artifactId, version);
        }

        URI resolveEmbedded(final String groupId, final String artifactId, final String version) throws IOException {
            executedOffline[0] = false;
            return super.resolveEmbedded(groupId, artifactId, version);
        }
    };
    URI uri = resolver.resolve(artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion());
    assertThat(uri).isNotNull();
    assertThat(uri.getPath()).endsWith(File.separator + "fake-uberfire-m2repo-editor-backend" + File.separator + "100-SNAPSHOT" + File.separator + "fake-uberfire-m2repo-editor-backend-100-SNAPSHOT.jar");
    result = Aether.getAether().getSystem().resolveArtifact(session, artifactRequest);
    assertThat(result.isMissing()).isFalse();
    assertThat(result.isResolved()).isTrue();
    assertThat(executedOffline[0]).isFalse();
}
Also used : RepositorySystemSession(org.eclipse.aether.RepositorySystemSession) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) ArtifactRequest(org.eclipse.aether.resolution.ArtifactRequest) File(java.io.File) URI(java.net.URI) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult) Test(org.junit.Test)

Example 58 with ArtifactResult

use of org.eclipse.aether.resolution.ArtifactResult in project kie-wb-common by kiegroup.

the class MavenArtifactResolverTest method deleteArtifactIFPresent.

private void deleteArtifactIFPresent() {
    ArtifactRequest artifactRequest = new ArtifactRequest();
    artifactRequest.setArtifact(getArtifact());
    try {
        ArtifactResult result = Aether.getAether().getSystem().resolveArtifact(Aether.getAether().getSession(), artifactRequest);
        File artifactFile = result.getArtifact().getFile();
        assertThat(artifactFile.delete()).isTrue();
    } catch (Exception ex) {
    }
}
Also used : ArtifactRequest(org.eclipse.aether.resolution.ArtifactRequest) File(java.io.File) IOException(java.io.IOException) InstallationException(org.eclipse.aether.installation.InstallationException) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult)

Example 59 with ArtifactResult

use of org.eclipse.aether.resolution.ArtifactResult 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)

Example 60 with ArtifactResult

use of org.eclipse.aether.resolution.ArtifactResult in project qpid-broker-j by apache.

the class ClasspathQuery method getJarFiles.

private static Set<File> getJarFiles(final Collection<String> gavs) {
    Set<File> jars = new HashSet<>();
    for (final String gav : gavs) {
        Artifact artifact = new DefaultArtifact(gav);
        DependencyFilter classpathFlter = DependencyFilterUtils.classpathFilter(JavaScopes.COMPILE);
        CollectRequest collectRequest = new CollectRequest();
        collectRequest.setRoot(new Dependency(artifact, JavaScopes.COMPILE));
        collectRequest.setRepositories(Booter.newRepositories());
        DependencyRequest dependencyRequest = new DependencyRequest(collectRequest, classpathFlter);
        List<ArtifactResult> artifactResults = null;
        try {
            artifactResults = _mavenRepositorySystem.resolveDependencies(_mavenRepositorySession, dependencyRequest).getArtifactResults();
        } catch (DependencyResolutionException e) {
            throw new RuntimeException(String.format("Error while dependency resolution for '%s'", gav), e);
        }
        if (artifactResults == null) {
            throw new RuntimeException(String.format("Could not resolve dependency for '%s'", gav));
        }
        for (ArtifactResult artifactResult : artifactResults) {
            System.out.println(artifactResult.getArtifact() + " resolved to " + artifactResult.getArtifact().getFile());
        }
        jars.addAll(artifactResults.stream().map(result -> result.getArtifact().getFile()).collect(Collectors.toSet()));
    }
    return jars;
}
Also used : DependencyFilter(org.eclipse.aether.graph.DependencyFilter) Dependency(org.eclipse.aether.graph.Dependency) CollectRequest(org.eclipse.aether.collection.CollectRequest) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult) DependencyRequest(org.eclipse.aether.resolution.DependencyRequest) DependencyResolutionException(org.eclipse.aether.resolution.DependencyResolutionException) File(java.io.File) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) HashSet(java.util.HashSet)

Aggregations

ArtifactResult (org.eclipse.aether.resolution.ArtifactResult)83 ArtifactRequest (org.eclipse.aether.resolution.ArtifactRequest)53 DefaultArtifact (org.eclipse.aether.artifact.DefaultArtifact)51 Artifact (org.eclipse.aether.artifact.Artifact)41 File (java.io.File)37 ArtifactResolutionException (org.eclipse.aether.resolution.ArtifactResolutionException)37 IOException (java.io.IOException)16 RemoteRepository (org.eclipse.aether.repository.RemoteRepository)16 ArrayList (java.util.ArrayList)15 Dependency (org.eclipse.aether.graph.Dependency)15 DefaultRepositorySystemSession (org.eclipse.aether.DefaultRepositorySystemSession)13 RepositorySystemSession (org.eclipse.aether.RepositorySystemSession)13 DependencyRequest (org.eclipse.aether.resolution.DependencyRequest)12 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)11 CollectRequest (org.eclipse.aether.collection.CollectRequest)11 ArtifactDescriptorResult (org.eclipse.aether.resolution.ArtifactDescriptorResult)10 FileNotFoundException (java.io.FileNotFoundException)9 RepositorySystem (org.eclipse.aether.RepositorySystem)8 Test (org.junit.Test)8 DependencyFilter (org.eclipse.aether.graph.DependencyFilter)7