mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-27 00:38:11 -07:00
Code review from @orangy.
This commit is contained in:
parent
c37cef5d84
commit
b0ef405867
5 changed files with 12 additions and 25 deletions
|
@ -186,13 +186,7 @@ public class Plugins @Inject constructor (val taskManagerProvider : Provider<Tas
|
|||
}
|
||||
|
||||
val allTasks : List<PluginTask>
|
||||
get() {
|
||||
val result = arrayListOf<PluginTask>()
|
||||
Plugins.plugins.forEach { plugin ->
|
||||
result.addAll(plugin.tasks)
|
||||
}
|
||||
return result
|
||||
}
|
||||
get() = Plugins.plugins.flatMap { it.tasks }
|
||||
|
||||
fun installPlugins(dependencies: List<IClasspathDependency>, classLoader: ClassLoader) {
|
||||
val executor = executors.newExecutor("Plugins", 5)
|
||||
|
|
|
@ -48,8 +48,7 @@ public class Kobalt {
|
|||
private val KOBALT_PROPERTIES = "kobalt.properties"
|
||||
private val LOCAL_PROPERTIES = "local.properties"
|
||||
|
||||
private val properties : Properties
|
||||
get() = readProperties()
|
||||
private val properties : Properties by lazy { readProperties() }
|
||||
|
||||
private fun readProperties() : Properties {
|
||||
val result = Properties()
|
||||
|
@ -59,13 +58,13 @@ public class Kobalt {
|
|||
if (url != null) {
|
||||
readProperties(result, url.openConnection().inputStream)
|
||||
} else {
|
||||
throw IllegalArgumentException("Couldn't find ${KOBALT_PROPERTIES}")
|
||||
throw AssertionError("Couldn't find $KOBALT_PROPERTIES")
|
||||
}
|
||||
|
||||
// local.properties can be used by external users
|
||||
Paths.get(LOCAL_PROPERTIES).let { path ->
|
||||
if (Files.exists(path)) {
|
||||
Files.newInputStream(path).let {
|
||||
Files.newInputStream(path).use {
|
||||
readProperties(result, it)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,9 +23,9 @@ public interface Plugin {
|
|||
}
|
||||
|
||||
fun addTask(project: Project, name: String, description: String = "",
|
||||
runBefore: List<String> = arrayListOf<String>(),
|
||||
runAfter: List<String> = arrayListOf<String>(),
|
||||
alwaysRunAfter: List<String> = arrayListOf<String>(),
|
||||
runBefore: List<String> = listOf<String>(),
|
||||
runAfter: List<String> = listOf<String>(),
|
||||
alwaysRunAfter: List<String> = listOf<String>(),
|
||||
task: (Project) -> TaskResult) {
|
||||
tasks.add(
|
||||
object : BasePluginTask(this, name, description, project) {
|
||||
|
|
|
@ -10,14 +10,8 @@ import java.util.*
|
|||
class PluginProperties @Inject constructor() {
|
||||
private val pluginProperties = hashMapOf<String, HashMap<String, Any>>()
|
||||
|
||||
fun put(pluginName: String, key: String, value: Any) {
|
||||
var map = pluginProperties[pluginName]
|
||||
if (map == null) {
|
||||
map = hashMapOf<String, Any>()
|
||||
pluginProperties.put(pluginName, map)
|
||||
}
|
||||
map.put(key, value)
|
||||
}
|
||||
fun put(pluginName: String, key: String, value: Any) =
|
||||
pluginProperties.getOrPut(pluginName) { hashMapOf<String, Any>() }.put(key, value)
|
||||
|
||||
fun get(pluginName: String, key: String) = pluginProperties[pluginName]?.get(key)
|
||||
}
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
package com.beust.kobalt.misc
|
||||
|
||||
fun toString<T>(name: String, vararg o: T) : String {
|
||||
val sb = StringBuffer()
|
||||
fun <T> toString(name: String, vararg o: T) : String {
|
||||
val sb = StringBuilder()
|
||||
|
||||
for (i in 0..o.size - 1 step 2) {
|
||||
if (i > 0) sb.append(", ")
|
||||
sb.append(o.get(i).toString() + ":" + o.get(i + 1))
|
||||
sb.append(o[i].toString() + ":" + o[i + 1])
|
||||
}
|
||||
return "{$name $sb}"
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue