mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 08:27:12 -07:00
Better zip test.
This commit is contained in:
parent
152ed057b4
commit
2f840a44fd
1 changed files with 32 additions and 3 deletions
|
@ -4,11 +4,18 @@ import com.beust.kobalt.api.Kobalt
|
|||
import com.beust.kobalt.misc.KFiles
|
||||
import com.beust.kobalt.misc.log
|
||||
import org.testng.annotations.Test
|
||||
import java.io.File
|
||||
import java.io.FileInputStream
|
||||
import java.io.InputStream
|
||||
import java.util.jar.JarFile
|
||||
import java.util.jar.JarInputStream
|
||||
|
||||
class VerifyKobaltZipTest : KobaltTest() {
|
||||
@Test
|
||||
fun verifySourceJarFile() {
|
||||
assertExistsInJar("kobalt-" + Kobalt.version + "-sources.jar", "com/beust/kobalt/Main.kt")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun verifyZipFile() {
|
||||
var success = true
|
||||
|
@ -16,7 +23,7 @@ class VerifyKobaltZipTest : KobaltTest() {
|
|||
var foundJar = false
|
||||
var foundWrapperJar = false
|
||||
|
||||
val jarFilePath = "kobalt-" + Kobalt.version + ".jar"
|
||||
val mainJarFilePath = "kobalt-" + Kobalt.version + ".jar"
|
||||
val zipFilePath = KFiles.joinDir("kobaltBuild", "libs", "kobalt-" + Kobalt.version + ".zip")
|
||||
val zipFile = JarFile(zipFilePath)
|
||||
val stream = JarInputStream(FileInputStream(zipFilePath))
|
||||
|
@ -24,11 +31,12 @@ class VerifyKobaltZipTest : KobaltTest() {
|
|||
while (entry != null) {
|
||||
if (entry.name == "kobaltw") {
|
||||
foundKobaltw = true
|
||||
} else if (entry.name.endsWith(jarFilePath)) {
|
||||
} else if (entry.name.endsWith(mainJarFilePath)) {
|
||||
val ins = zipFile.getInputStream(entry)
|
||||
if (ins.available() < 20000000) {
|
||||
throw KobaltException(jarFilePath + " is too small: " + jarFilePath)
|
||||
throw KobaltException(mainJarFilePath + " is too small: " + mainJarFilePath)
|
||||
}
|
||||
verifyMainJarFile(ins)
|
||||
foundJar = true
|
||||
} else if (entry.name.endsWith("kobalt-wrapper.jar")) {
|
||||
foundWrapperJar = true
|
||||
|
@ -51,4 +59,25 @@ class VerifyKobaltZipTest : KobaltTest() {
|
|||
}
|
||||
log(1, "$zipFilePath looks correct")
|
||||
}
|
||||
|
||||
private fun assertExistsInJar(jarName: String, fileName: String) {
|
||||
val sourceJarPath = KFiles.joinDir("kobaltBuild", "libs", jarName)
|
||||
assertExistsInJar(JarInputStream(FileInputStream(File(sourceJarPath))), fileName)
|
||||
}
|
||||
|
||||
private fun assertExistsInJar(stream: JarInputStream, fileName: String) {
|
||||
var entry = stream.nextEntry
|
||||
var found = false
|
||||
while (entry != null) {
|
||||
if (entry.name == fileName) found = true
|
||||
entry = stream.nextEntry
|
||||
}
|
||||
if (! found) {
|
||||
throw AssertionError("Couldn't find Main.kt in $fileName")
|
||||
}
|
||||
}
|
||||
|
||||
private fun verifyMainJarFile(ins: InputStream) {
|
||||
assertExistsInJar(JarInputStream(ins), "com/beust/kobalt/MainKt.class")
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue