From 7f8622d15ca26ed23bdefa11a465c34ac500655d Mon Sep 17 00:00:00 2001 From: Michael Golubev Date: Mon, 15 Jun 2015 14:34:37 +0200 Subject: [PATCH] IDEA-140955 - Docker: disable attach action if already attached --- .../agent/util/CloudAgentLoggingHandler.java | 3 +- .../agent/util/log/TerminalListener.java | 28 +++++++++++++ .../agent/util/log/TerminalPipe.java | 6 ++- .../deployment/DeploymentLogManager.java | 3 +- .../runtime/log/TerminalHandler.java | 21 ++++++++++ .../runtime/log/CloudTerminalProvider.java | 8 ++-- .../log/ConsoleTerminalHandlerImpl.java | 12 +++--- .../runtime/log/DeploymentLogManagerImpl.java | 6 ++- .../impl/runtime/log/LoggingHandlerBase.java | 2 + .../impl/runtime/log/LoggingHandlerImpl.java | 5 +++ .../impl/runtime/log/TerminalHandlerBase.java | 42 +++++++++++++++++++ .../util/CloudLoggingHandlerImpl.java | 13 +++++- .../util/CloudSilentLoggingHandlerImpl.java | 5 ++- .../cloud/CloudTerminalProviderImpl.java | 10 ++--- .../terminal/cloud/TerminalHandlerImpl.java | 4 +- 15 files changed, 141 insertions(+), 27 deletions(-) create mode 100644 platform/remote-servers/agent-rt/src/com/intellij/remoteServer/agent/util/log/TerminalListener.java create mode 100644 platform/remote-servers/api/src/com/intellij/remoteServer/runtime/log/TerminalHandler.java create mode 100644 platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/log/TerminalHandlerBase.java diff --git a/platform/remote-servers/agent-rt/src/com/intellij/remoteServer/agent/util/CloudAgentLoggingHandler.java b/platform/remote-servers/agent-rt/src/com/intellij/remoteServer/agent/util/CloudAgentLoggingHandler.java index 33613616c403..0121843b13ff 100644 --- a/platform/remote-servers/agent-rt/src/com/intellij/remoteServer/agent/util/CloudAgentLoggingHandler.java +++ b/platform/remote-servers/agent-rt/src/com/intellij/remoteServer/agent/util/CloudAgentLoggingHandler.java @@ -16,6 +16,7 @@ package com.intellij.remoteServer.agent.util; import com.intellij.remoteServer.agent.util.log.LogListener; +import com.intellij.remoteServer.agent.util.log.TerminalListener; import java.io.InputStream; import java.io.OutputStream; @@ -35,5 +36,5 @@ public interface CloudAgentLoggingHandler { boolean isTtySupported(); - void createTerminal(String pipeName, OutputStream terminalInput, InputStream terminalOutput); + TerminalListener createTerminal(String pipeName, OutputStream terminalInput, InputStream terminalOutput); } diff --git a/platform/remote-servers/agent-rt/src/com/intellij/remoteServer/agent/util/log/TerminalListener.java b/platform/remote-servers/agent-rt/src/com/intellij/remoteServer/agent/util/log/TerminalListener.java new file mode 100644 index 000000000000..bd1590b00cb8 --- /dev/null +++ b/platform/remote-servers/agent-rt/src/com/intellij/remoteServer/agent/util/log/TerminalListener.java @@ -0,0 +1,28 @@ +/* + * Copyright 2000-2015 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.remoteServer.agent.util.log; + +public interface TerminalListener { + + void close(); + + static TerminalListener NULL = new TerminalListener() { + + public void close() { + + } + }; +} diff --git a/platform/remote-servers/agent-rt/src/com/intellij/remoteServer/agent/util/log/TerminalPipe.java b/platform/remote-servers/agent-rt/src/com/intellij/remoteServer/agent/util/log/TerminalPipe.java index 9802bc61d12c..ec29fdb69c52 100644 --- a/platform/remote-servers/agent-rt/src/com/intellij/remoteServer/agent/util/log/TerminalPipe.java +++ b/platform/remote-servers/agent-rt/src/com/intellij/remoteServer/agent/util/log/TerminalPipe.java @@ -24,20 +24,22 @@ public abstract class TerminalPipe extends LogPipeBase { private final String myLogPipeName; private final CloudAgentLoggingHandler myLoggingHandler; + private TerminalListener myTerminalListener; public TerminalPipe(String logPipeName, CloudAgentLoggingHandler loggingHandler) { myLogPipeName = logPipeName; myLoggingHandler = loggingHandler; + myTerminalListener = TerminalListener.NULL; } @Override public void open() { - myLoggingHandler.createTerminal(myLogPipeName, getOutputStream(), getInputStream()); + myTerminalListener = myLoggingHandler.createTerminal(myLogPipeName, getOutputStream(), getInputStream()); } @Override public void close() { - + myTerminalListener.close(); } protected abstract OutputStream getOutputStream(); diff --git a/platform/remote-servers/api/src/com/intellij/remoteServer/runtime/deployment/DeploymentLogManager.java b/platform/remote-servers/api/src/com/intellij/remoteServer/runtime/deployment/DeploymentLogManager.java index d04f7d1bdb19..d69ef80dc1f4 100644 --- a/platform/remote-servers/api/src/com/intellij/remoteServer/runtime/deployment/DeploymentLogManager.java +++ b/platform/remote-servers/api/src/com/intellij/remoteServer/runtime/deployment/DeploymentLogManager.java @@ -16,6 +16,7 @@ package com.intellij.remoteServer.runtime.deployment; import com.intellij.remoteServer.runtime.log.LoggingHandler; +import com.intellij.remoteServer.runtime.log.TerminalHandler; import org.jetbrains.annotations.NotNull; import java.io.InputStream; @@ -33,5 +34,5 @@ public interface DeploymentLogManager { boolean isTtySupported(); - void addTerminal(@NotNull String presentableName, InputStream terminalOutput, OutputStream terminalInput); + TerminalHandler addTerminal(@NotNull String presentableName, InputStream terminalOutput, OutputStream terminalInput); } diff --git a/platform/remote-servers/api/src/com/intellij/remoteServer/runtime/log/TerminalHandler.java b/platform/remote-servers/api/src/com/intellij/remoteServer/runtime/log/TerminalHandler.java new file mode 100644 index 000000000000..dbeb989e32de --- /dev/null +++ b/platform/remote-servers/api/src/com/intellij/remoteServer/runtime/log/TerminalHandler.java @@ -0,0 +1,21 @@ +/* + * Copyright 2000-2015 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.remoteServer.runtime.log; + +public interface TerminalHandler { + + void close(); +} diff --git a/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/log/CloudTerminalProvider.java b/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/log/CloudTerminalProvider.java index ed2b1259a30a..da1a522129fa 100644 --- a/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/log/CloudTerminalProvider.java +++ b/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/log/CloudTerminalProvider.java @@ -26,10 +26,10 @@ public interface CloudTerminalProvider { ExtensionPointName EP_NAME = ExtensionPointName.create("com.intellij.remoteServer.CloudTerminalProvider"); - LoggingHandlerBase createTerminal(@NotNull String presentableName, - @NotNull Project project, - @NotNull InputStream terminalOutput, - @NotNull OutputStream terminalInput); + TerminalHandlerBase createTerminal(@NotNull String presentableName, + @NotNull Project project, + @NotNull InputStream terminalOutput, + @NotNull OutputStream terminalInput); boolean isTtySupported(); } diff --git a/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/log/ConsoleTerminalHandlerImpl.java b/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/log/ConsoleTerminalHandlerImpl.java index da41e8d0e820..e77efca79dbf 100644 --- a/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/log/ConsoleTerminalHandlerImpl.java +++ b/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/log/ConsoleTerminalHandlerImpl.java @@ -26,17 +26,17 @@ import org.jetbrains.annotations.Nullable; import javax.swing.*; import java.io.*; -public class ConsoleTerminalHandlerImpl extends LoggingHandlerBase { +public class ConsoleTerminalHandlerImpl extends TerminalHandlerBase { private static final Logger LOG = Logger.getInstance("#" + ConsoleTerminalHandlerImpl.class.getName()); public static final CloudTerminalProvider PROVIDER = new CloudTerminalProvider() { @Override - public LoggingHandlerBase createTerminal(@NotNull String presentableName, - @NotNull Project project, - @NotNull InputStream terminalOutput, - @NotNull OutputStream terminalInput) { + public TerminalHandlerBase createTerminal(@NotNull String presentableName, + @NotNull Project project, + @NotNull InputStream terminalOutput, + @NotNull OutputStream terminalInput) { return new ConsoleTerminalHandlerImpl(presentableName, project, terminalOutput, terminalInput); } @@ -86,7 +86,7 @@ public class ConsoleTerminalHandlerImpl extends LoggingHandlerBase { public void run() { BufferedReader outputReader = new BufferedReader(new InputStreamReader(terminalOutput)); try { - while (true) { + while (!isClosed()) { String line = outputReader.readLine(); if (line == null) { break; diff --git a/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/log/DeploymentLogManagerImpl.java b/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/log/DeploymentLogManagerImpl.java index ebc1a39c5ef3..4e125c0f944c 100644 --- a/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/log/DeploymentLogManagerImpl.java +++ b/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/log/DeploymentLogManagerImpl.java @@ -20,6 +20,7 @@ import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Disposer; import com.intellij.remoteServer.runtime.deployment.DeploymentLogManager; import com.intellij.remoteServer.runtime.log.LoggingHandler; +import com.intellij.remoteServer.runtime.log.TerminalHandler; import com.intellij.util.ArrayUtil; import org.jetbrains.annotations.NotNull; @@ -80,9 +81,10 @@ public class DeploymentLogManagerImpl implements DeploymentLogManager { } @Override - public void addTerminal(@NotNull final String presentableName, InputStream terminalOutput, OutputStream terminalInput) { - LoggingHandlerBase handler = getTerminalProvider().createTerminal(presentableName, myProject, terminalOutput, terminalInput); + public TerminalHandler addTerminal(@NotNull final String presentableName, InputStream terminalOutput, OutputStream terminalInput) { + TerminalHandlerBase handler = getTerminalProvider().createTerminal(presentableName, myProject, terminalOutput, terminalInput); addAdditionalLoggingHandler(handler); + return handler; } private static CloudTerminalProvider getTerminalProvider() { diff --git a/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/log/LoggingHandlerBase.java b/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/log/LoggingHandlerBase.java index 71be3380b3f0..121dc55dd48d 100644 --- a/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/log/LoggingHandlerBase.java +++ b/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/log/LoggingHandlerBase.java @@ -33,6 +33,8 @@ public abstract class LoggingHandlerBase implements Disposable { public abstract JComponent getComponent(); + public abstract boolean isClosed(); + @Override public void dispose() { diff --git a/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/log/LoggingHandlerImpl.java b/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/log/LoggingHandlerImpl.java index 5fb9b88b6e0e..9ee9d2a8b36f 100644 --- a/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/log/LoggingHandlerImpl.java +++ b/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/log/LoggingHandlerImpl.java @@ -63,4 +63,9 @@ public class LoggingHandlerImpl extends LoggingHandlerBase implements LoggingHan public void clear() { myConsole.clear(); } + + @Override + public boolean isClosed() { + return false; + } } diff --git a/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/log/TerminalHandlerBase.java b/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/log/TerminalHandlerBase.java new file mode 100644 index 000000000000..c1892c9c2374 --- /dev/null +++ b/platform/remote-servers/impl/src/com/intellij/remoteServer/impl/runtime/log/TerminalHandlerBase.java @@ -0,0 +1,42 @@ +/* + * Copyright 2000-2015 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.remoteServer.impl.runtime.log; + +import com.intellij.remoteServer.runtime.log.TerminalHandler; +import org.jetbrains.annotations.NotNull; + +import javax.swing.*; + +public abstract class TerminalHandlerBase extends LoggingHandlerBase implements TerminalHandler { + + private boolean myClosed = false; + + public TerminalHandlerBase(@NotNull String presentableName) { + super(presentableName); + } + + @Override + public abstract JComponent getComponent(); + + @Override + public boolean isClosed() { + return myClosed; + } + + public void close() { + myClosed = true; + } +} diff --git a/platform/remote-servers/impl/src/com/intellij/remoteServer/util/CloudLoggingHandlerImpl.java b/platform/remote-servers/impl/src/com/intellij/remoteServer/util/CloudLoggingHandlerImpl.java index 41ad5e1c59eb..89a8f5f27395 100644 --- a/platform/remote-servers/impl/src/com/intellij/remoteServer/util/CloudLoggingHandlerImpl.java +++ b/platform/remote-servers/impl/src/com/intellij/remoteServer/util/CloudLoggingHandlerImpl.java @@ -18,8 +18,10 @@ package com.intellij.remoteServer.util; import com.intellij.execution.process.ProcessHandler; import com.intellij.remoteServer.agent.util.CloudAgentLoggingHandler; import com.intellij.remoteServer.agent.util.log.LogListener; +import com.intellij.remoteServer.agent.util.log.TerminalListener; import com.intellij.remoteServer.runtime.deployment.DeploymentLogManager; import com.intellij.remoteServer.runtime.log.LoggingHandler; +import com.intellij.remoteServer.runtime.log.TerminalHandler; import org.jetbrains.annotations.Nullable; import java.io.InputStream; @@ -108,8 +110,15 @@ public class CloudLoggingHandlerImpl implements CloudAgentLoggingHandler { } @Override - public void createTerminal(final String pipeName, OutputStream terminalInput, InputStream terminalOutput) { - myLogManager.addTerminal(pipeName, terminalOutput, terminalInput); + public TerminalListener createTerminal(final String pipeName, OutputStream terminalInput, InputStream terminalOutput) { + final TerminalHandler terminalHandler = myLogManager.addTerminal(pipeName, terminalOutput, terminalInput); + return new TerminalListener() { + + @Override + public void close() { + terminalHandler.close(); + } + }; } private static class LogListenerImpl implements LogListener { diff --git a/platform/remote-servers/impl/src/com/intellij/remoteServer/util/CloudSilentLoggingHandlerImpl.java b/platform/remote-servers/impl/src/com/intellij/remoteServer/util/CloudSilentLoggingHandlerImpl.java index 02219bbfffb6..4e37d444d9b6 100644 --- a/platform/remote-servers/impl/src/com/intellij/remoteServer/util/CloudSilentLoggingHandlerImpl.java +++ b/platform/remote-servers/impl/src/com/intellij/remoteServer/util/CloudSilentLoggingHandlerImpl.java @@ -3,6 +3,7 @@ package com.intellij.remoteServer.util; import com.intellij.openapi.diagnostic.Logger; import com.intellij.remoteServer.agent.util.CloudAgentLoggingHandler; import com.intellij.remoteServer.agent.util.log.LogListener; +import com.intellij.remoteServer.agent.util.log.TerminalListener; import java.io.InputStream; import java.io.OutputStream; @@ -40,7 +41,7 @@ public class CloudSilentLoggingHandlerImpl implements CloudAgentLoggingHandler { } @Override - public void createTerminal(String pipeName, OutputStream terminalInput, InputStream terminalOutput) { - + public TerminalListener createTerminal(String pipeName, OutputStream terminalInput, InputStream terminalOutput) { + return TerminalListener.NULL; } } diff --git a/plugins/terminal/src/org/jetbrains/plugins/terminal/cloud/CloudTerminalProviderImpl.java b/plugins/terminal/src/org/jetbrains/plugins/terminal/cloud/CloudTerminalProviderImpl.java index 80d326507447..8c03be0bb62a 100644 --- a/plugins/terminal/src/org/jetbrains/plugins/terminal/cloud/CloudTerminalProviderImpl.java +++ b/plugins/terminal/src/org/jetbrains/plugins/terminal/cloud/CloudTerminalProviderImpl.java @@ -17,7 +17,7 @@ package org.jetbrains.plugins.terminal.cloud; import com.intellij.openapi.project.Project; import com.intellij.remoteServer.impl.runtime.log.CloudTerminalProvider; -import com.intellij.remoteServer.impl.runtime.log.LoggingHandlerBase; +import com.intellij.remoteServer.impl.runtime.log.TerminalHandlerBase; import org.jetbrains.annotations.NotNull; import java.io.InputStream; @@ -26,10 +26,10 @@ import java.io.OutputStream; public class CloudTerminalProviderImpl implements CloudTerminalProvider { @Override - public LoggingHandlerBase createTerminal(@NotNull String presentableName, - @NotNull Project project, - @NotNull InputStream terminalOutput, - @NotNull OutputStream terminalInput) { + public TerminalHandlerBase createTerminal(@NotNull String presentableName, + @NotNull Project project, + @NotNull InputStream terminalOutput, + @NotNull OutputStream terminalInput) { return new TerminalHandlerImpl(presentableName, project, terminalOutput, terminalInput); } diff --git a/plugins/terminal/src/org/jetbrains/plugins/terminal/cloud/TerminalHandlerImpl.java b/plugins/terminal/src/org/jetbrains/plugins/terminal/cloud/TerminalHandlerImpl.java index 12a898a8dde4..d57aae36bf9d 100644 --- a/plugins/terminal/src/org/jetbrains/plugins/terminal/cloud/TerminalHandlerImpl.java +++ b/plugins/terminal/src/org/jetbrains/plugins/terminal/cloud/TerminalHandlerImpl.java @@ -16,7 +16,7 @@ package org.jetbrains.plugins.terminal.cloud; import com.intellij.openapi.project.Project; -import com.intellij.remoteServer.impl.runtime.log.LoggingHandlerBase; +import com.intellij.remoteServer.impl.runtime.log.TerminalHandlerBase; import org.jetbrains.annotations.NotNull; import org.jetbrains.plugins.terminal.JBTabbedTerminalWidget; @@ -24,7 +24,7 @@ import javax.swing.*; import java.io.InputStream; import java.io.OutputStream; -public class TerminalHandlerImpl extends LoggingHandlerBase { +public class TerminalHandlerImpl extends TerminalHandlerBase { private final JBTabbedTerminalWidget myTerminalWidget;