Allow only single expression eval in cli compiler and kotlin runner
#KT-35740 fixed also add tests and drop logger usage in the cli dependencies manager: the logger is normally unitialized in the usage scenarios, but related warnings are annoying.
This commit is contained in:
@@ -42,9 +42,17 @@ object Main {
|
||||
var collectingExpressions = false
|
||||
var needsCompiler = false
|
||||
val arguments = arrayListOf<String>()
|
||||
val expressions = arrayListOf<String>()
|
||||
var expression: String? = null
|
||||
var noReflect = false
|
||||
|
||||
fun setExpression(expr: String) {
|
||||
if (expression == null) {
|
||||
expression = expr
|
||||
} else {
|
||||
throw RunnerException("Only single -e/-expression argument supported")
|
||||
}
|
||||
}
|
||||
|
||||
var i = 0
|
||||
while (i < args.size) {
|
||||
val arg = args[i]
|
||||
@@ -58,7 +66,7 @@ object Main {
|
||||
|
||||
if (collectingExpressions) {
|
||||
if ("-expression" == arg || "-e" == arg) {
|
||||
expressions.add(next())
|
||||
setExpression(next())
|
||||
i++
|
||||
continue
|
||||
} else {
|
||||
@@ -89,7 +97,7 @@ object Main {
|
||||
}
|
||||
}
|
||||
else if ("-expression" == arg || "-e" == arg) {
|
||||
expressions.add(next())
|
||||
setExpression(next())
|
||||
collectingExpressions = true
|
||||
needsCompiler = true
|
||||
}
|
||||
@@ -125,8 +133,8 @@ object Main {
|
||||
classpath.addPath(KOTLIN_HOME.toString() + "/lib/kotlin-reflect.jar")
|
||||
}
|
||||
|
||||
if (expressions.isNotEmpty()) {
|
||||
runner = ExpressionRunner(expressions)
|
||||
if (expression != null) {
|
||||
runner = ExpressionRunner(expression!!)
|
||||
} else if (runner == null) {
|
||||
runner = ReplRunner()
|
||||
needsCompiler = true
|
||||
|
||||
@@ -147,14 +147,11 @@ class ScriptRunner(private val path: String) : RunnerWithCompiler() {
|
||||
}
|
||||
}
|
||||
|
||||
class ExpressionRunner(private val code: List<String>) : RunnerWithCompiler() {
|
||||
class ExpressionRunner(private val code: String) : RunnerWithCompiler() {
|
||||
override fun run(classpath: List<URL>, arguments: List<String>, compilerClasspath: List<URL>) {
|
||||
val compilerArgs = ArrayList<String>().apply {
|
||||
addClasspathArgIfNeeded(classpath)
|
||||
code.forEach {
|
||||
add("-Xexpression")
|
||||
add(it)
|
||||
}
|
||||
add("-Xexpression=$code")
|
||||
addAll(arguments)
|
||||
}
|
||||
runCompiler(compilerClasspath, compilerArgs)
|
||||
|
||||
Reference in New Issue
Block a user