Skip to content

Commit 188e156

Browse files
committed
Enhance Gradle task detection and console view functionality
Updated Gradle task applicability checks, improved Kotest task name recognition in `GradleUtils`, and added hyperlink support in `KotestSMTRunnerConsoleView`.
1 parent ccf3521 commit 188e156

File tree

4 files changed

+25
-10
lines changed

4 files changed

+25
-10
lines changed

src/main/kotlin/io/kotest/plugin/intellij/console/KotestExecutionConsoleManager.kt

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import com.intellij.openapi.externalSystem.service.internal.ExternalSystemExecut
1515
import com.intellij.openapi.project.Project
1616
import com.intellij.openapi.util.Key
1717
import io.kotest.plugin.intellij.Constants
18+
import io.kotest.plugin.intellij.gradle.GradleUtils
1819
import jetbrains.buildServer.messages.serviceMessages.ServiceMessagesParser
1920
import org.jetbrains.plugins.gradle.util.GradleConstants
2021

@@ -89,19 +90,17 @@ class KotestExecutionConsoleManager : ExternalSystemExecutionConsoleManager<SMTR
8990

9091
/**
9192
* Returns true if this implementation of [ExternalSystemExecutionConsoleManager] should be used to
92-
* handle the output of the given [task]. We determine true if the task is a Gradle task
93-
* that contains a Kotest task name.
93+
* handle the output of the given [task]. We determine true if we are running tests and have the
94+
* kotest gradle plugin applied to the project
9495
*
9596
* This method is invoked for all extensions for each task that is executed by an external system.
9697
* It is up to this extension to determine if it is applicable for the given task.
9798
*/
9899
override fun isApplicableFor(task: ExternalSystemTask): Boolean {
99100
if (task is ExternalSystemExecuteTaskTask) {
100101
if (task.externalSystemId.id == GradleConstants.SYSTEM_ID.id) {
101-
println("Checking is applicable, tasks to execute: ${task.tasksToExecute}")
102-
return task.tasksToExecute.any {
103-
it.lowercase().endsWith("kotest")
104-
}
102+
println("Checking is applicable, tasks to execute: ${task.tasksToExecute} state=${task.state} data=${task.userDataString} externalPath=${task.externalProjectPath}")
103+
return GradleUtils.hasKotestTask(task.tasksToExecute)
105104
}
106105
}
107106
return false

src/main/kotlin/io/kotest/plugin/intellij/console/KotestSMTRunnerConsoleView.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package io.kotest.plugin.intellij.console
22

33
import com.intellij.build.BuildViewSettingsProvider
44
import com.intellij.execution.Platform
5+
import com.intellij.execution.filters.HyperlinkInfo
56
import com.intellij.execution.testframework.sm.runner.SMTRunnerEventsListener
67
import com.intellij.execution.testframework.sm.runner.ui.SMTRunnerConsoleView
78
import com.intellij.execution.ui.ConsoleViewContentType
@@ -24,6 +25,11 @@ class KotestSMTRunnerConsoleView(
2425

2526
override fun isExecutionViewHidden() = false
2627

28+
override fun printHyperlink(hyperlinkText: String, info: HyperlinkInfo?) {
29+
println("Hyperlink: $hyperlinkText")
30+
super.printHyperlink(hyperlinkText, info)
31+
}
32+
2733
override fun print(s: String, contentType: ConsoleViewContentType) {
2834
if (detectUnwantedEmptyLine(s)) return
2935
super.print(s, contentType)

src/main/kotlin/io/kotest/plugin/intellij/gradle/GradleUtils.kt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ object GradleUtils {
1616
*/
1717
fun hasGradlePlugin(module: Module?): Boolean {
1818
if (module == null) return false
19+
// GradleSettings.getInstance(module.project).linkedProjectsSettings.forEach { settings ->
20+
// val gm = ExternalSystemApiUtil.getManager() as GradleManager
21+
// gm.
22+
// }
1923
// if we have any kotest gradle task in the project, we assume the plugin is applied
2024
return kotestTasks(module).isNotEmpty()
2125
}
@@ -51,9 +55,11 @@ object GradleUtils {
5155

5256
fun isKotestTaskName(taskName: String): Boolean {
5357
return taskName == "kotest" // jvm only task name
54-
|| taskName.endsWith("Kotest") // thinks like linuxX84Kotest or jsKotest
55-
|| taskName.endsWith("kotestDebugUnitTest") // android
56-
|| taskName.endsWith("kotestReleaseUnitTest") // android
58+
|| taskName == "jvmKotest" // multiplatform jvm task name
59+
|| taskName == "jsKotest" // multiplatform js task name
60+
|| taskName == "wasmJsKotest" // multiplatform wasm js task name
61+
|| taskName == "wasmWasiKotest" // multiplatform wasm wasi task name
62+
|| taskName.matches("kotest[a-z]+UnitTest".toRegex()) // matches kotestReleaseUnitTest, kotestDebugUnitTest, etc.
5763
}
5864

5965
fun getIncludeArg(taskNames: List<String>): String? {

src/main/kotlin/io/kotest/plugin/intellij/run/GradleKotestTaskRunConfigurationProducer.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import org.jetbrains.kotlin.psi.KtClassOrObject
1616
import org.jetbrains.plugins.gradle.execution.GradleRunConfigurationProducer
1717
import org.jetbrains.plugins.gradle.service.execution.GradleRunConfiguration
1818

19+
private val KOTEST_RUN = Key.create<Boolean>("KOTEST_RUN")
20+
1921
/**
2022
* Runs a Kotest individual test or spec using the Kotest Gradle plugin.
2123
*
@@ -93,7 +95,9 @@ class GradleKotestTaskRunConfigurationProducer : GradleRunConfigurationProducer(
9395
// if we set this to true then intellij will send output to its own gradle test console,
9496
// but we want to display our own KotestSMTRunnerConsoleView.
9597
configuration.isRunAsTest = false
96-
configuration.putUserData<Boolean>(Key.create<Boolean>("kotest"), true)
98+
configuration.isShowConsoleOnStdErr = false
99+
configuration.isShowConsoleOnStdOut = false
100+
configuration.putUserData<Boolean>(KOTEST_RUN, true)
97101

98102
val runManager = RunManager.getInstance(project)
99103
runManager.setUniqueNameIfNeeded(configuration)

0 commit comments

Comments
 (0)