Add embeddable version of the jvm scripting host
#KT-27382 fixed
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
|
||||
plugins {
|
||||
kotlin("jvm")
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile(project(":examples:scripting-jvm-simple-script"))
|
||||
compileOnly(project(":kotlin-scripting-jvm-host"))
|
||||
compile(project(":kotlin-script-util"))
|
||||
testRuntimeOnly(projectRuntimeJar(":kotlin-compiler-embeddable"))
|
||||
testRuntimeOnly(project(":kotlin-scripting-jvm-host-embeddable"))
|
||||
testRuntimeOnly(project(":kotlin-reflect"))
|
||||
testRuntimeOnly(intellijDep()) { includeJars("guava", rootProject = rootProject) }
|
||||
testCompile(commonDep("junit"))
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
"main" { projectDefault() }
|
||||
"test" { projectDefault() }
|
||||
}
|
||||
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* 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.script.examples.jvm.embeddable.host
|
||||
|
||||
import org.jetbrains.kotlin.script.examples.jvm.simple.SimpleScript
|
||||
import java.io.File
|
||||
import kotlin.script.experimental.api.EvaluationResult
|
||||
import kotlin.script.experimental.api.ResultWithDiagnostics
|
||||
import kotlin.script.experimental.host.toScriptSource
|
||||
import kotlin.script.experimental.jvm.dependenciesFromCurrentContext
|
||||
import kotlin.script.experimental.jvm.jvm
|
||||
import kotlin.script.experimental.jvmhost.BasicJvmScriptingHost
|
||||
import kotlin.script.experimental.jvmhost.createJvmCompilationConfigurationFromTemplate
|
||||
|
||||
fun evalFile(scriptFile: File): ResultWithDiagnostics<EvaluationResult> {
|
||||
val compilationConfiguration = createJvmCompilationConfigurationFromTemplate<SimpleScript> {
|
||||
jvm {
|
||||
dependenciesFromCurrentContext(
|
||||
"scripting-jvm-simple-script", /* script library jar name */
|
||||
"guava",
|
||||
wholeClasspath = true
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
return BasicJvmScriptingHost().eval(scriptFile.toScriptSource(), compilationConfiguration, null)
|
||||
}
|
||||
|
||||
fun main(vararg args: String) {
|
||||
if (args.size != 1) {
|
||||
println("usage: <app> <script file>")
|
||||
} else {
|
||||
val scriptFile = File(args[0])
|
||||
println("Executing script $scriptFile")
|
||||
|
||||
val res = evalFile(scriptFile)
|
||||
|
||||
res.reports.forEach {
|
||||
println(" : ${it.message}" + if (it.exception == null) "" else ": ${it.exception}")
|
||||
}
|
||||
}
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* 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.script.examples.jvm.embeddable.test
|
||||
|
||||
import org.jetbrains.kotlin.script.examples.jvm.embeddable.host.evalFile
|
||||
import org.junit.Assert
|
||||
import java.io.File
|
||||
import org.junit.Test
|
||||
import kotlin.script.experimental.api.ResultWithDiagnostics
|
||||
|
||||
class SimpleTest {
|
||||
|
||||
@Test
|
||||
fun testSimple() {
|
||||
// see comments in the script file
|
||||
val res = evalFile(File("testData/useGuava.simplescript.kts"))
|
||||
|
||||
Assert.assertTrue(
|
||||
"test failed:\n ${res.reports.joinToString("\n ") { it.message + if (it.exception == null) "" else ": ${it.exception}" }}",
|
||||
res is ResultWithDiagnostics.Success
|
||||
)
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
|
||||
// assuming to be executed on proguarded compiler in which `newArrayList` is present, but `asList` ist removed
|
||||
// first pulling `newArrayList`, so with non-embeddable (not shaded) host/compiler the class `Lists` will be pulled from
|
||||
// the guava embedded into compiler, then using `asList`, which should not be present in this version of the class due to proguarding
|
||||
// So, the compilation should only succeed if shaded compiler is used and `Lists` are loaded from the non-embedded guava jar
|
||||
|
||||
val arr = com.google.common.collect.Lists.newArrayList<Int>()
|
||||
val lst = listOf("Hello", "Guava")
|
||||
val glist = com.google.common.collect.Lists.asList(lst.first(), lst[1], emptyArray())
|
||||
|
||||
println(glist.joinToString(", ", "", "!"))
|
||||
@@ -0,0 +1,36 @@
|
||||
|
||||
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
|
||||
import org.gradle.jvm.tasks.Jar
|
||||
|
||||
description = "Kotlin Scripting JVM host (for using with embeddable compiler)"
|
||||
|
||||
plugins { java }
|
||||
|
||||
val packedJars by configurations.creating
|
||||
|
||||
dependencies {
|
||||
packedJars(project(":kotlin-scripting-jvm-host")) { isTransitive = false }
|
||||
runtime(project(":kotlin-script-runtime"))
|
||||
runtime(project(":kotlin-stdlib"))
|
||||
runtime(project(":kotlin-scripting-common"))
|
||||
runtime(project(":kotlin-scripting-jvm"))
|
||||
runtime(project(":kotlin-script-util"))
|
||||
runtime(projectRuntimeJar(":kotlin-compiler-embeddable"))
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
"main" {}
|
||||
"test" {}
|
||||
}
|
||||
|
||||
noDefaultJar()
|
||||
|
||||
runtimeJar(rewriteDepsToShadedCompiler(
|
||||
task<ShadowJar>("shadowJar") {
|
||||
from(packedJars)
|
||||
}
|
||||
))
|
||||
sourcesJar()
|
||||
javadocJar()
|
||||
|
||||
publish()
|
||||
@@ -177,6 +177,7 @@ include ":kotlin-build-common",
|
||||
":kotlin-scripting-common",
|
||||
":kotlin-scripting-jvm",
|
||||
":kotlin-scripting-jvm-host",
|
||||
":kotlin-scripting-jvm-host-embeddable",
|
||||
":kotlin-scripting-intellij",
|
||||
":kotlin-scripting-compiler",
|
||||
":kotlin-scripting-idea",
|
||||
@@ -187,6 +188,7 @@ include ":kotlin-build-common",
|
||||
":examples:scripting-jvm-simple-script-host",
|
||||
":examples:scripting-jvm-maven-deps",
|
||||
":examples:scripting-jvm-maven-deps-host",
|
||||
":examples:scripting-jvm-embeddable-host",
|
||||
":pill:generate-all-tests",
|
||||
":libraries:kotlin-prepush-hook",
|
||||
":libraries:tools:mutability-annotations-compat",
|
||||
@@ -300,6 +302,7 @@ project(':kotlin-annotations-android').projectDir = "$rootDir/libraries/tools/ko
|
||||
project(':kotlin-scripting-common').projectDir = "$rootDir/libraries/scripting/common" as File
|
||||
project(':kotlin-scripting-jvm').projectDir = "$rootDir/libraries/scripting/jvm" as File
|
||||
project(':kotlin-scripting-jvm-host').projectDir = "$rootDir/libraries/scripting/jvm-host" as File
|
||||
project(':kotlin-scripting-jvm-host-embeddable').projectDir = "$rootDir/libraries/scripting/jvm-host-embeddable" as File
|
||||
project(':kotlin-scripting-intellij').projectDir = "$rootDir/libraries/scripting/intellij" as File
|
||||
project(':kotlin-scripting-compiler').projectDir = "$rootDir/plugins/scripting/scripting-cli" as File
|
||||
project(':kotlin-scripting-compiler-embeddable').projectDir = "$rootDir/plugins/scripting/scripting-embeddable" as File
|
||||
@@ -310,6 +313,7 @@ project(':examples:scripting-jvm-simple-script').projectDir = "$rootDir/librarie
|
||||
project(':examples:scripting-jvm-simple-script-host').projectDir = "$rootDir/libraries/examples/scripting/jvm-simple-script/host" as File
|
||||
project(':examples:scripting-jvm-maven-deps').projectDir = "$rootDir/libraries/examples/scripting/jvm-maven-deps/script" as File
|
||||
project(':examples:scripting-jvm-maven-deps-host').projectDir = "$rootDir/libraries/examples/scripting/jvm-maven-deps/host" as File
|
||||
project(':examples:scripting-jvm-embeddable-host').projectDir = "$rootDir/libraries/examples/scripting/jvm-embeddable-host" as File
|
||||
project(':pill:generate-all-tests').projectDir = "$rootDir/plugins/pill/generate-all-tests" as File
|
||||
project(':kotlin-imports-dumper-compiler-plugin').projectDir = "$rootDir/plugins/imports-dumper" as File
|
||||
project(':libraries:kotlin-prepush-hook').projectDir = "$rootDir/libraries/tools/kotlin-prepush-hook" as File
|
||||
|
||||
Reference in New Issue
Block a user