Skip to content

Commit

Permalink
added supported for user-provided KOTLIN_OPTS (fixes #8)
Browse files Browse the repository at this point in the history
  • Loading branch information
holgerbrandl committed Aug 3, 2016
1 parent c853ce3 commit 7ea436b
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 36 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.gradle
build/
target/

# Ignore Gradle GUI config
gradle-app.setting
Expand Down
7 changes: 4 additions & 3 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
=======

Expand Down
12 changes: 3 additions & 9 deletions examples/more_examples.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,6 @@ https://www.biostars.org/p/52698/



fun main(args: Array<String>) {
kutils.KscriptHelpers.processStdin { "huhu" + it }
}


kscript -s '
//DEPS de.mpicbg.scicomp:kutils:0.2-SNAPSHOT
kutils.KscriptHelpers.processStdin { "huhu" + it }
Expand All @@ -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
23 changes: 0 additions & 23 deletions examples/scratchpad.kts
Original file line number Diff line number Diff line change
@@ -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" }

28 changes: 28 additions & 0 deletions examples/unit_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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() {

}
7 changes: 7 additions & 0 deletions expandcp.kts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,13 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xs
<artifactId>resdep_template</artifactId>
<version>1.0-SNAPSHOT</version>
<repositories>
<repository>
<id>jcenter</id>
<url>http://jcenter.bintray.com/</url>
</repository>
</repositories>
<dependencies>
${depTags.joinToString("\n")}
</dependencies>
Expand Down
5 changes: 4 additions & 1 deletion kscript
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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} "$@"

0 comments on commit 7ea436b

Please sign in to comment.