From 7c058621bc95872e0efdf3b8c3364eac3ca20b8c Mon Sep 17 00:00:00 2001 From: marcin Date: Mon, 2 Dec 2024 16:22:21 +0100 Subject: [PATCH] Show notification if run configuration is not supported --- .../plugin/copilot/CopilotPluginUtil.kt | 4 ++-- .../plugin/hotswapagent/HotswapAgentRunner.kt | 19 ++++++++++++++++--- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/main/kotlin/com/vaadin/plugin/copilot/CopilotPluginUtil.kt b/src/main/kotlin/com/vaadin/plugin/copilot/CopilotPluginUtil.kt index 538afcf..0393026 100644 --- a/src/main/kotlin/com/vaadin/plugin/copilot/CopilotPluginUtil.kt +++ b/src/main/kotlin/com/vaadin/plugin/copilot/CopilotPluginUtil.kt @@ -52,8 +52,6 @@ class CopilotPluginUtil { private const val NORMALIZED_LINE_SEPARATOR = "\n" - private const val NOTIFICATION_GROUP = "Vaadin Copilot" - private enum class HANDLERS(val command: String) { WRITE("write"), WRITE_BASE64("writeBase64"), @@ -66,6 +64,8 @@ class CopilotPluginUtil { private val pluginVersion = PluginManagerCore.getPlugin(PluginId.getId("com.vaadin.intellij-plugin"))?.version + const val NOTIFICATION_GROUP = "Vaadin Copilot" + fun getPluginVersion(): String? { return pluginVersion } diff --git a/src/main/kotlin/com/vaadin/plugin/hotswapagent/HotswapAgentRunner.kt b/src/main/kotlin/com/vaadin/plugin/hotswapagent/HotswapAgentRunner.kt index 52bde65..f59cb5c 100644 --- a/src/main/kotlin/com/vaadin/plugin/hotswapagent/HotswapAgentRunner.kt +++ b/src/main/kotlin/com/vaadin/plugin/hotswapagent/HotswapAgentRunner.kt @@ -5,7 +5,10 @@ import com.intellij.execution.JavaRunConfigurationBase import com.intellij.execution.configurations.JavaCommandLine import com.intellij.execution.configurations.RunProfile import com.intellij.execution.runners.ExecutionEnvironment +import com.intellij.notification.Notification +import com.intellij.notification.NotificationType import com.intellij.openapi.application.ApplicationManager +import com.vaadin.plugin.copilot.CopilotPluginUtil.Companion.NOTIFICATION_GROUP class HotswapAgentRunner : GenericDebuggerRunner() { @@ -18,9 +21,19 @@ class HotswapAgentRunner : GenericDebuggerRunner() { } override fun execute(environment: ExecutionEnvironment) { - val runProfile = - environment.runProfile as? JavaRunConfigurationBase - ?: throw IllegalStateException("$runnerId can only run Java configurations") + + if (environment.runProfile !is JavaRunConfigurationBase) { + Notification( + NOTIFICATION_GROUP, + "To launch, open the Spring Boot application class and press \"Debug using Hotswap Agent\". " + + "Do not launch through Maven or Gradle.", + NotificationType.WARNING) + .setTitle("Only Spring Boot applications are supported") + .notify(environment.project) + return + } + + val runProfile = environment.runProfile as JavaRunConfigurationBase val javaCommandLine = environment.state as? JavaCommandLine ?: throw IllegalStateException("$runnerId needs a JavaCommandLine") val module = runProfile.configurationModule?.module ?: throw IllegalStateException("$runnerId needs a module")