mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 08:27:12 -07:00
Refactor.
This commit is contained in:
parent
2bb8c32243
commit
953814982f
1 changed files with 10 additions and 13 deletions
|
@ -3,10 +3,7 @@ package com.beust.kobalt.api
|
||||||
import com.beust.kobalt.Args
|
import com.beust.kobalt.Args
|
||||||
import com.beust.kobalt.misc.KFiles
|
import com.beust.kobalt.misc.KFiles
|
||||||
import com.beust.kobalt.misc.kobaltLog
|
import com.beust.kobalt.misc.kobaltLog
|
||||||
import java.io.File
|
import java.io.*
|
||||||
import java.io.FileInputStream
|
|
||||||
import java.io.FileOutputStream
|
|
||||||
import java.io.IOException
|
|
||||||
import java.net.URL
|
import java.net.URL
|
||||||
import java.util.jar.JarInputStream
|
import java.util.jar.JarInputStream
|
||||||
|
|
||||||
|
@ -14,13 +11,14 @@ import java.util.jar.JarInputStream
|
||||||
* Base class for templates that decompress a jar file.
|
* Base class for templates that decompress a jar file.
|
||||||
*/
|
*/
|
||||||
interface InputStreamJarTemplate : ITemplate {
|
interface InputStreamJarTemplate : ITemplate {
|
||||||
val inputStream: JarInputStream
|
val inputStream: InputStream
|
||||||
|
|
||||||
override fun generateTemplate(args: Args, classLoader: ClassLoader) {
|
override fun generateTemplate(args: Args, classLoader: ClassLoader) {
|
||||||
extractFile(inputStream, File("."))
|
extractFile(File("."))
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun extractFile(ins: JarInputStream, destDir: File) {
|
private fun extractFile(destDir: File) {
|
||||||
|
val ins = JarInputStream(inputStream)
|
||||||
var entry = ins.nextEntry
|
var entry = ins.nextEntry
|
||||||
while (entry != null) {
|
while (entry != null) {
|
||||||
val f = File(destDir.path + File.separator + entry.name)
|
val f = File(destDir.path + File.separator + entry.name)
|
||||||
|
@ -39,20 +37,19 @@ interface InputStreamJarTemplate : ITemplate {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract class ResourceJarTemplate(val jarName: String, val classLoader: ClassLoader) : InputStreamJarTemplate {
|
abstract class ResourceJarTemplate(jarName: String, val classLoader: ClassLoader) : InputStreamJarTemplate {
|
||||||
override val inputStream = JarInputStream(classLoader.getResource(jarName).openConnection().inputStream)
|
override val inputStream : InputStream = classLoader.getResource(jarName).openConnection().inputStream
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract class FileJarTemplate(val fileName: String, val classLoader: ClassLoader) : InputStreamJarTemplate {
|
abstract class FileJarTemplate(val fileName: String, val classLoader: ClassLoader) : InputStreamJarTemplate {
|
||||||
override val inputStream = JarInputStream(FileInputStream(File(fileName)))
|
override val inputStream = FileInputStream(File(fileName))
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract class HttpJarTemplate(val url: String, val classLoader: ClassLoader) : InputStreamJarTemplate {
|
abstract class HttpJarTemplate(val url: String, val classLoader: ClassLoader) : InputStreamJarTemplate {
|
||||||
override val inputStream : JarInputStream
|
override val inputStream : InputStream
|
||||||
get() {
|
get() {
|
||||||
try {
|
try {
|
||||||
val result = URL(url).openConnection().inputStream
|
return URL(url).openConnection().inputStream
|
||||||
return JarInputStream(result)
|
|
||||||
} catch(ex: IOException) {
|
} catch(ex: IOException) {
|
||||||
throw IllegalArgumentException("Couldn't connect to $url")
|
throw IllegalArgumentException("Couldn't connect to $url")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue