Switch to templates in the separate script runtime
This commit is contained in:
+9
@@ -0,0 +1,9 @@
|
||||
<component name="libraryTable">
|
||||
<library name="kotlin-script-runtime">
|
||||
<CLASSES>
|
||||
<root url="jar://$KOTLIN_BUNDLED$/lib/kotlin-script-runtime.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
</library>
|
||||
</component>
|
||||
@@ -15,6 +15,7 @@
|
||||
<property name="bootstrap.compiler.home" value="${bootstrap.home}/Kotlin/kotlinc"/>
|
||||
<property name="bootstrap.runtime" value="${bootstrap.compiler.home}/lib/kotlin-runtime.jar"/>
|
||||
<property name="bootstrap.reflect" value="${bootstrap.compiler.home}/lib/kotlin-reflect.jar"/>
|
||||
<property name="bootstrap.script.runtime" value="${bootstrap.compiler.home}/lib/kotlin-script-runtime.jar"/>
|
||||
<property name="bootstrap.kotlin.test" value="${bootstrap.compiler.home}/lib/kotlin-test.jar" />
|
||||
|
||||
<property name="output" value="${basedir}/dist"/>
|
||||
@@ -57,8 +58,8 @@
|
||||
little to no differences between the new and the newest runtime.
|
||||
-->
|
||||
<condition property="compiler.manifest.class.path"
|
||||
value="kotlin-runtime-internal-bootstrap.jar kotlin-reflect-internal-bootstrap.jar"
|
||||
else="kotlin-runtime.jar kotlin-reflect.jar">
|
||||
value="kotlin-runtime-internal-bootstrap.jar kotlin-reflect-internal-bootstrap.jar kotlin-script-runtime-internal-bootstrap.jar"
|
||||
else="kotlin-runtime.jar kotlin-reflect.jar kotlin-script-runtime.jar">
|
||||
<istrue value="${bootstrap.or.local.build}"/>
|
||||
</condition>
|
||||
|
||||
@@ -66,6 +67,7 @@
|
||||
<file file="${bootstrap.runtime}"/>
|
||||
<file file="${bootstrap.kotlin.test}" />
|
||||
<file file="${bootstrap.reflect}"/>
|
||||
<file file="${bootstrap.script.runtime}"/>
|
||||
<fileset dir="${idea.sdk}" includes="core/*.jar"/>
|
||||
<pathelement location="${protobuf.jar}"/>
|
||||
|
||||
@@ -190,6 +192,7 @@
|
||||
<sequential if:true="${bootstrap.or.local.build}">
|
||||
<copy file="${bootstrap.runtime}" tofile="${kotlin-home}/lib/kotlin-runtime-internal-bootstrap.jar"/>
|
||||
<copy file="${bootstrap.reflect}" tofile="${kotlin-home}/lib/kotlin-reflect-internal-bootstrap.jar"/>
|
||||
<copy file="${bootstrap.script.runtime}" tofile="${kotlin-home}/lib/kotlin-script-runtime-internal-bootstrap.jar"/>
|
||||
<copy file="${bootstrap.kotlin.test}" tofile="${kotlin-home}/lib/kotlin-test-internal-bootstrap.jar" failonerror="false"/>
|
||||
<jar destfile="${kotlin-home}/lib/kotlin-reflect-internal-bootstrap.jar" update="true">
|
||||
<manifest>
|
||||
@@ -206,6 +209,7 @@
|
||||
<sequential unless:true="${bootstrap.or.local.build}">
|
||||
<copy file="${bootstrap.runtime}" todir="${kotlin-home}/lib"/>
|
||||
<copy file="${bootstrap.reflect}" todir="${kotlin-home}/lib"/>
|
||||
<copy file="${bootstrap.script.runtime}" todir="${kotlin-home}/lib"/>
|
||||
<copy file="${bootstrap.kotlin.test}" todir="${kotlin-home}/lib"/>
|
||||
</sequential>
|
||||
</target>
|
||||
@@ -612,6 +616,9 @@
|
||||
<zipfileset src="${bootstrap.reflect}">
|
||||
<patternset refid="lib.metainf.patternset"/>
|
||||
</zipfileset>
|
||||
<zipfileset src="${bootstrap.script.runtime}">
|
||||
<patternset refid="lib.metainf.patternset"/>
|
||||
</zipfileset>
|
||||
|
||||
<manifest>
|
||||
<attribute name="Built-By" value="${manifest.impl.vendor}"/>
|
||||
@@ -640,6 +647,7 @@
|
||||
<classpath>
|
||||
<pathelement path="${bootstrap.runtime}"/>
|
||||
<pathelement path="${bootstrap.reflect}"/>
|
||||
<pathelement path="${bootstrap.script.runtime}"/>
|
||||
<pathelement path="${idea.sdk}/lib/util.jar"/>
|
||||
<pathelement path="${kotlin-home}/lib/kotlin-compiler.jar"/>
|
||||
</classpath>
|
||||
@@ -683,6 +691,7 @@
|
||||
<classpath>
|
||||
<pathelement path="${bootstrap.runtime}"/>
|
||||
<pathelement path="${bootstrap.reflect}"/>
|
||||
<pathelement path="${bootstrap.script.runtime}"/>
|
||||
<pathelement path="${bootstrap.kotlin.test}"/>
|
||||
<pathelement path="${protobuf.jar}"/>
|
||||
<pathelement path="${idea.sdk}/lib/junit-4.12.jar"/>
|
||||
@@ -812,6 +821,7 @@
|
||||
<pathelement path="${kotlin-home}/lib/kotlin-compiler.jar"/>
|
||||
<pathelement path="${bootstrap.runtime}"/>
|
||||
<pathelement path="${bootstrap.reflect}"/>
|
||||
<pathelement path="${bootstrap.script.runtime}"/>
|
||||
</classpath>
|
||||
</javac2>
|
||||
|
||||
@@ -1201,7 +1211,6 @@
|
||||
<delete dir="${output}/mock-runtime-src" failonerror="false"/>
|
||||
<mkdir dir="${output}/mock-runtime-src"/>
|
||||
<copy file="${basedir}/core/runtime.jvm/src/kotlin/TypeAliases.kt" todir="${output}/mock-runtime-src"/>
|
||||
<copy file="${basedir}/core/runtime.jvm/src/kotlin/script/Scripts.kt" todir="${output}/mock-runtime-src"/>
|
||||
<copy file="${basedir}/libraries/stdlib/src/kotlin/util/Standard.kt" todir="${output}/mock-runtime-src"/>
|
||||
<copy file="${basedir}/libraries/stdlib/src/kotlin/internal/Annotations.kt" todir="${output}/mock-runtime-src"/>
|
||||
|
||||
|
||||
@@ -344,6 +344,7 @@ class K2JVMCompiler : CLICompiler<K2JVMCompilerArguments>() {
|
||||
}
|
||||
if (!arguments.noStdlib) {
|
||||
classpath.add(paths.runtimePath)
|
||||
classpath.add(paths.scriptRuntimePath)
|
||||
}
|
||||
// "-no-stdlib" implies "-no-reflect": otherwise we would be able to transitively read stdlib classes through kotlin-reflect,
|
||||
// which is likely not what user wants since s/he manually provided "-no-stdlib"
|
||||
|
||||
@@ -122,8 +122,16 @@ public class CompileEnvironmentUtil {
|
||||
if (!runtimePath.exists()) {
|
||||
throw new CompileEnvironmentException("Couldn't find runtime library");
|
||||
}
|
||||
File scriptRuntimePath = PathUtil.getKotlinPathsForCompiler().getScriptRuntimePath();
|
||||
if (!scriptRuntimePath.exists()) {
|
||||
throw new CompileEnvironmentException("Couldn't find script runtime library");
|
||||
}
|
||||
|
||||
JarInputStream jis = new JarInputStream(new FileInputStream(runtimePath));
|
||||
copyJarImpl(stream, runtimePath);
|
||||
}
|
||||
|
||||
private static void copyJarImpl(JarOutputStream stream, File jarPath) throws IOException {
|
||||
JarInputStream jis = new JarInputStream(new FileInputStream(jarPath));
|
||||
try {
|
||||
while (true) {
|
||||
JarEntry e = jis.getNextJarEntry();
|
||||
|
||||
@@ -46,6 +46,7 @@ messages/**)
|
||||
-libraryjars '<jssejar>'
|
||||
-libraryjars '<bootstrap.runtime>'
|
||||
-libraryjars '<bootstrap.reflect>'
|
||||
-libraryjars '<bootstrap.script.runtime>'
|
||||
|
||||
-target 1.6
|
||||
-dontoptimize
|
||||
|
||||
@@ -77,7 +77,7 @@ open class KotlinJvmReplService(
|
||||
|
||||
protected val configuration = CompilerConfiguration().apply {
|
||||
addJvmClasspathRoots(PathUtil.getJdkClassesRoots())
|
||||
addJvmClasspathRoots(PathUtil.getKotlinPathsForCompiler().let { listOf(it.runtimePath, it.reflectPath) })
|
||||
addJvmClasspathRoots(PathUtil.getKotlinPathsForCompiler().let { listOf(it.runtimePath, it.reflectPath, it.scriptRuntimePath) })
|
||||
addJvmClasspathRoots(templateClasspath)
|
||||
put(CommonConfigurationKeys.MODULE_NAME, "kotlin-script")
|
||||
}
|
||||
|
||||
@@ -15,5 +15,6 @@
|
||||
<orderEntry type="module" module-name="container" exported="" />
|
||||
<orderEntry type="library" scope="TEST" name="kotlin-test" level="project" />
|
||||
<orderEntry type="module" module-name="resolution" exported="" />
|
||||
<orderEntry type="library" exported="" name="kotlin-script-runtime" level="project" />
|
||||
</component>
|
||||
</module>
|
||||
@@ -24,7 +24,7 @@ import org.jetbrains.kotlin.parsing.KotlinParserDefinition
|
||||
import org.jetbrains.kotlin.psi.KtScript
|
||||
import java.io.File
|
||||
import kotlin.reflect.KClass
|
||||
import kotlin.script.StandardScriptTemplate
|
||||
import kotlin.script.templates.standard.ScriptTemplateWithArgs
|
||||
|
||||
open class KotlinScriptDefinition(val template: KClass<out Any>) {
|
||||
|
||||
@@ -50,5 +50,5 @@ interface KotlinScriptExternalDependencies {
|
||||
val scripts: Iterable<File> get() = emptyList()
|
||||
}
|
||||
|
||||
object StandardScriptDefinition : KotlinScriptDefinition(StandardScriptTemplate::class)
|
||||
object StandardScriptDefinition : KotlinScriptDefinition(ScriptTemplateWithArgs::class)
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package
|
||||
|
||||
public final class Script : kotlin.script.StandardScriptTemplate {
|
||||
public final class Script : kotlin.script.templates.standard.ScriptTemplateWithArgs {
|
||||
public constructor Script(/*0*/ args: kotlin.Array<kotlin.String>)
|
||||
public final override /*1*/ /*fake_override*/ val args: kotlin.Array<kotlin.String>
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ package test {
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
|
||||
public final class A : kotlin.script.StandardScriptTemplate {
|
||||
public final class A : kotlin.script.templates.standard.ScriptTemplateWithArgs {
|
||||
public constructor A(/*0*/ args: kotlin.Array<kotlin.String>)
|
||||
public final override /*1*/ /*fake_override*/ val args: kotlin.Array<kotlin.String>
|
||||
public final val x: kotlin.Int = 1
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
package
|
||||
|
||||
public final class AccessForwardDeclarationInScript : kotlin.script.StandardScriptTemplate {
|
||||
public final class AccessForwardDeclarationInScript : kotlin.script.templates.standard.ScriptTemplateWithArgs {
|
||||
public constructor AccessForwardDeclarationInScript(/*0*/ args: kotlin.Array<kotlin.String>)
|
||||
public final override /*1*/ /*fake_override*/ val args: kotlin.Array<kotlin.String>
|
||||
public final val x: kotlin.Int = 2
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package
|
||||
|
||||
public final class ComplexScript : kotlin.script.StandardScriptTemplate {
|
||||
public final class ComplexScript : kotlin.script.templates.standard.ScriptTemplateWithArgs {
|
||||
public constructor ComplexScript(/*0*/ args: kotlin.Array<kotlin.String>)
|
||||
public final override /*1*/ /*fake_override*/ val args: kotlin.Array<kotlin.String>
|
||||
public final val y: kotlin.Int = 2
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package
|
||||
|
||||
public final class NestedInnerClass : kotlin.script.StandardScriptTemplate {
|
||||
public final class NestedInnerClass : kotlin.script.templates.standard.ScriptTemplateWithArgs {
|
||||
public constructor NestedInnerClass(/*0*/ args: kotlin.Array<kotlin.String>)
|
||||
public final override /*1*/ /*fake_override*/ val args: kotlin.Array<kotlin.String>
|
||||
public final val property: kotlin.String = ""
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package
|
||||
|
||||
public final class SimpleScript : kotlin.script.StandardScriptTemplate {
|
||||
public final class SimpleScript : kotlin.script.templates.standard.ScriptTemplateWithArgs {
|
||||
public constructor SimpleScript(/*0*/ args: kotlin.Array<kotlin.String>)
|
||||
public final override /*1*/ /*fake_override*/ val args: kotlin.Array<kotlin.String>
|
||||
public final val x: kotlin.Int = 1
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
package
|
||||
|
||||
public final class Imports : kotlin.script.StandardScriptTemplate {
|
||||
public final class Imports : kotlin.script.templates.standard.ScriptTemplateWithArgs {
|
||||
public constructor Imports(/*0*/ args: kotlin.Array<kotlin.String>)
|
||||
public final val al: java.util.ArrayList<kotlin.String>? = null
|
||||
public final override /*1*/ /*fake_override*/ val args: kotlin.Array<kotlin.String>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package
|
||||
|
||||
public final class TopLevelVariable : kotlin.script.StandardScriptTemplate {
|
||||
public final class TopLevelVariable : kotlin.script.templates.standard.ScriptTemplateWithArgs {
|
||||
public constructor TopLevelVariable(/*0*/ args: kotlin.Array<kotlin.String>)
|
||||
public final val a: kotlin.Int
|
||||
public final override /*1*/ /*fake_override*/ val args: kotlin.Array<kotlin.String>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package
|
||||
|
||||
public final class Script : kotlin.script.StandardScriptTemplate {
|
||||
public final class Script : kotlin.script.templates.standard.ScriptTemplateWithArgs {
|
||||
public constructor Script(/*0*/ args: kotlin.Array<kotlin.String>)
|
||||
public final override /*1*/ /*fake_override*/ val args: kotlin.Array<kotlin.String>
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
|
||||
Vendored
+1
-1
@@ -1,6 +1,6 @@
|
||||
package
|
||||
|
||||
public final class Script : kotlin.script.StandardScriptTemplate {
|
||||
public final class Script : kotlin.script.templates.standard.ScriptTemplateWithArgs {
|
||||
public constructor Script(/*0*/ args: kotlin.Array<kotlin.String>)
|
||||
public final override /*1*/ /*fake_override*/ val args: kotlin.Array<kotlin.String>
|
||||
public final val prop: kotlin.Int
|
||||
|
||||
+7
-2
@@ -51,6 +51,11 @@ public class ForTestCompileRuntime {
|
||||
return assertExists(new File("dist/kotlinc/lib/kotlin-reflect.jar"));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static File scriptRuntimeJarForTests() {
|
||||
return assertExists(new File("dist/kotlinc/lib/kotlin-script-runtime.jar"));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static File assertExists(@NotNull File file) {
|
||||
if (!file.exists()) {
|
||||
@@ -63,7 +68,7 @@ public class ForTestCompileRuntime {
|
||||
public static synchronized ClassLoader runtimeAndReflectJarClassLoader() {
|
||||
ClassLoader loader = reflectJarClassLoader.get();
|
||||
if (loader == null) {
|
||||
loader = createClassLoader(runtimeJarForTests(), reflectJarForTests(), kotlinTestJarForTests());
|
||||
loader = createClassLoader(runtimeJarForTests(), reflectJarForTests(), scriptRuntimeJarForTests(), kotlinTestJarForTests());
|
||||
reflectJarClassLoader = new SoftReference<ClassLoader>(loader);
|
||||
}
|
||||
return loader;
|
||||
@@ -73,7 +78,7 @@ public class ForTestCompileRuntime {
|
||||
public static synchronized ClassLoader runtimeJarClassLoader() {
|
||||
ClassLoader loader = runtimeJarClassLoader.get();
|
||||
if (loader == null) {
|
||||
loader = createClassLoader(runtimeJarForTests());
|
||||
loader = createClassLoader(runtimeJarForTests(), scriptRuntimeJarForTests());
|
||||
runtimeJarClassLoader = new SoftReference<ClassLoader>(loader);
|
||||
}
|
||||
return loader;
|
||||
|
||||
@@ -468,10 +468,12 @@ public class KotlinTestUtils {
|
||||
|
||||
if (configurationKind.getWithRuntime()) {
|
||||
JvmContentRootsKt.addJvmClasspathRoot(configuration, ForTestCompileRuntime.runtimeJarForTests());
|
||||
JvmContentRootsKt.addJvmClasspathRoot(configuration, ForTestCompileRuntime.scriptRuntimeJarForTests());
|
||||
JvmContentRootsKt.addJvmClasspathRoot(configuration, ForTestCompileRuntime.kotlinTestJarForTests());
|
||||
}
|
||||
else if (configurationKind.getWithMockRuntime()) {
|
||||
JvmContentRootsKt.addJvmClasspathRoot(configuration, ForTestCompileRuntime.mockRuntimeJarForTests());
|
||||
JvmContentRootsKt.addJvmClasspathRoot(configuration, ForTestCompileRuntime.scriptRuntimeJarForTests());
|
||||
}
|
||||
if (configurationKind.getWithReflection()) {
|
||||
JvmContentRootsKt.addJvmClasspathRoot(configuration, ForTestCompileRuntime.reflectJarForTests());
|
||||
|
||||
@@ -43,7 +43,7 @@ class GenericReplTest : TestCase() {
|
||||
|
||||
val repl = TestRepl(disposable,
|
||||
listOf(File(KotlinIntegrationTestBase.getCompilerLib(), "kotlin-runtime.jar")),
|
||||
"kotlin.script.StandardScriptTemplate")
|
||||
"kotlin.script.templates.standard.ScriptTemplateWithArgs")
|
||||
|
||||
val res1 = repl.replCompiler?.check(ReplCodeLine(0, "val x ="), emptyList())
|
||||
TestCase.assertTrue("Unexpected check results: $res1", res1 is ReplCheckResult.Incomplete)
|
||||
|
||||
@@ -494,7 +494,7 @@ class CompilerDaemonTest : KotlinIntegrationTestBase() {
|
||||
withDisposable { disposable ->
|
||||
val repl = KotlinRemoteReplCompiler(disposable, daemon!!, null, CompileService.TargetPlatform.JVM,
|
||||
classpathFromClassloader(),
|
||||
"kotlin.script.StandardScriptTemplate",
|
||||
"kotlin.script.templates.standard.ScriptTemplateWithArgs",
|
||||
System.err)
|
||||
|
||||
val localEvaluator = GenericReplCompiledEvaluator(emptyList(),
|
||||
@@ -543,7 +543,7 @@ class CompilerDaemonTest : KotlinIntegrationTestBase() {
|
||||
|
||||
val repl = KotlinRemoteReplEvaluator(disposable, daemon!!, null, CompileService.TargetPlatform.JVM,
|
||||
listOf(File(KotlinIntegrationTestBase.getCompilerLib(), "kotlin-runtime.jar")),
|
||||
"kotlin.script.StandardScriptTemplate",
|
||||
"kotlin.script.templates.standard.ScriptTemplateWithArgs",
|
||||
arrayOf(emptyArray<String>()), null,
|
||||
System.err, evalOut, evalErr, evalIn)
|
||||
|
||||
|
||||
@@ -37,12 +37,11 @@ import org.junit.Test
|
||||
import java.io.File
|
||||
import java.lang.Exception
|
||||
import java.lang.reflect.InvocationTargetException
|
||||
import java.net.URISyntaxException
|
||||
import java.net.URL
|
||||
import java.net.URLClassLoader
|
||||
import java.util.concurrent.Future
|
||||
import kotlin.reflect.KClass
|
||||
import kotlin.script.StandardScriptTemplate
|
||||
import kotlin.script.templates.standard.ScriptTemplateWithArgs
|
||||
|
||||
// TODO: the contetnts of this file should go into ScriptTest.kt and replace appropriate xml-based functionality,
|
||||
// as soon as the the latter is removed from the codebase
|
||||
@@ -179,7 +178,7 @@ class ScriptTemplateTest {
|
||||
|
||||
@Test
|
||||
fun testScriptWithStandardTemplate() {
|
||||
val aClass = compileScript("fib_std.kts", StandardScriptTemplate::class, runIsolated = false)
|
||||
val aClass = compileScript("fib_std.kts", ScriptTemplateWithArgs::class, runIsolated = false)
|
||||
Assert.assertNotNull(aClass)
|
||||
captureOut {
|
||||
aClass!!.getConstructor(Array<String>::class.java).newInstance(arrayOf("4", "other"))
|
||||
@@ -324,12 +323,12 @@ class TestKotlinScriptDependenciesResolver : TestKotlinScriptDummyDependenciesRe
|
||||
{
|
||||
val cp = script.annotations.flatMap {
|
||||
when (it) {
|
||||
is DependsOn -> listOf(if (it.path == "@{runtime}") kotlinPaths.runtimePath else File(it.path))
|
||||
is DependsOnTwo -> listOf(it.path1, it.path2).mapNotNull {
|
||||
is DependsOn -> if (it.path == "@{runtime}") listOf(kotlinPaths.runtimePath, kotlinPaths.scriptRuntimePath) else listOf(File(it.path))
|
||||
is DependsOnTwo -> listOf(it.path1, it.path2).flatMap {
|
||||
when {
|
||||
it.isBlank() -> null
|
||||
it == "@{runtime}" -> kotlinPaths.runtimePath
|
||||
else -> File(it)
|
||||
it.isBlank() -> emptyList()
|
||||
it == "@{runtime}" -> listOf(kotlinPaths.runtimePath, kotlinPaths.scriptRuntimePath)
|
||||
else -> listOf(File(it))
|
||||
}
|
||||
}
|
||||
is InvalidScriptResolverAnnotation -> throw Exception("Invalid annotation ${it.name}", it.error)
|
||||
|
||||
@@ -33,6 +33,9 @@ public interface KotlinPaths {
|
||||
@NotNull
|
||||
File getReflectPath();
|
||||
|
||||
@NotNull
|
||||
File getScriptRuntimePath();
|
||||
|
||||
@NotNull
|
||||
File getKotlinTestPath();
|
||||
|
||||
|
||||
@@ -52,6 +52,12 @@ public class KotlinPathsFromHomeDir implements KotlinPaths {
|
||||
return getLibraryFile(PathUtil.KOTLIN_JAVA_REFLECT_JAR);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public File getScriptRuntimePath() {
|
||||
return getLibraryFile(PathUtil.KOTLIN_JAVA_SCRIPT_RUNTIME_JAR);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public File getKotlinTestPath() {
|
||||
|
||||
@@ -32,6 +32,7 @@ public class PathUtil {
|
||||
public static final String JS_LIB_SRC_JAR_NAME = "kotlin-jslib-sources.jar";
|
||||
public static final String KOTLIN_JAVA_RUNTIME_JAR = "kotlin-runtime.jar";
|
||||
public static final String KOTLIN_JAVA_REFLECT_JAR = "kotlin-reflect.jar";
|
||||
public static final String KOTLIN_JAVA_SCRIPT_RUNTIME_JAR = "kotlin-script-runtime.jar";
|
||||
public static final String KOTLIN_TEST_JAR = "kotlin-test.jar";
|
||||
public static final String KOTLIN_JAVA_RUNTIME_SRC_JAR = "kotlin-runtime-sources.jar";
|
||||
public static final String KOTLIN_COMPILER_JAR = "kotlin-compiler.jar";
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package kotlin.script
|
||||
|
||||
/**
|
||||
* Default script definition template
|
||||
*/
|
||||
public abstract class StandardScriptTemplate(val args: Array<String>)
|
||||
|
||||
|
||||
/**
|
||||
* Script definition template without parameters
|
||||
*/
|
||||
public abstract class SimpleScriptTemplate()
|
||||
|
||||
|
||||
/**
|
||||
* Script definition template with generic bindings
|
||||
*/
|
||||
public abstract class ScriptTemplateWithBindings(val bindings: Map<String, Any?>)
|
||||
|
||||
|
||||
/**
|
||||
* Script definition template with standard arguments and generic bindings
|
||||
*/
|
||||
public abstract class ScriptTemplateWithArgsAndBindings(val args: Array<String>, val bindings: Map<String, Any?>)
|
||||
-1
@@ -24,7 +24,6 @@ import org.jetbrains.kotlin.idea.core.script.KotlinScriptConfigurationManager
|
||||
import org.jetbrains.kotlin.script.KotlinScriptDefinitionFromAnnotatedTemplate
|
||||
import org.jetbrains.kotlin.script.StandardScriptDefinition
|
||||
import org.jetbrains.kotlin.script.getScriptDefinition
|
||||
import kotlin.script.StandardScriptTemplate
|
||||
|
||||
class KotlinScriptResolveScopeProvider : ResolveScopeProvider() {
|
||||
override fun getResolveScope(file: VirtualFile, project: Project): GlobalSearchScope? {
|
||||
|
||||
@@ -70,7 +70,7 @@ class KotlinConsoleKeeper(val project: Project) {
|
||||
//paramList.add("-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005")
|
||||
|
||||
val kotlinPaths = PathUtil.getKotlinPathsForIdeaPlugin()
|
||||
val replClassPath = listOf(kotlinPaths.compilerPath, kotlinPaths.reflectPath, kotlinPaths.runtimePath)
|
||||
val replClassPath = listOf(kotlinPaths.compilerPath, kotlinPaths.reflectPath, kotlinPaths.runtimePath, kotlinPaths.scriptRuntimePath)
|
||||
.map { it.absolutePath }
|
||||
.joinToString(File.pathSeparator)
|
||||
|
||||
|
||||
+4
-8
@@ -29,13 +29,9 @@ class KotlinJsr223StandardScriptEngineFactory4Idea : KotlinJsr223JvmScriptEngine
|
||||
KotlinJsr223JvmScriptEngine4Idea(
|
||||
Disposer.newDisposable(),
|
||||
this,
|
||||
listOf(PathUtil.getKotlinPathsForIdeaPlugin().runtimePath),
|
||||
"kotlin.script.ScriptTemplateWithArgsAndBindings",
|
||||
{ ctx ->
|
||||
val bindings = ctx.getBindings(ScriptContext.ENGINE_SCOPE)
|
||||
arrayOf(
|
||||
(bindings[ScriptEngine.ARGV] as? Array<*>) ?: emptyArray<String>(),
|
||||
bindings) },
|
||||
arrayOf(Array<String>::class.java, Map::class.java)
|
||||
listOf(PathUtil.getKotlinPathsForIdeaPlugin().runtimePath, PathUtil.getKotlinPathsForIdeaPlugin().scriptRuntimePath),
|
||||
"kotlin.script.templates.standard.ScriptTemplateWithBindings",
|
||||
{ ctx -> arrayOf(ctx.getBindings(ScriptContext.ENGINE_SCOPE)) },
|
||||
arrayOf(Map::class.java)
|
||||
)
|
||||
}
|
||||
|
||||
+1
-1
@@ -187,7 +187,7 @@ private class ScriptCommandLineState(environment: ExecutionEnvironment, configur
|
||||
val params = commonParameters()
|
||||
|
||||
val kotlinPaths = PathUtil.getKotlinPathsForIdeaPlugin()
|
||||
listOf(kotlinPaths.compilerPath, kotlinPaths.reflectPath, kotlinPaths.runtimePath)
|
||||
listOf(kotlinPaths.compilerPath, kotlinPaths.reflectPath, kotlinPaths.runtimePath, kotlinPaths.scriptRuntimePath)
|
||||
.map { it.absolutePath }
|
||||
.forEach { dependencyJar -> params.classPath.add(dependencyJar) }
|
||||
|
||||
|
||||
@@ -125,6 +125,7 @@ private fun updateJar(
|
||||
val jarPath: File = when (libraryJarDescriptor) {
|
||||
LibraryJarDescriptor.RUNTIME_JAR -> paths.runtimePath
|
||||
LibraryJarDescriptor.REFLECT_JAR -> paths.reflectPath
|
||||
LibraryJarDescriptor.SCRIPT_RUNTIME_JAR -> paths.scriptRuntimePath
|
||||
LibraryJarDescriptor.TEST_JAR -> paths.kotlinTestPath
|
||||
LibraryJarDescriptor.RUNTIME_SRC_JAR -> paths.runtimeSourcesPath
|
||||
LibraryJarDescriptor.JS_STDLIB_JAR -> paths.jsStdLibJarPath
|
||||
@@ -160,6 +161,7 @@ fun findAllUsedLibraries(project: Project): MultiMap<Library, Module> {
|
||||
private enum class LibraryJarDescriptor private constructor(val jarName: String, val shouldExist: Boolean) {
|
||||
RUNTIME_JAR(PathUtil.KOTLIN_JAVA_RUNTIME_JAR, true),
|
||||
REFLECT_JAR(PathUtil.KOTLIN_JAVA_REFLECT_JAR, false),
|
||||
SCRIPT_RUNTIME_JAR(PathUtil.KOTLIN_JAVA_SCRIPT_RUNTIME_JAR, true),
|
||||
TEST_JAR(PathUtil.KOTLIN_TEST_JAR, false),
|
||||
RUNTIME_SRC_JAR(PathUtil.KOTLIN_JAVA_RUNTIME_SRC_JAR, false),
|
||||
JS_STDLIB_JAR(PathUtil.JS_LIB_JAR_NAME, true),
|
||||
|
||||
@@ -52,6 +52,7 @@ class KotlinUpdatePluginComponent : ApplicationComponent {
|
||||
// Force refresh jar handlers
|
||||
requestFullJarUpdate(ideaPluginPaths.runtimePath)
|
||||
requestFullJarUpdate(ideaPluginPaths.reflectPath)
|
||||
requestFullJarUpdate(ideaPluginPaths.scriptRuntimePath)
|
||||
requestFullJarUpdate(ideaPluginPaths.runtimeSourcesPath)
|
||||
|
||||
requestFullJarUpdate(ideaPluginPaths.jsStdLibJarPath)
|
||||
|
||||
@@ -55,10 +55,7 @@ class IdeaJsr223Test : PlatformTestCase() {
|
||||
bindings.put(ScriptEngine.ARGV, arrayOf("42"))
|
||||
bindings.put("abc", 13)
|
||||
|
||||
val res1 = engine.eval("2 + args[0].toInt()")
|
||||
assertEquals(44, res1)
|
||||
|
||||
val res2 = engine.eval("2 + (bindings[\"abc\"] as Int)")
|
||||
assertEquals(15, res2)
|
||||
val res1 = engine.eval("2 + (bindings[\"abc\"] as Int)")
|
||||
assertEquals(15, res1)
|
||||
}
|
||||
}
|
||||
|
||||
-20
@@ -1275,26 +1275,6 @@ public final class kotlin/reflect/KVisibility : java/lang/Enum {
|
||||
public static fun values ()[Lkotlin/reflect/KVisibility;
|
||||
}
|
||||
|
||||
public abstract class kotlin/script/ScriptTemplateWithArgsAndBindings {
|
||||
public fun <init> ([Ljava/lang/String;Ljava/util/Map;)V
|
||||
public final fun getArgs ()[Ljava/lang/String;
|
||||
public final fun getBindings ()Ljava/util/Map;
|
||||
}
|
||||
|
||||
public abstract class kotlin/script/ScriptTemplateWithBindings {
|
||||
public fun <init> (Ljava/util/Map;)V
|
||||
public final fun getBindings ()Ljava/util/Map;
|
||||
}
|
||||
|
||||
public abstract class kotlin/script/SimpleScriptTemplate {
|
||||
public fun <init> ()V
|
||||
}
|
||||
|
||||
public abstract class kotlin/script/StandardScriptTemplate {
|
||||
public fun <init> ([Ljava/lang/String;)V
|
||||
public final fun getArgs ()[Ljava/lang/String;
|
||||
}
|
||||
|
||||
public abstract interface annotation class org/jetbrains/annotations/Mutable : java/lang/annotation/Annotation {
|
||||
}
|
||||
|
||||
|
||||
+13
-22
@@ -25,7 +25,7 @@ import java.io.File
|
||||
import java.io.FileNotFoundException
|
||||
import javax.script.ScriptContext
|
||||
import javax.script.ScriptEngine
|
||||
import kotlin.script.StandardScriptTemplate
|
||||
import kotlin.script.templates.standard.ScriptTemplateWithArgs
|
||||
|
||||
class KotlinJsr223JvmLocalScriptEngineFactory : KotlinJsr223JvmScriptEngineFactoryBase() {
|
||||
|
||||
@@ -34,9 +34,9 @@ class KotlinJsr223JvmLocalScriptEngineFactory : KotlinJsr223JvmScriptEngineFacto
|
||||
Disposer.newDisposable(),
|
||||
this,
|
||||
listOf(kotlinRuntimeJar),
|
||||
"kotlin.script.ScriptTemplateWithArgsAndBindings",
|
||||
::makeArgumentsForTemplateWithArgsAndBindings,
|
||||
arrayOf(Array<String>::class.java, java.util.Map::class.java)
|
||||
"kotlin.script.templates.standard.ScriptTemplateWithBindings",
|
||||
{ ctx -> arrayOf(ctx.getBindings(ScriptContext.ENGINE_SCOPE)) },
|
||||
arrayOf(Map::class.java)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -48,9 +48,9 @@ class KotlinJsr223JvmDaemonLocalEvalScriptEngineFactory : KotlinJsr223JvmScriptE
|
||||
this,
|
||||
kotlinCompilerJar,
|
||||
listOf(kotlinRuntimeJar),
|
||||
"kotlin.script.ScriptTemplateWithArgsAndBindings",
|
||||
::makeArgumentsForTemplateWithArgsAndBindings,
|
||||
arrayOf(Array<String>::class.java, java.util.Map::class.java)
|
||||
"kotlin.script.templates.standard.ScriptTemplateWithBindings",
|
||||
{ ctx -> arrayOf(ctx.getBindings(ScriptContext.ENGINE_SCOPE)) },
|
||||
arrayOf(Map::class.java)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -62,27 +62,18 @@ class KotlinJsr223JvmDaemonRemoteEvalScriptEngineFactory : KotlinJsr223JvmScript
|
||||
this,
|
||||
kotlinCompilerJar,
|
||||
listOf(kotlinRuntimeJar),
|
||||
"kotlin.script.ScriptTemplateWithArgsAndBindings",
|
||||
::makeSerializableArgumentsForTemplateWithArgsAndBindings,
|
||||
arrayOf(Array<String>::class.java, java.util.Map::class.java)
|
||||
"kotlin.script.templates.standard.ScriptTemplateWithBindings",
|
||||
::makeSerializableArgumentsForTemplateWithBindings,
|
||||
arrayOf(Map::class.java)
|
||||
)
|
||||
}
|
||||
|
||||
private fun makeArgumentsForTemplateWithArgsAndBindings(ctx: ScriptContext): Array<Any?> {
|
||||
val bindings = ctx.getBindings(ScriptContext.ENGINE_SCOPE)
|
||||
return arrayOf(
|
||||
(bindings[ScriptEngine.ARGV] as? Array<*>) ?: emptyArray<String>(),
|
||||
bindings)
|
||||
}
|
||||
|
||||
private fun makeSerializableArgumentsForTemplateWithArgsAndBindings(ctx: ScriptContext): Array<Any?> {
|
||||
private fun makeSerializableArgumentsForTemplateWithBindings(ctx: ScriptContext): Array<Any?> {
|
||||
val bindings = ctx.getBindings(ScriptContext.ENGINE_SCOPE)
|
||||
val serializableBindings = linkedMapOf<String, Any>()
|
||||
// TODO: consider deeper analysis and copying to serializable data if possible
|
||||
serializableBindings.putAll(bindings)
|
||||
return arrayOf(
|
||||
(bindings[ScriptEngine.ARGV] as? Array<*>) ?: emptyArray<String>(),
|
||||
serializableBindings)
|
||||
return arrayOf(serializableBindings)
|
||||
}
|
||||
|
||||
private fun File.existsOrNull(): File? = existsAndCheckOrNull { true }
|
||||
@@ -94,5 +85,5 @@ private val kotlinCompilerJar = System.getProperty("kotlin.compiler.jar")?.let(:
|
||||
|
||||
private val kotlinRuntimeJar = System.getProperty("kotlin.java.runtime.jar")?.let(::File)?.existsOrNull()
|
||||
?: kotlinCompilerJar.let { File(it.parentFile, KOTLIN_JAVA_RUNTIME_JAR) }.existsOrNull()
|
||||
?: getResourcePathForClass(StandardScriptTemplate::class.java).existsOrNull()
|
||||
?: getResourcePathForClass(ScriptTemplateWithArgs::class.java).existsOrNull()
|
||||
?: throw FileNotFoundException("Cannot find kotlin runtime jar, set kotlin.java.runtime.jar property to proper location")
|
||||
|
||||
Reference in New Issue
Block a user