use of org.eclipse.aether.artifact.Artifact in project pinpoint by naver.
the class DependencyResolver method getNewestVersion.
public String getNewestVersion(String groupId, String artifactId) throws VersionRangeResolutionException {
Artifact artifact = new DefaultArtifact(groupId, artifactId, "jar", "[0,)");
VersionRangeRequest rangeRequest = new VersionRangeRequest();
rangeRequest.setArtifact(artifact);
rangeRequest.setRepositories(repositories);
VersionRangeResult rangeResult = system.resolveVersionRange(session, rangeRequest);
Version newestVersion = rangeResult.getHighestVersion();
return newestVersion.toString();
}
use of org.eclipse.aether.artifact.Artifact in project pinpoint by naver.
the class DependencyResolver method resolveArtifactsAndDependencies.
public List<File> resolveArtifactsAndDependencies(List<Artifact> artifacts) throws ArtifactResolutionException, DependencyResolutionException {
List<Dependency> dependencies = new ArrayList<Dependency>();
for (Artifact artifact : artifacts) {
dependencies.add(new Dependency(artifact, JavaScopes.RUNTIME));
}
CollectRequest collectRequest = new CollectRequest((Dependency) null, dependencies, repositories);
DependencyFilter classpathFilter = DependencyFilterUtils.classpathFilter(JavaScopes.RUNTIME);
DependencyRequest dependencyRequest = new DependencyRequest(collectRequest, classpathFilter);
DependencyResult result = system.resolveDependencies(session, dependencyRequest);
List<File> files = new ArrayList<File>();
for (ArtifactResult artifactResult : result.getArtifactResults()) {
files.add(artifactResult.getArtifact().getFile());
}
return files;
}
use of org.eclipse.aether.artifact.Artifact in project pinpoint by naver.
the class DependencyResolver method combination.
private Map<String, List<Artifact>> combination(List<List<List<Artifact>>> groups) {
if (groups.size() == 1) {
Map<String, List<Artifact>> result = new HashMap<String, List<Artifact>>();
List<List<Artifact>> group = groups.get(0);
if (group.size() == 1) {
result.put("", group.get(0));
} else {
for (List<Artifact> aCase : group) {
Artifact representative = aCase.get(0);
result.put(representative.getArtifactId() + "-" + representative.getVersion(), aCase);
}
}
return result;
}
List<List<Artifact>> thisGroup = groups.get(0);
Map<String, List<Artifact>> sub = combination(groups.subList(1, groups.size()));
Map<String, List<Artifact>> result = new HashMap<String, List<Artifact>>();
if (thisGroup.size() == 1) {
List<Artifact> thisArtifacts = thisGroup.get(0);
for (Entry<String, List<Artifact>> subEntry : sub.entrySet()) {
List<Artifact> subArtifacts = subEntry.getValue();
List<Artifact> t = new ArrayList<Artifact>(thisArtifacts.size() + subArtifacts.size());
t.addAll(thisArtifacts);
t.addAll(subArtifacts);
result.put(subEntry.getKey(), t);
}
} else {
for (List<Artifact> thisArtifacts : thisGroup) {
Artifact representative = thisArtifacts.get(0);
String thisKey = representative.getArtifactId() + "-" + representative.getVersion();
for (Entry<String, List<Artifact>> subEntry : sub.entrySet()) {
List<Artifact> subArtifacts = subEntry.getValue();
List<Artifact> t = new ArrayList<Artifact>(thisArtifacts.size() + subArtifacts.size());
t.addAll(thisArtifacts);
t.addAll(subArtifacts);
String subKey = subEntry.getKey();
String key = subKey.isEmpty() ? thisKey : thisKey + ", " + subKey;
result.put(key, t);
}
}
}
return result;
}
use of org.eclipse.aether.artifact.Artifact in project karaf by apache.
the class Dependency31Helper method artifactToMvn.
@Override
public String artifactToMvn(Object _artifact, String versionOrRange) {
Artifact artifact = (Artifact) _artifact;
String bundleName;
if (artifact.getExtension().equals("jar") && MavenUtil.isEmpty(artifact.getClassifier())) {
bundleName = String.format("mvn:%s/%s/%s", artifact.getGroupId(), artifact.getArtifactId(), versionOrRange);
} else {
if (MavenUtil.isEmpty(artifact.getClassifier())) {
bundleName = String.format("mvn:%s/%s/%s/%s", artifact.getGroupId(), artifact.getArtifactId(), versionOrRange, artifact.getExtension());
} else {
bundleName = String.format("mvn:%s/%s/%s/%s/%s", artifact.getGroupId(), artifact.getArtifactId(), versionOrRange, artifact.getExtension(), artifact.getClassifier());
}
}
return bundleName;
}
use of org.eclipse.aether.artifact.Artifact in project bnd by bndtools.
the class AetherRepository method put.
@Override
public PutResult put(InputStream stream, PutOptions options) throws Exception {
init();
DigestInputStream digestStream = new DigestInputStream(stream, MessageDigest.getInstance("SHA-1"));
final File tmpFile = IO.createTempFile(cacheDir, "put", ".bnd");
try {
IO.copy(digestStream, tmpFile);
byte[] digest = digestStream.getMessageDigest().digest();
if (options.digest != null && !Arrays.equals(options.digest, digest))
throw new IOException("Retrieved artifact digest doesn't match specified digest");
// Get basic info about the bundle we're deploying
Jar jar = new Jar(tmpFile);
Artifact artifact = ConversionUtils.fromBundleJar(jar);
artifact = artifact.setFile(tmpFile);
// Setup the Aether repo session and create the deployment request
DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();
session.setLocalRepositoryManager(repoSystem.newLocalRepositoryManager(session, localRepo));
final DeployRequest request = new DeployRequest();
request.addArtifact(artifact);
request.setRepository(remoteRepo);
// Capture the result including remote resource URI
final ResultHolder resultHolder = new ResultHolder();
session.setTransferListener(new AbstractTransferListener() {
@Override
public void transferSucceeded(TransferEvent event) {
TransferResource resource = event.getResource();
if (event.getRequestType() == RequestType.PUT && tmpFile.equals(resource.getFile())) {
PutResult result = new PutResult();
result.artifact = URI.create(resource.getRepositoryUrl() + resource.getResourceName());
resultHolder.result = result;
System.out.println("UPLOADED to: " + URI.create(resource.getRepositoryUrl() + resource.getResourceName()));
}
}
@Override
public void transferFailed(TransferEvent event) {
if (event.getRequestType() == RequestType.PUT && tmpFile.equals(event.getResource().getFile()))
resultHolder.error = event.getException();
}
@Override
public void transferCorrupted(TransferEvent event) throws TransferCancelledException {
if (event.getRequestType() == RequestType.PUT && tmpFile.equals(event.getResource().getFile()))
resultHolder.error = event.getException();
}
});
// Do the deploy and report results
repoSystem.deploy(session, request);
if (resultHolder.result != null) {
if (indexedRepo != null)
indexedRepo.reset();
return resultHolder.result;
} else if (resultHolder.error != null) {
throw new Exception("Error during artifact upload", resultHolder.error);
} else {
throw new Exception("Artifact was not uploaded");
}
} finally {
if (tmpFile != null && tmpFile.isFile())
IO.delete(tmpFile);
}
}
Aggregations