use of org.eclipse.aether.resolution.ArtifactResult in project karaf by apache.
the class Dependency31Helper method resolve.
@Override
public File resolve(Object artifact, Log log) {
ArtifactRequest request = new ArtifactRequest();
request.setArtifact((Artifact) artifact);
request.setRepositories(projectRepositories);
log.debug("Resolving artifact " + artifact + " from " + projectRepositories);
ArtifactResult result;
try {
result = repositorySystem.resolveArtifact(repositorySystemSession, request);
} catch (ArtifactResolutionException e) {
log.warn("Cound not resolve " + artifact, e);
return null;
}
log.debug("Resolved artifact " + artifact + " to " + result.getArtifact().getFile() + " from " + result.getRepository());
return result.getArtifact().getFile();
}
use of org.eclipse.aether.resolution.ArtifactResult in project karaf by apache.
the class Dependency31Helper method resolveById.
@Override
public File resolveById(String id, Log log) throws MojoFailureException {
if (id.startsWith("mvn:")) {
if (id.contains("!")) {
id = id.substring(0, "mvn:".length()) + id.substring(id.indexOf("!") + 1);
}
if (id.endsWith("/")) {
id = id.substring(0, id.length() - 1);
}
}
id = MavenUtil.mvnToAether(id);
ArtifactRequest request = new ArtifactRequest();
request.setArtifact(new DefaultArtifact(id));
request.setRepositories(projectRepositories);
log.debug("Resolving artifact " + id + " from " + projectRepositories);
ArtifactResult result;
try {
result = repositorySystem.resolveArtifact(repositorySystemSession, request);
} catch (ArtifactResolutionException e) {
log.warn("Could not resolve " + id, e);
throw new MojoFailureException(format("Couldn't resolve artifact %s", id), e);
}
log.debug("Resolved artifact " + id + " to " + result.getArtifact().getFile() + " from " + result.getRepository());
return result.getArtifact().getFile();
}
use of org.eclipse.aether.resolution.ArtifactResult in project bnd by bndtools.
the class AetherRepository method get.
@Override
public File get(String bsn, Version version, Map<String, String> properties, DownloadListener... listeners) throws Exception {
init();
// Use the index by preference
if (indexedRepo != null)
return indexedRepo.get(ConversionUtils.maybeMavenCoordsToBsn(bsn), version, properties, listeners);
File file = null;
boolean getSource = false;
try {
// Setup the Aether repo session and request
DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();
session.setLocalRepositoryManager(repoSystem.newLocalRepositoryManager(session, localRepo));
if (bsn.endsWith(".source")) {
String originalBsn = properties.get("bsn");
if (originalBsn != null) {
bsn = originalBsn;
getSource = true;
}
}
String[] coords = ConversionUtils.getGroupAndArtifactForBsn(bsn);
MavenVersion mvnVersion = new MavenVersion(version);
String versionStr = null;
if ("exact".equals(properties.get("strategy")) || getSource) {
versionStr = properties.get("version");
} else {
versionStr = mvnVersion.toString();
}
Artifact artifact = null;
if (getSource) {
artifact = new DefaultArtifact(coords[0], coords[1], "sources", "jar", versionStr);
} else {
artifact = new DefaultArtifact(coords[0], coords[1], "jar", versionStr);
}
ArtifactRequest request = new ArtifactRequest();
request.setArtifact(artifact);
request.setRepositories(Collections.singletonList(remoteRepo));
// Log the transfer
session.setTransferListener(new AbstractTransferListener() {
@Override
public void transferStarted(TransferEvent event) throws TransferCancelledException {
System.err.println(event);
}
@Override
public void transferSucceeded(TransferEvent event) {
System.err.println(event);
}
@Override
public void transferFailed(TransferEvent event) {
System.err.println(event);
}
});
try {
// Resolve the version
ArtifactResult artifactResult = repoSystem.resolveArtifact(session, request);
artifact = artifactResult.getArtifact();
file = artifact.getFile();
} catch (ArtifactResolutionException ex) {
// could not download artifact, simply return null
}
return file;
} finally {
for (DownloadListener dl : listeners) {
if (file != null)
dl.success(file);
else
dl.failure(null, "Download failed");
}
}
}
use of org.eclipse.aether.resolution.ArtifactResult in project bnd by bndtools.
the class DependencyResolver method getFileSetRepository.
public FileSetRepository getFileSetRepository(String name, Collection<File> bundlesInputParameter, boolean useMavenDependencies) throws Exception {
Collection<File> bundles = new ArrayList<>();
if (useMavenDependencies) {
Map<File, ArtifactResult> dependencies = resolve();
bundles.addAll(dependencies.keySet());
// TODO Find a better way to get all the artifacts produced by this project!!!
File current = new File(project.getBuild().getDirectory(), project.getBuild().getFinalName() + ".jar");
if (current.exists() && !bundles.contains(current)) {
bundles.add(current);
}
}
if (bundlesInputParameter != null) {
bundles.addAll(bundlesInputParameter);
}
return new FileSetRepository(name, bundles);
}
use of org.eclipse.aether.resolution.ArtifactResult in project bnd by bndtools.
the class DependencyResolver method discoverArtifacts.
private void discoverArtifacts(Map<File, ArtifactResult> files, List<DependencyNode> nodes, String parent, List<RemoteRepository> remoteRepositories) throws MojoExecutionException {
for (DependencyNode node : nodes) {
// Ensure that the file is downloaded so we can index it
try {
ArtifactResult resolvedArtifact = postProcessor.postProcessResult(system.resolveArtifact(session, new ArtifactRequest(node.getArtifact(), remoteRepositories, parent)));
logger.debug("Located file: {} for artifact {}", resolvedArtifact.getArtifact().getFile(), resolvedArtifact);
files.put(resolvedArtifact.getArtifact().getFile(), resolvedArtifact);
} catch (ArtifactResolutionException e) {
throw new MojoExecutionException("Failed to resolve the dependency " + node.getArtifact().toString(), e);
}
if (includeTransitive) {
discoverArtifacts(files, node.getChildren(), node.getRequestContext(), remoteRepositories);
} else {
logger.debug("Ignoring transitive dependencies of {}", node.getDependency());
}
}
}
Aggregations