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 use broken JBR in IntelliJ 2024.2.3 #123

Merged
merged 3 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.vaadin.plugin.hotswapagent

import com.intellij.openapi.ui.DialogWrapper
import javax.swing.Action
import javax.swing.JComponent
import javax.swing.JPanel
import javax.swing.JTextArea

class BadJBRFoundDialog() : DialogWrapper(true) {

private val message: String

override fun createActions(): Array<Action> {
return arrayOf(myOKAction)
}

init {
message = buildString {
append(
"HotswapAgent requires running with a JetBrains Runtime JDK which implements the low level hotswap functionality.\n\n")
append("Your IntelliJ IDEA installation includes a bundled JetBrains Runtime JDK which is known not work for this purpose.\n\n")
append("You can resolve this by one of the following:\n")
append("- Downgrade IntelliJ IDEA to version 2024.2.2 or earlier which bundle a working version\n");
append("- Once released, upgrade IntelliJ IDEA to a version newer than 2024.2.3\n");
append(
"- Download a newer JetBrains runtime from https://github.com/JetBrains/JetBrainsRuntime/releases and set your run configuration to use it.")
append("\n")
}
title = "Unable to Find a Suitable JDK"
init()
}

override fun createCenterPanel(): JComponent {
return JPanel().apply { add(JTextArea(message)) }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,13 @@ class HotswapAgentProgramPatcher : JavaProgramPatcher() {
}
if (!JdkUtil.isJetbrainsRuntime(javaParameters.jdk)) {
// Use the bundled Jetbrains Runtime
javaParameters.jdk =
JdkUtil.getCompatibleJetbrainsJdk(module)
?: throw IllegalArgumentException("The bundled JBR is not compatible with the project JDK")
try {
javaParameters.jdk =
JdkUtil.getCompatibleJetbrainsJdk(module)
?: throw IllegalArgumentException("The bundled JBR is not compatible with the project JDK")
} catch (e:BrokenJbrException) {
throw IllegalArgumentException("The bundled JBR is known to be broken")
}
}
val agentInHome = VaadinHomeUtil.getHotSwapAgentJar()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,25 @@ class HotswapAgentRunner : GenericDebuggerRunner() {
val module = runProfile.configurationModule?.module ?: throw IllegalStateException("$runnerId needs a module")

val javaParameters = javaCommandLine.javaParameters
val jdkOk = JdkUtil.isJetbrainsRuntime(javaParameters.jdk) || JdkUtil.getCompatibleJetbrainsJdk(module) != null
if (jdkOk) {
super.execute(environment)
} else {
val bundledJetbrainsJdk = JdkUtil.getSdkMajorVersion(JdkUtil.getBundledJetbrainsJdk())
val projectSdkMajor = JdkUtil.getProjectSdkVersion(module)
try {
val jdkOk =
JdkUtil.isJetbrainsRuntime(javaParameters.jdk) || JdkUtil.getCompatibleJetbrainsJdk(module) != null

if (jdkOk) {
super.execute(environment)
} else {
val bundledJetbrainsJdk = JdkUtil.getSdkMajorVersion(JdkUtil.getBundledJetbrainsJdk())
val projectSdkMajor = JdkUtil.getProjectSdkVersion(module)

ApplicationManager.getApplication().invokeLater {
NoJBRFoundDialog(bundledJetbrainsJdk, projectSdkMajor).show()
}
}
} catch (e:BrokenJbrException) {
ApplicationManager.getApplication().invokeLater {
NoJBRFoundDialog(bundledJetbrainsJdk, projectSdkMajor).show()
BadJBRFoundDialog().show()
}
}

}
}
22 changes: 21 additions & 1 deletion src/main/kotlin/com/vaadin/plugin/hotswapagent/JdkUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import com.intellij.openapi.roots.ProjectRootManager
import org.jetbrains.idea.maven.project.MavenProjectsManager
import org.jetbrains.jps.model.java.JdkVersionDetector
import org.jetbrains.plugins.gradle.util.GradleUtil
import java.io.File

class JdkUtil {

Expand All @@ -33,13 +34,28 @@ class JdkUtil {
JavaSdk.getInstance().getVersion(jbrSdk)
?: throw IllegalArgumentException("Unable to detect bundled sdk version")

if (isBrokenJbr(jbrSdk)) {
throw BrokenJbrException();
}

if (projectJavaVersion == null ||
bundledSdkVersion.maxLanguageLevel.toJavaVersion().isAtLeast(projectJavaVersion)) {
bundledSdkVersion.maxLanguageLevel.toJavaVersion().isAtLeast(projectJavaVersion)
) {
return jbrSdk
}
return null
}

private fun isBrokenJbr(sdk: Sdk): Boolean {
val release = File(sdk.homePath, "release");
val version = sdk.versionString;
if (version != null && version.contains("21.0.4") && release.exists()) {
return release.readText().contains("JAVA_RUNTIME_VERSION=\"21.0.4+13-b509.17\"");
}

return false;
}

private fun getProjectJavaVersion(module: Module): Int? {
// If a target version is specified in Maven or Gradle, that defines the version needed
// to run the app.
Expand Down Expand Up @@ -76,3 +92,7 @@ class JdkUtil {
}
}
}

class BrokenJbrException : Exception() {

}
Loading