Skip to content

Commit 637ea1e

Browse files
committed
Fixed problem with inability to resolve kt files.
1 parent b949f14 commit 637ea1e

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import java.io.File
88
import java.io.FileInputStream
99
import java.io.InputStreamReader
1010
import java.lang.IllegalArgumentException
11-
import java.net.URI
1211
import java.net.URL
1312
import java.net.UnknownHostException
1413
import java.util.*
@@ -85,7 +84,7 @@ fun main(args: Array<String>) {
8584
quit(0)
8685
}
8786

88-
// note: with current impt we still don't support `kscript -1` where "-1" is a valid kotlin expression
87+
// note: with current implementation we still don't support `kscript -1` where "-1" is a valid kotlin expression
8988
val userArgs = args.dropWhile { it.startsWith("-") && it != "-" }.drop(1)
9089
val kscriptArgs = args.take(args.size - userArgs.size)
9190

@@ -102,7 +101,6 @@ fun main(args: Array<String>) {
102101
if (docopt.getBoolean("clear-cache")) {
103102
info("Cleaning up cache...")
104103
KSCRIPT_CACHE_DIR.listFiles().forEach { it.delete() }
105-
// evalBash("rm -f ${KSCRIPT_CACHE_DIR}/*")
106104
quit(0)
107105
}
108106

@@ -281,6 +279,7 @@ fun main(args: Array<String>) {
281279
}
282280

283281
var extClassPath = "${jarFile}${CP_SEPARATOR_CHAR}${KOTLIN_HOME}${File.separatorChar}lib${File.separatorChar}kotlin-script-runtime.jar"
282+
284283
if (classpath.isNotEmpty())
285284
extClassPath += CP_SEPARATOR_CHAR + classpath
286285

@@ -404,5 +403,6 @@ private fun resolvePreambles(rawScript: File, enableSupportApi: Boolean): File {
404403

405404
scriptFile = Script(scriptFile).prependWith("//INCLUDE ${preambleFile.absolutePath}").createTmpScript()
406405
}
406+
407407
return scriptFile
408408
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ data class IncludeResult(val scriptFile: File, val includes: List<URL> = emptyLi
1818
/** Resolve include declarations in a script file. Resolved script will be put into another temporary script */
1919
fun resolveIncludes(file: File): IncludeResult {
2020
val includes = mutableListOf<URI>()
21+
//TODO: in case initial file is a remote file, we shouldn't allow local references, so initial 'true' here is a wrong assumption
22+
//TODO: first resolve redirects: https://stackoverflow.com/questions/2659000/java-how-to-find-the-redirected-url-of-a-url
2123
val lines = resolve(true, file.toURI(), includes)
22-
val script = Script(lines)
24+
val script = Script(lines, file.extension)
2325

2426
return IncludeResult(script.consolidateStructure().createTmpScript(), includes.map { it.toURL() })
2527
}

test/test_suite.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ echo "Configuring KScript for further testing..."
5454
export PATH=${PROJECT_DIR}/build/libs:$PATH
5555
echo "KScript path for testing: $(which kscript)"
5656

57+
# Fake idea binary... Maybe good idea to use it instead of real idea binary?
58+
#echo "#!/usr/bin/env bash" > "${PROJECT_DIR}/build/libs/idea"
59+
#echo "echo $*" >> "${PROJECT_DIR}/build/libs/idea"
60+
5761
########################################################################################################################
5862
SUITE="script input modes"
5963
echo
@@ -132,7 +136,7 @@ assert_end "$SUITE"
132136
#assert_end "$SUITE"
133137

134138
########################################################################################################################
135-
SUITE="Environment"
139+
SUITE="environment"
136140
echo
137141
echo "Starting $SUITE tests:"
138142

@@ -220,7 +224,7 @@ assert_statement 'echo "foo${NL}bar" | kscript --text "lines.split().select(1, 2
220224
assert_end "$SUITE"
221225

222226
########################################################################################################################
223-
SUITE=".kt support"
227+
SUITE="kt support"
224228
echo
225229
echo "Starting $SUITE tests:"
226230

0 commit comments

Comments
 (0)