mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-25 07:57:12 -07:00
Add MANIFEST.MF at the top of the jar file
This commit is contained in:
parent
7a2c4f34da
commit
52f5ceb3d6
2 changed files with 18 additions and 19 deletions
|
@ -17,15 +17,29 @@ 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: Manifest?) : Closeable {
|
||||
class MetaArchive(private val outputFile: File, val manifest: Manifest?) : Closeable {
|
||||
companion object {
|
||||
val MANIFEST_MF = "META-INF/MANIFEST.MF"
|
||||
}
|
||||
|
||||
private val zos = ZipArchiveOutputStream(outputFile).apply {
|
||||
private val zos= ZipArchiveOutputStream(outputFile).apply {
|
||||
encoding = "UTF-8"
|
||||
}
|
||||
|
||||
init {
|
||||
// If no manifest was passed, create an empty one so it's the first one in the archive
|
||||
val m = manifest ?: Manifest()
|
||||
Files.createTempFile("kobalt", "tmpManifest").toFile().let { manifestFile ->
|
||||
FileOutputStream(manifestFile).use { fos ->
|
||||
m.write(fos)
|
||||
}
|
||||
|
||||
val entry = zos.createArchiveEntry(manifestFile, MetaArchive.MANIFEST_MF)
|
||||
addEntry(entry, FileInputStream(manifestFile))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fun addFile(f: File, entryFile: File, path: String?) {
|
||||
val file = f.normalize()
|
||||
FileInputStream(file).use { inputStream ->
|
||||
|
@ -57,19 +71,7 @@ class MetaArchive(outputFile: File, val manifest: Manifest?) : Closeable {
|
|||
private fun okToAdd(name: String): Boolean = ! seen.contains(name)
|
||||
&& ! KFiles.isExcluded(name, DEFAULT_JAR_EXCLUDES)
|
||||
|
||||
override fun close() {
|
||||
if (manifest != null) {
|
||||
Files.createTempFile("aaa", "bbb").toFile().let { manifestFile ->
|
||||
FileOutputStream(manifestFile).use { fos ->
|
||||
manifest.write(fos)
|
||||
}
|
||||
|
||||
val entry = zos.createArchiveEntry(manifestFile, MetaArchive.MANIFEST_MF)
|
||||
addEntry(entry, FileInputStream(manifestFile))
|
||||
}
|
||||
}
|
||||
zos.close()
|
||||
}
|
||||
override fun close() = zos.close()
|
||||
|
||||
private fun addEntry(entry: ArchiveEntry, inputStream: FileInputStream) {
|
||||
zos.putArchiveEntry(entry)
|
||||
|
|
|
@ -90,10 +90,7 @@ class OsgiPlugin @Inject constructor(val configActor: ConfigActor<OsgiConfig>, v
|
|||
val fileSystem = FileSystems.newFileSystem(toFile, null)
|
||||
fileSystem.use { fs ->
|
||||
JarFile(jarFile).use { jf ->
|
||||
val mf = jf.getEntry(MetaArchive.MANIFEST_MF)
|
||||
if (mf == null) {
|
||||
Files.createDirectories(fs.getPath("META-INF/"))
|
||||
}
|
||||
val mf = jf.getEntry(MetaArchive.MANIFEST_MF) ?: Files.createDirectories(fs.getPath("META-INF/"))
|
||||
val jarManifest = fs.getPath(MetaArchive.MANIFEST_MF)
|
||||
Files.write(jarManifest, listOf(lines2),
|
||||
if (mf != null) StandardOpenOption.APPEND else StandardOpenOption.CREATE)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue