Search in sources :

Example 11 with MavenVersion

use of aQute.bnd.version.MavenVersion in project bnd by bndtools.

the class MavenVersionTest method testQualifierWithoutSeparator.

public void testQualifierWithoutSeparator() {
    MavenVersion mv = MavenVersion.parseString("1.2.3rc1");
    assertEquals(new Version(1, 2, 3, "rc1"), mv.getOSGiVersion());
    assertFalse(mv.isSnapshot());
    mv = MavenVersion.parseString("1.2rc1");
    assertEquals(new Version(1, 2, 0, "rc1"), mv.getOSGiVersion());
    assertFalse(mv.isSnapshot());
    mv = MavenVersion.parseString("1rc1");
    assertEquals(new Version(1, 0, 0, "rc1"), mv.getOSGiVersion());
    assertFalse(mv.isSnapshot());
}
Also used : MavenVersion(aQute.bnd.version.MavenVersion) Version(aQute.bnd.version.Version) MavenVersion(aQute.bnd.version.MavenVersion)

Example 12 with MavenVersion

use of aQute.bnd.version.MavenVersion in project bnd by bndtools.

the class MavenVersionTest method testQualifierWithDashSeparator.

public void testQualifierWithDashSeparator() {
    MavenVersion mv = MavenVersion.parseString("1.2.3-beta-1");
    assertEquals(new Version(1, 2, 3, "beta-1"), mv.getOSGiVersion());
    assertFalse(mv.isSnapshot());
}
Also used : MavenVersion(aQute.bnd.version.MavenVersion) Version(aQute.bnd.version.Version) MavenVersion(aQute.bnd.version.MavenVersion)

Example 13 with MavenVersion

use of aQute.bnd.version.MavenVersion in project bnd by bndtools.

the class Macro method version.

String version(Version version, String mask) {
    if (version == null) {
        String v = domain.getProperty("@");
        if (v == null) {
            return LITERALVALUE;
        }
        version = new Version(v);
    }
    StringBuilder sb = new StringBuilder();
    String del = "";
    for (int i = 0; i < mask.length(); i++) {
        char c = mask.charAt(i);
        String result = null;
        if (c != '~') {
            if (i == 3) {
                result = version.getQualifier();
                MavenVersion mv = new MavenVersion(version);
                if (c == 'S') {
                    // we have a request for a Maven snapshot
                    if (mv.isSnapshot())
                        return sb.append("-SNAPSHOT").toString();
                } else if (c == 's') {
                    // we have a request for a Maven snapshot
                    if (mv.isSnapshot())
                        return sb.append("-SNAPSHOT").toString();
                    else
                        return sb.toString();
                }
            } else if (Character.isDigit(c)) {
                // Handle masks like +00, =+0
                result = String.valueOf(c);
            } else {
                int x = version.get(i);
                switch(c) {
                    case '+':
                        x++;
                        break;
                    case '-':
                        x--;
                        break;
                    case '=':
                        break;
                }
                result = Integer.toString(x);
            }
            if (result != null) {
                sb.append(del);
                del = ".";
                sb.append(result);
            }
        }
    }
    return sb.toString();
}
Also used : MavenVersion(aQute.bnd.version.MavenVersion) Version(aQute.bnd.version.Version) MavenVersion(aQute.bnd.version.MavenVersion)

Example 14 with MavenVersion

use of aQute.bnd.version.MavenVersion in project bnd by bndtools.

the class ConversionUtils method fromBundleJar.

public static final Artifact fromBundleJar(Jar jar) throws Exception {
    String groupId;
    String artifactId;
    String bsn = jar.getBsn();
    groupId = jar.getManifest().getMainAttributes().getValue("Maven-GroupId");
    if (groupId != null) {
        String groupPrefix = groupId + ".";
        if (bsn.startsWith(groupPrefix)) {
            if (bsn.length() <= groupPrefix.length())
                throw new IllegalArgumentException("Artifact ID appears to be empty");
            artifactId = bsn.substring(groupPrefix.length());
        } else {
            artifactId = bsn;
        }
    } else {
        int lastDot = bsn.lastIndexOf('.');
        if (lastDot < 0)
            throw new IllegalArgumentException(String.format("Cannot split symbolic name '%s' into group ID and artifact ID", bsn));
        if (lastDot == 0)
            throw new IllegalArgumentException("Group ID appears to be empty");
        if (lastDot >= bsn.length() - 1)
            throw new IllegalArgumentException("Artifact ID appear to be empty");
        groupId = bsn.substring(0, lastDot);
        artifactId = bsn.substring(lastDot + 1);
    }
    String versionString = jar.getVersion();
    if (versionString == null)
        versionString = "0";
    else if (!Verifier.isVersion(versionString))
        throw new IllegalArgumentException("Invalid version " + versionString);
    Version version = Version.parseVersion(versionString);
    return new DefaultArtifact(groupId, artifactId, JAR_EXTENSION, new MavenVersion(version).toString());
}
Also used : MavenVersion(aQute.bnd.version.MavenVersion) Version(aQute.bnd.version.Version) MavenVersion(aQute.bnd.version.MavenVersion) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact)

Example 15 with MavenVersion

use of aQute.bnd.version.MavenVersion in project bnd by bndtools.

the class MetadataTest method testProgramParsing.

public void testProgramParsing() throws Exception {
    try (InputStream in = new FileInputStream(IO.getFile("testresources/parser/commons-dbcp.xml"))) {
        ProgramMetadata parse = MetadataParser.parseProgramMetadata(in);
        assertNotNull(parse);
        assertEquals("commons.dbcp", parse.group);
        assertEquals("commons-dbcp", parse.artifact);
        assertEquals(2, parse.versions.size());
        assertTrue(parse.versions.contains(new MavenVersion("1.4.1-SNAPSHOT")));
        assertTrue(parse.versions.contains(new MavenVersion("1.5-SNAPSHOT")));
    }
}
Also used : MavenVersion(aQute.bnd.version.MavenVersion) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ProgramMetadata(aQute.maven.provider.MetadataParser.ProgramMetadata) FileInputStream(java.io.FileInputStream)

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