IDEA-140955 - Docker: disable attach action if already attached

This commit is contained in:
Michael Golubev
2015-06-15 14:45:47 +02:00
parent 8d0f5398fd
commit 7f8622d15c
15 changed files with 141 additions and 27 deletions
@@ -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);
}
@@ -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() {
}
};
}
@@ -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();
@@ -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);
}
@@ -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();
}
@@ -26,10 +26,10 @@ public interface CloudTerminalProvider {
ExtensionPointName<CloudTerminalProvider> 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();
}
@@ -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;
@@ -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() {
@@ -33,6 +33,8 @@ public abstract class LoggingHandlerBase implements Disposable {
public abstract JComponent getComponent();
public abstract boolean isClosed();
@Override
public void dispose() {
@@ -63,4 +63,9 @@ public class LoggingHandlerImpl extends LoggingHandlerBase implements LoggingHan
public void clear() {
myConsole.clear();
}
@Override
public boolean isClosed() {
return false;
}
}
@@ -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;
}
}
@@ -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 {
@@ -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;
}
}
@@ -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);
}
@@ -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;