From f992f916861a1ef7d131c7cb599fd76c925a1534 Mon Sep 17 00:00:00 2001 From: Ilya Chernikov Date: Fri, 9 Sep 2016 13:41:24 +0200 Subject: [PATCH] Add kotlin-script-util lib with tests - collection of standard templates and resolvers --- libraries/pom.xml | 1 + libraries/tools/kotlin-script-util/pom.xml | 114 +++++++++++++ .../kotlin/script/util/annotations.kt | 26 +++ .../jetbrains/kotlin/script/util/resolve.kt | 109 ++++++++++++ .../kotlin/script/util/resolvers/basic.kt | 44 +++++ .../kotlin/script/util/resolvers/maven.kt | 58 +++++++ .../jetbrains/kotlin/script/util/templates.kt | 33 ++++ .../kotlin/script/util/ScriptUtilIT.kt | 161 ++++++++++++++++++ .../resources/scripts/args-hello-world.kts | 8 + .../scripts/args-junit-hello-world.kts | 12 ++ .../scripts/bindings-hello-world.kts | 8 + .../resources/scripts/bnd-hello-world.kts | 8 + .../resources/scripts/std-hello-world.kts | 8 + .../scripts/std-junit-hello-world.kts | 8 + 14 files changed, 598 insertions(+) create mode 100644 libraries/tools/kotlin-script-util/pom.xml create mode 100644 libraries/tools/kotlin-script-util/src/main/kotlin/org/jetbrains/kotlin/script/util/annotations.kt create mode 100644 libraries/tools/kotlin-script-util/src/main/kotlin/org/jetbrains/kotlin/script/util/resolve.kt create mode 100644 libraries/tools/kotlin-script-util/src/main/kotlin/org/jetbrains/kotlin/script/util/resolvers/basic.kt create mode 100644 libraries/tools/kotlin-script-util/src/main/kotlin/org/jetbrains/kotlin/script/util/resolvers/maven.kt create mode 100644 libraries/tools/kotlin-script-util/src/main/kotlin/org/jetbrains/kotlin/script/util/templates.kt create mode 100644 libraries/tools/kotlin-script-util/src/test/kotlin/org/jetbrains/kotlin/script/util/ScriptUtilIT.kt create mode 100644 libraries/tools/kotlin-script-util/src/test/resources/scripts/args-hello-world.kts create mode 100644 libraries/tools/kotlin-script-util/src/test/resources/scripts/args-junit-hello-world.kts create mode 100644 libraries/tools/kotlin-script-util/src/test/resources/scripts/bindings-hello-world.kts create mode 100644 libraries/tools/kotlin-script-util/src/test/resources/scripts/bnd-hello-world.kts create mode 100644 libraries/tools/kotlin-script-util/src/test/resources/scripts/std-hello-world.kts create mode 100644 libraries/tools/kotlin-script-util/src/test/resources/scripts/std-junit-hello-world.kts diff --git a/libraries/pom.xml b/libraries/pom.xml index dc2388ddd2f..d8588a8b22c 100644 --- a/libraries/pom.xml +++ b/libraries/pom.xml @@ -104,6 +104,7 @@ tools/kotlin-gradle-plugin-api tools/kotlin-android-extensions tools/kotlin-maven-plugin-test + tools/kotlin-script-util examples/kotlin-java-example examples/js-example diff --git a/libraries/tools/kotlin-script-util/pom.xml b/libraries/tools/kotlin-script-util/pom.xml new file mode 100644 index 00000000000..9a56fd9caf4 --- /dev/null +++ b/libraries/tools/kotlin-script-util/pom.xml @@ -0,0 +1,114 @@ + + + + 4.0.0 + + 1.4.1 + 3.0.4 + + + + org.jetbrains.kotlin + kotlin-project + 1.1-SNAPSHOT + ../../pom.xml + + + kotlin-script-util + jar + + Kotlin scripting support utilities + + + + jetbrains-utils + http://repository.jetbrains.com/utils + + + + + + org.jetbrains.kotlin + kotlin-stdlib + ${project.version} + + + org.jetbrains.kotlin + kotlin-compiler + ${project.version} + + + com.jcabi + jcabi-aether + 0.10.1 + + + org.sonatype.aether + aether-api + 1.13.1 + + + org.apache.maven + maven-core + 3.0.3 + + + + + ${project.basedir}/src/main/kotlin + ${project.basedir}/src/test/kotlin + + + + org.apache.maven.plugins + maven-dependency-plugin + 2.3 + + + + properties + + + + + + kotlin-maven-plugin + org.jetbrains.kotlin + ${project.version} + + + + compile + compile + compile + + + + test-compile + test-compile + test-compile + + + + + maven-failsafe-plugin + 2.6 + + + ${org.jetbrains.kotlin:kotlin-stdlib:jar} + + + + + + integration-test + verify + + + + + + + diff --git a/libraries/tools/kotlin-script-util/src/main/kotlin/org/jetbrains/kotlin/script/util/annotations.kt b/libraries/tools/kotlin-script-util/src/main/kotlin/org/jetbrains/kotlin/script/util/annotations.kt new file mode 100644 index 00000000000..23544b7c71b --- /dev/null +++ b/libraries/tools/kotlin-script-util/src/main/kotlin/org/jetbrains/kotlin/script/util/annotations.kt @@ -0,0 +1,26 @@ +/* + * 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.util + +@Target(AnnotationTarget.FILE, AnnotationTarget.EXPRESSION, AnnotationTarget.LOCAL_VARIABLE, AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY) +@Retention(AnnotationRetention.RUNTIME) +annotation class DependsOn(val value: String) + +@Target(AnnotationTarget.FILE, AnnotationTarget.EXPRESSION, AnnotationTarget.LOCAL_VARIABLE, AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY) +@Retention(AnnotationRetention.RUNTIME) +annotation class Repository(val value: String) + diff --git a/libraries/tools/kotlin-script-util/src/main/kotlin/org/jetbrains/kotlin/script/util/resolve.kt b/libraries/tools/kotlin-script-util/src/main/kotlin/org/jetbrains/kotlin/script/util/resolve.kt new file mode 100644 index 00000000000..ec102702a50 --- /dev/null +++ b/libraries/tools/kotlin-script-util/src/main/kotlin/org/jetbrains/kotlin/script/util/resolve.kt @@ -0,0 +1,109 @@ +/* + * 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.util + +import org.jetbrains.kotlin.script.* +import org.jetbrains.kotlin.script.util.resolvers.DirectResolver +import org.jetbrains.kotlin.script.util.resolvers.FlatLibDirectoryResolver +import org.jetbrains.kotlin.script.util.resolvers.MavenResolver +import org.jetbrains.kotlin.script.util.resolvers.Resolver +import java.io.File +import java.lang.Exception +import java.lang.IllegalArgumentException +import java.net.URL +import java.net.URLClassLoader +import java.util.concurrent.Future +import kotlin.reflect.KClass + +open class KotlinAnnotatedScriptDependenciesResolver(val baseClassPath: List, resolvers: Iterable) + : ScriptDependenciesResolver +{ + private val resolvers: MutableList = resolvers.toMutableList() + + @AcceptedAnnotations(DependsOn::class, Repository::class) + override fun resolve(script: ScriptContents, + environment: Map?, + report: (ScriptDependenciesResolver.ReportSeverity, String, ScriptContents.Position?) -> Unit, + previousDependencies: KotlinScriptExternalDependencies? + ): Future + = (if (previousDependencies != null && resolveFromAnnotations(script).isEmpty()) previousDependencies + else + object : KotlinScriptExternalDependencies { + override val classpath: Iterable = if (resolvers.isEmpty()) baseClassPath else baseClassPath + resolveFromAnnotations(script) + override val imports: Iterable = + previousDependencies?.let { emptyList() } ?: listOf(DependsOn::class.java.`package`.name + ".*") + } + ).asFuture() + + private fun resolveFromAnnotations(script: ScriptContents): List { + script.annotations.forEach { + when (it) { + is Repository -> + when { + File(it.value).run { exists() && isDirectory } -> resolvers.add(FlatLibDirectoryResolver(File(it.value))) + else -> throw IllegalArgumentException("Illegal argument for Repository annotation: ${it.value}") + } + is DependsOn -> {} + is InvalidScriptResolverAnnotation -> throw Exception("Invalid annotation ${it.name}", it.error) + else -> throw Exception("Unknown annotation ${it.javaClass}") + } + } + return script.annotations.filterIsInstance(DependsOn::class.java).flatMap { dep -> + resolvers.asSequence().mapNotNull { it.tryResolve(dep) }.firstOrNull() ?: + throw Exception("Unable to resolve dependency $dep") + } + } +} + +private fun URL.toFile() = + try { + File(toURI().schemeSpecificPart) + } + catch (e: java.net.URISyntaxException) { + if (protocol != "file") null + else File(file) + } + +private fun classpathFromClassloader(classLoader: ClassLoader): List? = + generateSequence(classLoader) { it.parent }.toList().flatMap { (it as? URLClassLoader)?.urLs?.mapNotNull { it.toFile() } ?: emptyList() } + +private fun classpathFromClasspathProperty(): List? = + System.getProperty("java.class.path")?.let { + it.split(String.format("\\%s", File.pathSeparatorChar).toRegex()).dropLastWhile(String::isEmpty).toTypedArray() + .map(::File) + } + +private fun classpathFromClass(classLoader: ClassLoader, klass: KClass): List? { + val clp = "${klass.qualifiedName?.replace('.', '/')}.class" + val url = classLoader.getResource(clp) + return url?.toURI()?.path?.removeSuffix(clp)?.let { + listOf(File(it)) + } +} + +val defaultScriptBaseClasspath: List by lazy { + classpathFromClass(Thread.currentThread().contextClassLoader, KotlinAnnotatedScriptDependenciesResolver::class) + ?: classpathFromClasspathProperty() + ?: classpathFromClassloader(Thread.currentThread().contextClassLoader) + ?: emptyList() +} + +class DefaultKotlinResolver() : + KotlinAnnotatedScriptDependenciesResolver(defaultScriptBaseClasspath, arrayListOf()) + +class DefaultKotlinAnnotatedScriptDependenciesResolver : + KotlinAnnotatedScriptDependenciesResolver(defaultScriptBaseClasspath, arrayListOf(DirectResolver(), MavenResolver())) diff --git a/libraries/tools/kotlin-script-util/src/main/kotlin/org/jetbrains/kotlin/script/util/resolvers/basic.kt b/libraries/tools/kotlin-script-util/src/main/kotlin/org/jetbrains/kotlin/script/util/resolvers/basic.kt new file mode 100644 index 00000000000..fc57d83f61d --- /dev/null +++ b/libraries/tools/kotlin-script-util/src/main/kotlin/org/jetbrains/kotlin/script/util/resolvers/basic.kt @@ -0,0 +1,44 @@ +/* + * 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.util.resolvers + +import org.jetbrains.kotlin.script.util.DependsOn +import java.io.File +import java.lang.IllegalArgumentException + +interface Resolver { + fun tryResolve(dependsOn: DependsOn): Iterable? +} + +class DirectResolver : Resolver { + override fun tryResolve(dependsOn: DependsOn): Iterable? = + if (dependsOn.value.isNotBlank() && File(dependsOn.value).exists()) listOf(File(dependsOn.value)) else null +} + +class FlatLibDirectoryResolver(val path: File) : Resolver { + + init { + if (!path.exists() || !path.isDirectory) throw IllegalArgumentException("Invalid flat lib directory repository path '$path'") + } + + override fun tryResolve(dependsOn: DependsOn): Iterable? = + when { + dependsOn.value.isNotBlank() && File(path, dependsOn.value).exists() -> listOf(File(path, dependsOn.value)) + // TODO: add coordinates and wildcard matching + else -> null + } +} diff --git a/libraries/tools/kotlin-script-util/src/main/kotlin/org/jetbrains/kotlin/script/util/resolvers/maven.kt b/libraries/tools/kotlin-script-util/src/main/kotlin/org/jetbrains/kotlin/script/util/resolvers/maven.kt new file mode 100644 index 00000000000..60a875a9309 --- /dev/null +++ b/libraries/tools/kotlin-script-util/src/main/kotlin/org/jetbrains/kotlin/script/util/resolvers/maven.kt @@ -0,0 +1,58 @@ +/* + * 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.util.resolvers + +import com.jcabi.aether.Aether +import org.jetbrains.kotlin.script.util.DependsOn +import java.io.File +import java.util.* +import org.sonatype.aether.repository.RemoteRepository +import org.sonatype.aether.resolution.DependencyResolutionException +import org.sonatype.aether.util.artifact.DefaultArtifact +import org.sonatype.aether.util.artifact.JavaScopes + +val mavenCentral = RemoteRepository("maven-central", "default", "http://repo1.maven.org/maven2/") + +class MavenResolver(val reportError: ((String) -> Unit) = {}): Resolver { + + // TODO: make robust + val localRepo = File(File(System.getProperty("user.home")!!, ".m2"), "repository") + + val repos: ArrayList = arrayListOf() + + private fun currentRepos() = if (repos.isEmpty()) arrayListOf(mavenCentral) else repos + + override fun tryResolve(dependsOn: DependsOn): Iterable? { + if (dependsOn.value.count { it == ':' } == 2) { + try { + val deps = Aether(currentRepos(), localRepo).resolve( + DefaultArtifact(dependsOn.value), + JavaScopes.RUNTIME) + if (deps != null) + return deps.map { it.file } + else { + reportError("resolving [${dependsOn.value}] failed: no results") + } + } + catch (e: DependencyResolutionException) { + reportError("resolving [${dependsOn.value}] failed: $e") + } + return listOf() + } + return null + } +} diff --git a/libraries/tools/kotlin-script-util/src/main/kotlin/org/jetbrains/kotlin/script/util/templates.kt b/libraries/tools/kotlin-script-util/src/main/kotlin/org/jetbrains/kotlin/script/util/templates.kt new file mode 100644 index 00000000000..7bc18f86c70 --- /dev/null +++ b/libraries/tools/kotlin-script-util/src/main/kotlin/org/jetbrains/kotlin/script/util/templates.kt @@ -0,0 +1,33 @@ +/* + * 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. + */ + +@file:Suppress("unused") // an API + +package org.jetbrains.kotlin.script.util + +import org.jetbrains.kotlin.script.ScriptTemplateDefinition + +@ScriptTemplateDefinition(resolver = DefaultKotlinResolver::class, scriptFilePattern = ".*\\.kts") +abstract class StandardScript(val args: Array) + +@ScriptTemplateDefinition(resolver = DefaultKotlinAnnotatedScriptDependenciesResolver::class, scriptFilePattern = ".*\\.kts") +abstract class StandardScriptWithAnnotatedResolving(val args: Array) + +@ScriptTemplateDefinition(resolver = DefaultKotlinResolver::class, scriptFilePattern = ".*\\.kts") +abstract class ScriptWithBindings(val bindings: Map) + +@ScriptTemplateDefinition(resolver = DefaultKotlinAnnotatedScriptDependenciesResolver::class, scriptFilePattern = ".*\\.kts") +abstract class ScriptWithBindingsAndAnnotatedResolving(val bindings: Map) diff --git a/libraries/tools/kotlin-script-util/src/test/kotlin/org/jetbrains/kotlin/script/util/ScriptUtilIT.kt b/libraries/tools/kotlin-script-util/src/test/kotlin/org/jetbrains/kotlin/script/util/ScriptUtilIT.kt new file mode 100644 index 00000000000..188b455d5b2 --- /dev/null +++ b/libraries/tools/kotlin-script-util/src/test/kotlin/org/jetbrains/kotlin/script/util/ScriptUtilIT.kt @@ -0,0 +1,161 @@ +/* + * 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.util + +import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys +import org.jetbrains.kotlin.cli.common.messages.* +import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles +import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment +import org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler +import org.jetbrains.kotlin.cli.jvm.config.addJvmClasspathRoot +import org.jetbrains.kotlin.cli.jvm.config.addJvmClasspathRoots +import org.jetbrains.kotlin.codegen.CompilationException +import com.intellij.openapi.util.Disposer +import org.jetbrains.kotlin.config.CommonConfigurationKeys +import org.jetbrains.kotlin.config.CompilerConfiguration +import org.jetbrains.kotlin.config.JVMConfigurationKeys +import org.jetbrains.kotlin.config.addKotlinSourceRoot +import org.jetbrains.kotlin.script.KotlinScriptDefinition +import org.jetbrains.kotlin.script.KotlinScriptDefinitionFromTemplate +import org.jetbrains.kotlin.utils.PathUtil +import org.junit.Assert +import org.junit.Test +import java.io.ByteArrayOutputStream +import java.io.File +import java.io.PrintStream +import kotlin.reflect.KClass + +class ScriptUtilIT { + + companion object { + private val argsHelloWorldOutput = +"""Hello, world! +a1 +done +""" + private val bindingsHelloWorldOutput = +"""Hello, world! +a1 = 42 +done +""" + } + + @Test + fun testArgsHelloWorld() { + val scriptClass = compileScript("args-hello-world.kts", StandardScript::class) + Assert.assertNotNull(scriptClass) + val ctor = scriptClass?.getConstructor(Array::class.java) + Assert.assertNotNull(ctor) + captureOut { + ctor!!.newInstance(arrayOf("a1")) + }.let { + Assert.assertEquals(argsHelloWorldOutput, it) + } + } + + @Test + fun testBndHelloWorld() { + val scriptClass = compileScript("bindings-hello-world.kts", ScriptWithBindings::class) + Assert.assertNotNull(scriptClass) + val ctor = scriptClass?.getConstructor(Map::class.java) + Assert.assertNotNull(ctor) + captureOut { + ctor!!.newInstance(hashMapOf("a1" to 42)) + }.let { + Assert.assertEquals(bindingsHelloWorldOutput, it) + } + } + + @Test + fun testResolveStdHelloWorld() { + Assert.assertNull(compileScript("args-junit-hello-world.kts", StandardScript::class)) + + val scriptClass = compileScript("args-junit-hello-world.kts", StandardScriptWithAnnotatedResolving::class) + Assert.assertNotNull(scriptClass) + captureOut { + scriptClass!!.getConstructor(Array::class.java)!!.newInstance(arrayOf("a1")) + }.let { + Assert.assertEquals(argsHelloWorldOutput, it) + } + } + + private fun compileScript( + scriptFileName: String, + scriptTemplate: KClass, + environment: Map? = null, + runIsolated: Boolean = true, + suppressOutput: Boolean = false): Class<*>? = + compileScriptImpl("src/test/resources/scripts/" + scriptFileName, KotlinScriptDefinitionFromTemplate(scriptTemplate, null, null, environment), runIsolated, suppressOutput) + + private fun compileScriptImpl( + scriptPath: String, + scriptDefinition: KotlinScriptDefinition, + runIsolated: Boolean, + suppressOutput: Boolean): Class<*>? + { + val paths = PathUtil.getKotlinPathsForDistDirectory() + val messageCollector = + if (suppressOutput) MessageCollector.NONE + else PrintingMessageCollector(System.err, MessageRenderer.PLAIN_FULL_PATHS, false) + + val rootDisposable = Disposer.newDisposable() + try { + val configuration = CompilerConfiguration().apply { + addJvmClasspathRoots(PathUtil.getJdkClassesRoots()) + val rtJar = System.getProperty("runtimeJar") + Assert.assertNotNull(rtJar) + addJvmClasspathRoot(File(rtJar)) + put(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, messageCollector) + addKotlinSourceRoot(scriptPath) + put(CommonConfigurationKeys.MODULE_NAME, "kotlin-script-util-test") + add(JVMConfigurationKeys.SCRIPT_DEFINITIONS, scriptDefinition) + put(JVMConfigurationKeys.RETAIN_OUTPUT_IN_MEMORY, true) + put(JVMConfigurationKeys.INCLUDE_RUNTIME, true) + } + + val environment = KotlinCoreEnvironment.createForProduction(rootDisposable, configuration, EnvironmentConfigFiles.JVM_CONFIG_FILES) + + try { + return if (runIsolated) KotlinToJVMBytecodeCompiler.compileScript(environment, paths) + else KotlinToJVMBytecodeCompiler.compileScript(environment, this.javaClass.classLoader) + } + catch (e: CompilationException) { + messageCollector.report(CompilerMessageSeverity.EXCEPTION, OutputMessageUtil.renderException(e), + MessageUtil.psiElementToMessageLocation(e.element)) + return null + } + catch (t: Throwable) { + MessageCollectorUtil.reportException(messageCollector, t) + throw t + } + + } + finally { + Disposer.dispose(rootDisposable) + } + } + + private fun captureOut(body: () -> Unit): String { + val outStream = ByteArrayOutputStream() + val prevOut = System.out + System.setOut(PrintStream(outStream)) + body() + System.out.flush() + System.setOut(prevOut) + return outStream.toString() + } +} diff --git a/libraries/tools/kotlin-script-util/src/test/resources/scripts/args-hello-world.kts b/libraries/tools/kotlin-script-util/src/test/resources/scripts/args-hello-world.kts new file mode 100644 index 00000000000..2d332bd05aa --- /dev/null +++ b/libraries/tools/kotlin-script-util/src/test/resources/scripts/args-hello-world.kts @@ -0,0 +1,8 @@ + +println("Hello, world!") + +if (args.isNotEmpty()) { + println(args.joinToString()) +} + +println("done") diff --git a/libraries/tools/kotlin-script-util/src/test/resources/scripts/args-junit-hello-world.kts b/libraries/tools/kotlin-script-util/src/test/resources/scripts/args-junit-hello-world.kts new file mode 100644 index 00000000000..7d91efb1c7b --- /dev/null +++ b/libraries/tools/kotlin-script-util/src/test/resources/scripts/args-junit-hello-world.kts @@ -0,0 +1,12 @@ + +@file:DependsOn("junit:junit:4.11") + +org.junit.Assert.assertTrue(true) + +println("Hello, world!") + +if (args.isNotEmpty()) { + println(args.joinToString()) +} + +println("done") diff --git a/libraries/tools/kotlin-script-util/src/test/resources/scripts/bindings-hello-world.kts b/libraries/tools/kotlin-script-util/src/test/resources/scripts/bindings-hello-world.kts new file mode 100644 index 00000000000..d22bbaf90e0 --- /dev/null +++ b/libraries/tools/kotlin-script-util/src/test/resources/scripts/bindings-hello-world.kts @@ -0,0 +1,8 @@ + +println("Hello, world!") + +if (bindings.isNotEmpty()) { + println(bindings.entries.joinToString { "${it.key} = ${it.value}" }) +} + +println("done") diff --git a/libraries/tools/kotlin-script-util/src/test/resources/scripts/bnd-hello-world.kts b/libraries/tools/kotlin-script-util/src/test/resources/scripts/bnd-hello-world.kts new file mode 100644 index 00000000000..b0e051318a5 --- /dev/null +++ b/libraries/tools/kotlin-script-util/src/test/resources/scripts/bnd-hello-world.kts @@ -0,0 +1,8 @@ + +println("Hello, world!") + +if (bindings.isNotEmpty()) { + println(bindings.joinToString { "${it.key} = ${it.value}" }) +} + +println("done") diff --git a/libraries/tools/kotlin-script-util/src/test/resources/scripts/std-hello-world.kts b/libraries/tools/kotlin-script-util/src/test/resources/scripts/std-hello-world.kts new file mode 100644 index 00000000000..2d332bd05aa --- /dev/null +++ b/libraries/tools/kotlin-script-util/src/test/resources/scripts/std-hello-world.kts @@ -0,0 +1,8 @@ + +println("Hello, world!") + +if (args.isNotEmpty()) { + println(args.joinToString()) +} + +println("done") diff --git a/libraries/tools/kotlin-script-util/src/test/resources/scripts/std-junit-hello-world.kts b/libraries/tools/kotlin-script-util/src/test/resources/scripts/std-junit-hello-world.kts new file mode 100644 index 00000000000..2d332bd05aa --- /dev/null +++ b/libraries/tools/kotlin-script-util/src/test/resources/scripts/std-junit-hello-world.kts @@ -0,0 +1,8 @@ + +println("Hello, world!") + +if (args.isNotEmpty()) { + println(args.joinToString()) +} + +println("done")