Skip to content

Commit 99ec901

Browse files
committed
prepared runtime opts parsing for annotation support (closes #48)
1 parent 4cf1b0a commit 99ec901

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ install:
6464
- java -version
6565
- mvn --version
6666
- kscript 'println("kotlin rocks")'
67+
- kscript ${KSCRIPT_HOME}/test/resources/multi_line_deps.kts
6768
# - resdeps.kts org.org.docopt:org.docopt:0.6.0-SNAPSHOT log4j:log4j:1.2.14
6869
# - kscript ${KSCRIPT_HOME}/test/resources/multi_line_deps.kts
6970

src/main/kotlin/kscript/app/Kscript.kt

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -230,16 +230,18 @@ fun collectDependencies(scriptText: List<String>): List<String> {
230230
fun collectRuntimeOptions(scriptText: List<String>): String {
231231
val koptsPrefix = "//KOTLIN_OPTS "
232232

233-
// Append $KSCRIPT_KOTLIN_OPTS.
234-
// Overriding //KOTLIN_OPTS lines in the script relies on the JVM processing
235-
// arguments in order, which seems to be the case for Oracle, OpenJDK, and J9.
236-
val kscriptOpts = System.getenv()["KSCRIPT_KOTLIN_OPTS"]
237-
238-
return scriptText.
233+
var kotlinOpts = scriptText.
239234
filter { it.startsWith(koptsPrefix) }.
240-
map { it.replaceFirst(koptsPrefix, "").trim() }.
241-
joinToString(" ").
242-
plus(kscriptOpts ?: "")
235+
map { it.replaceFirst(koptsPrefix, "").trim() }
236+
237+
//todo add support for @file:KotlinOpts here
238+
239+
// Append $KSCRIPT_KOTLIN_OPTS if defined in the parent environment
240+
System.getenv()["KSCRIPT_KOTLIN_OPTS"]?.run {
241+
kotlinOpts = kotlinOpts + this
242+
}
243+
244+
return kotlinOpts.joinToString(" ")
243245
}
244246

245247

test/test_suite.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ assert "source ${KSCRIPT_HOME}/test/resources/cmd_subst_test.sh" "command substi
4646

4747
## make sure that it runs with local script files
4848
assert "source ${KSCRIPT_HOME}/test/resources/local_script_file.sh" "kscript rocks!"
49-
assert "echo foo" "bar" # known to fail
49+
#assert "echo foo" "bar" # known to fail
5050

5151
## make sure that it runs with local script files
5252
assert "kscript ${KSCRIPT_HOME}/test/resources/multi_line_deps.kts" "kscript is cool!"

0 commit comments

Comments
 (0)