mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 16:28:12 -07:00
fix NPEs
This commit is contained in:
parent
9d4aa26109
commit
252c0fce36
2 changed files with 14 additions and 13 deletions
|
@ -32,20 +32,22 @@ public class DepFactory @Inject constructor(val localRepo: LocalRepo,
|
||||||
return FileDependency(id.substring(FileDependency.PREFIX_FILE.length))
|
return FileDependency(id.substring(FileDependency.PREFIX_FILE.length))
|
||||||
} else {
|
} else {
|
||||||
val mavenId = MavenId.create(id)
|
val mavenId = MavenId.create(id)
|
||||||
|
var version = mavenId.version
|
||||||
var packaging = mavenId.packaging
|
var packaging = mavenId.packaging
|
||||||
var repoResult: RepoFinder.RepoResult?
|
var repoResult: RepoFinder.RepoResult?
|
||||||
|
|
||||||
val version = mavenId.version ?:
|
if (version == null || MavenId.isRangedVersion(version)) {
|
||||||
if (localFirst) {
|
var localVersion: String? = version
|
||||||
localRepo.findLocalVersion(mavenId.groupId, mavenId.artifactId, mavenId.packaging)
|
if (localFirst) localVersion = localRepo.findLocalVersion(mavenId.groupId, mavenId.artifactId, mavenId.packaging)
|
||||||
} else {
|
if (!localFirst || localVersion == null) {
|
||||||
repoResult = remoteRepo.findCorrectRepo(id)
|
repoResult = remoteRepo.findCorrectRepo(id)
|
||||||
if (!repoResult.found) {
|
if (!repoResult.found) {
|
||||||
throw KobaltException("Couldn't resolve $id")
|
throw KobaltException("Couldn't resolve $id")
|
||||||
} else {
|
} else {
|
||||||
repoResult.version?.version
|
version = repoResult.version?.version
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return MavenDependency(MavenId.create(mavenId.groupId, mavenId.artifactId, packaging, version),
|
return MavenDependency(MavenId.create(mavenId.groupId, mavenId.artifactId, packaging, version),
|
||||||
executor, localRepo, remoteRepo, pomFactory, downloadManager)
|
executor, localRepo, remoteRepo, pomFactory, downloadManager)
|
||||||
|
|
|
@ -27,7 +27,7 @@ public class DownloadTest @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun deleteDir(): Boolean {
|
private fun deleteDir(): Boolean {
|
||||||
val dir = File(localRepo.toFullPath("$groupId"))
|
val dir = File(localRepo.toFullPath(groupId))
|
||||||
val result = dir.deleteRecursively()
|
val result = dir.deleteRecursively()
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
@ -45,7 +45,7 @@ public class DownloadTest @Inject constructor(
|
||||||
Assert.assertTrue(file.exists())
|
Assert.assertTrue(file.exists())
|
||||||
}
|
}
|
||||||
} else {
|
} 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 future = dep.jarFile
|
||||||
val file = future.get()
|
val file = future.get()
|
||||||
Assert.assertFalse(future is CompletedFuture)
|
Assert.assertFalse(future is CompletedFuture)
|
||||||
Assert.assertEquals(file.name, jarFile)
|
Assert.assertNotNull(file)
|
||||||
Assert.assertTrue(file.exists())
|
Assert.assertTrue(file.exists())
|
||||||
} else {
|
} else {
|
||||||
warn("Couldn't delete directory, not running test \"shouldDownloadNoVersion\"")
|
warn("Couldn't delete directory, not running test \"shouldDownloadNoVersion\"")
|
||||||
|
@ -75,10 +75,9 @@ public class DownloadTest @Inject constructor(
|
||||||
@Test
|
@Test
|
||||||
public fun shouldDownloadRangedVersion() {
|
public fun shouldDownloadRangedVersion() {
|
||||||
File(localRepo.toFullPath("javax/servlet/servlet-api")).deleteRecursively()
|
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 dep = depFactory.create("javax.servlet:servlet-api:${range}", executor)
|
||||||
val future = dep.jarFile
|
val future = dep.jarFile
|
||||||
val file = future.get()
|
val file = future.get()
|
||||||
|
@ -103,8 +102,8 @@ public class DownloadTest @Inject constructor(
|
||||||
val dep = depFactory.create(idNoVersion, executor, localFirst = false)
|
val dep = depFactory.create(idNoVersion, executor, localFirst = false)
|
||||||
val future = dep.jarFile
|
val future = dep.jarFile
|
||||||
val file = future.get()
|
val file = future.get()
|
||||||
Assert.assertEquals(file.name, jarFile)
|
Assert.assertNotNull(file)
|
||||||
Assert.assertTrue(file.exists())
|
Assert.assertTrue(file.exists(), "Should find ${file}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue