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());
}
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());
}
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();
}
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());
}
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")));
}
}
Aggregations