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();
}
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();
}
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) {
}
}
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;
}
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;
}
Aggregations