1919import com .intellij .execution .executors .DefaultDebugExecutor ;
2020import com .intellij .execution .process .ProcessEvent ;
2121import com .intellij .execution .process .ProcessListener ;
22+ import com .intellij .execution .process .ProcessOutputType ;
2223import com .intellij .execution .remote .RemoteConfiguration ;
2324import com .intellij .execution .remote .RemoteConfigurationType ;
2425import com .intellij .execution .runners .ExecutionEnvironment ;
4849 * ProcessListener which tracks the message Listening for transport dt_socket at address: $PORT' to start the
4950 * remote debugger of the given port $PORT.
5051 */
51- class AttachDebuggerProcessListener implements ProcessListener {
52+ public class AttachDebuggerProcessListener implements ProcessListener {
5253
5354 private final static Logger LOGGER = LoggerFactory .getLogger (AttachDebuggerProcessListener .class );
5455
@@ -73,30 +74,32 @@ class AttachDebuggerProcessListener implements ProcessListener {
7374
7475 @ Override
7576 public void onTextAvailable (@ NotNull ProcessEvent event , @ NotNull Key outputType ) {
76- String message = event .getText ();
77- if (!connected && debugPort != null && message .startsWith (LISTENING_FOR_TRANSPORT_DT_SOCKET_AT_ADDRESS + debugPort )) {
78- connected = true ;
79- ProgressManager .getInstance ().run (new Task .Backgroundable (project , QUARKUS_CONFIGURATION , false ) {
80- @ Override
81- public void run (@ NotNull ProgressIndicator indicator ) {
82- String name = env .getRunProfile ().getName ();
83- createRemoteConfiguration (indicator , debugPort , name );
77+ if (ProcessOutputType .isStdout (outputType )) {
78+ String message = event .getText ();
79+ if (!connected && debugPort != null && message .startsWith (LISTENING_FOR_TRANSPORT_DT_SOCKET_AT_ADDRESS + debugPort )) {
80+ connected = true ;
81+ ProgressManager .getInstance ().run (new Task .Backgroundable (project , QUARKUS_CONFIGURATION , true ) {
82+ @ Override
83+ public void run (@ NotNull ProgressIndicator indicator ) {
84+ String name = env .getRunProfile ().getName ();
85+ createRemoteConfiguration (indicator , debugPort , name );
86+ }
87+ });
88+ } else if (!quteConnected && message .startsWith (QUTE_LISTENING_ON_PORT )) {
89+ quteConnected = true ;
90+ Integer quteDebugPort = getQuteDebugPort (message );
91+ if (quteDebugPort == null ) {
92+ LOGGER .error ("Cannot extract Qute debug port from the given message: {}" , message );
93+ return ;
8494 }
85- });
86- } else if (! quteConnected && message . startsWith ( QUTE_LISTENING_ON_PORT )) {
87- quteConnected = true ;
88- Integer quteDebugPort = getQuteDebugPort ( message );
89- if ( quteDebugPort == null ) {
90- LOGGER . error ( "Cannot extract Qute debug port from the given message: {}" , message );
91- return ;
95+ ProgressManager . getInstance (). run ( new Task . Backgroundable ( project , QUARKUS_CONFIGURATION , true ) {
96+ @ Override
97+ public void run ( @ NotNull ProgressIndicator indicator ) {
98+ String name = env . getRunProfile (). getName ( );
99+ createQuteConfiguration ( indicator , quteDebugPort , name );
100+ }
101+ }) ;
92102 }
93- ProgressManager .getInstance ().run (new Task .Backgroundable (project , QUARKUS_CONFIGURATION , false ) {
94- @ Override
95- public void run (@ NotNull ProgressIndicator indicator ) {
96- String name = env .getRunProfile ().getName ();
97- createQuteConfiguration (indicator , quteDebugPort , name );
98- }
99- });
100103 }
101104 }
102105
@@ -131,9 +134,19 @@ private void createRemoteConfiguration(@NotNull ProgressIndicator indicator, int
131134 }
132135
133136 private void createQuteConfiguration (@ NotNull ProgressIndicator indicator , int port , String name ) {
137+ createQuteConfiguration (port , name , project , indicator , true );
138+ }
139+
140+ public static void createQuteConfiguration (int port ,
141+ @ NotNull String name ,
142+ @ NotNull Project project ,
143+ @ NotNull ProgressIndicator indicator ,
144+ boolean waitForPortAvailable ) {
134145 indicator .setText ("Connecting Qute debugger to port " + port );
135146 try {
136- waitForPortAvailable (port , indicator );
147+ if (waitForPortAvailable ) {
148+ waitForPortAvailable (port , indicator );
149+ }
137150 RunnerAndConfigurationSettings settings = RunManager .getInstance (project ).createConfiguration (name + " (Qute)" , QuteConfigurationType .class );
138151 QuteRunConfiguration quteConfiguration = (QuteRunConfiguration ) settings .getConfiguration ();
139152 quteConfiguration .setAttachPort (Integer .toString (port ));
@@ -145,7 +158,7 @@ private void createQuteConfiguration(@NotNull ProgressIndicator indicator, int p
145158 }
146159 }
147160
148- private void waitForPortAvailable (int port , ProgressIndicator monitor ) throws IOException {
161+ private static void waitForPortAvailable (int port , ProgressIndicator monitor ) throws IOException {
149162 long start = System .currentTimeMillis ();
150163 while (System .currentTimeMillis () - start < 120_000 && !monitor .isCanceled ()) {
151164 try (Socket socket = new Socket ("localhost" , port )) {
0 commit comments