Do not add current directory to "kotlin" classpath

As "java" does, do not include the current directory to the classpath if
the explicit classpath is specified. This is more stable than always
adding the current directory, and users can easily add the ".:" to the
beginning of the explicit classpath themselves

 #KT-17100 Fixed
This commit is contained in:
Alexander Udalov
2017-03-29 17:42:19 +03:00
parent 3b8110f51c
commit 64dfa6d33d
2 changed files with 44 additions and 20 deletions
@@ -40,8 +40,6 @@ object Main {
val arguments = arrayListOf<String>()
var noReflect = false
classpath.addPaths(".")
var i = 0
while (i < args.size) {
val arg = args[i]
@@ -65,7 +63,9 @@ object Main {
printVersionAndExit()
}
else if ("-classpath" == arg || "-cp" == arg) {
classpath.addPaths(next())
for (path in next().split(File.pathSeparator).filter(String::isNotEmpty)) {
classpath.addPath(path)
}
}
else if ("-expression" == arg || "-e" == arg) {
runner = ExpressionRunner(next())
@@ -92,10 +92,14 @@ object Main {
i++
}
classpath.addPaths(KOTLIN_HOME.toString() + "/lib/kotlin-runtime.jar")
if (classpath.isEmpty()) {
classpath.addPath(".")
}
classpath.addPath(KOTLIN_HOME.toString() + "/lib/kotlin-runtime.jar")
if (!noReflect) {
classpath.addPaths(KOTLIN_HOME.toString() + "/lib/kotlin-reflect.jar")
classpath.addPath(KOTLIN_HOME.toString() + "/lib/kotlin-reflect.jar")
}
if (runner == null) {
@@ -105,10 +109,8 @@ object Main {
runner.run(classpath, arguments)
}
private fun MutableList<URL>.addPaths(paths: String) {
for (path in paths.split(File.pathSeparator)) {
add(File(path).absoluteFile.toURI().toURL())
}
private fun MutableList<URL>.addPath(path: String) {
add(File(path).absoluteFile.toURI().toURL())
}
@JvmStatic