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,31 +3,36 @@ package com.beust.kobalt.archive
|
||||||
import com.beust.kobalt.Glob
|
import com.beust.kobalt.Glob
|
||||||
import com.beust.kobalt.misc.KFiles
|
import com.beust.kobalt.misc.KFiles
|
||||||
import org.apache.commons.compress.archivers.ArchiveEntry
|
import org.apache.commons.compress.archivers.ArchiveEntry
|
||||||
|
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry
|
||||||
import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream
|
import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream
|
||||||
import java.io.Closeable
|
import java.io.Closeable
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.FileInputStream
|
import java.io.FileInputStream
|
||||||
import java.io.FileOutputStream
|
import java.io.FileOutputStream
|
||||||
import java.nio.file.Files
|
import java.nio.file.Files
|
||||||
|
import java.util.jar.Manifest
|
||||||
import org.apache.commons.compress.archivers.zip.ZipFile as ApacheZipFile
|
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.
|
* 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.
|
* 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 {
|
private val zos = ZipArchiveOutputStream(outputFile).apply {
|
||||||
encoding = "UTF-8"
|
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 ->
|
FileInputStream(file).use { inputStream ->
|
||||||
val entry = zos.createArchiveEntry(file, path)
|
val actualPath = if (path != null) path + entryFile.path else entryFile.path
|
||||||
|
ZipArchiveEntry(actualPath).let { entry ->
|
||||||
maybeAddEntry(entry) {
|
maybeAddEntry(entry) {
|
||||||
addEntry(entry, inputStream)
|
addEntry(entry, inputStream)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun addArchive(jarFile: File) {
|
fun addArchive(jarFile: File) {
|
||||||
ApacheZipFile(jarFile).use { jar ->
|
ApacheZipFile(jarFile).use { jar ->
|
||||||
|
|
|
@ -55,7 +55,10 @@ class JarUtils {
|
||||||
kobaltLog(2, " Writing contents of jar file $foundFile")
|
kobaltLog(2, " Writing contents of jar file $foundFile")
|
||||||
metaArchive.addArchive(foundFile)
|
metaArchive.addArchive(foundFile)
|
||||||
} else {
|
} 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) {
|
} catch(ex: Exception) {
|
||||||
onError(ex)
|
onError(ex)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue