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

Fix expandJarFiles.

This commit is contained in:
Cedric Beust 2016-02-18 02:25:35 +04:00
parent e015253f2d
commit 26fbf6164d
3 changed files with 25 additions and 17 deletions

View file

@ -65,7 +65,7 @@ public class JarUtils {
val includedFile = IncludedFile(From(foundFile.path), To(""), listOf(IFileSpec.GlobSpec("**")))
addSingleFile(".", includedFile, outputStream, expandJarFiles)
} else {
if (expandJarFiles && foundFile.name.endsWith(".jar") && ! foundFile.path.contains("resources")) {
if (file.expandJarFiles && foundFile.name.endsWith(".jar") && ! file.from.contains("resources")) {
log(2, "Writing contents of jar file $foundFile")
val stream = JarInputStream(FileInputStream(localFile))
var entry = stream.nextEntry
@ -154,8 +154,9 @@ open class Direction(open val p: String) {
else p + "/"
}
class IncludedFile(val fromOriginal: From, val toOriginal: To, val specs: List<IFileSpec>) {
constructor(specs: List<IFileSpec>) : this(From(""), To(""), specs)
class IncludedFile(val fromOriginal: From, val toOriginal: To, val specs: List<IFileSpec>,
val expandJarFiles: Boolean = false) {
constructor(specs: List<IFileSpec>, expandJarFiles: Boolean = false) : this(From(""), To(""), specs, expandJarFiles)
fun from(s: String) = File(if (fromOriginal.isCurrentDir()) s else KFiles.joinDir(from, s))
val from: String get() = fromOriginal.path.replace("\\", "/")
fun to(s: String) = File(if (toOriginal.isCurrentDir()) s else KFiles.joinDir(to, s))

View file

@ -70,7 +70,8 @@ class JarGenerator @Inject constructor(val dependencyManager: DependencyManager)
if (! seen.contains(file.path)) {
seen.add(file.path)
if (! KFiles.isExcluded(file, jar.excludes)) {
result.add(IncludedFile(arrayListOf(IFileSpec.FileSpec(file.path))))
result.add(IncludedFile(specs = arrayListOf(IFileSpec.FileSpec(file.path)),
expandJarFiles = true))
}
}
}

View file

@ -3,6 +3,7 @@ package com.beust.kobalt
import com.beust.kobalt.api.Kobalt
import com.beust.kobalt.misc.KFiles
import com.beust.kobalt.misc.log
import org.testng.Assert
import org.testng.annotations.Test
import java.io.File
import java.io.FileInputStream
@ -11,6 +12,9 @@ import java.util.jar.JarFile
import java.util.jar.JarInputStream
class VerifyKobaltZipTest : KobaltTest() {
private fun verifyMainJarFile(ins: InputStream) {
assertExistsInJarInputStream(JarInputStream(ins), "com/beust/kobalt/MainKt.class", "templates/plugin.jar")
}
@Test
fun verifySourceJarFile() {
assertExistsInJar("kobalt-" + Kobalt.version + "-sources.jar", "com/beust/kobalt/Main.kt")
@ -60,24 +64,26 @@ 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 assertExistsInJarInputStream(ins: JarInputStream, vararg fileNames: String) {
with(jarContents(ins)) {
fileNames.forEach { fileName ->
Assert.assertTrue(contains(fileName), "Couldn't find $fileName")
}
}
}
private fun assertExistsInJar(stream: JarInputStream, fileName: String) {
private fun assertExistsInJar(jarName: String, vararg fileNames: String) {
val sourceJarPath = KFiles.joinDir("kobaltBuild", "libs", jarName)
assertExistsInJarInputStream(JarInputStream(FileInputStream(File(sourceJarPath))), *fileNames)
}
private fun jarContents(stream: JarInputStream) : Set<String> {
val result = hashSetOf<String>()
var entry = stream.nextEntry
var found = false
while (entry != null) {
if (entry.name == fileName) found = true
result.add(entry.name)
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")
return result
}
}