Get rid of kotlinx-coroutines usage in scripting libs and plugins
the dependency on the coroutines library caused various problems like KT-30778, or stdlib/runtime version conflicts. The only function used was `runBlocking`, so this change replaces it with the internal implementation based on the similar internal thing from the stdlib. #KT-30778 fixed
This commit is contained in:
committed by
TeamCityServer
parent
9b1de90452
commit
0cd29adcc7
@@ -7,6 +7,7 @@ dependencies {
|
|||||||
compile(project(":kotlin-scripting-jvm"))
|
compile(project(":kotlin-scripting-jvm"))
|
||||||
compile(project(":kotlin-scripting-dependencies"))
|
compile(project(":kotlin-scripting-dependencies"))
|
||||||
compile(project(":kotlin-scripting-dependencies-maven"))
|
compile(project(":kotlin-scripting-dependencies-maven"))
|
||||||
|
compile(commonDep("org.jetbrains.kotlinx", "kotlinx-coroutines-core"))
|
||||||
}
|
}
|
||||||
|
|
||||||
sourceSets {
|
sourceSets {
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ project.updateJvmTarget("1.6")
|
|||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compile(kotlinStdlib())
|
compile(kotlinStdlib())
|
||||||
compile(commonDep("org.jetbrains.kotlinx", "kotlinx-coroutines-core"))
|
|
||||||
compileOnly(project(":kotlin-reflect-api"))
|
compileOnly(project(":kotlin-reflect-api"))
|
||||||
testCompile(commonDep("junit"))
|
testCompile(commonDep("junit"))
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-3
@@ -18,9 +18,8 @@
|
|||||||
|
|
||||||
package kotlin.script.experimental.host
|
package kotlin.script.experimental.host
|
||||||
|
|
||||||
import kotlinx.coroutines.CoroutineScope
|
|
||||||
import kotlinx.coroutines.runBlocking
|
|
||||||
import kotlin.script.experimental.api.*
|
import kotlin.script.experimental.api.*
|
||||||
|
import kotlin.script.experimental.impl.internalScriptingRunSuspend
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The base class for scripting host implementations
|
* The base class for scripting host implementations
|
||||||
@@ -32,7 +31,9 @@ abstract class BasicScriptingHost(
|
|||||||
/**
|
/**
|
||||||
* The overridable wrapper for executing evaluation in a desired coroutines context
|
* The overridable wrapper for executing evaluation in a desired coroutines context
|
||||||
*/
|
*/
|
||||||
open fun <T> runInCoroutineContext(block: suspend CoroutineScope.() -> T): T = runBlocking { block() }
|
open fun <T> runInCoroutineContext(block: suspend () -> T): T =
|
||||||
|
@Suppress("DEPRECATION_ERROR")
|
||||||
|
internalScriptingRunSuspend { block() }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The default implementation of the evaluation function
|
* The default implementation of the evaluation function
|
||||||
|
|||||||
@@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package kotlin.script.experimental.impl
|
||||||
|
|
||||||
|
import kotlin.coroutines.Continuation
|
||||||
|
import kotlin.coroutines.CoroutineContext
|
||||||
|
import kotlin.coroutines.EmptyCoroutineContext
|
||||||
|
import kotlin.coroutines.startCoroutine
|
||||||
|
|
||||||
|
// Copied with modifications form kotlin.coroutines.jvm.internal.runSuspend/RunSuspend
|
||||||
|
// to use as an equivalent of runBlocking without dependency on the kotlinx.coroutines
|
||||||
|
|
||||||
|
@Deprecated("For internal use only, use kotlinx.coroutines instead", level = DeprecationLevel.ERROR)
|
||||||
|
fun <T> internalScriptingRunSuspend(block: suspend () -> T) : T {
|
||||||
|
val run = InternalScriptingRunSuspend<T>()
|
||||||
|
block.startCoroutine(run)
|
||||||
|
return run.await()
|
||||||
|
}
|
||||||
|
|
||||||
|
private class InternalScriptingRunSuspend<T> : Continuation<T> {
|
||||||
|
override val context: CoroutineContext
|
||||||
|
get() = EmptyCoroutineContext
|
||||||
|
|
||||||
|
@Suppress("RESULT_CLASS_IN_RETURN_TYPE")
|
||||||
|
var result: Result<T>? = null
|
||||||
|
|
||||||
|
override fun resumeWith(result: Result<T>) = synchronized(this) {
|
||||||
|
this.result = result
|
||||||
|
@Suppress("PLATFORM_CLASS_MAPPED_TO_KOTLIN") (this as Object).notifyAll()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun await(): T = synchronized(this) {
|
||||||
|
while (true) {
|
||||||
|
when (val result: Result<T>? = this.result) {
|
||||||
|
null -> @Suppress("PLATFORM_CLASS_MAPPED_TO_KOTLIN") (this as Object).wait()
|
||||||
|
else -> break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result!!.getOrThrow()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -33,6 +33,7 @@ dependencies {
|
|||||||
testImplementation(commonDep("junit"))
|
testImplementation(commonDep("junit"))
|
||||||
testRuntimeOnly("org.slf4j:slf4j-nop:1.7.30")
|
testRuntimeOnly("org.slf4j:slf4j-nop:1.7.30")
|
||||||
testImplementation(kotlin("reflect"))
|
testImplementation(kotlin("reflect"))
|
||||||
|
testImplementation(commonDep("org.jetbrains.kotlinx", "kotlinx-coroutines-core"))
|
||||||
}
|
}
|
||||||
|
|
||||||
sourceSets {
|
sourceSets {
|
||||||
|
|||||||
@@ -8,8 +8,8 @@ project.updateJvmTarget("1.6")
|
|||||||
dependencies {
|
dependencies {
|
||||||
compile(kotlinStdlib())
|
compile(kotlinStdlib())
|
||||||
compile(project(":kotlin-scripting-common"))
|
compile(project(":kotlin-scripting-common"))
|
||||||
testCompile(commonDep("org.jetbrains.kotlinx", "kotlinx-coroutines-core"))
|
|
||||||
testCompile(commonDep("junit"))
|
testCompile(commonDep("junit"))
|
||||||
|
testImplementation(commonDep("org.jetbrains.kotlinx", "kotlinx-coroutines-core"))
|
||||||
}
|
}
|
||||||
|
|
||||||
sourceSets {
|
sourceSets {
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ dependencies {
|
|||||||
testCompile(projectTests(":compiler:tests-common"))
|
testCompile(projectTests(":compiler:tests-common"))
|
||||||
testCompile(project(":kotlin-scripting-compiler"))
|
testCompile(project(":kotlin-scripting-compiler"))
|
||||||
testCompile(project(":daemon-common")) // TODO: fix import (workaround for jps build)
|
testCompile(project(":daemon-common")) // TODO: fix import (workaround for jps build)
|
||||||
|
testImplementation(commonDep("org.jetbrains.kotlinx", "kotlinx-coroutines-core"))
|
||||||
|
|
||||||
testRuntimeOnly(project(":kotlin-compiler"))
|
testRuntimeOnly(project(":kotlin-compiler"))
|
||||||
testRuntimeOnly(project(":kotlin-reflect"))
|
testRuntimeOnly(project(":kotlin-reflect"))
|
||||||
|
|||||||
+3
-2
@@ -5,7 +5,6 @@
|
|||||||
|
|
||||||
package kotlin.script.experimental.jvmhost.repl
|
package kotlin.script.experimental.jvmhost.repl
|
||||||
|
|
||||||
import kotlinx.coroutines.runBlocking
|
|
||||||
import org.jetbrains.kotlin.backend.common.push
|
import org.jetbrains.kotlin.backend.common.push
|
||||||
import org.jetbrains.kotlin.cli.common.repl.*
|
import org.jetbrains.kotlin.cli.common.repl.*
|
||||||
import org.jetbrains.kotlin.scripting.compiler.plugin.impl.KJvmReplCompilerBase
|
import org.jetbrains.kotlin.scripting.compiler.plugin.impl.KJvmReplCompilerBase
|
||||||
@@ -15,6 +14,7 @@ import org.jetbrains.kotlin.scripting.compiler.plugin.repl.ReplCodeAnalyzerBase
|
|||||||
import java.util.concurrent.locks.ReentrantReadWriteLock
|
import java.util.concurrent.locks.ReentrantReadWriteLock
|
||||||
import kotlin.concurrent.write
|
import kotlin.concurrent.write
|
||||||
import kotlin.script.experimental.api.*
|
import kotlin.script.experimental.api.*
|
||||||
|
import kotlin.script.experimental.impl.internalScriptingRunSuspend
|
||||||
import kotlin.script.experimental.host.ScriptingHostConfiguration
|
import kotlin.script.experimental.host.ScriptingHostConfiguration
|
||||||
import kotlin.script.experimental.host.withDefaultsFrom
|
import kotlin.script.experimental.host.withDefaultsFrom
|
||||||
import kotlin.script.experimental.jvm.defaultJvmScriptingHostConfiguration
|
import kotlin.script.experimental.jvm.defaultJvmScriptingHostConfiguration
|
||||||
@@ -56,7 +56,8 @@ class JvmReplCompiler(
|
|||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
when (val res = runBlocking { replCompiler.compile(listOf(snippet), scriptCompilationConfiguration) }) {
|
@Suppress("DEPRECATION_ERROR")
|
||||||
|
when (val res = internalScriptingRunSuspend { replCompiler.compile(listOf(snippet), scriptCompilationConfiguration) }) {
|
||||||
is ResultWithDiagnostics.Success -> {
|
is ResultWithDiagnostics.Success -> {
|
||||||
val lineId = LineId(codeLine.no, 0, snippet.hashCode())
|
val lineId = LineId(codeLine.no, 0, snippet.hashCode())
|
||||||
replCompilerState.apply {
|
replCompilerState.apply {
|
||||||
|
|||||||
+3
-2
@@ -5,13 +5,13 @@
|
|||||||
|
|
||||||
package kotlin.script.experimental.jvmhost.repl
|
package kotlin.script.experimental.jvmhost.repl
|
||||||
|
|
||||||
import kotlinx.coroutines.runBlocking
|
|
||||||
import org.jetbrains.kotlin.cli.common.repl.*
|
import org.jetbrains.kotlin.cli.common.repl.*
|
||||||
import org.jetbrains.kotlin.cli.common.repl.ReplEvaluator
|
import org.jetbrains.kotlin.cli.common.repl.ReplEvaluator
|
||||||
import java.util.concurrent.locks.ReentrantReadWriteLock
|
import java.util.concurrent.locks.ReentrantReadWriteLock
|
||||||
import kotlin.concurrent.write
|
import kotlin.concurrent.write
|
||||||
import kotlin.reflect.KClass
|
import kotlin.reflect.KClass
|
||||||
import kotlin.script.experimental.api.*
|
import kotlin.script.experimental.api.*
|
||||||
|
import kotlin.script.experimental.impl.internalScriptingRunSuspend
|
||||||
import kotlin.script.experimental.jvm.BasicJvmScriptEvaluator
|
import kotlin.script.experimental.jvm.BasicJvmScriptEvaluator
|
||||||
import kotlin.script.experimental.jvm.baseClassLoader
|
import kotlin.script.experimental.jvm.baseClassLoader
|
||||||
import kotlin.script.experimental.jvm.impl.KJvmCompiledScript
|
import kotlin.script.experimental.jvm.impl.KJvmCompiledScript
|
||||||
@@ -60,7 +60,8 @@ class JvmReplEvaluator(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val res = runBlocking { scriptEvaluator(compiledScript, currentConfiguration) }
|
@Suppress("DEPRECATION_ERROR")
|
||||||
|
val res = internalScriptingRunSuspend { scriptEvaluator(compiledScript, currentConfiguration) }
|
||||||
|
|
||||||
when (res) {
|
when (res) {
|
||||||
is ResultWithDiagnostics.Success -> {
|
is ResultWithDiagnostics.Success -> {
|
||||||
|
|||||||
+3
-2
@@ -5,7 +5,6 @@
|
|||||||
|
|
||||||
package kotlin.script.experimental.jvm.impl
|
package kotlin.script.experimental.jvm.impl
|
||||||
|
|
||||||
import kotlinx.coroutines.runBlocking
|
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import kotlin.script.dependencies.Environment
|
import kotlin.script.dependencies.Environment
|
||||||
import kotlin.script.dependencies.ScriptContents
|
import kotlin.script.dependencies.ScriptContents
|
||||||
@@ -16,6 +15,7 @@ import kotlin.script.experimental.dependencies.ScriptDependencies
|
|||||||
import kotlin.script.experimental.dependencies.ScriptReport
|
import kotlin.script.experimental.dependencies.ScriptReport
|
||||||
import kotlin.script.experimental.host.FileScriptSource
|
import kotlin.script.experimental.host.FileScriptSource
|
||||||
import kotlin.script.experimental.host.toScriptSource
|
import kotlin.script.experimental.host.toScriptSource
|
||||||
|
import kotlin.script.experimental.impl.internalScriptingRunSuspend
|
||||||
import kotlin.script.experimental.jvm.JvmDependency
|
import kotlin.script.experimental.jvm.JvmDependency
|
||||||
import kotlin.script.experimental.jvm.compat.mapToLegacyScriptReportPosition
|
import kotlin.script.experimental.jvm.compat.mapToLegacyScriptReportPosition
|
||||||
import kotlin.script.experimental.jvm.compat.mapToLegacyScriptReportSeverity
|
import kotlin.script.experimental.jvm.compat.mapToLegacyScriptReportSeverity
|
||||||
@@ -27,7 +27,8 @@ class BridgeDependenciesResolver(
|
|||||||
) : AsyncDependenciesResolver {
|
) : AsyncDependenciesResolver {
|
||||||
|
|
||||||
override fun resolve(scriptContents: ScriptContents, environment: Environment): DependenciesResolver.ResolveResult =
|
override fun resolve(scriptContents: ScriptContents, environment: Environment): DependenciesResolver.ResolveResult =
|
||||||
runBlocking {
|
@Suppress("DEPRECATION_ERROR")
|
||||||
|
internalScriptingRunSuspend {
|
||||||
resolveAsync(scriptContents, environment)
|
resolveAsync(scriptContents, environment)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,13 +5,13 @@
|
|||||||
|
|
||||||
package kotlin.script.experimental.jvm
|
package kotlin.script.experimental.jvm
|
||||||
|
|
||||||
import kotlin.coroutines.Continuation
|
import kotlin.script.experimental.api.ScriptCompilationConfiguration
|
||||||
import kotlin.coroutines.CoroutineContext
|
import kotlin.script.experimental.api.baseClass
|
||||||
import kotlin.coroutines.EmptyCoroutineContext
|
import kotlin.script.experimental.api.hostConfiguration
|
||||||
import kotlin.coroutines.startCoroutine
|
import kotlin.script.experimental.api.onFailure
|
||||||
import kotlin.script.experimental.api.*
|
|
||||||
import kotlin.script.experimental.host.createEvaluationConfigurationFromTemplate
|
import kotlin.script.experimental.host.createEvaluationConfigurationFromTemplate
|
||||||
import kotlin.script.experimental.host.withDefaultsFrom
|
import kotlin.script.experimental.host.withDefaultsFrom
|
||||||
|
import kotlin.script.experimental.impl.internalScriptingRunSuspend
|
||||||
import kotlin.script.experimental.jvm.impl.createScriptFromClassLoader
|
import kotlin.script.experimental.jvm.impl.createScriptFromClassLoader
|
||||||
|
|
||||||
@Suppress("unused") // script codegen generates a call to it
|
@Suppress("unused") // script codegen generates a call to it
|
||||||
@@ -29,42 +29,11 @@ fun runCompiledScript(scriptClass: Class<*>, vararg args: String) {
|
|||||||
mainArguments(args)
|
mainArguments(args)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
runScriptSuspend {
|
@Suppress("DEPRECATION_ERROR")
|
||||||
|
internalScriptingRunSuspend {
|
||||||
evaluator(script, evaluationConfiguration).onFailure {
|
evaluator(script, evaluationConfiguration).onFailure {
|
||||||
it.reports.forEach(System.err::println)
|
it.reports.forEach(System.err::println)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copied form kotlin.coroutines.jvm.internal.runSuspend/RunSuspend to create a runner without dependency on the kotlinx.coroutines
|
|
||||||
private fun runScriptSuspend(block: suspend () -> Unit) {
|
|
||||||
val run = RunScriptSuspend()
|
|
||||||
block.startCoroutine(run)
|
|
||||||
run.await()
|
|
||||||
}
|
|
||||||
|
|
||||||
private class RunScriptSuspend : Continuation<Unit> {
|
|
||||||
override val context: CoroutineContext
|
|
||||||
get() = EmptyCoroutineContext
|
|
||||||
|
|
||||||
@Suppress("RESULT_CLASS_IN_RETURN_TYPE")
|
|
||||||
var result: Result<Unit>? = null
|
|
||||||
|
|
||||||
override fun resumeWith(result: Result<Unit>) = synchronized(this) {
|
|
||||||
this.result = result
|
|
||||||
@Suppress("PLATFORM_CLASS_MAPPED_TO_KOTLIN") (this as Object).notifyAll()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun await() = synchronized(this) {
|
|
||||||
while (true) {
|
|
||||||
when (val result = this.result) {
|
|
||||||
null -> @Suppress("PLATFORM_CLASS_MAPPED_TO_KOTLIN") (this as Object).wait()
|
|
||||||
else -> {
|
|
||||||
result.getOrThrow() // throw up failure
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|||||||
@@ -38,7 +38,6 @@ dependencies {
|
|||||||
embedded(project(":kotlin-scripting-jvm-host-unshaded")) { isTransitive = false }
|
embedded(project(":kotlin-scripting-jvm-host-unshaded")) { isTransitive = false }
|
||||||
embedded(project(":kotlin-scripting-dependencies")) { isTransitive = false }
|
embedded(project(":kotlin-scripting-dependencies")) { isTransitive = false }
|
||||||
embedded("org.apache.ivy:ivy:2.5.0")
|
embedded("org.apache.ivy:ivy:2.5.0")
|
||||||
embedded(commonDep("org.jetbrains.kotlinx", "kotlinx-coroutines-core")) { isTransitive = false }
|
|
||||||
embedded(commonDep("org.jetbrains.kotlinx:kotlinx-collections-immutable-jvm")) {
|
embedded(commonDep("org.jetbrains.kotlinx:kotlinx-collections-immutable-jvm")) {
|
||||||
isTransitive = false
|
isTransitive = false
|
||||||
attributes {
|
attributes {
|
||||||
|
|||||||
@@ -5,7 +5,6 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.mainKts
|
package org.jetbrains.kotlin.mainKts
|
||||||
|
|
||||||
import kotlinx.coroutines.runBlocking
|
|
||||||
import org.jetbrains.kotlin.mainKts.impl.Directories
|
import org.jetbrains.kotlin.mainKts.impl.Directories
|
||||||
import org.jetbrains.kotlin.mainKts.impl.IvyResolver
|
import org.jetbrains.kotlin.mainKts.impl.IvyResolver
|
||||||
import java.io.File
|
import java.io.File
|
||||||
@@ -19,6 +18,7 @@ import kotlin.script.experimental.dependencies.*
|
|||||||
import kotlin.script.experimental.host.FileBasedScriptSource
|
import kotlin.script.experimental.host.FileBasedScriptSource
|
||||||
import kotlin.script.experimental.host.FileScriptSource
|
import kotlin.script.experimental.host.FileScriptSource
|
||||||
import kotlin.script.experimental.host.ScriptingHostConfiguration
|
import kotlin.script.experimental.host.ScriptingHostConfiguration
|
||||||
|
import kotlin.script.experimental.impl.internalScriptingRunSuspend
|
||||||
import kotlin.script.experimental.jvm.*
|
import kotlin.script.experimental.jvm.*
|
||||||
import kotlin.script.experimental.jvm.compat.mapLegacyDiagnosticSeverity
|
import kotlin.script.experimental.jvm.compat.mapLegacyDiagnosticSeverity
|
||||||
import kotlin.script.experimental.jvm.compat.mapLegacyScriptPosition
|
import kotlin.script.experimental.jvm.compat.mapLegacyScriptPosition
|
||||||
@@ -135,7 +135,8 @@ class MainKtsConfigurator : RefineScriptCompilationConfigurationHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
val resolveResult = try {
|
val resolveResult = try {
|
||||||
runBlocking {
|
@Suppress("DEPRECATION_ERROR")
|
||||||
|
internalScriptingRunSuspend {
|
||||||
resolver.resolveFromScriptSourceAnnotations(annotations.filter { it.annotation is DependsOn || it.annotation is Repository })
|
resolver.resolveFromScriptSourceAnnotations(annotations.filter { it.annotation is DependsOn || it.annotation is Repository })
|
||||||
}
|
}
|
||||||
} catch (e: Throwable) {
|
} catch (e: Throwable) {
|
||||||
|
|||||||
+3
-2
@@ -17,7 +17,6 @@
|
|||||||
package org.jetbrains.kotlin.script.util
|
package org.jetbrains.kotlin.script.util
|
||||||
|
|
||||||
import com.intellij.openapi.util.Disposer
|
import com.intellij.openapi.util.Disposer
|
||||||
import kotlinx.coroutines.runBlocking
|
|
||||||
import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys
|
import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys
|
||||||
import org.jetbrains.kotlin.cli.common.config.addKotlinSourceRoot
|
import org.jetbrains.kotlin.cli.common.config.addKotlinSourceRoot
|
||||||
import org.jetbrains.kotlin.cli.common.messages.*
|
import org.jetbrains.kotlin.cli.common.messages.*
|
||||||
@@ -55,6 +54,7 @@ import kotlin.reflect.KClass
|
|||||||
import kotlin.script.experimental.api.onSuccess
|
import kotlin.script.experimental.api.onSuccess
|
||||||
import kotlin.script.experimental.api.valueOr
|
import kotlin.script.experimental.api.valueOr
|
||||||
import kotlin.script.experimental.host.toScriptSource
|
import kotlin.script.experimental.host.toScriptSource
|
||||||
|
import kotlin.script.experimental.impl.internalScriptingRunSuspend
|
||||||
import kotlin.script.experimental.jvm.defaultJvmScriptingHostConfiguration
|
import kotlin.script.experimental.jvm.defaultJvmScriptingHostConfiguration
|
||||||
import kotlin.script.experimental.jvm.util.scriptCompilationClasspathFromContext
|
import kotlin.script.experimental.jvm.util.scriptCompilationClasspathFromContext
|
||||||
|
|
||||||
@@ -199,7 +199,8 @@ done
|
|||||||
val script = File(scriptPath).toScriptSource()
|
val script = File(scriptPath).toScriptSource()
|
||||||
val newScriptDefinition = ScriptDefinitionProvider.getInstance(environment.project)!!.findDefinition(script)!!
|
val newScriptDefinition = ScriptDefinitionProvider.getInstance(environment.project)!!.findDefinition(script)!!
|
||||||
val compiledScript = scriptCompiler.compile(script, newScriptDefinition.compilationConfiguration).onSuccess {
|
val compiledScript = scriptCompiler.compile(script, newScriptDefinition.compilationConfiguration).onSuccess {
|
||||||
runBlocking {
|
@Suppress("DEPRECATION_ERROR")
|
||||||
|
internalScriptingRunSuspend {
|
||||||
it.getClass(newScriptDefinition.evaluationConfiguration)
|
it.getClass(newScriptDefinition.evaluationConfiguration)
|
||||||
}
|
}
|
||||||
}.valueOr {
|
}.valueOr {
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ dependencies {
|
|||||||
runtimeOnly(project(":kotlin-scripting-common"))
|
runtimeOnly(project(":kotlin-scripting-common"))
|
||||||
runtimeOnly(project(":kotlin-scripting-jvm"))
|
runtimeOnly(project(":kotlin-scripting-jvm"))
|
||||||
runtimeOnly(kotlinStdlib())
|
runtimeOnly(kotlinStdlib())
|
||||||
runtimeOnly(commonDep("org.jetbrains.kotlinx", "kotlinx-coroutines-core"))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
publish()
|
publish()
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ dependencies {
|
|||||||
compile(project(":kotlin-scripting-jvm"))
|
compile(project(":kotlin-scripting-jvm"))
|
||||||
compile(kotlinStdlib())
|
compile(kotlinStdlib())
|
||||||
compileOnly(project(":kotlin-reflect-api"))
|
compileOnly(project(":kotlin-reflect-api"))
|
||||||
compile(commonDep("org.jetbrains.kotlinx", "kotlinx-coroutines-core"))
|
|
||||||
compileOnly(intellijCoreDep()) { includeJars("intellij-core") }
|
compileOnly(intellijCoreDep()) { includeJars("intellij-core") }
|
||||||
compileOnly(intellijDep()) { includeJars("asm-all", rootProject = rootProject) }
|
compileOnly(intellijDep()) { includeJars("asm-all", rootProject = rootProject) }
|
||||||
|
|
||||||
|
|||||||
+4
-3
@@ -5,11 +5,11 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.scripting.resolve
|
package org.jetbrains.kotlin.scripting.resolve
|
||||||
|
|
||||||
import kotlinx.coroutines.runBlocking
|
|
||||||
import kotlin.script.dependencies.Environment
|
import kotlin.script.dependencies.Environment
|
||||||
import kotlin.script.dependencies.ScriptContents
|
import kotlin.script.dependencies.ScriptContents
|
||||||
import kotlin.script.experimental.dependencies.AsyncDependenciesResolver
|
import kotlin.script.experimental.dependencies.AsyncDependenciesResolver
|
||||||
import kotlin.script.experimental.dependencies.DependenciesResolver
|
import kotlin.script.experimental.dependencies.DependenciesResolver
|
||||||
|
import kotlin.script.experimental.impl.internalScriptingRunSuspend
|
||||||
|
|
||||||
// wraps AsyncDependenciesResolver to provide implementation for synchronous DependenciesResolver::resolve
|
// wraps AsyncDependenciesResolver to provide implementation for synchronous DependenciesResolver::resolve
|
||||||
class AsyncDependencyResolverWrapper(
|
class AsyncDependencyResolverWrapper(
|
||||||
@@ -18,8 +18,9 @@ class AsyncDependencyResolverWrapper(
|
|||||||
|
|
||||||
override fun resolve(
|
override fun resolve(
|
||||||
scriptContents: ScriptContents, environment: Environment
|
scriptContents: ScriptContents, environment: Environment
|
||||||
): DependenciesResolver.ResolveResult
|
): DependenciesResolver.ResolveResult =
|
||||||
= runBlocking { delegate.resolveAsync(scriptContents, environment) }
|
@Suppress("DEPRECATION_ERROR")
|
||||||
|
internalScriptingRunSuspend { delegate.resolveAsync(scriptContents, environment) }
|
||||||
|
|
||||||
|
|
||||||
suspend override fun resolveAsync(
|
suspend override fun resolveAsync(
|
||||||
|
|||||||
+3
-2
@@ -16,7 +16,6 @@ import com.intellij.psi.PsiElement
|
|||||||
import com.intellij.psi.PsiFile
|
import com.intellij.psi.PsiFile
|
||||||
import com.intellij.psi.PsiManager
|
import com.intellij.psi.PsiManager
|
||||||
import com.intellij.testFramework.LightVirtualFile
|
import com.intellij.testFramework.LightVirtualFile
|
||||||
import kotlinx.coroutines.runBlocking
|
|
||||||
import org.jetbrains.kotlin.idea.KotlinLanguage
|
import org.jetbrains.kotlin.idea.KotlinLanguage
|
||||||
import org.jetbrains.kotlin.psi.KtAnnotationEntry
|
import org.jetbrains.kotlin.psi.KtAnnotationEntry
|
||||||
import org.jetbrains.kotlin.psi.KtFile
|
import org.jetbrains.kotlin.psi.KtFile
|
||||||
@@ -34,6 +33,7 @@ import kotlin.script.experimental.dependencies.AsyncDependenciesResolver
|
|||||||
import kotlin.script.experimental.dependencies.DependenciesResolver
|
import kotlin.script.experimental.dependencies.DependenciesResolver
|
||||||
import kotlin.script.experimental.dependencies.ScriptDependencies
|
import kotlin.script.experimental.dependencies.ScriptDependencies
|
||||||
import kotlin.script.experimental.host.*
|
import kotlin.script.experimental.host.*
|
||||||
|
import kotlin.script.experimental.impl.internalScriptingRunSuspend
|
||||||
import kotlin.script.experimental.jvm.*
|
import kotlin.script.experimental.jvm.*
|
||||||
import kotlin.script.experimental.jvm.compat.mapToDiagnostics
|
import kotlin.script.experimental.jvm.compat.mapToDiagnostics
|
||||||
import kotlin.script.experimental.jvm.impl.toClassPathOrEmpty
|
import kotlin.script.experimental.jvm.impl.toClassPathOrEmpty
|
||||||
@@ -255,7 +255,8 @@ fun refineScriptCompilationConfiguration(
|
|||||||
// runBlocking is using there to avoid loading dependencies asynchronously
|
// runBlocking is using there to avoid loading dependencies asynchronously
|
||||||
// because it leads to starting more than one gradle daemon in case of resolving dependencies in build.gradle.kts
|
// because it leads to starting more than one gradle daemon in case of resolving dependencies in build.gradle.kts
|
||||||
// It is more efficient to use one hot daemon consistently than multiple daemon in parallel
|
// It is more efficient to use one hot daemon consistently than multiple daemon in parallel
|
||||||
runBlocking {
|
@Suppress("DEPRECATION_ERROR")
|
||||||
|
internalScriptingRunSuspend {
|
||||||
resolver.resolveAsync(scriptContents, environment)
|
resolver.resolveAsync(scriptContents, environment)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ dependencies {
|
|||||||
testCompile(commonDep("junit:junit"))
|
testCompile(commonDep("junit:junit"))
|
||||||
|
|
||||||
testImplementation(intellijCoreDep()) { includeJars("intellij-core") }
|
testImplementation(intellijCoreDep()) { includeJars("intellij-core") }
|
||||||
|
testImplementation(commonDep("org.jetbrains.kotlinx", "kotlinx-coroutines-core"))
|
||||||
testRuntimeOnly(intellijDep()) { includeJars("jps-model", "jna") }
|
testRuntimeOnly(intellijDep()) { includeJars("jps-model", "jna") }
|
||||||
|
|
||||||
testImplementation(project(":kotlin-reflect"))
|
testImplementation(project(":kotlin-reflect"))
|
||||||
|
|||||||
+5
-5
@@ -6,7 +6,6 @@
|
|||||||
package org.jetbrains.kotlin.scripting.compiler.plugin
|
package org.jetbrains.kotlin.scripting.compiler.plugin
|
||||||
|
|
||||||
import com.intellij.core.JavaCoreProjectEnvironment
|
import com.intellij.core.JavaCoreProjectEnvironment
|
||||||
import kotlinx.coroutines.runBlocking
|
|
||||||
import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys
|
import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys
|
||||||
import org.jetbrains.kotlin.cli.common.ExitCode
|
import org.jetbrains.kotlin.cli.common.ExitCode
|
||||||
import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments
|
import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments
|
||||||
@@ -20,11 +19,11 @@ import org.jetbrains.kotlin.scripting.configuration.ScriptingConfigurationKeys
|
|||||||
import org.jetbrains.kotlin.scripting.definitions.ScriptDefinitionProvider
|
import org.jetbrains.kotlin.scripting.definitions.ScriptDefinitionProvider
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.Serializable
|
import java.io.Serializable
|
||||||
import java.util.*
|
|
||||||
import kotlin.script.experimental.api.*
|
import kotlin.script.experimental.api.*
|
||||||
import kotlin.script.experimental.host.FileScriptSource
|
import kotlin.script.experimental.host.FileScriptSource
|
||||||
import kotlin.script.experimental.host.StringScriptSource
|
import kotlin.script.experimental.host.StringScriptSource
|
||||||
import kotlin.script.experimental.host.toScriptSource
|
import kotlin.script.experimental.host.toScriptSource
|
||||||
|
import kotlin.script.experimental.impl.internalScriptingRunSuspend
|
||||||
import kotlin.script.experimental.jvm.util.renderError
|
import kotlin.script.experimental.jvm.util.renderError
|
||||||
|
|
||||||
abstract class AbstractScriptEvaluationExtension : ScriptEvaluationExtension {
|
abstract class AbstractScriptEvaluationExtension : ScriptEvaluationExtension {
|
||||||
@@ -132,19 +131,20 @@ abstract class AbstractScriptEvaluationExtension : ScriptEvaluationExtension {
|
|||||||
): ExitCode {
|
): ExitCode {
|
||||||
val scriptCompiler = createScriptCompiler(environment)
|
val scriptCompiler = createScriptCompiler(environment)
|
||||||
|
|
||||||
return runBlocking {
|
@Suppress("DEPRECATION_ERROR")
|
||||||
|
return internalScriptingRunSuspend {
|
||||||
val compiledScript = scriptCompiler.compile(script, scriptCompilationConfiguration).valueOr {
|
val compiledScript = scriptCompiler.compile(script, scriptCompilationConfiguration).valueOr {
|
||||||
for (report in it.reports) {
|
for (report in it.reports) {
|
||||||
messageCollector.report(report.severity.toCompilerMessageSeverity(), report.render(withSeverity = false))
|
messageCollector.report(report.severity.toCompilerMessageSeverity(), report.render(withSeverity = false))
|
||||||
}
|
}
|
||||||
return@runBlocking ExitCode.COMPILATION_ERROR
|
return@internalScriptingRunSuspend ExitCode.COMPILATION_ERROR
|
||||||
}
|
}
|
||||||
|
|
||||||
val evalResult = createScriptEvaluator().invoke(compiledScript, evaluationConfiguration).valueOr {
|
val evalResult = createScriptEvaluator().invoke(compiledScript, evaluationConfiguration).valueOr {
|
||||||
for (report in it.reports) {
|
for (report in it.reports) {
|
||||||
messageCollector.report(report.severity.toCompilerMessageSeverity(), report.render(withSeverity = false))
|
messageCollector.report(report.severity.toCompilerMessageSeverity(), report.render(withSeverity = false))
|
||||||
}
|
}
|
||||||
return@runBlocking ExitCode.INTERNAL_ERROR
|
return@internalScriptingRunSuspend ExitCode.INTERNAL_ERROR
|
||||||
}
|
}
|
||||||
|
|
||||||
when (evalResult.returnValue) {
|
when (evalResult.returnValue) {
|
||||||
|
|||||||
Reference in New Issue
Block a user