diff --git a/.idea/libraries/kotlin_script_runtime.xml b/.idea/libraries/kotlin_script_runtime.xml new file mode 100644 index 00000000000..ed74f6a8c45 --- /dev/null +++ b/.idea/libraries/kotlin_script_runtime.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/build.xml b/build.xml index 8afdb189435..12580475578 100644 --- a/build.xml +++ b/build.xml @@ -15,6 +15,7 @@ + @@ -57,8 +58,8 @@ little to no differences between the new and the newest runtime. --> + 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"> @@ -66,6 +67,7 @@ + @@ -190,6 +192,7 @@ + @@ -206,6 +209,7 @@ + @@ -612,6 +616,9 @@ + + + @@ -640,6 +647,7 @@ + @@ -683,6 +691,7 @@ + @@ -812,6 +821,7 @@ + @@ -1201,7 +1211,6 @@ - diff --git a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/K2JVMCompiler.kt b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/K2JVMCompiler.kt index 8d608dadee1..fdd4bf96010 100644 --- a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/K2JVMCompiler.kt +++ b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/K2JVMCompiler.kt @@ -344,6 +344,7 @@ class K2JVMCompiler : CLICompiler() { } 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" diff --git a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/CompileEnvironmentUtil.java b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/CompileEnvironmentUtil.java index cfc63c9d4d3..bef1060514f 100644 --- a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/CompileEnvironmentUtil.java +++ b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/CompileEnvironmentUtil.java @@ -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(); diff --git a/compiler/compiler.pro b/compiler/compiler.pro index 34da2b2ed90..9a1702e6c6a 100644 --- a/compiler/compiler.pro +++ b/compiler/compiler.pro @@ -46,6 +46,7 @@ messages/**) -libraryjars '' -libraryjars '' -libraryjars '' +-libraryjars '' -target 1.6 -dontoptimize diff --git a/compiler/daemon/src/org/jetbrains/kotlin/daemon/KotlinRemoteReplService.kt b/compiler/daemon/src/org/jetbrains/kotlin/daemon/KotlinRemoteReplService.kt index 98f351f9e26..b7dc5d7a422 100644 --- a/compiler/daemon/src/org/jetbrains/kotlin/daemon/KotlinRemoteReplService.kt +++ b/compiler/daemon/src/org/jetbrains/kotlin/daemon/KotlinRemoteReplService.kt @@ -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") } diff --git a/compiler/frontend/frontend.iml b/compiler/frontend/frontend.iml index 15545ccb1bf..8d1a3a6b0bf 100644 --- a/compiler/frontend/frontend.iml +++ b/compiler/frontend/frontend.iml @@ -15,5 +15,6 @@ + \ No newline at end of file diff --git a/compiler/frontend/src/org/jetbrains/kotlin/script/KotlinScriptDefinition.kt b/compiler/frontend/src/org/jetbrains/kotlin/script/KotlinScriptDefinition.kt index 2f1981f46d4..e2b6da55f9b 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/script/KotlinScriptDefinition.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/script/KotlinScriptDefinition.kt @@ -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) { @@ -50,5 +50,5 @@ interface KotlinScriptExternalDependencies { val scripts: Iterable get() = emptyList() } -object StandardScriptDefinition : KotlinScriptDefinition(StandardScriptTemplate::class) +object StandardScriptDefinition : KotlinScriptDefinition(ScriptTemplateWithArgs::class) diff --git a/compiler/testData/diagnostics/tests/annotations/DanglingInScript.txt b/compiler/testData/diagnostics/tests/annotations/DanglingInScript.txt index 77797394836..db958b87345 100644 --- a/compiler/testData/diagnostics/tests/annotations/DanglingInScript.txt +++ b/compiler/testData/diagnostics/tests/annotations/DanglingInScript.txt @@ -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) public final override /*1*/ /*fake_override*/ val args: kotlin.Array public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean diff --git a/compiler/testData/diagnostics/tests/redeclarations/ScriptAndClassConflict.txt b/compiler/testData/diagnostics/tests/redeclarations/ScriptAndClassConflict.txt index a7872f938a8..b776267872e 100644 --- a/compiler/testData/diagnostics/tests/redeclarations/ScriptAndClassConflict.txt +++ b/compiler/testData/diagnostics/tests/redeclarations/ScriptAndClassConflict.txt @@ -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) public final override /*1*/ /*fake_override*/ val args: kotlin.Array public final val x: kotlin.Int = 1 diff --git a/compiler/testData/diagnostics/tests/script/AccessForwardDeclarationInScript.txt b/compiler/testData/diagnostics/tests/script/AccessForwardDeclarationInScript.txt index b3b4151179c..cfffc423c8f 100644 --- a/compiler/testData/diagnostics/tests/script/AccessForwardDeclarationInScript.txt +++ b/compiler/testData/diagnostics/tests/script/AccessForwardDeclarationInScript.txt @@ -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) public final override /*1*/ /*fake_override*/ val args: kotlin.Array public final val x: kotlin.Int = 2 diff --git a/compiler/testData/diagnostics/tests/script/ComplexScript.txt b/compiler/testData/diagnostics/tests/script/ComplexScript.txt index 4ae83741290..5ae0be711ce 100644 --- a/compiler/testData/diagnostics/tests/script/ComplexScript.txt +++ b/compiler/testData/diagnostics/tests/script/ComplexScript.txt @@ -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) public final override /*1*/ /*fake_override*/ val args: kotlin.Array public final val y: kotlin.Int = 2 diff --git a/compiler/testData/diagnostics/tests/script/NestedInnerClass.txt b/compiler/testData/diagnostics/tests/script/NestedInnerClass.txt index 465ceac936c..9a006a11b98 100644 --- a/compiler/testData/diagnostics/tests/script/NestedInnerClass.txt +++ b/compiler/testData/diagnostics/tests/script/NestedInnerClass.txt @@ -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) public final override /*1*/ /*fake_override*/ val args: kotlin.Array public final val property: kotlin.String = "" diff --git a/compiler/testData/diagnostics/tests/script/SimpleScript.txt b/compiler/testData/diagnostics/tests/script/SimpleScript.txt index 1ba84b1ff22..36b380081fd 100644 --- a/compiler/testData/diagnostics/tests/script/SimpleScript.txt +++ b/compiler/testData/diagnostics/tests/script/SimpleScript.txt @@ -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) public final override /*1*/ /*fake_override*/ val args: kotlin.Array public final val x: kotlin.Int = 1 diff --git a/compiler/testData/diagnostics/tests/script/imports.txt b/compiler/testData/diagnostics/tests/script/imports.txt index fe0006cb14a..6e4526cb092 100644 --- a/compiler/testData/diagnostics/tests/script/imports.txt +++ b/compiler/testData/diagnostics/tests/script/imports.txt @@ -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) public final val al: java.util.ArrayList? = null public final override /*1*/ /*fake_override*/ val args: kotlin.Array diff --git a/compiler/testData/diagnostics/tests/script/topLevelVariable.txt b/compiler/testData/diagnostics/tests/script/topLevelVariable.txt index 8b292aec73f..7198a69e79e 100644 --- a/compiler/testData/diagnostics/tests/script/topLevelVariable.txt +++ b/compiler/testData/diagnostics/tests/script/topLevelVariable.txt @@ -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) public final val a: kotlin.Int public final override /*1*/ /*fake_override*/ val args: kotlin.Array diff --git a/compiler/testData/diagnostics/tests/script/varInScript.txt b/compiler/testData/diagnostics/tests/script/varInScript.txt index 07050eef627..2af487a2ded 100644 --- a/compiler/testData/diagnostics/tests/script/varInScript.txt +++ b/compiler/testData/diagnostics/tests/script/varInScript.txt @@ -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) public final override /*1*/ /*fake_override*/ val args: kotlin.Array public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean diff --git a/compiler/testData/diagnostics/tests/sourceCompatibility/noLocalDelegatedPropertyInScript.txt b/compiler/testData/diagnostics/tests/sourceCompatibility/noLocalDelegatedPropertyInScript.txt index 71ae5dfc4c6..d58077a0542 100644 --- a/compiler/testData/diagnostics/tests/sourceCompatibility/noLocalDelegatedPropertyInScript.txt +++ b/compiler/testData/diagnostics/tests/sourceCompatibility/noLocalDelegatedPropertyInScript.txt @@ -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) public final override /*1*/ /*fake_override*/ val args: kotlin.Array public final val prop: kotlin.Int diff --git a/compiler/tests-common/org/jetbrains/kotlin/codegen/forTestCompile/ForTestCompileRuntime.java b/compiler/tests-common/org/jetbrains/kotlin/codegen/forTestCompile/ForTestCompileRuntime.java index fc7698b9d9e..e34f53277a4 100644 --- a/compiler/tests-common/org/jetbrains/kotlin/codegen/forTestCompile/ForTestCompileRuntime.java +++ b/compiler/tests-common/org/jetbrains/kotlin/codegen/forTestCompile/ForTestCompileRuntime.java @@ -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(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(loader); } return loader; diff --git a/compiler/tests-common/org/jetbrains/kotlin/test/KotlinTestUtils.java b/compiler/tests-common/org/jetbrains/kotlin/test/KotlinTestUtils.java index 4903fe927a1..2ad50cbb5a8 100644 --- a/compiler/tests-common/org/jetbrains/kotlin/test/KotlinTestUtils.java +++ b/compiler/tests-common/org/jetbrains/kotlin/test/KotlinTestUtils.java @@ -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()); diff --git a/compiler/tests/org/jetbrains/kotlin/cli/jvm/repl/GenericReplTest.kt b/compiler/tests/org/jetbrains/kotlin/cli/jvm/repl/GenericReplTest.kt index 2946bd87459..7d9b85566e2 100644 --- a/compiler/tests/org/jetbrains/kotlin/cli/jvm/repl/GenericReplTest.kt +++ b/compiler/tests/org/jetbrains/kotlin/cli/jvm/repl/GenericReplTest.kt @@ -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) diff --git a/compiler/tests/org/jetbrains/kotlin/daemon/CompilerDaemonTest.kt b/compiler/tests/org/jetbrains/kotlin/daemon/CompilerDaemonTest.kt index ffbe7c2aba1..dc47481ca67 100644 --- a/compiler/tests/org/jetbrains/kotlin/daemon/CompilerDaemonTest.kt +++ b/compiler/tests/org/jetbrains/kotlin/daemon/CompilerDaemonTest.kt @@ -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()), null, System.err, evalOut, evalErr, evalIn) diff --git a/compiler/tests/org/jetbrains/kotlin/scripts/ScriptTemplateTest.kt b/compiler/tests/org/jetbrains/kotlin/scripts/ScriptTemplateTest.kt index 05bb0bfaa56..8cd27d201d0 100644 --- a/compiler/tests/org/jetbrains/kotlin/scripts/ScriptTemplateTest.kt +++ b/compiler/tests/org/jetbrains/kotlin/scripts/ScriptTemplateTest.kt @@ -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::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) diff --git a/compiler/util/src/org/jetbrains/kotlin/utils/KotlinPaths.java b/compiler/util/src/org/jetbrains/kotlin/utils/KotlinPaths.java index c671087ce4a..f8afd48bd97 100644 --- a/compiler/util/src/org/jetbrains/kotlin/utils/KotlinPaths.java +++ b/compiler/util/src/org/jetbrains/kotlin/utils/KotlinPaths.java @@ -33,6 +33,9 @@ public interface KotlinPaths { @NotNull File getReflectPath(); + @NotNull + File getScriptRuntimePath(); + @NotNull File getKotlinTestPath(); diff --git a/compiler/util/src/org/jetbrains/kotlin/utils/KotlinPathsFromHomeDir.java b/compiler/util/src/org/jetbrains/kotlin/utils/KotlinPathsFromHomeDir.java index 63c0f04f80b..b86448ecf13 100644 --- a/compiler/util/src/org/jetbrains/kotlin/utils/KotlinPathsFromHomeDir.java +++ b/compiler/util/src/org/jetbrains/kotlin/utils/KotlinPathsFromHomeDir.java @@ -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() { diff --git a/compiler/util/src/org/jetbrains/kotlin/utils/PathUtil.java b/compiler/util/src/org/jetbrains/kotlin/utils/PathUtil.java index a8559d003d0..8e2469f166b 100644 --- a/compiler/util/src/org/jetbrains/kotlin/utils/PathUtil.java +++ b/compiler/util/src/org/jetbrains/kotlin/utils/PathUtil.java @@ -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"; diff --git a/core/runtime.jvm/src/kotlin/script/Scripts.kt b/core/runtime.jvm/src/kotlin/script/Scripts.kt deleted file mode 100644 index 9117e9e3dab..00000000000 --- a/core/runtime.jvm/src/kotlin/script/Scripts.kt +++ /dev/null @@ -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) - - -/** - * Script definition template without parameters - */ -public abstract class SimpleScriptTemplate() - - -/** - * Script definition template with generic bindings - */ -public abstract class ScriptTemplateWithBindings(val bindings: Map) - - -/** - * Script definition template with standard arguments and generic bindings - */ -public abstract class ScriptTemplateWithArgsAndBindings(val args: Array, val bindings: Map) diff --git a/idea/idea-core/src/org/jetbrains/kotlin/idea/core/script/dependencies/KotlinScriptResolveScopeProvider.kt b/idea/idea-core/src/org/jetbrains/kotlin/idea/core/script/dependencies/KotlinScriptResolveScopeProvider.kt index a7e86659f03..d57ede6228a 100644 --- a/idea/idea-core/src/org/jetbrains/kotlin/idea/core/script/dependencies/KotlinScriptResolveScopeProvider.kt +++ b/idea/idea-core/src/org/jetbrains/kotlin/idea/core/script/dependencies/KotlinScriptResolveScopeProvider.kt @@ -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? { diff --git a/idea/idea-repl/src/org/jetbrains/kotlin/console/KotlinConsoleKeeper.kt b/idea/idea-repl/src/org/jetbrains/kotlin/console/KotlinConsoleKeeper.kt index 154626df875..02224e59c90 100644 --- a/idea/idea-repl/src/org/jetbrains/kotlin/console/KotlinConsoleKeeper.kt +++ b/idea/idea-repl/src/org/jetbrains/kotlin/console/KotlinConsoleKeeper.kt @@ -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) diff --git a/idea/idea-repl/src/org/jetbrains/kotlin/jsr223/KotlinJsr223StandardScriptEngineFactory4Idea.kt b/idea/idea-repl/src/org/jetbrains/kotlin/jsr223/KotlinJsr223StandardScriptEngineFactory4Idea.kt index 9fc7c21845f..b39ed959fde 100644 --- a/idea/idea-repl/src/org/jetbrains/kotlin/jsr223/KotlinJsr223StandardScriptEngineFactory4Idea.kt +++ b/idea/idea-repl/src/org/jetbrains/kotlin/jsr223/KotlinJsr223StandardScriptEngineFactory4Idea.kt @@ -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(), - bindings) }, - arrayOf(Array::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) ) } diff --git a/idea/src/org/jetbrains/kotlin/idea/run/script/standalone/KotlinStandaloneScriptRunConfiguration.kt b/idea/src/org/jetbrains/kotlin/idea/run/script/standalone/KotlinStandaloneScriptRunConfiguration.kt index 8263b160ef2..5e58356f92f 100644 --- a/idea/src/org/jetbrains/kotlin/idea/run/script/standalone/KotlinStandaloneScriptRunConfiguration.kt +++ b/idea/src/org/jetbrains/kotlin/idea/run/script/standalone/KotlinStandaloneScriptRunConfiguration.kt @@ -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) } diff --git a/idea/src/org/jetbrains/kotlin/idea/versions/KotlinRuntimeLibraryUtil.kt b/idea/src/org/jetbrains/kotlin/idea/versions/KotlinRuntimeLibraryUtil.kt index 9b4ed728862..272dafa0097 100644 --- a/idea/src/org/jetbrains/kotlin/idea/versions/KotlinRuntimeLibraryUtil.kt +++ b/idea/src/org/jetbrains/kotlin/idea/versions/KotlinRuntimeLibraryUtil.kt @@ -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 { 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), diff --git a/idea/src/org/jetbrains/kotlin/idea/versions/KotlinUpdatePluginComponent.kt b/idea/src/org/jetbrains/kotlin/idea/versions/KotlinUpdatePluginComponent.kt index 0fb698d37b9..d81a759afe8 100644 --- a/idea/src/org/jetbrains/kotlin/idea/versions/KotlinUpdatePluginComponent.kt +++ b/idea/src/org/jetbrains/kotlin/idea/versions/KotlinUpdatePluginComponent.kt @@ -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) diff --git a/idea/tests/org/jetbrains/kotlin/idea/repl/IdeaJsr223Test.kt b/idea/tests/org/jetbrains/kotlin/idea/repl/IdeaJsr223Test.kt index 46f2cb2ab28..b5737d16dc4 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/repl/IdeaJsr223Test.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/repl/IdeaJsr223Test.kt @@ -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) } } diff --git a/libraries/tools/binary-compatibility-validator/reference-public-api/kotlin-runtime.txt b/libraries/tools/binary-compatibility-validator/reference-public-api/kotlin-runtime.txt index dbd150725c1..3e5c0e42cf1 100644 --- a/libraries/tools/binary-compatibility-validator/reference-public-api/kotlin-runtime.txt +++ b/libraries/tools/binary-compatibility-validator/reference-public-api/kotlin-runtime.txt @@ -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 ([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 (Ljava/util/Map;)V - public final fun getBindings ()Ljava/util/Map; -} - -public abstract class kotlin/script/SimpleScriptTemplate { - public fun ()V -} - -public abstract class kotlin/script/StandardScriptTemplate { - public fun ([Ljava/lang/String;)V - public final fun getArgs ()[Ljava/lang/String; -} - public abstract interface annotation class org/jetbrains/annotations/Mutable : java/lang/annotation/Annotation { } diff --git a/libraries/tools/kotlin-script-util/src/main/kotlin/org/jetbrains/kotlin/script/jsr223/KotlinJsr223ScriptEngineFactoryExamples.kt b/libraries/tools/kotlin-script-util/src/main/kotlin/org/jetbrains/kotlin/script/jsr223/KotlinJsr223ScriptEngineFactoryExamples.kt index c28801343d3..63c76584fc0 100644 --- a/libraries/tools/kotlin-script-util/src/main/kotlin/org/jetbrains/kotlin/script/jsr223/KotlinJsr223ScriptEngineFactoryExamples.kt +++ b/libraries/tools/kotlin-script-util/src/main/kotlin/org/jetbrains/kotlin/script/jsr223/KotlinJsr223ScriptEngineFactoryExamples.kt @@ -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::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::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::class.java, java.util.Map::class.java) + "kotlin.script.templates.standard.ScriptTemplateWithBindings", + ::makeSerializableArgumentsForTemplateWithBindings, + arrayOf(Map::class.java) ) } -private fun makeArgumentsForTemplateWithArgsAndBindings(ctx: ScriptContext): Array { - val bindings = ctx.getBindings(ScriptContext.ENGINE_SCOPE) - return arrayOf( - (bindings[ScriptEngine.ARGV] as? Array<*>) ?: emptyArray(), - bindings) -} - -private fun makeSerializableArgumentsForTemplateWithArgsAndBindings(ctx: ScriptContext): Array { +private fun makeSerializableArgumentsForTemplateWithBindings(ctx: ScriptContext): Array { val bindings = ctx.getBindings(ScriptContext.ENGINE_SCOPE) val serializableBindings = linkedMapOf() // TODO: consider deeper analysis and copying to serializable data if possible serializableBindings.putAll(bindings) - return arrayOf( - (bindings[ScriptEngine.ARGV] as? Array<*>) ?: emptyArray(), - 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")