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