diff --git a/src/main/kotlin/com/beust/kobalt/maven/DepFactory.kt b/src/main/kotlin/com/beust/kobalt/maven/DepFactory.kt index df443d60..7896b652 100644 --- a/src/main/kotlin/com/beust/kobalt/maven/DepFactory.kt +++ b/src/main/kotlin/com/beust/kobalt/maven/DepFactory.kt @@ -32,20 +32,22 @@ public class DepFactory @Inject constructor(val localRepo: LocalRepo, return FileDependency(id.substring(FileDependency.PREFIX_FILE.length)) } else { val mavenId = MavenId.create(id) + var version = mavenId.version var packaging = mavenId.packaging var repoResult: RepoFinder.RepoResult? - val version = mavenId.version ?: - if (localFirst) { - localRepo.findLocalVersion(mavenId.groupId, mavenId.artifactId, mavenId.packaging) - } else { + if (version == null || MavenId.isRangedVersion(version)) { + var localVersion: String? = version + if (localFirst) localVersion = localRepo.findLocalVersion(mavenId.groupId, mavenId.artifactId, mavenId.packaging) + if (!localFirst || localVersion == null) { repoResult = remoteRepo.findCorrectRepo(id) if (!repoResult.found) { throw KobaltException("Couldn't resolve $id") } else { - repoResult.version?.version + version = repoResult.version?.version } } + } return MavenDependency(MavenId.create(mavenId.groupId, mavenId.artifactId, packaging, version), executor, localRepo, remoteRepo, pomFactory, downloadManager) diff --git a/src/test/kotlin/com/beust/kobalt/maven/DownloadTest.kt b/src/test/kotlin/com/beust/kobalt/maven/DownloadTest.kt index 4748815c..c6bc996f 100644 --- a/src/test/kotlin/com/beust/kobalt/maven/DownloadTest.kt +++ b/src/test/kotlin/com/beust/kobalt/maven/DownloadTest.kt @@ -27,7 +27,7 @@ public class DownloadTest @Inject constructor( } private fun deleteDir(): Boolean { - val dir = File(localRepo.toFullPath("$groupId")) + val dir = File(localRepo.toFullPath(groupId)) val result = dir.deleteRecursively() return result } @@ -45,7 +45,7 @@ public class DownloadTest @Inject constructor( Assert.assertTrue(file.exists()) } } else { - warn("Couldn't delete directory, not running test \"shouldDownloadNoVersion\"") + warn("Couldn't delete directory, not running test \"shouldDownloadWithVersion\"") } } @@ -65,7 +65,7 @@ public class DownloadTest @Inject constructor( val future = dep.jarFile val file = future.get() Assert.assertFalse(future is CompletedFuture) - Assert.assertEquals(file.name, jarFile) + Assert.assertNotNull(file) Assert.assertTrue(file.exists()) } else { warn("Couldn't delete directory, not running test \"shouldDownloadNoVersion\"") @@ -75,10 +75,9 @@ public class DownloadTest @Inject constructor( @Test public fun shouldDownloadRangedVersion() { File(localRepo.toFullPath("javax/servlet/servlet-api")).deleteRecursively() - testRange("[2.5,)", "3.0-alpha-1") - } + val range = "[2.5,)" + val expected = "3.0-alpha-1" - private fun testRange(range: String, expected: String) { val dep = depFactory.create("javax.servlet:servlet-api:${range}", executor) val future = dep.jarFile val file = future.get() @@ -103,8 +102,8 @@ public class DownloadTest @Inject constructor( val dep = depFactory.create(idNoVersion, executor, localFirst = false) val future = dep.jarFile val file = future.get() - Assert.assertEquals(file.name, jarFile) - Assert.assertTrue(file.exists()) + Assert.assertNotNull(file) + Assert.assertTrue(file.exists(), "Should find ${file}") } }