Search in sources :

Example 1 with MavenVersion

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");
        }
    }
}
Also used : AbstractTransferListener(org.eclipse.aether.transfer.AbstractTransferListener) TransferCancelledException(org.eclipse.aether.transfer.TransferCancelledException) TransferEvent(org.eclipse.aether.transfer.TransferEvent) Artifact(org.eclipse.aether.artifact.Artifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) MavenVersion(aQute.bnd.version.MavenVersion) ArtifactRequest(org.eclipse.aether.resolution.ArtifactRequest) DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession) File(java.io.File) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact)

Example 2 with MavenVersion

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());
}
Also used : MavenVersion(aQute.bnd.version.MavenVersion) Program(aQute.maven.api.Program) Archive(aQute.maven.api.Archive) Revision(aQute.maven.api.Revision) File(java.io.File)

Example 3 with MavenVersion

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);
}
Also used : MavenVersion(aQute.bnd.version.MavenVersion)

Example 4 with MavenVersion

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);
}
Also used : MavenVersion(aQute.bnd.version.MavenVersion)

Example 5 with MavenVersion

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);
}
Also used : MavenVersion(aQute.bnd.version.MavenVersion)

Aggregations

MavenVersion (aQute.bnd.version.MavenVersion)21 Version (aQute.bnd.version.Version)13 File (java.io.File)2 DefaultArtifact (org.eclipse.aether.artifact.DefaultArtifact)2 Archive (aQute.maven.api.Archive)1 Program (aQute.maven.api.Program)1 Revision (aQute.maven.api.Revision)1 ProgramMetadata (aQute.maven.provider.MetadataParser.ProgramMetadata)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 DefaultRepositorySystemSession (org.eclipse.aether.DefaultRepositorySystemSession)1 Artifact (org.eclipse.aether.artifact.Artifact)1 ArtifactRequest (org.eclipse.aether.resolution.ArtifactRequest)1 ArtifactResolutionException (org.eclipse.aether.resolution.ArtifactResolutionException)1 ArtifactResult (org.eclipse.aether.resolution.ArtifactResult)1 AbstractTransferListener (org.eclipse.aether.transfer.AbstractTransferListener)1 TransferCancelledException (org.eclipse.aether.transfer.TransferCancelledException)1 TransferEvent (org.eclipse.aether.transfer.TransferEvent)1