Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Do not depend on Gradle plugin #290

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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
Loading