4444import com .intellij .ui .content .Content ;
4545import com .intellij .util .NotNullFunction ;
4646import com .intellij .util .PathsList ;
47- import com .jcraft .jsch .Session ;
4847import org .jetbrains .annotations .NonNls ;
4948import org .jetbrains .annotations .NotNull ;
5049import org .jetbrains .annotations .Nullable ;
@@ -63,8 +62,6 @@ public class AppCommandLineState extends JavaCommandLineState {
6362 @ NotNull
6463 private final EmbeddedLinuxJVMRunConfiguration configuration ;
6564 @ NotNull
66- private final ExecutionEnvironment environment ;
67- @ NotNull
6865 private final RunnerSettings runnerSettings ;
6966 @ NotNull
7067 private final EmbeddedLinuxJVMOutputForwarder outputForwarder ;
@@ -82,7 +79,6 @@ public class AppCommandLineState extends JavaCommandLineState {
8279 public AppCommandLineState (@ NotNull ExecutionEnvironment environment , @ NotNull EmbeddedLinuxJVMRunConfiguration configuration ) {
8380 super (environment );
8481 this .configuration = configuration ;
85- this .environment = environment ;
8682 this .runnerSettings = environment .getRunnerSettings ();
8783 this .project = environment .getProject ();
8884 this .isDebugMode = runnerSettings instanceof DebuggingRunnerData ;
@@ -136,35 +132,40 @@ protected OSProcessHandler startProcess() throws ExecutionException {
136132 handler .addProcessListener (new ProcessAdapter () {
137133 private void closeSSHConnection () {
138134 try {
139- closeSSHThreads ();
140135 if (isDebugMode ) {
141136 //todo fix tcp connection closing issue random error message showing up
142- closeRemoteVM ();
137+ final DebuggerSession debuggerSession = DebuggerManagerEx .getInstanceEx (project ).getContext ().getDebuggerSession ();
138+ if (debuggerSession == null ) {
139+ return ;
140+ }
141+
142+ final DebugProcessImpl debugProcess = debuggerSession .getProcess ();
143+ if (debugProcess .isDetached () || debugProcess .isDetaching ()) {
144+ debugProcess .stop (true );
145+ debugProcess .dispose ();
146+ debuggerSession .dispose ();
147+ }
143148 }
144- Session session = EmbeddedLinuxJVMConsoleView .getInstance (project ).getSession ();
145149 } catch (Exception e ) {
146150 }
147151 }
148152
149- private void closeSSHThreads () {
150- // for (Thread thread : SSHHandlerTarget.threads) {
151- // thread.interrupt();
153+ /**
154+ * closes debug session
155+ */
156+ private void closeDescriptors () {
157+ //todo remove remote debugger console
158+ final Collection <RunContentDescriptor > descriptors =
159+ ExecutionHelper .findRunningConsoleByTitle (project , new NotNullFunction <String , Boolean >() {
160+ @ NotNull
161+ @ Override
162+ public Boolean fun (String title ) {
163+ return AppCommandLineState .getRunConfigurationName (configuration .getRunnerParameters ().getPort ()).equals (title );
164+ }
165+ });
166+ // for (RunContentDescriptor descriptor : descriptors) {
167+ // final Content content = descriptor.getAttachedContent();
152168// }
153- // SSHHandlerTarget.threads.clear();
154- }
155-
156- private void closeRemoteVM () {
157- final DebuggerSession debuggerSession = DebuggerManagerEx .getInstanceEx (project ).getContext ().getDebuggerSession ();
158- if (debuggerSession == null ) {
159- return ;
160- }
161-
162- final DebugProcessImpl debugProcess = debuggerSession .getProcess ();
163- if (debugProcess .isDetached () || debugProcess .isDetaching ()) {
164- debugProcess .stop (true );
165- debugProcess .dispose ();
166- debuggerSession .dispose ();
167- }
168169 }
169170
170171 /**
@@ -179,6 +180,9 @@ public void processWillTerminate(ProcessEvent event, boolean willBeDestroyed) {
179180 @ Override
180181 public void run (@ NotNull ProgressIndicator progressIndicator ) {
181182 closeSSHConnection ();
183+ if (isDebugMode ) {
184+ closeDescriptors ();
185+ }
182186 }
183187 });
184188 super .processWillTerminate (event , willBeDestroyed );
0 commit comments