Skip to content

Commit 8349654

Browse files
committed
fix: Debugging Quarkus application is broken in 2025.3 EAP
Signed-off-by: azerr <azerr@redhat.com>
1 parent 92abab6 commit 8349654

File tree

4 files changed

+47
-58
lines changed

4 files changed

+47
-58
lines changed

src/main/java/com/redhat/devtools/intellij/quarkus/buildtool/maven/QuarkusMavenDebugProgramRunner.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public boolean canRun(@NotNull final String executorId, @NotNull final RunProfil
3737
if (!executorId.equals(DefaultDebugExecutor.EXECUTOR_ID)) {
3838
return false;
3939
}
40-
// Debuging...
40+
// Debugging...
4141
if (profile instanceof QuarkusRunConfiguration quarkusRunConfiguration) {
4242
// returns true if the profile is a QuarkusRunConfiguration which wraps a Maven configuration
4343
BuildToolDelegate delegate = BuildToolDelegate.getDelegate(quarkusRunConfiguration.getModule());

src/main/java/com/redhat/devtools/intellij/quarkus/run/AttachDebuggerExecutionListener.java

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@
1616
import com.intellij.execution.ExecutionListener;
1717
import com.intellij.execution.RunnerAndConfigurationSettings;
1818
import com.intellij.execution.executors.DefaultDebugExecutor;
19+
import com.intellij.execution.process.BaseOSProcessHandler;
1920
import com.intellij.execution.process.ProcessHandler;
2021
import com.intellij.execution.runners.ExecutionEnvironment;
2122
import com.intellij.openapi.project.Project;
2223
import org.jetbrains.annotations.NotNull;
24+
import org.jetbrains.annotations.Nullable;
2325

2426
/**
2527
* Execution listener singleton which tracks any process starting to add in debug mode
@@ -42,13 +44,40 @@ public void processStarting(@NotNull String executorId,
4244
}
4345
// Debug mode...
4446
RunnerAndConfigurationSettings settings = env.getRunnerAndConfigurationSettings();
45-
if (settings != null && settings.getConfiguration() instanceof QuarkusRunConfiguration) {
47+
if (settings.getConfiguration() instanceof QuarkusRunConfiguration) {
4648
// The execution has been done by debugging a Quarkus run configuration (Gradle / Maven)
4749
// add a AttachDebuggerProcessListener to track
4850
// 'Listening for transport dt_socket at address: $PORT' message and starts
49-
// the remote debugger with the givenport $PORT
50-
handler.addProcessListener(new AttachDebuggerProcessListener(project, env));
51+
// the remote debugger with the given port $PORT
52+
handler.addProcessListener(new AttachDebuggerProcessListener(project, env, getDebugPort(handler)));
5153
}
5254
}
5355

56+
/**
57+
* Returns the port declared in teh command line with -Ddebug= and null otherwise.
58+
* @param handler the process handler.
59+
* @return the port declared in teh command line with -Ddebug= and null otherwise.
60+
*/
61+
private @Nullable Integer getDebugPort(@NotNull ProcessHandler handler) {
62+
if (handler instanceof BaseOSProcessHandler osProcessHandler) {
63+
String commandLine = osProcessHandler.getCommandLine();
64+
int startIndex = commandLine.indexOf("-Ddebug=");
65+
if(startIndex != -1) {
66+
StringBuilder port = new StringBuilder();
67+
for (int i = startIndex+"-Ddebug=".length(); i < commandLine.length(); i++) {
68+
char c = commandLine.charAt(i);
69+
if (Character.isDigit(c)) {
70+
port.append(c);
71+
} else {
72+
break;
73+
}
74+
}
75+
if (!port.isEmpty()) {
76+
return Integer.parseInt(port.toString());
77+
}
78+
}
79+
}
80+
return null;
81+
}
82+
5483
}

src/main/java/com/redhat/devtools/intellij/quarkus/run/AttachDebuggerProcessListener.java

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -59,25 +59,23 @@ class AttachDebuggerProcessListener implements ProcessListener {
5959

6060
private final Project project;
6161
private final ExecutionEnvironment env;
62+
private final @Nullable Integer debugPort;
6263
private boolean connected; // to prevent from several messages like 'Listening for transport dt_socket at address:'
6364
private boolean quteConnected; // to prevent from several messages like 'Listening for transport dt_socket at address:'
6465

6566
AttachDebuggerProcessListener(@NotNull Project project,
66-
@NotNull ExecutionEnvironment env) {
67+
@NotNull ExecutionEnvironment env,
68+
@Nullable Integer debugPort) {
6769
this.project = project;
6870
this.env = env;
71+
this.debugPort = debugPort;
6972
}
7073

7174
@Override
7275
public void onTextAvailable(@NotNull ProcessEvent event, @NotNull Key outputType) {
7376
String message = event.getText();
74-
if (!connected && message.startsWith(LISTENING_FOR_TRANSPORT_DT_SOCKET_AT_ADDRESS)) {
77+
if (!connected && debugPort != null && message.startsWith(LISTENING_FOR_TRANSPORT_DT_SOCKET_AT_ADDRESS + debugPort)) {
7578
connected = true;
76-
Integer debugPort = getDebugPort(message);
77-
if (debugPort == null) {
78-
LOGGER.error("Cannot extract port from the given message: {}", message);
79-
return;
80-
}
8179
ProgressManager.getInstance().run(new Task.Backgroundable(project, QUARKUS_CONFIGURATION, false) {
8280
@Override
8381
public void run(@NotNull ProgressIndicator indicator) {
@@ -102,16 +100,6 @@ public void run(@NotNull ProgressIndicator indicator) {
102100
}
103101
}
104102

105-
@Nullable
106-
private static Integer getDebugPort(String message) {
107-
try {
108-
String port = message.substring(LISTENING_FOR_TRANSPORT_DT_SOCKET_AT_ADDRESS.length()).trim();
109-
return Integer.valueOf(port);
110-
} catch (Exception e) {
111-
return null;
112-
}
113-
}
114-
115103
@Nullable
116104
private static Integer getQuteDebugPort(String message) {
117105
try {

src/main/java/com/redhat/devtools/intellij/quarkus/run/QuarkusRunConfiguration.java

Lines changed: 9 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -13,47 +13,24 @@
1313
import com.intellij.execution.*;
1414
import com.intellij.execution.configurations.*;
1515
import com.intellij.execution.executors.DefaultDebugExecutor;
16-
import com.intellij.execution.process.ProcessEvent;
17-
import com.intellij.execution.process.ProcessHandler;
18-
import com.intellij.execution.process.ProcessListener;
19-
import com.intellij.execution.remote.RemoteConfiguration;
20-
import com.intellij.execution.remote.RemoteConfigurationType;
2116
import com.intellij.execution.runners.ExecutionEnvironment;
2217
import com.intellij.execution.runners.ExecutionEnvironmentBuilder;
23-
import com.intellij.execution.runners.ExecutionUtil;
2418
import com.intellij.execution.runners.RunConfigurationWithSuppressedDefaultRunAction;
25-
import com.intellij.java.library.JavaLibraryUtil;
26-
import com.intellij.openapi.actionSystem.DataContext;
27-
import com.intellij.openapi.application.ApplicationManager;
28-
import com.intellij.openapi.externalSystem.service.execution.ExternalSystemRunnableState;
2919
import com.intellij.openapi.module.Module;
3020
import com.intellij.openapi.options.SettingsEditor;
31-
import com.intellij.openapi.progress.ProgressIndicator;
32-
import com.intellij.openapi.progress.ProgressManager;
33-
import com.intellij.openapi.progress.Task;
3421
import com.intellij.openapi.project.Project;
35-
import com.intellij.openapi.ui.Messages;
36-
import com.intellij.openapi.util.Key;
37-
import com.intellij.openapi.wm.ToolWindowId;
38-
import com.intellij.psi.util.PsiClassUtil;
3922
import com.intellij.util.net.NetUtils;
40-
import com.redhat.devtools.intellij.lsp4mp4ij.psi.core.PsiUtils;
4123
import com.redhat.devtools.intellij.quarkus.QuarkusModuleUtil;
4224
import com.redhat.devtools.intellij.quarkus.buildtool.BuildToolDelegate;
4325
import com.redhat.devtools.intellij.quarkus.telemetry.TelemetryEventName;
4426
import com.redhat.devtools.intellij.quarkus.telemetry.TelemetryManager;
45-
import com.redhat.devtools.intellij.qute.psi.internal.QuteJavaConstants;
4627
import com.redhat.devtools.intellij.qute.psi.utils.PsiTypeUtils;
4728
import org.jetbrains.annotations.NotNull;
4829
import org.jetbrains.annotations.Nullable;
4930
import org.slf4j.Logger;
5031
import org.slf4j.LoggerFactory;
5132

5233
import java.io.IOException;
53-
import java.net.ConnectException;
54-
import java.net.ServerSocket;
55-
import java.net.Socket;
56-
import java.nio.charset.StandardCharsets;
5734
import java.util.Collection;
5835
import java.util.HashMap;
5936
import java.util.Map;
@@ -70,7 +47,7 @@ public class QuarkusRunConfiguration extends ModuleBasedConfiguration<RunConfigu
7047

7148
static final String QUARKUS_CONFIGURATION = "Quarkus Configuration";
7249

73-
private static final int DEFAULT_PORT = 5005 ;
50+
private static final int DEFAULT_PORT = 5005;
7451

7552
public QuarkusRunConfiguration(Project project, ConfigurationFactory factory, String name) {
7653
super(name, getRunConfigurationModule(project), factory);
@@ -124,12 +101,11 @@ public SettingsEditor<? extends RunConfiguration> getConfigurationEditor() {
124101
}
125102

126103
private int allocateLocalPort() {
127-
try {
128-
return NetUtils.findAvailableSocketPort();
129-
}
130-
catch (IOException e) {
131-
LOGGER.warn("Unexpected I/O exception occurred on attempt to find a free port to use for external system task debugging", e);
132-
}
104+
try {
105+
return NetUtils.findAvailableSocketPort();
106+
} catch (IOException e) {
107+
LOGGER.warn("Unexpected I/O exception occurred on attempt to find a free port to use for external system task debugging", e);
108+
}
133109
return DEFAULT_PORT;
134110
}
135111

@@ -159,7 +135,7 @@ public RunProfileState getState(@NotNull Executor executor, @NotNull ExecutionEn
159135
if (settings != null) {
160136
QuarkusRunConfigurationManager.getInstance(module.getProject()); // to be sure that Quarkus execution listener is registered
161137
long groupId = ExecutionEnvironment.getNextUnusedExecutionId();
162-
state = doRunConfiguration(settings, executor, DefaultExecutionTarget.INSTANCE, groupId, null);
138+
state = doRunConfiguration(settings, executor, DefaultExecutionTarget.INSTANCE, groupId);
163139
}
164140
} else {
165141
telemetryData.put("tool", "not found");
@@ -175,7 +151,7 @@ private boolean isQuteDebuggerInstalled(@NotNull Module module) {
175151
// We check if "io.quarkus.qute.runtime.debug.DebugQuteEngineObserver" is in the classpath
176152
// Note: we cannot check if "io.quarkus.qute.debug.adapter.RegisterDebugServerAdapter" is in classpath
177153
// because "io.quarkus.qute.debug.adapter.RegisterDebugServerAdapter" is not available in the standard IJ classpath
178-
return PsiTypeUtils.findType("io.quarkus.qute.runtime.debug.DebugQuteEngineObserver", module, null) != null;
154+
return PsiTypeUtils.findType("io.quarkus.qute.runtime.debug.DebugQuteEngineObserver", module, null) != null;
179155
}
180156

181157
public String getProfile() {
@@ -202,8 +178,7 @@ public void setEnv(Map<String, String> env) {
202178
private static RunProfileState doRunConfiguration(@NotNull RunnerAndConfigurationSettings configuration,
203179
@NotNull Executor executor,
204180
@Nullable ExecutionTarget targetOrNullForDefault,
205-
@Nullable Long executionId,
206-
@Nullable DataContext dataContext) throws ExecutionException {
181+
@Nullable Long executionId) throws ExecutionException {
207182
ExecutionEnvironmentBuilder builder = createEnvironment(executor, configuration);
208183
if (builder == null) {
209184
return null;
@@ -216,9 +191,6 @@ private static RunProfileState doRunConfiguration(@NotNull RunnerAndConfiguratio
216191
if (executionId != null) {
217192
builder.executionId(executionId);
218193
}
219-
if (dataContext != null) {
220-
builder.dataContext(dataContext);
221-
}
222194
return configuration.getConfiguration().getState(executor, builder.build());
223195
}
224196

0 commit comments

Comments
 (0)