diff --git a/src/main/kotlin/com/beust/kobalt/maven/MavenId.kt b/src/main/kotlin/com/beust/kobalt/maven/MavenId.kt index ec2fa733..41216b21 100644 --- a/src/main/kotlin/com/beust/kobalt/maven/MavenId.kt +++ b/src/main/kotlin/com/beust/kobalt/maven/MavenId.kt @@ -23,10 +23,18 @@ public class MavenId(val id: String) { } groupId = c[0] artifactId = c[1] - packaging = if (c.size == 4) c[2] else null - version = if (c.size == 4) c[3] else if (c.size == 3 && ! c[2].isBlank()) c[2] else null + if (! c[2].isEmpty()) { + if (isVersion(c[2])) { + version = c[2] + } else { + packaging = c[2] + version = c[3] + } + } } + private fun isVersion(s: String) : Boolean = Character.isDigit(s.get(0)) + val hasVersion = version != null val toId = MavenId.toId(groupId, artifactId, packaging, version) diff --git a/src/test/kotlin/com/beust/kobalt/maven/MavenIdTest.kt b/src/test/kotlin/com/beust/kobalt/maven/MavenIdTest.kt new file mode 100644 index 00000000..fcc4999e --- /dev/null +++ b/src/test/kotlin/com/beust/kobalt/maven/MavenIdTest.kt @@ -0,0 +1,33 @@ +package com.beust.kobalt.maven + +import org.testng.Assert +import org.testng.annotations.DataProvider +import org.testng.annotations.Test + +@Test +class MavenIdTest { + @DataProvider + fun dp() : Array> { + return arrayOf( + arrayOf("javax.inject:javax.inject:", "javax.inject", "javax.inject", null, null, null), + arrayOf("org.jetbrains.kotlin:kotlin-compiler-embeddable:1.0.0-beta-1038", + "org.jetbrains.kotlin", "kotlin-compiler-embeddable", "1.0.0-beta-1038", + null, null), + arrayOf("com.google.inject:guice:4.0:no_aop", + "com.google.inject", "guice", "4.0", null, "no_aop"), + arrayOf("com.android.support:appcompat-v7:aar:22.2.1", + "com.android.support", "appcompat-v7", "22.2.1", "aar", null) + ) + } + + @Test(dataProvider = "dp") + fun parseVersions(id: String, groupId: String, artifactId: String, version: String?, + packaging: String?, qualifier: String?) { + val mi = MavenId(id) + Assert.assertEquals(mi.groupId, groupId) + Assert.assertEquals(mi.artifactId, artifactId) + Assert.assertEquals(mi.version, version) + Assert.assertEquals(mi.packaging, packaging) +// Assert.assertEquals(mi.qualifier, qualifier) + } +} \ No newline at end of file