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

fix: Turn off frame deactivation policy for Spring apps #87

Merged
merged 1 commit into from
Sep 19, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@ import com.intellij.execution.JavaRunConfigurationBase
import com.intellij.execution.configurations.JavaParameters
import com.intellij.execution.configurations.RunProfile
import com.intellij.execution.runners.JavaProgramPatcher
import com.intellij.openapi.diagnostic.Logger
import com.vaadin.plugin.utils.VaadinHomeUtil


class HotswapAgentProgramPatcher : JavaProgramPatcher() {

private val LOG: Logger = Logger.getInstance(HotswapAgentProgramPatcher::class.java)

override fun patchJavaParameters(executor: Executor?, runProfile: RunProfile?, javaParameters: JavaParameters?) {
if (executor !is HotswapAgentExecutor) {
return
Expand All @@ -21,6 +25,9 @@ class HotswapAgentProgramPatcher : JavaProgramPatcher() {
}
val module = runProfile.configurationModule?.module ?: return

if (runProfile.javaClass.simpleName == "SpringBootApplicationRunConfiguration") {
turnOffFrameDeactivationPolicy(runProfile);
}
if (!JdkUtil.isJetbrainsRuntime(javaParameters.jdk)) {
// Use the bundled Jetbrains Runtime
javaParameters.jdk = JdkUtil.getCompatibleJetbrainsJdk(module)
Expand Down Expand Up @@ -50,5 +57,20 @@ class HotswapAgentProgramPatcher : JavaProgramPatcher() {
paramsList.add("-javaagent:$agentInHome")
}

private fun turnOffFrameDeactivationPolicy(runProfile: JavaRunConfigurationBase) {
try {
val getOptions = runProfile.javaClass.getDeclaredMethod("getOptions")
getOptions.trySetAccessible();
var options = getOptions.invoke(runProfile);
var policy = options.javaClass.getDeclaredField("frameDeactivationUpdatePolicy\$delegate")
policy.trySetAccessible();

val prop = policy.get(options);

prop.javaClass.getMethod("parseAndSetValue", String::class.java).invoke(prop, null);
} catch (e: Exception) {
LOG.debug("Failed to turn off frame deactivation policy", e)
}
}
}