Pack scripting plugin into kotlin-scripting-embeddable for use in Gradle
This commit is contained in:
@@ -55,7 +55,7 @@ test.dependsOn(":kotlin-allopen:install",
|
||||
":examples:annotation-processor-example:install",
|
||||
":kotlin-scripting-common:install",
|
||||
":kotlin-scripting-jvm:install",
|
||||
":kotlin-scripting-gradle:install")
|
||||
":kotlin-scripting-compiler-embeddable:install")
|
||||
|
||||
|
||||
// Validate that all dependencies 'install' tasks are added to 'test' dependencies
|
||||
|
||||
@@ -56,16 +56,12 @@ dependencies {
|
||||
extension = 'jar'
|
||||
}
|
||||
}
|
||||
compileOnly project(':kotlin-scripting-gradle')
|
||||
|
||||
runtime project(path: ':kotlin-compiler-embeddable', configuration: "runtimeJar")
|
||||
runtime project(path: ':kotlin-annotation-processing-gradle', configuration: "runtimeJar")
|
||||
runtime project(path: ':kotlin-android-extensions', configuration: 'runtimeJar')
|
||||
runtime project(path: ':kotlin-compiler-runner', configuration: 'runtimeJar')
|
||||
runtime project(':kotlin-reflect')
|
||||
runtime project(':kotlin-scripting-common')
|
||||
runtime project(':kotlin-scripting-compiler')
|
||||
runtime project(path: ':kotlin-scripting-gradle', configuration: 'runtimeJar')
|
||||
|
||||
// com.android.tools.build:gradle has ~50 unneeded transitive dependencies
|
||||
agp25CompileOnly('com.android.tools.build:gradle:3.0.0-alpha1') { transitive = false }
|
||||
@@ -155,5 +151,9 @@ pluginBundle {
|
||||
id = 'org.jetbrains.kotlin.kapt'
|
||||
description = displayName = 'Kotlin Kapt plugin'
|
||||
}
|
||||
kotlinScriptingPlugin {
|
||||
id = 'org.jetbrains.kotlin.plugin.scripting'
|
||||
description = displayName = 'Gradle plugin for kotlin scripting'
|
||||
}
|
||||
}
|
||||
}
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.gradle.scripting
|
||||
|
||||
open class ScriptingExtension {
|
||||
internal val myScriptDefinitions = mutableListOf<String>()
|
||||
internal val myScriptDefinitionsClasspath = mutableListOf<String>()
|
||||
internal var myDisableScriptDefinitionsFromClasspath = false
|
||||
internal val myScriptResolverEnvironment = mutableMapOf<String, String?>()
|
||||
|
||||
open fun scriptDefinition(fqName: String) {
|
||||
myScriptDefinitions.add(fqName)
|
||||
}
|
||||
|
||||
open fun scriptDefinitions(fqNames: List<String>) {
|
||||
myScriptDefinitions.addAll(fqNames)
|
||||
}
|
||||
|
||||
open fun scriptDefinitions(vararg fqNames: String) {
|
||||
myScriptDefinitions.addAll(fqNames)
|
||||
}
|
||||
|
||||
open fun scriptDefinitionsClasspath(vararg paths: String) {
|
||||
myScriptDefinitionsClasspath.addAll(paths)
|
||||
}
|
||||
|
||||
open fun scriptDefinitionsClasspath(paths: List<String>) {
|
||||
myScriptDefinitionsClasspath.addAll(paths)
|
||||
}
|
||||
|
||||
open fun disableScriptDefinitionsFromClasspath(disable: Boolean) {
|
||||
myDisableScriptDefinitionsFromClasspath = disable
|
||||
}
|
||||
|
||||
open fun scriptResolverEnvironment(vararg pairs: Pair<String, String?>) {
|
||||
myScriptResolverEnvironment.putAll(pairs)
|
||||
}
|
||||
|
||||
open fun scriptResolverEnvironment(pairs: List<Pair<String, String?>>) {
|
||||
myScriptResolverEnvironment.putAll(pairs)
|
||||
}
|
||||
}
|
||||
+73
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.gradle.scripting.internal
|
||||
|
||||
import org.gradle.api.Plugin
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.tasks.SourceSet
|
||||
import org.gradle.api.tasks.compile.AbstractCompile
|
||||
import org.jetbrains.kotlin.gradle.plugin.JetBrainsSubpluginArtifact
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinGradleSubplugin
|
||||
import org.jetbrains.kotlin.gradle.plugin.SubpluginArtifact
|
||||
import org.jetbrains.kotlin.gradle.plugin.SubpluginOption
|
||||
import org.jetbrains.kotlin.gradle.scripting.ScriptingExtension
|
||||
|
||||
class ScriptingGradleSubplugin : Plugin<Project> {
|
||||
companion object {
|
||||
fun isEnabled(project: Project) = project.plugins.findPlugin(ScriptingGradleSubplugin::class.java) != null
|
||||
}
|
||||
|
||||
override fun apply(project: Project) {}
|
||||
}
|
||||
|
||||
class ScriptingKotlinGradleSubplugin : KotlinGradleSubplugin<AbstractCompile> {
|
||||
companion object {
|
||||
const val SCRIPTING_ARTIFACT_NAME = "kotlin-scripting-compiler-embeddable"
|
||||
|
||||
val SCRIPT_DEFINITIONS_OPTION = "script-definitions"
|
||||
val SCRIPT_DEFINITIONS_CLASSPATH_OPTION = "script-definitions-classpath"
|
||||
val DISABLE_SCRIPT_DEFINITIONS_FROM_CLSSPATH_OPTION = "disable-script-definitions-from-classpath"
|
||||
val LEGACY_SCRIPT_RESOLVER_ENVIRONMENT_OPTION = "script-resolver-environment"
|
||||
}
|
||||
|
||||
override fun isApplicable(project: Project, task: AbstractCompile) =
|
||||
ScriptingGradleSubplugin.isEnabled(project)
|
||||
|
||||
override fun apply(
|
||||
project: Project,
|
||||
kotlinCompile: AbstractCompile,
|
||||
javaCompile: AbstractCompile,
|
||||
variantData: Any?,
|
||||
androidProjectHandler: Any?,
|
||||
javaSourceSet: SourceSet?
|
||||
): List<SubpluginOption> {
|
||||
if (!ScriptingGradleSubplugin.isEnabled(project)) return emptyList()
|
||||
|
||||
val scriptingExtension = project.extensions.findByType(ScriptingExtension::class.java)
|
||||
?: project.extensions.create("kotlinScripting", ScriptingExtension::class.java)
|
||||
|
||||
val options = mutableListOf<SubpluginOption>()
|
||||
|
||||
for (scriptDef in scriptingExtension.myScriptDefinitions) {
|
||||
options += SubpluginOption(SCRIPT_DEFINITIONS_OPTION, scriptDef)
|
||||
}
|
||||
for (path in scriptingExtension.myScriptDefinitionsClasspath) {
|
||||
options += SubpluginOption(SCRIPT_DEFINITIONS_CLASSPATH_OPTION, path)
|
||||
}
|
||||
if (scriptingExtension.myDisableScriptDefinitionsFromClasspath) {
|
||||
options += SubpluginOption(DISABLE_SCRIPT_DEFINITIONS_FROM_CLSSPATH_OPTION, "true")
|
||||
}
|
||||
for (pair in scriptingExtension.myScriptResolverEnvironment) {
|
||||
options += SubpluginOption(LEGACY_SCRIPT_RESOLVER_ENVIRONMENT_OPTION, "${pair.key}=${pair.value}")
|
||||
}
|
||||
|
||||
return options
|
||||
}
|
||||
|
||||
override fun getCompilerPluginId() = "kotlin.scripting"
|
||||
override fun getPluginArtifact(): SubpluginArtifact =
|
||||
JetBrainsSubpluginArtifact(artifactId = SCRIPTING_ARTIFACT_NAME)
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
implementation-class=org.jetbrains.kotlin.gradle.scripting.internal.ScriptingGradleSubplugin
|
||||
+1
@@ -0,0 +1 @@
|
||||
implementation-class=org.jetbrains.kotlin.gradle.scripting.internal.ScriptingGradleSubplugin
|
||||
+2
-1
@@ -1,2 +1,3 @@
|
||||
org.jetbrains.kotlin.gradle.internal.AndroidSubplugin
|
||||
org.jetbrains.kotlin.gradle.internal.Kapt3KotlinGradleSubplugin
|
||||
org.jetbrains.kotlin.gradle.internal.Kapt3KotlinGradleSubplugin
|
||||
org.jetbrains.kotlin.gradle.scripting.internal.ScriptingKotlinGradleSubplugin
|
||||
Reference in New Issue
Block a user