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:
+2
-2
@@ -53,8 +53,8 @@ abstract class AbstractScriptEvaluationExtension : ScriptEvaluationExtension {
|
||||
setupScriptConfiguration(configuration)
|
||||
|
||||
val script = when {
|
||||
arguments is K2JVMCompilerArguments && arguments.expressions != null -> {
|
||||
StringScriptSource(arguments.expressions!!.joinToString("\n"), "script.kts")
|
||||
arguments is K2JVMCompilerArguments && arguments.expression != null -> {
|
||||
StringScriptSource(arguments.expression!!, "script.kts")
|
||||
}
|
||||
arguments.script -> {
|
||||
val scriptFile = File(arguments.freeArgs.first())
|
||||
|
||||
+1
-1
@@ -47,6 +47,6 @@ class JvmCliScriptEvaluationExtension : AbstractScriptEvaluationExtension() {
|
||||
}
|
||||
|
||||
override fun isAccepted(arguments: CommonCompilerArguments): Boolean =
|
||||
arguments is K2JVMCompilerArguments && (arguments.script || arguments.expressions != null)
|
||||
arguments is K2JVMCompilerArguments && (arguments.script || arguments.expression != null)
|
||||
}
|
||||
|
||||
|
||||
-7
@@ -40,11 +40,6 @@ class CliScriptDependenciesProvider(project: Project) : ScriptDependenciesProvid
|
||||
|
||||
ServiceManager.getService(project, ScriptReportSink::class.java)?.attachReports(file.virtualFile, result.reports)
|
||||
|
||||
if (result is ResultWithDiagnostics.Success) {
|
||||
log.info("[kts] new cached deps for $path: ${result.value.dependenciesClassPath.joinToString(File.pathSeparator)}")
|
||||
} else {
|
||||
log.info("[kts] new cached errors for $path:\n ${result.reports.joinToString("\n ") { it.message + if (it.exception == null) "" else ": ${it.exception}" }}")
|
||||
}
|
||||
cacheLock.write {
|
||||
cache.put(path, result)
|
||||
}
|
||||
@@ -53,5 +48,3 @@ class CliScriptDependenciesProvider(project: Project) : ScriptDependenciesProvid
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private val log = Logger.getInstance(ScriptDependenciesProvider::class.java)
|
||||
|
||||
+1
-1
@@ -99,7 +99,7 @@ internal fun reportArgumentsIgnoredGenerally(
|
||||
K2JVMCompilerArguments::commonSources,
|
||||
K2JVMCompilerArguments::allWarningsAsErrors,
|
||||
K2JVMCompilerArguments::script,
|
||||
K2JVMCompilerArguments::expressions,
|
||||
K2JVMCompilerArguments::expression,
|
||||
K2JVMCompilerArguments::scriptTemplates,
|
||||
K2JVMCompilerArguments::scriptResolverEnvironment,
|
||||
K2JVMCompilerArguments::disableStandardScript,
|
||||
|
||||
+10
@@ -60,6 +60,16 @@ class ScriptingWithCliCompilerTest {
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testExpressionWithComma() {
|
||||
runWithK2JVMCompiler(
|
||||
arrayOf(
|
||||
"-Xexpression",
|
||||
"listOf(1,2)"
|
||||
),
|
||||
listOf("\\[1, 2\\]")
|
||||
)
|
||||
}
|
||||
|
||||
private fun getMainKtsClassPath(): List<File> {
|
||||
return listOf(
|
||||
|
||||
Reference in New Issue
Block a user