use of aQute.bnd.version.MavenVersion 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 aQute.bnd.version.MavenVersion in project bnd by bndtools.
the class MavenRepoTest method testBasic.
public void testBasic() throws Exception {
Program program = Program.valueOf("commons-cli", "commons-cli");
List<Revision> revisions = storage.getRevisions(program);
assertNotNull(revisions);
assertEquals(3, revisions.size());
Revision revision = program.version(new MavenVersion("1.4-SNAPSHOT"));
assertTrue(revisions.contains(revision));
List<Archive> snapshotArchives = storage.getSnapshotArchives(revision);
assertNotNull(snapshotArchives);
assertEquals(10, snapshotArchives.size());
Archive archive = storage.getResolvedArchive(revision, "pom", null);
assertNotNull(archive);
assertEquals("1.4-20160119.062305-9", archive.snapshot.toString());
File file = storage.get(archive).getValue();
assertNotNull(file);
assertEquals(10373L, file.length());
}
use of aQute.bnd.version.MavenVersion in project bnd by bndtools.
the class ArchiveTest method testValueOfWithExtensionAndClassifier.
public void testValueOfWithExtensionAndClassifier() {
Archive a = Archive.valueOf("a.b.c:def:ext:class:1.3");
assertEquals("a.b.c", a.revision.program.group);
assertEquals("def", a.revision.program.artifact);
assertEquals(new MavenVersion("1.3"), a.revision.version);
assertEquals("ext", a.extension);
assertEquals("class", a.classifier);
assertEquals("a/b/c/def/1.3/def-1.3-class.ext", a.localPath);
assertEquals("a/b/c/def/1.3/def-1.3-class.ext", a.remotePath);
}
use of aQute.bnd.version.MavenVersion in project bnd by bndtools.
the class ArchiveTest method testValueOfWithExtension.
public void testValueOfWithExtension() {
Archive a = Archive.valueOf("a.b.c:def:ext:1.3");
assertEquals("a.b.c", a.revision.program.group);
assertEquals("def", a.revision.program.artifact);
assertEquals(new MavenVersion("1.3"), a.revision.version);
assertEquals("ext", a.extension);
assertEquals("", a.classifier);
assertEquals("a/b/c/def/1.3/def-1.3.ext", a.localPath);
assertEquals("a/b/c/def/1.3/def-1.3.ext", a.remotePath);
}
use of aQute.bnd.version.MavenVersion in project bnd by bndtools.
the class ArchiveTest method testSnapshot.
public void testSnapshot() {
Archive a = Archive.valueOf("a.b.c:def:1.3-SNAPSHOT");
assertTrue(a.isSnapshot());
assertFalse(a.isResolved());
Archive resolveSnapshot = a.resolveSnapshot(new MavenVersion("123456789"));
assertTrue(resolveSnapshot.isSnapshot());
assertTrue(resolveSnapshot.isResolved());
assertEquals("a/b/c/def/1.3-SNAPSHOT/def-1.3-SNAPSHOT.jar", resolveSnapshot.localPath);
assertEquals("a/b/c/def/1.3-SNAPSHOT/def-123456789.jar", resolveSnapshot.remotePath);
}
Aggregations