Switch to templates in the separate script runtime

This commit is contained in:
Ilya Chernikov
2016-10-11 10:03:41 +02:00
parent c2b5c11781
commit 846797ff61
36 changed files with 99 additions and 128 deletions
+9
View File
@@ -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>
+12 -3
View File
@@ -15,6 +15,7 @@
<property name="bootstrap.compiler.home" value="${bootstrap.home}/Kotlin/kotlinc"/> <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.runtime" value="${bootstrap.compiler.home}/lib/kotlin-runtime.jar"/>
<property name="bootstrap.reflect" value="${bootstrap.compiler.home}/lib/kotlin-reflect.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="bootstrap.kotlin.test" value="${bootstrap.compiler.home}/lib/kotlin-test.jar" />
<property name="output" value="${basedir}/dist"/> <property name="output" value="${basedir}/dist"/>
@@ -57,8 +58,8 @@
little to no differences between the new and the newest runtime. little to no differences between the new and the newest runtime.
--> -->
<condition property="compiler.manifest.class.path" <condition property="compiler.manifest.class.path"
value="kotlin-runtime-internal-bootstrap.jar kotlin-reflect-internal-bootstrap.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"> else="kotlin-runtime.jar kotlin-reflect.jar kotlin-script-runtime.jar">
<istrue value="${bootstrap.or.local.build}"/> <istrue value="${bootstrap.or.local.build}"/>
</condition> </condition>
@@ -66,6 +67,7 @@
<file file="${bootstrap.runtime}"/> <file file="${bootstrap.runtime}"/>
<file file="${bootstrap.kotlin.test}" /> <file file="${bootstrap.kotlin.test}" />
<file file="${bootstrap.reflect}"/> <file file="${bootstrap.reflect}"/>
<file file="${bootstrap.script.runtime}"/>
<fileset dir="${idea.sdk}" includes="core/*.jar"/> <fileset dir="${idea.sdk}" includes="core/*.jar"/>
<pathelement location="${protobuf.jar}"/> <pathelement location="${protobuf.jar}"/>
@@ -190,6 +192,7 @@
<sequential if:true="${bootstrap.or.local.build}"> <sequential if:true="${bootstrap.or.local.build}">
<copy file="${bootstrap.runtime}" tofile="${kotlin-home}/lib/kotlin-runtime-internal-bootstrap.jar"/> <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.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"/> <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"> <jar destfile="${kotlin-home}/lib/kotlin-reflect-internal-bootstrap.jar" update="true">
<manifest> <manifest>
@@ -206,6 +209,7 @@
<sequential unless:true="${bootstrap.or.local.build}"> <sequential unless:true="${bootstrap.or.local.build}">
<copy file="${bootstrap.runtime}" todir="${kotlin-home}/lib"/> <copy file="${bootstrap.runtime}" todir="${kotlin-home}/lib"/>
<copy file="${bootstrap.reflect}" 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"/> <copy file="${bootstrap.kotlin.test}" todir="${kotlin-home}/lib"/>
</sequential> </sequential>
</target> </target>
@@ -612,6 +616,9 @@
<zipfileset src="${bootstrap.reflect}"> <zipfileset src="${bootstrap.reflect}">
<patternset refid="lib.metainf.patternset"/> <patternset refid="lib.metainf.patternset"/>
</zipfileset> </zipfileset>
<zipfileset src="${bootstrap.script.runtime}">
<patternset refid="lib.metainf.patternset"/>
</zipfileset>
<manifest> <manifest>
<attribute name="Built-By" value="${manifest.impl.vendor}"/> <attribute name="Built-By" value="${manifest.impl.vendor}"/>
@@ -640,6 +647,7 @@
<classpath> <classpath>
<pathelement path="${bootstrap.runtime}"/> <pathelement path="${bootstrap.runtime}"/>
<pathelement path="${bootstrap.reflect}"/> <pathelement path="${bootstrap.reflect}"/>
<pathelement path="${bootstrap.script.runtime}"/>
<pathelement path="${idea.sdk}/lib/util.jar"/> <pathelement path="${idea.sdk}/lib/util.jar"/>
<pathelement path="${kotlin-home}/lib/kotlin-compiler.jar"/> <pathelement path="${kotlin-home}/lib/kotlin-compiler.jar"/>
</classpath> </classpath>
@@ -683,6 +691,7 @@
<classpath> <classpath>
<pathelement path="${bootstrap.runtime}"/> <pathelement path="${bootstrap.runtime}"/>
<pathelement path="${bootstrap.reflect}"/> <pathelement path="${bootstrap.reflect}"/>
<pathelement path="${bootstrap.script.runtime}"/>
<pathelement path="${bootstrap.kotlin.test}"/> <pathelement path="${bootstrap.kotlin.test}"/>
<pathelement path="${protobuf.jar}"/> <pathelement path="${protobuf.jar}"/>
<pathelement path="${idea.sdk}/lib/junit-4.12.jar"/> <pathelement path="${idea.sdk}/lib/junit-4.12.jar"/>
@@ -812,6 +821,7 @@
<pathelement path="${kotlin-home}/lib/kotlin-compiler.jar"/> <pathelement path="${kotlin-home}/lib/kotlin-compiler.jar"/>
<pathelement path="${bootstrap.runtime}"/> <pathelement path="${bootstrap.runtime}"/>
<pathelement path="${bootstrap.reflect}"/> <pathelement path="${bootstrap.reflect}"/>
<pathelement path="${bootstrap.script.runtime}"/>
</classpath> </classpath>
</javac2> </javac2>
@@ -1201,7 +1211,6 @@
<delete dir="${output}/mock-runtime-src" failonerror="false"/> <delete dir="${output}/mock-runtime-src" failonerror="false"/>
<mkdir dir="${output}/mock-runtime-src"/> <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/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/util/Standard.kt" todir="${output}/mock-runtime-src"/>
<copy file="${basedir}/libraries/stdlib/src/kotlin/internal/Annotations.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) { if (!arguments.noStdlib) {
classpath.add(paths.runtimePath) 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, // "-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" // which is likely not what user wants since s/he manually provided "-no-stdlib"
@@ -122,8 +122,16 @@ public class CompileEnvironmentUtil {
if (!runtimePath.exists()) { if (!runtimePath.exists()) {
throw new CompileEnvironmentException("Couldn't find runtime library"); 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 { try {
while (true) { while (true) {
JarEntry e = jis.getNextJarEntry(); JarEntry e = jis.getNextJarEntry();
+1
View File
@@ -46,6 +46,7 @@ messages/**)
-libraryjars '<jssejar>' -libraryjars '<jssejar>'
-libraryjars '<bootstrap.runtime>' -libraryjars '<bootstrap.runtime>'
-libraryjars '<bootstrap.reflect>' -libraryjars '<bootstrap.reflect>'
-libraryjars '<bootstrap.script.runtime>'
-target 1.6 -target 1.6
-dontoptimize -dontoptimize
@@ -77,7 +77,7 @@ open class KotlinJvmReplService(
protected val configuration = CompilerConfiguration().apply { protected val configuration = CompilerConfiguration().apply {
addJvmClasspathRoots(PathUtil.getJdkClassesRoots()) 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) addJvmClasspathRoots(templateClasspath)
put(CommonConfigurationKeys.MODULE_NAME, "kotlin-script") put(CommonConfigurationKeys.MODULE_NAME, "kotlin-script")
} }
+1
View File
@@ -15,5 +15,6 @@
<orderEntry type="module" module-name="container" exported="" /> <orderEntry type="module" module-name="container" exported="" />
<orderEntry type="library" scope="TEST" name="kotlin-test" level="project" /> <orderEntry type="library" scope="TEST" name="kotlin-test" level="project" />
<orderEntry type="module" module-name="resolution" exported="" /> <orderEntry type="module" module-name="resolution" exported="" />
<orderEntry type="library" exported="" name="kotlin-script-runtime" level="project" />
</component> </component>
</module> </module>
@@ -24,7 +24,7 @@ import org.jetbrains.kotlin.parsing.KotlinParserDefinition
import org.jetbrains.kotlin.psi.KtScript import org.jetbrains.kotlin.psi.KtScript
import java.io.File import java.io.File
import kotlin.reflect.KClass import kotlin.reflect.KClass
import kotlin.script.StandardScriptTemplate import kotlin.script.templates.standard.ScriptTemplateWithArgs
open class KotlinScriptDefinition(val template: KClass<out Any>) { open class KotlinScriptDefinition(val template: KClass<out Any>) {
@@ -50,5 +50,5 @@ interface KotlinScriptExternalDependencies {
val scripts: Iterable<File> get() = emptyList() val scripts: Iterable<File> get() = emptyList()
} }
object StandardScriptDefinition : KotlinScriptDefinition(StandardScriptTemplate::class) object StandardScriptDefinition : KotlinScriptDefinition(ScriptTemplateWithArgs::class)
@@ -1,6 +1,6 @@
package 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 constructor Script(/*0*/ args: kotlin.Array<kotlin.String>)
public final override /*1*/ /*fake_override*/ val 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 public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
@@ -9,7 +9,7 @@ package test {
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String 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 constructor A(/*0*/ args: kotlin.Array<kotlin.String>)
public final override /*1*/ /*fake_override*/ val args: kotlin.Array<kotlin.String> public final override /*1*/ /*fake_override*/ val args: kotlin.Array<kotlin.String>
public final val x: kotlin.Int = 1 public final val x: kotlin.Int = 1
@@ -1,6 +1,6 @@
package 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 constructor AccessForwardDeclarationInScript(/*0*/ args: kotlin.Array<kotlin.String>)
public final override /*1*/ /*fake_override*/ val args: kotlin.Array<kotlin.String> public final override /*1*/ /*fake_override*/ val args: kotlin.Array<kotlin.String>
public final val x: kotlin.Int = 2 public final val x: kotlin.Int = 2
@@ -1,6 +1,6 @@
package 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 constructor ComplexScript(/*0*/ args: kotlin.Array<kotlin.String>)
public final override /*1*/ /*fake_override*/ val args: kotlin.Array<kotlin.String> public final override /*1*/ /*fake_override*/ val args: kotlin.Array<kotlin.String>
public final val y: kotlin.Int = 2 public final val y: kotlin.Int = 2
@@ -1,6 +1,6 @@
package 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 constructor NestedInnerClass(/*0*/ args: kotlin.Array<kotlin.String>)
public final override /*1*/ /*fake_override*/ val args: kotlin.Array<kotlin.String> public final override /*1*/ /*fake_override*/ val args: kotlin.Array<kotlin.String>
public final val property: kotlin.String = "" public final val property: kotlin.String = ""
@@ -1,6 +1,6 @@
package 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 constructor SimpleScript(/*0*/ args: kotlin.Array<kotlin.String>)
public final override /*1*/ /*fake_override*/ val args: kotlin.Array<kotlin.String> public final override /*1*/ /*fake_override*/ val args: kotlin.Array<kotlin.String>
public final val x: kotlin.Int = 1 public final val x: kotlin.Int = 1
+1 -1
View File
@@ -1,6 +1,6 @@
package 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 constructor Imports(/*0*/ args: kotlin.Array<kotlin.String>)
public final val al: java.util.ArrayList<kotlin.String>? = null public final val al: java.util.ArrayList<kotlin.String>? = null
public final override /*1*/ /*fake_override*/ val args: kotlin.Array<kotlin.String> public final override /*1*/ /*fake_override*/ val args: kotlin.Array<kotlin.String>
@@ -1,6 +1,6 @@
package 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 constructor TopLevelVariable(/*0*/ args: kotlin.Array<kotlin.String>)
public final val a: kotlin.Int public final val a: kotlin.Int
public final override /*1*/ /*fake_override*/ val args: kotlin.Array<kotlin.String> public final override /*1*/ /*fake_override*/ val args: kotlin.Array<kotlin.String>
+1 -1
View File
@@ -1,6 +1,6 @@
package 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 constructor Script(/*0*/ args: kotlin.Array<kotlin.String>)
public final override /*1*/ /*fake_override*/ val 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 public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
@@ -1,6 +1,6 @@
package 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 constructor Script(/*0*/ args: kotlin.Array<kotlin.String>)
public final override /*1*/ /*fake_override*/ val args: kotlin.Array<kotlin.String> public final override /*1*/ /*fake_override*/ val args: kotlin.Array<kotlin.String>
public final val prop: kotlin.Int public final val prop: kotlin.Int
@@ -51,6 +51,11 @@ public class ForTestCompileRuntime {
return assertExists(new File("dist/kotlinc/lib/kotlin-reflect.jar")); 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 @NotNull
private static File assertExists(@NotNull File file) { private static File assertExists(@NotNull File file) {
if (!file.exists()) { if (!file.exists()) {
@@ -63,7 +68,7 @@ public class ForTestCompileRuntime {
public static synchronized ClassLoader runtimeAndReflectJarClassLoader() { public static synchronized ClassLoader runtimeAndReflectJarClassLoader() {
ClassLoader loader = reflectJarClassLoader.get(); ClassLoader loader = reflectJarClassLoader.get();
if (loader == null) { if (loader == null) {
loader = createClassLoader(runtimeJarForTests(), reflectJarForTests(), kotlinTestJarForTests()); loader = createClassLoader(runtimeJarForTests(), reflectJarForTests(), scriptRuntimeJarForTests(), kotlinTestJarForTests());
reflectJarClassLoader = new SoftReference<ClassLoader>(loader); reflectJarClassLoader = new SoftReference<ClassLoader>(loader);
} }
return loader; return loader;
@@ -73,7 +78,7 @@ public class ForTestCompileRuntime {
public static synchronized ClassLoader runtimeJarClassLoader() { public static synchronized ClassLoader runtimeJarClassLoader() {
ClassLoader loader = runtimeJarClassLoader.get(); ClassLoader loader = runtimeJarClassLoader.get();
if (loader == null) { if (loader == null) {
loader = createClassLoader(runtimeJarForTests()); loader = createClassLoader(runtimeJarForTests(), scriptRuntimeJarForTests());
runtimeJarClassLoader = new SoftReference<ClassLoader>(loader); runtimeJarClassLoader = new SoftReference<ClassLoader>(loader);
} }
return loader; return loader;
@@ -468,10 +468,12 @@ public class KotlinTestUtils {
if (configurationKind.getWithRuntime()) { if (configurationKind.getWithRuntime()) {
JvmContentRootsKt.addJvmClasspathRoot(configuration, ForTestCompileRuntime.runtimeJarForTests()); JvmContentRootsKt.addJvmClasspathRoot(configuration, ForTestCompileRuntime.runtimeJarForTests());
JvmContentRootsKt.addJvmClasspathRoot(configuration, ForTestCompileRuntime.scriptRuntimeJarForTests());
JvmContentRootsKt.addJvmClasspathRoot(configuration, ForTestCompileRuntime.kotlinTestJarForTests()); JvmContentRootsKt.addJvmClasspathRoot(configuration, ForTestCompileRuntime.kotlinTestJarForTests());
} }
else if (configurationKind.getWithMockRuntime()) { else if (configurationKind.getWithMockRuntime()) {
JvmContentRootsKt.addJvmClasspathRoot(configuration, ForTestCompileRuntime.mockRuntimeJarForTests()); JvmContentRootsKt.addJvmClasspathRoot(configuration, ForTestCompileRuntime.mockRuntimeJarForTests());
JvmContentRootsKt.addJvmClasspathRoot(configuration, ForTestCompileRuntime.scriptRuntimeJarForTests());
} }
if (configurationKind.getWithReflection()) { if (configurationKind.getWithReflection()) {
JvmContentRootsKt.addJvmClasspathRoot(configuration, ForTestCompileRuntime.reflectJarForTests()); JvmContentRootsKt.addJvmClasspathRoot(configuration, ForTestCompileRuntime.reflectJarForTests());
@@ -43,7 +43,7 @@ class GenericReplTest : TestCase() {
val repl = TestRepl(disposable, val repl = TestRepl(disposable,
listOf(File(KotlinIntegrationTestBase.getCompilerLib(), "kotlin-runtime.jar")), 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()) val res1 = repl.replCompiler?.check(ReplCodeLine(0, "val x ="), emptyList())
TestCase.assertTrue("Unexpected check results: $res1", res1 is ReplCheckResult.Incomplete) TestCase.assertTrue("Unexpected check results: $res1", res1 is ReplCheckResult.Incomplete)
@@ -494,7 +494,7 @@ class CompilerDaemonTest : KotlinIntegrationTestBase() {
withDisposable { disposable -> withDisposable { disposable ->
val repl = KotlinRemoteReplCompiler(disposable, daemon!!, null, CompileService.TargetPlatform.JVM, val repl = KotlinRemoteReplCompiler(disposable, daemon!!, null, CompileService.TargetPlatform.JVM,
classpathFromClassloader(), classpathFromClassloader(),
"kotlin.script.StandardScriptTemplate", "kotlin.script.templates.standard.ScriptTemplateWithArgs",
System.err) System.err)
val localEvaluator = GenericReplCompiledEvaluator(emptyList(), val localEvaluator = GenericReplCompiledEvaluator(emptyList(),
@@ -543,7 +543,7 @@ class CompilerDaemonTest : KotlinIntegrationTestBase() {
val repl = KotlinRemoteReplEvaluator(disposable, daemon!!, null, CompileService.TargetPlatform.JVM, val repl = KotlinRemoteReplEvaluator(disposable, daemon!!, null, CompileService.TargetPlatform.JVM,
listOf(File(KotlinIntegrationTestBase.getCompilerLib(), "kotlin-runtime.jar")), listOf(File(KotlinIntegrationTestBase.getCompilerLib(), "kotlin-runtime.jar")),
"kotlin.script.StandardScriptTemplate", "kotlin.script.templates.standard.ScriptTemplateWithArgs",
arrayOf(emptyArray<String>()), null, arrayOf(emptyArray<String>()), null,
System.err, evalOut, evalErr, evalIn) System.err, evalOut, evalErr, evalIn)
@@ -37,12 +37,11 @@ import org.junit.Test
import java.io.File import java.io.File
import java.lang.Exception import java.lang.Exception
import java.lang.reflect.InvocationTargetException import java.lang.reflect.InvocationTargetException
import java.net.URISyntaxException
import java.net.URL import java.net.URL
import java.net.URLClassLoader import java.net.URLClassLoader
import java.util.concurrent.Future import java.util.concurrent.Future
import kotlin.reflect.KClass 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, // 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 // as soon as the the latter is removed from the codebase
@@ -179,7 +178,7 @@ class ScriptTemplateTest {
@Test @Test
fun testScriptWithStandardTemplate() { 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) Assert.assertNotNull(aClass)
captureOut { captureOut {
aClass!!.getConstructor(Array<String>::class.java).newInstance(arrayOf("4", "other")) aClass!!.getConstructor(Array<String>::class.java).newInstance(arrayOf("4", "other"))
@@ -324,12 +323,12 @@ class TestKotlinScriptDependenciesResolver : TestKotlinScriptDummyDependenciesRe
{ {
val cp = script.annotations.flatMap { val cp = script.annotations.flatMap {
when (it) { when (it) {
is DependsOn -> listOf(if (it.path == "@{runtime}") kotlinPaths.runtimePath else File(it.path)) is DependsOn -> if (it.path == "@{runtime}") listOf(kotlinPaths.runtimePath, kotlinPaths.scriptRuntimePath) else listOf(File(it.path))
is DependsOnTwo -> listOf(it.path1, it.path2).mapNotNull { is DependsOnTwo -> listOf(it.path1, it.path2).flatMap {
when { when {
it.isBlank() -> null it.isBlank() -> emptyList()
it == "@{runtime}" -> kotlinPaths.runtimePath it == "@{runtime}" -> listOf(kotlinPaths.runtimePath, kotlinPaths.scriptRuntimePath)
else -> File(it) else -> listOf(File(it))
} }
} }
is InvalidScriptResolverAnnotation -> throw Exception("Invalid annotation ${it.name}", it.error) is InvalidScriptResolverAnnotation -> throw Exception("Invalid annotation ${it.name}", it.error)
@@ -33,6 +33,9 @@ public interface KotlinPaths {
@NotNull @NotNull
File getReflectPath(); File getReflectPath();
@NotNull
File getScriptRuntimePath();
@NotNull @NotNull
File getKotlinTestPath(); File getKotlinTestPath();
@@ -52,6 +52,12 @@ public class KotlinPathsFromHomeDir implements KotlinPaths {
return getLibraryFile(PathUtil.KOTLIN_JAVA_REFLECT_JAR); return getLibraryFile(PathUtil.KOTLIN_JAVA_REFLECT_JAR);
} }
@Override
@NotNull
public File getScriptRuntimePath() {
return getLibraryFile(PathUtil.KOTLIN_JAVA_SCRIPT_RUNTIME_JAR);
}
@NotNull @NotNull
@Override @Override
public File getKotlinTestPath() { 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 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_RUNTIME_JAR = "kotlin-runtime.jar";
public static final String KOTLIN_JAVA_REFLECT_JAR = "kotlin-reflect.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_TEST_JAR = "kotlin-test.jar";
public static final String KOTLIN_JAVA_RUNTIME_SRC_JAR = "kotlin-runtime-sources.jar"; public static final String KOTLIN_JAVA_RUNTIME_SRC_JAR = "kotlin-runtime-sources.jar";
public static final String KOTLIN_COMPILER_JAR = "kotlin-compiler.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?>)
@@ -24,7 +24,6 @@ import org.jetbrains.kotlin.idea.core.script.KotlinScriptConfigurationManager
import org.jetbrains.kotlin.script.KotlinScriptDefinitionFromAnnotatedTemplate import org.jetbrains.kotlin.script.KotlinScriptDefinitionFromAnnotatedTemplate
import org.jetbrains.kotlin.script.StandardScriptDefinition import org.jetbrains.kotlin.script.StandardScriptDefinition
import org.jetbrains.kotlin.script.getScriptDefinition import org.jetbrains.kotlin.script.getScriptDefinition
import kotlin.script.StandardScriptTemplate
class KotlinScriptResolveScopeProvider : ResolveScopeProvider() { class KotlinScriptResolveScopeProvider : ResolveScopeProvider() {
override fun getResolveScope(file: VirtualFile, project: Project): GlobalSearchScope? { 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") //paramList.add("-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005")
val kotlinPaths = PathUtil.getKotlinPathsForIdeaPlugin() 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 } .map { it.absolutePath }
.joinToString(File.pathSeparator) .joinToString(File.pathSeparator)
@@ -29,13 +29,9 @@ class KotlinJsr223StandardScriptEngineFactory4Idea : KotlinJsr223JvmScriptEngine
KotlinJsr223JvmScriptEngine4Idea( KotlinJsr223JvmScriptEngine4Idea(
Disposer.newDisposable(), Disposer.newDisposable(),
this, this,
listOf(PathUtil.getKotlinPathsForIdeaPlugin().runtimePath), listOf(PathUtil.getKotlinPathsForIdeaPlugin().runtimePath, PathUtil.getKotlinPathsForIdeaPlugin().scriptRuntimePath),
"kotlin.script.ScriptTemplateWithArgsAndBindings", "kotlin.script.templates.standard.ScriptTemplateWithBindings",
{ ctx -> { ctx -> arrayOf(ctx.getBindings(ScriptContext.ENGINE_SCOPE)) },
val bindings = ctx.getBindings(ScriptContext.ENGINE_SCOPE) arrayOf(Map::class.java)
arrayOf(
(bindings[ScriptEngine.ARGV] as? Array<*>) ?: emptyArray<String>(),
bindings) },
arrayOf(Array<String>::class.java, Map::class.java)
) )
} }
@@ -187,7 +187,7 @@ private class ScriptCommandLineState(environment: ExecutionEnvironment, configur
val params = commonParameters() val params = commonParameters()
val kotlinPaths = PathUtil.getKotlinPathsForIdeaPlugin() val kotlinPaths = PathUtil.getKotlinPathsForIdeaPlugin()
listOf(kotlinPaths.compilerPath, kotlinPaths.reflectPath, kotlinPaths.runtimePath) listOf(kotlinPaths.compilerPath, kotlinPaths.reflectPath, kotlinPaths.runtimePath, kotlinPaths.scriptRuntimePath)
.map { it.absolutePath } .map { it.absolutePath }
.forEach { dependencyJar -> params.classPath.add(dependencyJar) } .forEach { dependencyJar -> params.classPath.add(dependencyJar) }
@@ -125,6 +125,7 @@ private fun updateJar(
val jarPath: File = when (libraryJarDescriptor) { val jarPath: File = when (libraryJarDescriptor) {
LibraryJarDescriptor.RUNTIME_JAR -> paths.runtimePath LibraryJarDescriptor.RUNTIME_JAR -> paths.runtimePath
LibraryJarDescriptor.REFLECT_JAR -> paths.reflectPath LibraryJarDescriptor.REFLECT_JAR -> paths.reflectPath
LibraryJarDescriptor.SCRIPT_RUNTIME_JAR -> paths.scriptRuntimePath
LibraryJarDescriptor.TEST_JAR -> paths.kotlinTestPath LibraryJarDescriptor.TEST_JAR -> paths.kotlinTestPath
LibraryJarDescriptor.RUNTIME_SRC_JAR -> paths.runtimeSourcesPath LibraryJarDescriptor.RUNTIME_SRC_JAR -> paths.runtimeSourcesPath
LibraryJarDescriptor.JS_STDLIB_JAR -> paths.jsStdLibJarPath 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) { private enum class LibraryJarDescriptor private constructor(val jarName: String, val shouldExist: Boolean) {
RUNTIME_JAR(PathUtil.KOTLIN_JAVA_RUNTIME_JAR, true), RUNTIME_JAR(PathUtil.KOTLIN_JAVA_RUNTIME_JAR, true),
REFLECT_JAR(PathUtil.KOTLIN_JAVA_REFLECT_JAR, false), 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), TEST_JAR(PathUtil.KOTLIN_TEST_JAR, false),
RUNTIME_SRC_JAR(PathUtil.KOTLIN_JAVA_RUNTIME_SRC_JAR, false), RUNTIME_SRC_JAR(PathUtil.KOTLIN_JAVA_RUNTIME_SRC_JAR, false),
JS_STDLIB_JAR(PathUtil.JS_LIB_JAR_NAME, true), JS_STDLIB_JAR(PathUtil.JS_LIB_JAR_NAME, true),
@@ -52,6 +52,7 @@ class KotlinUpdatePluginComponent : ApplicationComponent {
// Force refresh jar handlers // Force refresh jar handlers
requestFullJarUpdate(ideaPluginPaths.runtimePath) requestFullJarUpdate(ideaPluginPaths.runtimePath)
requestFullJarUpdate(ideaPluginPaths.reflectPath) requestFullJarUpdate(ideaPluginPaths.reflectPath)
requestFullJarUpdate(ideaPluginPaths.scriptRuntimePath)
requestFullJarUpdate(ideaPluginPaths.runtimeSourcesPath) requestFullJarUpdate(ideaPluginPaths.runtimeSourcesPath)
requestFullJarUpdate(ideaPluginPaths.jsStdLibJarPath) requestFullJarUpdate(ideaPluginPaths.jsStdLibJarPath)
@@ -55,10 +55,7 @@ class IdeaJsr223Test : PlatformTestCase() {
bindings.put(ScriptEngine.ARGV, arrayOf("42")) bindings.put(ScriptEngine.ARGV, arrayOf("42"))
bindings.put("abc", 13) bindings.put("abc", 13)
val res1 = engine.eval("2 + args[0].toInt()") val res1 = engine.eval("2 + (bindings[\"abc\"] as Int)")
assertEquals(44, res1) assertEquals(15, res1)
val res2 = engine.eval("2 + (bindings[\"abc\"] as Int)")
assertEquals(15, res2)
} }
} }
@@ -1275,26 +1275,6 @@ public final class kotlin/reflect/KVisibility : java/lang/Enum {
public static fun values ()[Lkotlin/reflect/KVisibility; 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 { public abstract interface annotation class org/jetbrains/annotations/Mutable : java/lang/annotation/Annotation {
} }
@@ -25,7 +25,7 @@ import java.io.File
import java.io.FileNotFoundException import java.io.FileNotFoundException
import javax.script.ScriptContext import javax.script.ScriptContext
import javax.script.ScriptEngine import javax.script.ScriptEngine
import kotlin.script.StandardScriptTemplate import kotlin.script.templates.standard.ScriptTemplateWithArgs
class KotlinJsr223JvmLocalScriptEngineFactory : KotlinJsr223JvmScriptEngineFactoryBase() { class KotlinJsr223JvmLocalScriptEngineFactory : KotlinJsr223JvmScriptEngineFactoryBase() {
@@ -34,9 +34,9 @@ class KotlinJsr223JvmLocalScriptEngineFactory : KotlinJsr223JvmScriptEngineFacto
Disposer.newDisposable(), Disposer.newDisposable(),
this, this,
listOf(kotlinRuntimeJar), listOf(kotlinRuntimeJar),
"kotlin.script.ScriptTemplateWithArgsAndBindings", "kotlin.script.templates.standard.ScriptTemplateWithBindings",
::makeArgumentsForTemplateWithArgsAndBindings, { ctx -> arrayOf(ctx.getBindings(ScriptContext.ENGINE_SCOPE)) },
arrayOf(Array<String>::class.java, java.util.Map::class.java) arrayOf(Map::class.java)
) )
} }
@@ -48,9 +48,9 @@ class KotlinJsr223JvmDaemonLocalEvalScriptEngineFactory : KotlinJsr223JvmScriptE
this, this,
kotlinCompilerJar, kotlinCompilerJar,
listOf(kotlinRuntimeJar), listOf(kotlinRuntimeJar),
"kotlin.script.ScriptTemplateWithArgsAndBindings", "kotlin.script.templates.standard.ScriptTemplateWithBindings",
::makeArgumentsForTemplateWithArgsAndBindings, { ctx -> arrayOf(ctx.getBindings(ScriptContext.ENGINE_SCOPE)) },
arrayOf(Array<String>::class.java, java.util.Map::class.java) arrayOf(Map::class.java)
) )
} }
@@ -62,27 +62,18 @@ class KotlinJsr223JvmDaemonRemoteEvalScriptEngineFactory : KotlinJsr223JvmScript
this, this,
kotlinCompilerJar, kotlinCompilerJar,
listOf(kotlinRuntimeJar), listOf(kotlinRuntimeJar),
"kotlin.script.ScriptTemplateWithArgsAndBindings", "kotlin.script.templates.standard.ScriptTemplateWithBindings",
::makeSerializableArgumentsForTemplateWithArgsAndBindings, ::makeSerializableArgumentsForTemplateWithBindings,
arrayOf(Array<String>::class.java, java.util.Map::class.java) arrayOf(Map::class.java)
) )
} }
private fun makeArgumentsForTemplateWithArgsAndBindings(ctx: ScriptContext): Array<Any?> { private fun makeSerializableArgumentsForTemplateWithBindings(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?> {
val bindings = ctx.getBindings(ScriptContext.ENGINE_SCOPE) val bindings = ctx.getBindings(ScriptContext.ENGINE_SCOPE)
val serializableBindings = linkedMapOf<String, Any>() val serializableBindings = linkedMapOf<String, Any>()
// TODO: consider deeper analysis and copying to serializable data if possible // TODO: consider deeper analysis and copying to serializable data if possible
serializableBindings.putAll(bindings) serializableBindings.putAll(bindings)
return arrayOf( return arrayOf(serializableBindings)
(bindings[ScriptEngine.ARGV] as? Array<*>) ?: emptyArray<String>(),
serializableBindings)
} }
private fun File.existsOrNull(): File? = existsAndCheckOrNull { true } 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() private val kotlinRuntimeJar = System.getProperty("kotlin.java.runtime.jar")?.let(::File)?.existsOrNull()
?: kotlinCompilerJar.let { File(it.parentFile, KOTLIN_JAVA_RUNTIME_JAR) }.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") ?: throw FileNotFoundException("Cannot find kotlin runtime jar, set kotlin.java.runtime.jar property to proper location")