From 7ea436b687d1f9d969a2262cf0055d2f3f788e21 Mon Sep 17 00:00:00 2001 From: Holger Brandl Date: Wed, 3 Aug 2016 17:22:05 +0200 Subject: [PATCH] added supported for user-provided KOTLIN_OPTS (fixes #8) --- .gitignore | 1 + NEWS.md | 7 ++++--- README.md | 14 ++++++++++++++ examples/more_examples.sh | 12 +++--------- examples/scratchpad.kts | 23 ----------------------- examples/unit_tests.sh | 28 ++++++++++++++++++++++++++++ expandcp.kts | 7 +++++++ kscript | 5 ++++- 8 files changed, 61 insertions(+), 36 deletions(-) diff --git a/.gitignore b/.gitignore index 67146586..8f80b43d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ .gradle build/ +target/ # Ignore Gradle GUI config gradle-app.setting diff --git a/NEWS.md b/NEWS.md index e821d5e8..c58a1621 100644 --- a/NEWS.md +++ b/NEWS.md @@ -3,9 +3,10 @@ ## v1.1 * Support for stdin and process substitution as script source. See [examples](examples/unit_tests.sh) -* TBD: versioning and auto-update -* TBD: basic command-line help +* versioning and auto-update +* basic command-line help +* Added support for `KOTLIN_OPTS` (see [#8](https://github.com/holgerbrandl/kscript/issues/8)) -## +## v1.0 Initial Release \ No newline at end of file diff --git a/README.md b/README.md index 695cccf8..8f60c9be 100644 --- a/README.md +++ b/README.md @@ -110,6 +110,20 @@ The initial version of `kscript` was kindly contributed by Oscar Gonzalez. `kscript` works better with [Intellij](https://www.jetbrains.com/idea/), since extended multi-line shebang-headers are not (yet?) supported by Intellij's' Kotlin plugin (even if the kotlin-script parser seems to be able to handle them). However, for dependency resolution, `kotlin script` relies on such mutli-line shebang headers (see [here](https://github.com/andrewoma/kotlin-script#mvncp)). In contrast, since `kscript` just works with just a standard shebang line, code parsing works very well in Intellij. +FAQ +============ + +### How to adjust the memory the JVM running my scriptlets? + +`kscript` allows to provide a `//KOTLIN_OPTS` line followed by parameters passed on to `kotlin` similar to how dependencies are defined: +```kotlin +#!/usr/bin/env kscript +//KOTLIN_OPTS -J-Xmx5g -J-server + +println("Hello from Kotlin with 5g of heap memory in server mode!") +``` + + Issues ======= diff --git a/examples/more_examples.sh b/examples/more_examples.sh index 3611cfb9..baeafccb 100644 --- a/examples/more_examples.sh +++ b/examples/more_examples.sh @@ -46,11 +46,6 @@ https://www.biostars.org/p/52698/ -fun main(args: Array) { - kutils.KscriptHelpers.processStdin { "huhu" + it } -} - - kscript -s ' //DEPS de.mpicbg.scicomp:kutils:0.2-SNAPSHOT kutils.KscriptHelpers.processStdin { "huhu" + it } @@ -62,11 +57,10 @@ kscript -st '"huhu" + it' ## REPL test: Filter-Join fasta files by ID -kotlinc -classpath $(expandcp.kts de.mpicbg.scicomp:kutils:0.2-SNAPSHOT) +kotlinc -classpath $(expandcp.kts de.mpicbg.scicomp:kutils:0.2) <<"EOF" +import de.mpicbg.scicomp.kscript.* - -kutils.KscriptHelpers.processStdin { "huhu" + it } -kscript +"house\nasdf".processLines { "huhu" + it } EOF \ No newline at end of file diff --git a/examples/scratchpad.kts b/examples/scratchpad.kts index 42cc6bc3..b535d1e3 100755 --- a/examples/scratchpad.kts +++ b/examples/scratchpad.kts @@ -1,24 +1 @@ #!/usr/bin/env kscript - -import de.mpicbg.scicomp.kscript.processLines - -println("ok") -println(args.joinToString()) - -// test - - -//generateSequence() { readLine() }.map { -//File(args[0]).readLines().map {} - -java.io.File(args[0]).useLines { - it.map { - if (!it.startsWith(">")) { - it.substring(0, 20) - } else it - }.forEach { println(it) } -} - - -java.io.File(args[0]).processLines { it + "foo" } - diff --git a/examples/unit_tests.sh b/examples/unit_tests.sh index c0f1fa57..291e505d 100644 --- a/examples/unit_tests.sh +++ b/examples/unit_tests.sh @@ -47,3 +47,31 @@ println((1+3).toString() + " test") kscript <(cat .test.kts) + + +## (4) KOTLIN_OPTS ( + +kscript - <<"EOF" | grep "^-ea" +//KOTLIN_OPTS -J-Xmx5g -J-server -J-ea + +import java.lang.management.ManagementFactory +import java.lang.management.RuntimeMXBean + +println("Hello from Kotlin with 5g of heap memory in server mode!") + +val bean = ManagementFactory.getRuntimeMXBean() +val aList = bean.inputArguments + +for (i in aList.indices) { + println(aList[i]) +} + +EOF + + + + + +public void runtimeParameters() { + +} \ No newline at end of file diff --git a/expandcp.kts b/expandcp.kts index 073031d1..eba77f2b 100755 --- a/expandcp.kts +++ b/expandcp.kts @@ -80,6 +80,13 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xs resdep_template 1.0-SNAPSHOT + + + jcenter + http://jcenter.bintray.com/ + + + ${depTags.joinToString("\n")} diff --git a/kscript b/kscript index f984cf56..e9d7954f 100755 --- a/kscript +++ b/kscript @@ -65,6 +65,8 @@ if ! which expandcp.kts &> /dev/null; then fi dependencies=$(grep -F "//DEPS" ${scriptFile} | head -n1 | cut -f2- -d' ' | tr ',;' ' ') +kotlin_opts=$(grep -F "//KOTLIN_OPTS" ${scriptFile} | head -n1 | cut -f2- -d' ') + #dependencies=" org.docopt:docopt:0.6.0-SNAPSHOT log4j:log4j:1.2.14 " if [ -n "$dependencies" ]; then @@ -132,4 +134,5 @@ fi #jar ufm ${jarFile} ${mainJava}.manimain #jar tf ${jarFile} -exec kotlin -classpath ${jarFile}:"$classpath" Main_${className} "$@" +echo KOTLIN_OPTS are ${kotlin_opts} +exec kotlin ${kotlin_opts} -classpath ${jarFile}:"$classpath" Main_${className} "$@"