mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 00:17:11 -07:00
Fix the zip task.
This commit is contained in:
parent
91260d2f57
commit
2b3fc7a2c9
2 changed files with 14 additions and 6 deletions
|
@ -3,28 +3,33 @@ package com.beust.kobalt.archive
|
|||
import com.beust.kobalt.Glob
|
||||
import com.beust.kobalt.misc.KFiles
|
||||
import org.apache.commons.compress.archivers.ArchiveEntry
|
||||
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry
|
||||
import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream
|
||||
import java.io.Closeable
|
||||
import java.io.File
|
||||
import java.io.FileInputStream
|
||||
import java.io.FileOutputStream
|
||||
import java.nio.file.Files
|
||||
import java.util.jar.Manifest
|
||||
import org.apache.commons.compress.archivers.zip.ZipFile as ApacheZipFile
|
||||
|
||||
/**
|
||||
* Abstraction of a zip/jar/war archive that automatically manages the addition of expanded jar files.
|
||||
* Uses ZipArchiveOutputStream for fast inclusion of expanded jar files.
|
||||
*/
|
||||
class MetaArchive(outputFile: File, val manifest: java.util.jar.Manifest?) : Closeable {
|
||||
class MetaArchive(outputFile: File, val manifest: Manifest?) : Closeable {
|
||||
private val zos = ZipArchiveOutputStream(outputFile).apply {
|
||||
encoding = "UTF-8"
|
||||
}
|
||||
|
||||
fun addFile(file: File, path: String) {
|
||||
fun addFile(f: File, entryFile: File, path: String?) {
|
||||
val file = f.normalize()
|
||||
FileInputStream(file).use { inputStream ->
|
||||
val entry = zos.createArchiveEntry(file, path)
|
||||
maybeAddEntry(entry) {
|
||||
addEntry(entry, inputStream)
|
||||
val actualPath = if (path != null) path + entryFile.path else entryFile.path
|
||||
ZipArchiveEntry(actualPath).let { entry ->
|
||||
maybeAddEntry(entry) {
|
||||
addEntry(entry, inputStream)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -55,7 +55,10 @@ class JarUtils {
|
|||
kobaltLog(2, " Writing contents of jar file $foundFile")
|
||||
metaArchive.addArchive(foundFile)
|
||||
} else {
|
||||
metaArchive.addFile(File(directory, fromFile.path), foundFile.path)
|
||||
val fp = foundFile.path
|
||||
val toPath = File(file.to).normalize().path
|
||||
val finalPath = if (toPath.isEmpty()) null else (toPath + "/")
|
||||
metaArchive.addFile(File(directory, fromFile.path), foundFile, finalPath)
|
||||
}
|
||||
} catch(ex: Exception) {
|
||||
onError(ex)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue