Skip to content

Commit

Permalink
Merge branch 'main' into feat/compile-files
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcinVaadin authored Jan 27, 2025
2 parents 2ad8efc + de0765f commit caacce5
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 8 deletions.
1 change: 0 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ dependencies {
intellijIdeaUltimate(buildVersion)
bundledPlugin("com.intellij.java")
bundledPlugin("org.jetbrains.idea.maven")
bundledPlugin("org.jetbrains.plugins.gradle")
bundledPlugin("com.intellij.properties")
bundledPlugin("com.intellij.microservices.jvm")
bundledPlugin("JavaScript")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import com.vaadin.plugin.copilot.handler.Handler
import com.vaadin.plugin.copilot.handler.HandlerResponse
import com.vaadin.plugin.copilot.handler.RedoHandler
import com.vaadin.plugin.copilot.handler.RefreshHandler
import com.vaadin.plugin.copilot.handler.RestartApplicationHandler
import com.vaadin.plugin.copilot.handler.ShowInIdeHandler
import com.vaadin.plugin.copilot.handler.UndoHandler
import com.vaadin.plugin.copilot.handler.WriteBase64FileHandler
Expand Down Expand Up @@ -75,6 +76,7 @@ class CopilotPluginUtil {
SHOW_IN_IDE("showInIde"),
GET_MODULE_PATHS("getModulePaths"),
COMPILE_FILES("compileFiles"),
RESTART_APPLICATION("restartApplication"),
}

private val pluginVersion = PluginManagerCore.getPlugin(PluginId.getId("com.vaadin.intellij-plugin"))?.version
Expand Down Expand Up @@ -102,6 +104,7 @@ class CopilotPluginUtil {
HANDLERS.REFRESH.command -> return RefreshHandler(project)
HANDLERS.GET_MODULE_PATHS.command -> return GetModulePathsHandler(project)
HANDLERS.COMPILE_FILES.command -> return CompileFilesHandler(project, data)
HANDLERS.RESTART_APPLICATION.command -> return RestartApplicationHandler(project)
else -> {
LOG.warn("Command $command not supported by plugin")
return object : Handler {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.vaadin.plugin.copilot.handler

import com.intellij.execution.runners.ExecutionUtil
import com.intellij.execution.ui.RunContentManager
import com.intellij.openapi.application.runInEdt
import com.intellij.openapi.project.Project

class RestartApplicationHandler(project: Project) : AbstractHandler(project) {

override fun run(): HandlerResponse {
runInEdt {
val contentManager = RunContentManager.getInstance(project)
val selectedDescriptor = contentManager.selectedContent
if (selectedDescriptor != null) {
LOG.debug("Restarting ${selectedDescriptor.displayName} (${project.name})")
ExecutionUtil.restart(selectedDescriptor)
} else {
LOG.debug("Restart of ${project.name} failed - content not found")
}
}
return RESPONSE_OK
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ package com.vaadin.plugin.hotswapagent

import com.intellij.execution.JavaRunConfigurationBase
import com.intellij.execution.RunManager
import com.intellij.execution.configurations.RunConfiguration
import com.intellij.execution.executors.DefaultDebugExecutor
import com.intellij.openapi.project.Project
import com.vaadin.plugin.utils.VaadinIcons
import javax.swing.Icon
import org.jetbrains.idea.maven.execution.MavenRunConfiguration
import org.jetbrains.plugins.gradle.service.execution.GradleRunConfiguration

class HotswapAgentExecutor : DefaultDebugExecutor() {

Expand Down Expand Up @@ -58,6 +57,14 @@ class HotswapAgentExecutor : DefaultDebugExecutor() {
override fun isApplicable(project: Project): Boolean {
val selectedConfiguration = RunManager.getInstance(project).selectedConfiguration?.configuration
return selectedConfiguration is JavaRunConfigurationBase &&
(selectedConfiguration !is MavenRunConfiguration || selectedConfiguration !is GradleRunConfiguration)
(!isMaven(selectedConfiguration) || !isGradle(selectedConfiguration))
}

private fun isMaven(configuration: RunConfiguration): Boolean {
return configuration.javaClass.name.contains("MavenRunConfiguration")
}

private fun isGradle(configuration: RunConfiguration): Boolean {
return configuration.javaClass.name.contains("GradleRunConfiguration")
}
}
20 changes: 18 additions & 2 deletions src/main/kotlin/com/vaadin/plugin/hotswapagent/JdkUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,26 @@ package com.vaadin.plugin.hotswapagent

import com.intellij.externalSystem.JavaModuleData
import com.intellij.openapi.application.PathManager
import com.intellij.openapi.externalSystem.model.DataNode
import com.intellij.openapi.externalSystem.model.Key
import com.intellij.openapi.externalSystem.model.ProjectSystemId
import com.intellij.openapi.externalSystem.model.project.ModuleData
import com.intellij.openapi.externalSystem.util.ExternalSystemApiUtil
import com.intellij.openapi.module.Module
import com.intellij.openapi.project.Project
import com.intellij.openapi.projectRoots.JavaSdk
import com.intellij.openapi.projectRoots.Sdk
import com.intellij.openapi.roots.ProjectRootManager
import java.io.File
import org.jetbrains.idea.maven.project.MavenProjectsManager
import org.jetbrains.jps.model.java.JdkVersionDetector
import org.jetbrains.plugins.gradle.util.GradleUtil

class JdkUtil {

companion object {

val GRADLE_SYSTEM_ID: ProjectSystemId = ProjectSystemId("GRADLE")

fun isJetbrainsRuntime(jdk: Sdk?): Boolean {
val homePath = jdk?.homePath ?: throw IllegalStateException("JDK has no home path: $jdk")
val jdkInfo = JdkVersionDetector.getInstance().detectJdkVersionInfo(homePath)
Expand Down Expand Up @@ -78,7 +84,7 @@ class JdkUtil {
}

private fun getGradleJavaVersion(module: Module): Int? {
val gradleModuleData = GradleUtil.findGradleModuleData(module) ?: return null
val gradleModuleData = findGradleModuleData(module) ?: return null
val javaModuleData =
ExternalSystemApiUtil.find(gradleModuleData, Key.create<JavaModuleData>(JavaModuleData::class.java, 1))
?.data ?: return null
Expand All @@ -95,6 +101,16 @@ class JdkUtil {
val projectSdk = ProjectRootManager.getInstance(module.project)?.projectSdk ?: return null
return getSdkMajorVersion(projectSdk)
}

private fun findGradleModuleData(module: Module): DataNode<ModuleData>? {
val projectPath = ExternalSystemApiUtil.getExternalProjectPath(module)
if (projectPath == null) {
return null
} else {
val project: Project = module.project
return ExternalSystemApiUtil.findModuleNode(project, GRADLE_SYSTEM_ID, projectPath)
}
}
}
}

Expand Down
2 changes: 0 additions & 2 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@
<depends>com.intellij.modules.platform</depends>
<depends>com.intellij.modules.java</depends>
<depends>org.jetbrains.idea.maven</depends>
<depends>org.jetbrains.plugins.gradle</depends>


<!-- Vaadin Endpoints IntelliJ Ultimate dependencies -->
<depends>com.intellij.properties</depends>
Expand Down

0 comments on commit caacce5

Please sign in to comment.