Use Gradle properties to pass plugin-related arguments

This commit is contained in:
Yan Zhulanow
2015-02-26 21:32:34 +03:00
parent eebed9a8b1
commit 2f83e600f5
2 changed files with 8 additions and 16 deletions
@@ -47,9 +47,6 @@ abstract class AbstractKotlinCompile<T : CommonCompilerArguments>() : AbstractCo
private val logger = Logging.getLogger(this.javaClass)
override fun getLogger() = logger
var compilerPluginClasspaths: Array<String> = array()
var compilerPluginArguments: Array<String> = array()
[TaskAction]
override fun compile() {
getLogger().debug("Starting ${javaClass} task")
@@ -104,8 +101,8 @@ public open class KotlinCompile() : AbstractKotlinCompile<K2JVMCompilerArguments
val srcDirsSources = HashSet<SourceDirectorySet>()
override fun populateTargetSpecificArgs(args: K2JVMCompilerArguments) {
args.pluginClasspaths = compilerPluginClasspaths
args.pluginOptions = compilerPluginArguments
args.pluginClasspaths = property("compilerPluginClasspaths") as? Array<String>
args.pluginOptions = property("compilerPluginArguments") as? Array<String>
if (StringUtils.isEmpty(kotlinOptions.classpath)) {
val existingClasspathEntries = getClasspath().filter({ it != null && it.exists() })
@@ -451,30 +451,25 @@ private class SubpluginEnvironment(
val subplugins: List<KotlinGradleSubplugin>
) {
private fun AbstractCompile.setKotlinTaskProperty(methodName: String, value: Array<String>) {
val function = javaClass.getMethod(methodName, javaClass<Array<String>>())
function.invoke(this, value)
}
fun addSubpluginArguments(project: Project, compileTask: AbstractCompile) {
val realPluginClasspaths = arrayListOf<String>()
val pluginArguments = arrayListOf<String>()
fun getPluginOptionString(pluginId: String, key: String, value: String) = "plugin:$pluginId:$key=$value"
subplugins.forEach { subplugin ->
val args = subplugin.getExtraArguments(project, compileTask)
if (args != null) {
realPluginClasspaths.addAll(subpluginClasspaths[subplugin])
val subpluginClasspath = subpluginClasspaths[subplugin]
if (args != null && subpluginClasspath != null) {
realPluginClasspaths.addAll(subpluginClasspath)
for (arg in args) {
//TODO: fix (getPluginOptionString is in plugin-api)
fun getPluginOptionString(pluginId: String, key: String, value: String) = "plugin:$pluginId:$key=$value"
val option = getPluginOptionString(subplugin.getPluginName(), arg.key, arg.value)
pluginArguments.add(option)
}
}
}
compileTask.setKotlinTaskProperty("setCompilerPluginClasspaths", realPluginClasspaths.copyToArray())
compileTask.setKotlinTaskProperty("setCompilerPluginArguments", pluginArguments.copyToArray())
compileTask.setProperty("compilerPluginClasspaths", realPluginClasspaths.copyToArray())
compileTask.setProperty("compilerPluginArguments", pluginArguments.copyToArray())
}
}