Refactor scripting examples:
- split into script def and host part - remove bad dependencies - organize it in a way that should be typical for user scenarios
This commit is contained in:
@@ -1 +0,0 @@
|
||||
import org.jetbrains.kotlin.gradle.dsl.Coroutines
|
||||
@@ -0,0 +1 @@
|
||||
import org.jetbrains.kotlin.gradle.dsl.Coroutines
|
||||
+5
-16
@@ -1,12 +1,12 @@
|
||||
/*
|
||||
* Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* 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.simple
|
||||
package org.jetbrains.kotlin.script.examples.jvm.simple.host
|
||||
|
||||
import org.jetbrains.kotlin.script.util.KotlinJars
|
||||
import org.jetbrains.kotlin.utils.PathUtil
|
||||
import org.jetbrains.kotlin.script.examples.jvm.simple.MyScript
|
||||
import org.jetbrains.kotlin.script.util.*
|
||||
import java.io.File
|
||||
import kotlin.script.experimental.api.*
|
||||
import kotlin.script.experimental.definitions.ScriptDefinitionFromAnnotatedBaseClass
|
||||
@@ -14,26 +14,15 @@ import kotlin.script.experimental.host.toScriptSource
|
||||
import kotlin.script.experimental.jvm.*
|
||||
import kotlin.script.experimental.jvmhost.impl.KJVMCompilerImpl
|
||||
|
||||
val stdlibFile: File by lazy {
|
||||
KotlinJars.stdlib
|
||||
?: throw Exception("Unable to find kotlin stdlib, please specify it explicitly via \"kotlin.java.stdlib.jar\" property")
|
||||
}
|
||||
|
||||
val selfFile: File by lazy {
|
||||
PathUtil.getResourcePathForClass(MyScript::class.java).takeIf(File::exists)
|
||||
?: throw Exception("Unable to get path to the script base")
|
||||
}
|
||||
|
||||
inline fun myJvmConfig(
|
||||
from: HeterogeneousMap = HeterogeneousMap(),
|
||||
crossinline body: JvmScriptCompileConfigurationParams.Builder.() -> Unit = {}
|
||||
) = jvmConfigWithJavaHome(from) {
|
||||
signature<MyScript>()
|
||||
dependencies(listOf(stdlibFile), listOf(selfFile))
|
||||
dependencies(scriptCompilationClasspathFromContext("script" /* script library jar name */))
|
||||
body()
|
||||
}
|
||||
|
||||
|
||||
fun evalFile(scriptFile: File): ResultWithDiagnostics<EvaluationResult> {
|
||||
val scriptCompiler = JvmScriptCompiler(KJVMCompilerImpl(), DummyCompiledJvmScriptCache())
|
||||
val scriptDefinition = ScriptDefinitionFromAnnotatedBaseClass(MyScript::class)
|
||||
+1
-1
@@ -5,7 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.script.examples.jvm.simple.test
|
||||
|
||||
import org.jetbrains.kotlin.script.examples.jvm.simple.evalFile
|
||||
import org.jetbrains.kotlin.script.examples.jvm.simple.host.evalFile
|
||||
import org.junit.Assert
|
||||
import java.io.File
|
||||
import org.junit.Test
|
||||
Reference in New Issue
Block a user