-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Debug run config invalid with Gradle
Fixes #1311 Signed-off-by: azerr <[email protected]>
- Loading branch information
1 parent
e246f7f
commit 9fb002d
Showing
12 changed files
with
561 additions
and
143 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
112 changes: 112 additions & 0 deletions
112
...com/redhat/devtools/intellij/quarkus/buildtool/gradle/GradleRunAndDebugProgramRunner.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. | ||
package com.redhat.devtools.intellij.quarkus.buildtool.gradle; | ||
|
||
import com.intellij.build.BuildView; | ||
import com.intellij.execution.ExecutionException; | ||
import com.intellij.execution.ExecutionManager; | ||
import com.intellij.execution.ExecutionResult; | ||
import com.intellij.execution.configurations.RunProfile; | ||
import com.intellij.execution.configurations.RunProfileState; | ||
import com.intellij.execution.configurations.RunnerSettings; | ||
import com.intellij.execution.runners.ExecutionEnvironment; | ||
import com.intellij.execution.runners.ProgramRunner; | ||
import com.intellij.execution.runners.RunContentBuilder; | ||
import com.intellij.execution.testframework.HistoryTestRunnableState; | ||
import com.intellij.execution.ui.RunContentDescriptor; | ||
import com.intellij.openapi.externalSystem.service.execution.ExternalSystemRunnableState; | ||
import com.redhat.devtools.intellij.quarkus.buildtool.BuildToolDelegate; | ||
import com.redhat.devtools.intellij.quarkus.buildtool.maven.MavenToolDelegate; | ||
import com.redhat.devtools.intellij.quarkus.run.QuarkusRunConfiguration; | ||
import org.jetbrains.concurrency.Promises; | ||
|
||
/** | ||
* Program runner to run/debug a Gradle configuration. | ||
* <p> | ||
* This class is a copy/paste from the Intellij | ||
* <a href="https://github.com/JetBrains/intellij-community/blob/master/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/execution/ExternalSystemTaskRunner.kt">ExternalSystemTaskRunner</a> | ||
* since this class cannot be extended. | ||
*/ | ||
public class GradleRunAndDebugProgramRunner implements ProgramRunner<RunnerSettings> { | ||
|
||
private static final String RUNNER_ID = "GradleRunAndDebugProgramRunner"; | ||
|
||
@Override | ||
public String getRunnerId() { | ||
return RUNNER_ID; | ||
} | ||
|
||
@Override | ||
public boolean canRun(String executorId, RunProfile profile) { | ||
// For running / debugging Gradle 'quarkusDev', the program runner must be executed | ||
// with the standard IJ 'ExternalSystemTaskRunner' which works only if | ||
// the profile is an 'ExternalSystemRunConfiguration'. As QuarkusRunConfiguration | ||
// wraps the profile, this condition is not matched. | ||
// GradleRunAndDebugProgramRunner should extend ExternalSystemTaskRunner but as this class | ||
// is final, GradleRunAndDebugProgramRunner is a copy/paste of ExternalSystemTaskRunner | ||
// and the profile check is done by checking if QuarkusRunConfiguration wraps a Gradle run/debug configuration. | ||
if (profile instanceof QuarkusRunConfiguration quarkusRunConfiguration) { | ||
// returns true if the profile is a QuarkusRunConfiguration which wraps a Gradle configuration | ||
BuildToolDelegate delegate = BuildToolDelegate.getDelegate(quarkusRunConfiguration.getModule()); | ||
return !(delegate instanceof MavenToolDelegate); | ||
} | ||
return false; | ||
} | ||
|
||
@Override | ||
public void execute(ExecutionEnvironment environment) throws ExecutionException { | ||
RunProfileState state = environment.getState(); | ||
if (state == null) { | ||
return; | ||
} | ||
ExecutionManager.getInstance(environment.getProject()).startRunProfile(environment, () -> { | ||
try { | ||
return Promises.resolvedPromise(doExecute(state, environment)); | ||
} catch (ExecutionException e) { | ||
throw new RuntimeException(e); | ||
} | ||
}); | ||
} | ||
|
||
private RunContentDescriptor doExecute(RunProfileState state, ExecutionEnvironment environment) throws ExecutionException { | ||
if (!(state instanceof ExternalSystemRunnableState) && !(state instanceof HistoryTestRunnableState)) { | ||
return null; | ||
} | ||
|
||
RunContentDescriptor runContentDescriptor; | ||
ExecutionResult executionResult = state.execute(environment.getExecutor(), this); | ||
if (executionResult == null) { | ||
return null; | ||
} | ||
runContentDescriptor = new RunContentBuilder(executionResult, environment).showRunContent(environment.getContentToReuse()); | ||
if (runContentDescriptor == null) { | ||
return null; | ||
} | ||
|
||
if (state instanceof HistoryTestRunnableState) { | ||
return runContentDescriptor; | ||
} | ||
|
||
((ExternalSystemRunnableState) state).setContentDescriptor(runContentDescriptor); | ||
|
||
if (executionResult.getExecutionConsole() instanceof BuildView) { | ||
return runContentDescriptor; | ||
} | ||
|
||
RunContentDescriptor descriptor = new RunContentDescriptor( | ||
runContentDescriptor.getExecutionConsole(), | ||
runContentDescriptor.getProcessHandler(), | ||
runContentDescriptor.getComponent(), | ||
runContentDescriptor.getDisplayName(), | ||
runContentDescriptor.getIcon(), | ||
null, | ||
runContentDescriptor.getRestartActions() | ||
) { | ||
@Override | ||
public boolean isHiddenContent() { | ||
return true; | ||
} | ||
}; | ||
descriptor.setRunnerLayoutUi(runContentDescriptor.getRunnerLayoutUi()); | ||
return descriptor; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
.../com/redhat/devtools/intellij/quarkus/buildtool/maven/QuarkusMavenDebugProgramRunner.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 Red Hat Inc. and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 | ||
* which is available at https://www.apache.org/licenses/LICENSE-2.0. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 | ||
* | ||
* Contributors: | ||
* Red Hat Inc. - initial API and implementation | ||
*******************************************************************************/ | ||
package com.redhat.devtools.intellij.quarkus.buildtool.maven; | ||
|
||
import com.intellij.debugger.impl.GenericDebuggerRunner; | ||
import com.intellij.execution.configurations.RunProfile; | ||
import com.intellij.execution.executors.DefaultDebugExecutor; | ||
import com.redhat.devtools.intellij.quarkus.buildtool.BuildToolDelegate; | ||
import com.redhat.devtools.intellij.quarkus.run.QuarkusRunConfiguration; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
/** | ||
* Program runner to debug a Maven configuration. | ||
*/ | ||
public class QuarkusMavenDebugProgramRunner extends GenericDebuggerRunner { | ||
|
||
private static final String RUNNER_ID = "QuarkusMavenDebugProgramRunner"; | ||
|
||
@Override | ||
public String getRunnerId() { | ||
return RUNNER_ID; | ||
} | ||
|
||
@Override | ||
public boolean canRun(@NotNull final String executorId, @NotNull final RunProfile profile) { | ||
if (!executorId.equals(DefaultDebugExecutor.EXECUTOR_ID)) { | ||
return false; | ||
} | ||
// Debuging... | ||
if (profile instanceof QuarkusRunConfiguration quarkusRunConfiguration) { | ||
// returns true if the profile is a QuarkusRunConfiguration which wraps a Maven configuration | ||
BuildToolDelegate delegate = BuildToolDelegate.getDelegate(quarkusRunConfiguration.getModule()); | ||
return (delegate instanceof MavenToolDelegate); | ||
} | ||
return false; | ||
} | ||
} |
Oops, something went wrong.