(CoroutineDebugger) Added check if agent is not available in target jvm
This commit is contained in:
+11
-13
@@ -6,10 +6,7 @@
|
||||
package org.jetbrains.kotlin.idea.configuration
|
||||
|
||||
import com.intellij.openapi.diagnostic.Logger
|
||||
import com.intellij.openapi.util.text.StringUtil
|
||||
import com.intellij.util.Consumer
|
||||
import com.intellij.util.SystemProperties
|
||||
import org.jetbrains.kotlin.idea.debugger.coroutine.standaloneCoroutineDebuggerEnabled
|
||||
import org.jetbrains.plugins.gradle.service.project.AbstractProjectResolverExtension
|
||||
|
||||
class KotlinGradleCoroutineDebugProjectResolver : AbstractProjectResolverExtension() {
|
||||
@@ -24,16 +21,17 @@ class KotlinGradleCoroutineDebugProjectResolver : AbstractProjectResolverExtensi
|
||||
}
|
||||
|
||||
private fun setupCoroutineAgentForJvmForkedTestTasks(initScriptConsumer: Consumer<String>) {
|
||||
val lines = arrayOf(
|
||||
"gradle.taskGraph.beforeTask { Task task ->",
|
||||
" if (task instanceof Test) {",
|
||||
" def kotlinxCoroutinesDebugJar = task.classpath.find { it.name.startsWith(\"kotlinx-coroutines-debug\") }",
|
||||
" if (kotlinxCoroutinesDebugJar)",
|
||||
" task.jvmArgs (\"-javaagent:\${kotlinxCoroutinesDebugJar?.absolutePath}\", \"-ea\")",
|
||||
" }",
|
||||
"}"
|
||||
)
|
||||
val script = StringUtil.join(lines, SystemProperties.getLineSeparator())
|
||||
val script =
|
||||
//language=Gradle
|
||||
"""
|
||||
gradle.taskGraph.beforeTask { Task task ->
|
||||
if (task instanceof Test) {
|
||||
def kotlinxCoroutinesDebugJar = task.classpath.find { it.name.startsWith("kotlinx-coroutines-debug") }
|
||||
if (kotlinxCoroutinesDebugJar)
|
||||
task.jvmArgs ("-javaagent:${'$'}{kotlinxCoroutinesDebugJar?.absolutePath}", "-ea")
|
||||
}
|
||||
}
|
||||
""".trimIndent()
|
||||
initScriptConsumer.consume(script)
|
||||
}
|
||||
}
|
||||
-2
@@ -101,6 +101,4 @@ class DebuggerConnection(
|
||||
}
|
||||
}
|
||||
|
||||
fun standaloneCoroutineDebuggerEnabled() = Registry.`is`("kotlin.debugger.coroutines.standalone")
|
||||
|
||||
fun coroutineDebuggerTraceEnabled() = Registry.`is`("kotlin.debugger.coroutines.trace")
|
||||
|
||||
+8
-1
@@ -8,10 +8,17 @@ package org.jetbrains.kotlin.idea.debugger.coroutine.data
|
||||
class CoroutineInfoCache(
|
||||
val cache: MutableList<CoroutineInfoData> = mutableListOf(), var state: CacheState = CacheState.INIT
|
||||
) {
|
||||
fun ok(infoList: List<CoroutineInfoData>) {
|
||||
fun ok(infoList: List<CoroutineInfoData>): CoroutineInfoCache {
|
||||
cache.clear()
|
||||
cache.addAll(infoList)
|
||||
state = CacheState.OK
|
||||
return this
|
||||
}
|
||||
|
||||
fun ok(): CoroutineInfoCache {
|
||||
cache.clear()
|
||||
state = CacheState.OK
|
||||
return this
|
||||
}
|
||||
|
||||
fun fail(): CoroutineInfoCache {
|
||||
|
||||
+13
-4
@@ -6,6 +6,7 @@ package org.jetbrains.kotlin.idea.debugger.coroutine.proxy
|
||||
|
||||
import com.intellij.debugger.engine.DebuggerManagerThreadImpl
|
||||
import com.intellij.debugger.engine.SuspendContextImpl
|
||||
import com.intellij.openapi.util.registry.Registry
|
||||
import org.jetbrains.kotlin.idea.debugger.coroutine.command.CoroutineBuilder
|
||||
import org.jetbrains.kotlin.idea.debugger.coroutine.data.CoroutineInfoCache
|
||||
import org.jetbrains.kotlin.idea.debugger.coroutine.data.CoroutineInfoData
|
||||
@@ -25,7 +26,7 @@ class CoroutineDebugProbesProxy(val suspendContext: SuspendContextImpl) {
|
||||
val coroutineInfoCache = CoroutineInfoCache()
|
||||
try {
|
||||
val executionContext = suspendContext.executionContext() ?: return coroutineInfoCache.fail()
|
||||
val libraryAgentProxy = findProvider(executionContext)
|
||||
val libraryAgentProxy = findProvider(executionContext) ?: return coroutineInfoCache.ok()
|
||||
val infoList = libraryAgentProxy.dumpCoroutinesInfo()
|
||||
coroutineInfoCache.ok(infoList)
|
||||
} catch (e: Throwable) {
|
||||
@@ -35,8 +36,16 @@ class CoroutineDebugProbesProxy(val suspendContext: SuspendContextImpl) {
|
||||
return coroutineInfoCache
|
||||
}
|
||||
|
||||
private fun findProvider(executionContext: DefaultExecutionContext) =
|
||||
CoroutineLibraryAgent2Proxy.instance(executionContext) ?: CoroutineNoLibraryProxy(executionContext)
|
||||
private fun findProvider(executionContext: DefaultExecutionContext): CoroutineInfoProvider? {
|
||||
val agentProxy = CoroutineLibraryAgent2Proxy.instance(executionContext)
|
||||
if (agentProxy != null)
|
||||
return agentProxy
|
||||
if (standaloneCoroutineDebuggerEnabled())
|
||||
return CoroutineNoLibraryProxy(executionContext)
|
||||
return null
|
||||
}
|
||||
|
||||
fun frameBuilder() = CoroutineBuilder(suspendContext)
|
||||
}
|
||||
}
|
||||
|
||||
fun standaloneCoroutineDebuggerEnabled() = Registry.`is`("kotlin.debugger.coroutines.standalone")
|
||||
|
||||
Reference in New Issue
Block a user