-
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 <azerr@redhat.com>
- Loading branch information
1 parent
e246f7f
commit cd5bc58
Showing
6 changed files
with
168 additions
and
43 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
src/main/java/com/redhat/devtools/intellij/quarkus/run/AttachDebuggerExecutionListener.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,38 @@ | ||
package com.redhat.devtools.intellij.quarkus.run; | ||
|
||
import com.intellij.execution.ExecutionListener; | ||
import com.intellij.execution.RunnerAndConfigurationSettings; | ||
import com.intellij.execution.executors.DefaultDebugExecutor; | ||
import com.intellij.execution.process.ProcessEvent; | ||
import com.intellij.execution.process.ProcessHandler; | ||
import com.intellij.execution.process.ProcessListener; | ||
import com.intellij.execution.runners.ExecutionEnvironment; | ||
import com.intellij.openapi.progress.ProgressIndicator; | ||
import com.intellij.openapi.progress.ProgressManager; | ||
import com.intellij.openapi.progress.Task; | ||
import com.intellij.openapi.project.Project; | ||
import com.intellij.openapi.util.Key; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import static com.redhat.devtools.intellij.quarkus.run.QuarkusRunConfiguration.QUARKUS_CONFIGURATION; | ||
|
||
class AttachDebuggerExecutionListener implements ExecutionListener { | ||
|
||
private final @NotNull Project project; | ||
|
||
AttachDebuggerExecutionListener(@NotNull Project project) { | ||
this.project = project; | ||
} | ||
|
||
public void processStarting(@NotNull String executorId, | ||
@NotNull ExecutionEnvironment env, | ||
@NotNull ProcessHandler handler) { | ||
if (!DefaultDebugExecutor.EXECUTOR_ID.equals(executorId)) { | ||
return; | ||
} | ||
RunnerAndConfigurationSettings settings = env.getRunnerAndConfigurationSettings(); | ||
if (settings != null && settings.getConfiguration() instanceof QuarkusRunConfiguration) { | ||
handler.addProcessListener(new AttachDebuggerProcessListener(project, env)); | ||
} | ||
} | ||
} |
91 changes: 91 additions & 0 deletions
91
src/main/java/com/redhat/devtools/intellij/quarkus/run/AttachDebuggerProcessListener.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,91 @@ | ||
package com.redhat.devtools.intellij.quarkus.run; | ||
|
||
import com.intellij.execution.DefaultExecutionTarget; | ||
import com.intellij.execution.RunManager; | ||
import com.intellij.execution.RunnerAndConfigurationSettings; | ||
import com.intellij.execution.executors.DefaultDebugExecutor; | ||
import com.intellij.execution.process.ProcessEvent; | ||
import com.intellij.execution.process.ProcessListener; | ||
import com.intellij.execution.remote.RemoteConfiguration; | ||
import com.intellij.execution.remote.RemoteConfigurationType; | ||
import com.intellij.execution.runners.ExecutionEnvironment; | ||
import com.intellij.execution.runners.ExecutionUtil; | ||
import com.intellij.openapi.application.ApplicationManager; | ||
import com.intellij.openapi.progress.ProgressIndicator; | ||
import com.intellij.openapi.progress.ProgressManager; | ||
import com.intellij.openapi.progress.Task; | ||
import com.intellij.openapi.project.Project; | ||
import com.intellij.openapi.ui.Messages; | ||
import com.intellij.openapi.util.Key; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.io.IOException; | ||
import java.net.ConnectException; | ||
import java.net.Socket; | ||
import java.nio.charset.StandardCharsets; | ||
|
||
import static com.redhat.devtools.intellij.quarkus.run.QuarkusRunConfiguration.QUARKUS_CONFIGURATION; | ||
|
||
class AttachDebuggerProcessListener implements ProcessListener { | ||
|
||
private static final String JWDP_HANDSHAKE = "JDWP-Handshake"; | ||
|
||
private final Project project; | ||
private final ExecutionEnvironment env; | ||
private boolean connected; | ||
|
||
AttachDebuggerProcessListener(@NotNull Project project, | ||
@NotNull ExecutionEnvironment env) { | ||
this.project = project; | ||
this.env = env; | ||
} | ||
|
||
@Override | ||
public void onTextAvailable(@NotNull ProcessEvent event, @NotNull Key outputType) { | ||
String message = event.getText(); | ||
if (!connected && message.startsWith("Listening for transport dt_socket at address: ")) { | ||
connected = true; | ||
String s = message.substring("Listening for transport dt_socket at address: ".length(), message.length()).trim(); | ||
int port = Integer.valueOf(s); | ||
ProgressManager.getInstance().run(new Task.Backgroundable(project, QUARKUS_CONFIGURATION, false) { | ||
@Override | ||
public void run(@NotNull ProgressIndicator indicator) { | ||
String name = env.getRunProfile().getName(); | ||
createRemoteConfiguration(indicator, port,name); | ||
} | ||
}); | ||
} | ||
} | ||
|
||
private void createRemoteConfiguration(ProgressIndicator indicator, int port, String name) { | ||
indicator.setText("Connecting Java debugger to port " + port); | ||
try { | ||
waitForPortAvailable(port, indicator); | ||
RunnerAndConfigurationSettings settings = RunManager.getInstance(project).createConfiguration(name + " (Remote)", RemoteConfigurationType.class); | ||
RemoteConfiguration remoteConfiguration = (RemoteConfiguration) settings.getConfiguration(); | ||
remoteConfiguration.PORT = Integer.toString(port); | ||
long groupId = ExecutionEnvironment.getNextUnusedExecutionId(); | ||
ExecutionUtil.runConfiguration(settings, DefaultDebugExecutor.getDebugExecutorInstance(), DefaultExecutionTarget.INSTANCE, groupId); | ||
} catch (IOException e) { | ||
ApplicationManager.getApplication() | ||
.invokeLater(() -> Messages.showErrorDialog("Can' t connector to port " + port, "Quarkus")); | ||
} | ||
} | ||
|
||
private void waitForPortAvailable(int port, ProgressIndicator monitor) throws IOException { | ||
long start = System.currentTimeMillis(); | ||
while (System.currentTimeMillis() - start < 120_000 && !monitor.isCanceled()) { | ||
try (Socket socket = new Socket("localhost", port)) { | ||
socket.getOutputStream().write(JWDP_HANDSHAKE.getBytes(StandardCharsets.US_ASCII)); | ||
return; | ||
} catch (ConnectException e) { | ||
try { | ||
Thread.sleep(1000L); | ||
} catch (InterruptedException e1) { | ||
throw new IOException(e1); | ||
} | ||
} | ||
} | ||
throw new IOException("Can't connect remote debuger to port " + port); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...n/java/com/redhat/devtools/intellij/quarkus/run/QuarkusExternalSystemTaskDebugRunner.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,28 @@ | ||
package com.redhat.devtools.intellij.quarkus.run; | ||
|
||
import com.intellij.execution.configurations.RunProfile; | ||
import com.intellij.execution.executors.DefaultDebugExecutor; | ||
import com.intellij.openapi.externalSystem.service.execution.ExternalSystemRunConfiguration; | ||
import com.intellij.openapi.externalSystem.service.execution.ExternalSystemTaskDebugRunner; | ||
import com.redhat.devtools.intellij.quarkus.buildtool.BuildToolDelegate; | ||
import com.redhat.devtools.intellij.quarkus.buildtool.maven.MavenToolDelegate; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class QuarkusExternalSystemTaskDebugRunner extends ExternalSystemTaskDebugRunner { | ||
|
||
private static final Logger log = LoggerFactory.getLogger(QuarkusExternalSystemTaskDebugRunner.class); | ||
|
||
@Override | ||
public boolean canRun(@NotNull String executorId, @NotNull RunProfile profile) { | ||
if (!DefaultDebugExecutor.EXECUTOR_ID.equals(executorId)) { | ||
return false; | ||
} | ||
if (profile instanceof QuarkusRunConfiguration quarkusRunConfiguration) { | ||
BuildToolDelegate delegate = BuildToolDelegate.getDelegate(quarkusRunConfiguration.getModule()); | ||
return !(delegate instanceof MavenToolDelegate); | ||
} | ||
return false; | ||
} | ||
} |
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
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