mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-27 00:38:11 -07:00
Use use() more.
This commit is contained in:
parent
d26ae330a7
commit
0e728289c8
5 changed files with 40 additions and 68 deletions
|
@ -205,24 +205,19 @@ public class Plugins @Inject constructor (val taskManagerProvider : Provider<Tas
|
||||||
//
|
//
|
||||||
// Inspect the jar, open the manifest, instantiate the main class and add it to the plugin repo
|
// Inspect the jar, open the manifest, instantiate the main class and add it to the plugin repo
|
||||||
//
|
//
|
||||||
var fis: FileInputStream? = null
|
FileInputStream(it.jarFile.get()).use { fis ->
|
||||||
var jis: JarInputStream? = null
|
JarInputStream(fis).use { jis ->
|
||||||
try {
|
val manifest = jis.manifest
|
||||||
fis = FileInputStream(it.jarFile.get())
|
val mainClass = manifest.mainAttributes.getValue(Plugins.MANIFEST_PLUGIN_CLASS) ?:
|
||||||
jis = JarInputStream(fis)
|
throw KobaltException("Couldn't find \"${Plugins.MANIFEST_PLUGIN_CLASS}\" in the " +
|
||||||
val manifest = jis.manifest
|
"manifest of $it")
|
||||||
val mainClass = manifest.mainAttributes.getValue(Plugins.MANIFEST_PLUGIN_CLASS) ?:
|
|
||||||
throw KobaltException("Couldn't find \"${Plugins.MANIFEST_PLUGIN_CLASS}\" in the " +
|
|
||||||
"manifest of $it")
|
|
||||||
|
|
||||||
val pluginClassName = mainClass.removeSuffix(" ")
|
val pluginClassName = mainClass.removeSuffix(" ")
|
||||||
val c = instantiateClassName(classLoader, pluginClassName)
|
val c = instantiateClassName(classLoader, pluginClassName)
|
||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
Plugins.addPlugin(c as Class<BasePlugin>)
|
Plugins.addPlugin(c as Class<BasePlugin>)
|
||||||
log(1, "Added plugin $c")
|
log(1, "Added plugin $c")
|
||||||
} finally {
|
}
|
||||||
jis?.close()
|
|
||||||
fis?.close()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
executor.shutdown()
|
executor.shutdown()
|
||||||
|
|
|
@ -68,17 +68,13 @@ class Kurl @Inject constructor(@Assisted val url: String) {
|
||||||
val string: String
|
val string: String
|
||||||
get() {
|
get() {
|
||||||
val sb = StringBuilder()
|
val sb = StringBuilder()
|
||||||
connection.inputStream.let { inputStream ->
|
connection.inputStream.use { inputStream ->
|
||||||
val reader = BufferedReader(InputStreamReader(inputStream))
|
val reader = BufferedReader(InputStreamReader(inputStream))
|
||||||
|
|
||||||
var line: String? = reader.readLine()
|
var line: String? = reader.readLine()
|
||||||
try {
|
while (line != null) {
|
||||||
while (line != null) {
|
sb.append(line).append('\n')
|
||||||
sb.append(line).append('\n')
|
line = reader.readLine()
|
||||||
line = reader.readLine()
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
inputStream.close()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -179,14 +179,4 @@ public class KFiles {
|
||||||
function: Function1<String, Boolean>): List<String> {
|
function: Function1<String, Boolean>): List<String> {
|
||||||
return KFiles.findRecursively(rootDir, directories, function)
|
return KFiles.findRecursively(rootDir, directories, function)
|
||||||
}
|
}
|
||||||
|
|
||||||
public fun saveFile(file: File, bytes: ByteArray) {
|
|
||||||
file.parentFile.mkdirs()
|
|
||||||
val os = file.outputStream()
|
|
||||||
try {
|
|
||||||
os.write(bytes)
|
|
||||||
} finally {
|
|
||||||
os.close()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,6 @@ import com.beust.kobalt.maven.IClasspathDependency
|
||||||
import com.beust.kobalt.maven.LocalRepo
|
import com.beust.kobalt.maven.LocalRepo
|
||||||
import com.beust.kobalt.misc.KFiles
|
import com.beust.kobalt.misc.KFiles
|
||||||
import com.beust.kobalt.misc.KobaltExecutors
|
import com.beust.kobalt.misc.KobaltExecutors
|
||||||
import com.beust.kobalt.misc.log
|
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import javax.inject.Singleton
|
import javax.inject.Singleton
|
||||||
|
@ -87,8 +86,6 @@ class KotlinPlugin @Inject constructor(
|
||||||
|
|
||||||
private fun compilePrivate(project: Project, cpList: List<IClasspathDependency>, sources: List<String>,
|
private fun compilePrivate(project: Project, cpList: List<IClasspathDependency>, sources: List<String>,
|
||||||
outputDirectory: File): TaskResult {
|
outputDirectory: File): TaskResult {
|
||||||
log(1, " Compiling ${sources.size} files with classpath size ${cpList.size}")
|
|
||||||
|
|
||||||
return kotlinCompilePrivate {
|
return kotlinCompilePrivate {
|
||||||
classpath(cpList.map { it.jarFile.get().absolutePath })
|
classpath(cpList.map { it.jarFile.get().absolutePath })
|
||||||
sourceFiles(sources)
|
sourceFiles(sources)
|
||||||
|
|
|
@ -1,13 +1,11 @@
|
||||||
package com.beust.kobalt.plugin.packaging
|
package com.beust.kobalt.plugin.packaging
|
||||||
|
|
||||||
import com.beust.kobalt.IFileSpec
|
import com.beust.kobalt.IFileSpec
|
||||||
import com.beust.kobalt.file
|
|
||||||
import com.beust.kobalt.misc.log
|
import com.beust.kobalt.misc.log
|
||||||
import java.io.*
|
import java.io.*
|
||||||
import java.util.jar.JarEntry
|
import java.util.jar.JarEntry
|
||||||
import java.util.jar.JarFile
|
import java.util.jar.JarFile
|
||||||
import java.util.jar.JarInputStream
|
import java.util.jar.JarInputStream
|
||||||
import java.util.jar.JarOutputStream
|
|
||||||
import java.util.zip.ZipEntry
|
import java.util.zip.ZipEntry
|
||||||
import java.util.zip.ZipOutputStream
|
import java.util.zip.ZipOutputStream
|
||||||
|
|
||||||
|
@ -137,46 +135,42 @@ public class JarUtils {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun removeDuplicateEntries(fromJarFile: File, toFile: File) {
|
// fun removeDuplicateEntries(fromJarFile: File, toFile: File) {
|
||||||
val fromFile = JarFile(fromJarFile)
|
// val fromFile = JarFile(fromJarFile)
|
||||||
var entries = fromFile.entries()
|
// var entries = fromFile.entries()
|
||||||
val os = JarOutputStream(FileOutputStream(toFile))
|
// val os = JarOutputStream(FileOutputStream(toFile))
|
||||||
val seen = hashSetOf<String>()
|
// val seen = hashSetOf<String>()
|
||||||
while (entries.hasMoreElements()) {
|
// while (entries.hasMoreElements()) {
|
||||||
val entry = entries.nextElement()
|
// val entry = entries.nextElement()
|
||||||
if (! seen.contains(entry.name)) {
|
// if (! seen.contains(entry.name)) {
|
||||||
val ins = fromFile.getInputStream(entry)
|
// val ins = fromFile.getInputStream(entry)
|
||||||
addEntry(ins, JarEntry(entry), os)
|
// addEntry(ins, JarEntry(entry), os)
|
||||||
}
|
// }
|
||||||
seen.add(entry.name)
|
// seen.add(entry.name)
|
||||||
}
|
// }
|
||||||
os.close()
|
// os.close()
|
||||||
|
//
|
||||||
log(1, "Deduplicated $fromFile.name")
|
// log(1, "Deduplicated $fromFile.name")
|
||||||
}
|
// }
|
||||||
|
|
||||||
fun extractJarFile(jarFile: File, destDir: File) {
|
fun extractJarFile(jarFile: File, destDir: File) {
|
||||||
val jar = java.util.jar.JarFile(jarFile)
|
val jar = java.util.jar.JarFile(jarFile)
|
||||||
val enumEntries = jar.entries()
|
val enumEntries = jar.entries()
|
||||||
while (enumEntries.hasMoreElements()) {
|
while (enumEntries.hasMoreElements()) {
|
||||||
val file = enumEntries.nextElement() as JarEntry
|
val file = enumEntries.nextElement()
|
||||||
val f = File(destDir.path + java.io.File.separator + file.name)
|
val f = File(destDir.path + java.io.File.separator + file.name)
|
||||||
if (file.isDirectory) {
|
if (file.isDirectory) {
|
||||||
f.mkdir()
|
f.mkdir()
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
var ins: InputStream? = null
|
|
||||||
var fos: OutputStream? = null
|
jar.getInputStream(file).use { ins ->
|
||||||
try {
|
|
||||||
ins = jar.getInputStream(file)
|
|
||||||
f.parentFile.mkdirs()
|
f.parentFile.mkdirs()
|
||||||
fos = FileOutputStream(f)
|
FileOutputStream(f).use { fos ->
|
||||||
while (ins.available() > 0) {
|
while (ins.available() > 0) {
|
||||||
fos.write(ins.read())
|
fos.write(ins.read())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} finally {
|
|
||||||
fos?.close()
|
|
||||||
ins?.close()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue