Providing plugin classpath through JPS extensions

This commit is contained in:
Yan Zhulanow
2014-10-17 19:52:39 +04:00
parent c94844f6dc
commit af9c5cc45d
4 changed files with 23 additions and 6 deletions
@@ -22,4 +22,5 @@ import org.jetbrains.jps.incremental.CompileContext
public trait KotlinJpsCompilerArgumentsProvider {
public fun getExtraArguments(moduleBuildTarget: ModuleBuildTarget, context: CompileContext): List<String>
public fun getClasspath(moduleBuildTarget: ModuleBuildTarget, context: CompileContext): List<String>
}
@@ -142,11 +142,20 @@ public class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR
val representativeTarget = chunk.representativeTarget()
fun concatenate(strings: Array<String>?, cp: List<String>) = array(*(strings ?: array<String>()), *cp.copyToArray())
for (argumentProvider in ServiceLoader.load(javaClass<KotlinJpsCompilerArgumentsProvider>())) {
// appending to pluginOptions
commonArguments.pluginOptions = array(
*(commonArguments.pluginOptions ?: array<String>()),
*argumentProvider.getExtraArguments(representativeTarget, context).copyToArray()
commonArguments.pluginOptions = concatenate(commonArguments.pluginOptions,
argumentProvider.getExtraArguments(representativeTarget, context))
// appending to classpath
commonArguments.pluginClasspaths = concatenate(commonArguments.pluginClasspaths,
argumentProvider.getClasspath(representativeTarget, context))
messageCollector.report(
INFO,
"Plugin loaded: ${argumentProvider.javaClass.getSimpleName()}",
NO_LOCATION
)
}
@@ -12,6 +12,6 @@
<orderEntry type="library" scope="PROVIDED" name="android" level="project" />
<orderEntry type="library" name="kotlin-runtime" level="project" />
<orderEntry type="module" module-name="android-compiler-plugin" />
<orderEntry type="module" module-name="util" scope="PROVIDED" />
</component>
</module>
</module>
@@ -22,8 +22,9 @@ import org.jetbrains.jps.incremental.CompileContext
import org.jetbrains.jps.model.module.JpsModule
import java.io.File
import org.jetbrains.jps.android.AndroidJpsUtil
import org.jetbrains.kotlin.android.AndroidCommandLineProcessor
import org.jetbrains.kotlin.compiler.plugin.CliOption
import org.jetbrains.kotlin.android.AndroidCommandLineProcessor
import org.jetbrains.jet.utils.PathUtil
public class KotlinAndroidJpsPlugin : KotlinJpsCompilerArgumentsProvider {
override fun getExtraArguments(moduleBuildTarget: ModuleBuildTarget, context: CompileContext): List<String> {
@@ -34,6 +35,12 @@ public class KotlinAndroidJpsPlugin : KotlinJpsCompilerArgumentsProvider {
)
}
override fun getClasspath(moduleBuildTarget: ModuleBuildTarget, context: CompileContext): List<String> {
return listOf(
File(PathUtil.getJarPathForClass(javaClass).getParentFile().getParentFile(), "android-compiler-plugin.jar").getAbsolutePath()
)
}
private fun makePluginOption(option: CliOption, value: String): String {
return "plugin:${AndroidCommandLineProcessor.ANDROID_COMPILER_PLUGIN_ID}:${option.name}=$value"
}