Refactor JSR223 to support Compilable interface, drop daemon eval engine and sample, simplify

This commit is contained in:
Ilya Chernikov
2016-12-06 19:14:05 +01:00
parent b19d61e2f4
commit cb7f22ffec
13 changed files with 227 additions and 451 deletions
@@ -52,7 +52,7 @@ class KotlinJsr223ScriptEngineIT {
val factory = ScriptEngineManager().getEngineByExtension("kts").factory
Assert.assertNotNull(factory)
val engine = factory!!.scriptEngine
Assert.assertNotNull(engine as? KotlinJsr223JvmDaemonLocalEvalScriptEngine)
Assert.assertNotNull(engine as? KotlinJsr223JvmDaemonCompileScriptEngine)
Assert.assertSame(factory, engine!!.factory)
val bindings = engine.createBindings()
Assert.assertTrue(bindings is SimpleBindings)
@@ -1,91 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<properties>
<maven-plugin-anno.version>1.4.1</maven-plugin-anno.version>
<maven.version>3.0.4</maven.version>
</properties>
<parent>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-project</artifactId>
<version>1.1-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<artifactId>kotlin-jsr223-daemon-remote-eval-example</artifactId>
<packaging>jar</packaging>
<description>Sample Kotlin JSR 223 scripting jar with daemon (out-of-process) compilation and evaluation</description>
<dependencies>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-runtime</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-script-runtime</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-compiler</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-script-util</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<build>
<testSourceDirectory>${project.basedir}/src/test/kotlin</testSourceDirectory>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>kotlin-maven-plugin</artifactId>
<groupId>org.jetbrains.kotlin</groupId>
<version>${project.version}</version>
<executions>
<execution>
<id>compile</id>
<phase>compile</phase>
<goals> <goal>compile</goal> </goals>
</execution>
<execution>
<id>test-compile</id>
<phase>test-compile</phase>
<goals> <goal>test-compile</goal> </goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
@@ -1 +0,0 @@
org.jetbrains.kotlin.script.jsr223.KotlinJsr223JvmDaemonRemoteEvalScriptEngineFactory
@@ -1,68 +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 org.jetbrains.kotlin.script.jsr223
import org.jetbrains.kotlin.config.KotlinCompilerVersion
import org.junit.Assert
import org.junit.Test
import javax.script.ScriptEngine
import javax.script.ScriptEngineManager
import javax.script.SimpleBindings
class KotlinJsr223ScriptEngineIT {
@Test
fun testEngineFactory() {
val factory = ScriptEngineManager().getEngineByExtension("kts").factory
Assert.assertNotNull(factory)
factory!!.apply {
Assert.assertEquals("kotlin", languageName)
Assert.assertEquals(KotlinCompilerVersion.VERSION, languageVersion)
Assert.assertEquals("kotlin", engineName)
Assert.assertEquals(KotlinCompilerVersion.VERSION, engineVersion)
Assert.assertEquals(listOf("kts"), extensions)
Assert.assertEquals(listOf("text/x-kotlin"), mimeTypes)
Assert.assertEquals(listOf("kotlin"), names)
Assert.assertEquals("obj.method(arg1, arg2, arg3)", getMethodCallSyntax("obj", "method", "arg1", "arg2", "arg3"))
Assert.assertEquals("print(\"Hello, world!\")", getOutputStatement("Hello, world!"))
Assert.assertEquals(KotlinCompilerVersion.VERSION, getParameter(ScriptEngine.LANGUAGE_VERSION))
val sep = System.getProperty("line.separator")
val prog = arrayOf("val x: Int = 3", "var y = x + 2")
Assert.assertEquals(prog.joinToString(sep) + sep, getProgram(*prog))
}
}
@Test
fun testEngine() {
val factory = ScriptEngineManager().getEngineByExtension("kts").factory
Assert.assertNotNull(factory)
val engine = factory!!.scriptEngine
Assert.assertNotNull(engine as? KotlinJsr223JvmDaemonRemoteEvalScriptEngine)
Assert.assertSame(factory, engine!!.factory)
val bindings = engine.createBindings()
Assert.assertTrue(bindings is SimpleBindings)
}
@Test
fun testSimpleEval() {
val engine = ScriptEngineManager().getEngineByExtension("kts")!!
val res1 = engine.eval("val x = 3")
Assert.assertNull(res1)
val res2 = engine.eval("x + 2")
Assert.assertEquals(5, res2)
}
}