Providing plugin classpath through JPS extensions
This commit is contained in:
@@ -22,4 +22,5 @@ import org.jetbrains.jps.incremental.CompileContext
|
|||||||
|
|
||||||
public trait KotlinJpsCompilerArgumentsProvider {
|
public trait KotlinJpsCompilerArgumentsProvider {
|
||||||
public fun getExtraArguments(moduleBuildTarget: ModuleBuildTarget, context: CompileContext): List<String>
|
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()
|
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>())) {
|
for (argumentProvider in ServiceLoader.load(javaClass<KotlinJpsCompilerArgumentsProvider>())) {
|
||||||
// appending to pluginOptions
|
// appending to pluginOptions
|
||||||
commonArguments.pluginOptions = array(
|
commonArguments.pluginOptions = concatenate(commonArguments.pluginOptions,
|
||||||
*(commonArguments.pluginOptions ?: array<String>()),
|
argumentProvider.getExtraArguments(representativeTarget, context))
|
||||||
*argumentProvider.getExtraArguments(representativeTarget, context).copyToArray()
|
// 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" scope="PROVIDED" name="android" level="project" />
|
||||||
<orderEntry type="library" name="kotlin-runtime" level="project" />
|
<orderEntry type="library" name="kotlin-runtime" level="project" />
|
||||||
<orderEntry type="module" module-name="android-compiler-plugin" />
|
<orderEntry type="module" module-name="android-compiler-plugin" />
|
||||||
|
<orderEntry type="module" module-name="util" scope="PROVIDED" />
|
||||||
</component>
|
</component>
|
||||||
</module>
|
</module>
|
||||||
|
|
||||||
|
|||||||
@@ -22,8 +22,9 @@ import org.jetbrains.jps.incremental.CompileContext
|
|||||||
import org.jetbrains.jps.model.module.JpsModule
|
import org.jetbrains.jps.model.module.JpsModule
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import org.jetbrains.jps.android.AndroidJpsUtil
|
import org.jetbrains.jps.android.AndroidJpsUtil
|
||||||
import org.jetbrains.kotlin.android.AndroidCommandLineProcessor
|
|
||||||
import org.jetbrains.kotlin.compiler.plugin.CliOption
|
import org.jetbrains.kotlin.compiler.plugin.CliOption
|
||||||
|
import org.jetbrains.kotlin.android.AndroidCommandLineProcessor
|
||||||
|
import org.jetbrains.jet.utils.PathUtil
|
||||||
|
|
||||||
public class KotlinAndroidJpsPlugin : KotlinJpsCompilerArgumentsProvider {
|
public class KotlinAndroidJpsPlugin : KotlinJpsCompilerArgumentsProvider {
|
||||||
override fun getExtraArguments(moduleBuildTarget: ModuleBuildTarget, context: CompileContext): List<String> {
|
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 {
|
private fun makePluginOption(option: CliOption, value: String): String {
|
||||||
return "plugin:${AndroidCommandLineProcessor.ANDROID_COMPILER_PLUGIN_ID}:${option.name}=$value"
|
return "plugin:${AndroidCommandLineProcessor.ANDROID_COMPILER_PLUGIN_ID}:${option.name}=$value"
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user