Last active
October 13, 2015 04:31
-
-
Save jkschneider/d1fdd0b96d5e71a8a282 to your computer and use it in GitHub Desktop.
Grab control file info and war dependencies from a debian file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.netflix.debian | |
import org.apache.commons.compress.archivers.* | |
import org.apache.commons.compress.compressors.CompressorStreamFactory | |
import java.io.* | |
fun main(args: Array<String>) { | |
val libPattern = "WEB-INF/lib/(.+)\\.jar".toRegex() | |
FileInputStream("pisces.deb").archiveStream { entry, debIn -> | |
when (entry.name) { | |
"control.tar.gz" -> | |
debIn.unzippedEntry().archiveStream { controlEntry, controlIn -> | |
if (controlEntry.name == "./control") { | |
controlIn.reader().readText().splitToSequence("\n").forEach { println(it) } | |
} | |
} | |
"data.tar.gz" -> | |
debIn.unzippedEntry().archiveStream { dataEntry, dataIn -> | |
if (dataEntry.name.matches("./apps/tomcat/webapps/.+\\.war".toRegex())) { | |
dataIn.archiveStream { warEntry, warIn -> | |
val jar = libPattern.match(warEntry.name)?.groups?.get(1)?.value | |
if (jar is String) { | |
println(jar) | |
} | |
} | |
} | |
} | |
} | |
}.close() | |
} | |
fun InputStream.unzippedEntry() = CompressorStreamFactory().createCompressorInputStream(BufferedInputStream(this)) | |
fun InputStream.archiveStream(archivePredicate: (ArchiveEntry, InputStream) -> Unit): InputStream { | |
val buffered = buffered() | |
val arIn = ArchiveStreamFactory().createArchiveInputStream(buffered) | |
while (true) { | |
val arEntry = arIn.nextEntry ?: break | |
archivePredicate.invoke(arEntry, arIn) | |
} | |
return buffered | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Makes some assumptions about the location of the war, but you get the idea... Extension functions are amazing to take a really unfriendly library like commons-compress and make it functional-like.