1
0
Fork 0
mirror of https://github.com/ethauvin/kobalt.git synced 2025-04-26 08:27:12 -07:00

MavenId fixes.

This commit is contained in:
Cedric Beust 2015-10-28 22:20:34 -07:00
parent e252a5386c
commit 54f9dde73d
2 changed files with 43 additions and 2 deletions

View file

@ -23,10 +23,18 @@ public class MavenId(val id: String) {
} }
groupId = c[0] groupId = c[0]
artifactId = c[1] artifactId = c[1]
packaging = if (c.size == 4) c[2] else null if (! c[2].isEmpty()) {
version = if (c.size == 4) c[3] else if (c.size == 3 && ! c[2].isBlank()) c[2] else null 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 hasVersion = version != null
val toId = MavenId.toId(groupId, artifactId, packaging, version) val toId = MavenId.toId(groupId, artifactId, packaging, version)

View file

@ -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<Array<out Any?>> {
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)
}
}