From 436b39433367c08bec8dcbd2bb3acbf1f5253001 Mon Sep 17 00:00:00 2001 From: Alexander Koshevoy Date: Fri, 25 Dec 2015 16:37:43 +0300 Subject: [PATCH 1/2] PY-17573 Initial steps to Docker Compose as Python remote interpreter --- .../DockerComposeCredentialsHolder.java | 83 +++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 platform/platform-impl/src/com/intellij/remote/DockerComposeCredentialsHolder.java diff --git a/platform/platform-impl/src/com/intellij/remote/DockerComposeCredentialsHolder.java b/platform/platform-impl/src/com/intellij/remote/DockerComposeCredentialsHolder.java new file mode 100644 index 000000000000..9a57daf2e6c9 --- /dev/null +++ b/platform/platform-impl/src/com/intellij/remote/DockerComposeCredentialsHolder.java @@ -0,0 +1,83 @@ +/* + * 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.remote; + +import com.intellij.openapi.util.text.StringUtil; +import org.jdom.Element; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * @author Alexander Koshevoy + */ +public class DockerComposeCredentialsHolder { + public static final String DOCKER_MACHINE_NAME = "DOCKER_MACHINE_NAME"; + public static final String DOCKER_COMPOSE_FILE_PATH = "DOCKER_COMPOSE_FILE_PATH"; + public static final String DOCKER_COMPOSE_SERVICE_NAME = "DOCKER_COMPOSE_SERVICE_NAME"; + public static final String DOCKER_REMOTE_PROJECT_PATH = "DOCKER_REMOTE_PROJECT_PATH"; + + private String myMachineName; + + private String myComposeFilePath; + + private String myComposeServiceName; + + private String myRemoteProjectPath; + + public DockerComposeCredentialsHolder() { + } + + public DockerComposeCredentialsHolder(@Nullable String machineName, + @Nullable String composeFilePath, + @Nullable String composeServiceName, + @Nullable String remoteProjectPath) { + myMachineName = machineName; + myComposeFilePath = composeFilePath; + myComposeServiceName = composeServiceName; + myRemoteProjectPath = remoteProjectPath; + } + + public String getMachineName() { + return myMachineName; + } + + public String getComposeFilePath() { + return myComposeFilePath; + } + + public String getComposeServiceName() { + return myComposeServiceName; + } + + public String getRemoteProjectPath() { + return myRemoteProjectPath; + } + + public void save(@NotNull Element element) { + if (StringUtil.isNotEmpty(myMachineName)) { + element.setAttribute(DOCKER_MACHINE_NAME, myMachineName); + } + element.setAttribute(DOCKER_COMPOSE_FILE_PATH, myComposeFilePath); + element.setAttribute(DOCKER_COMPOSE_SERVICE_NAME, myComposeServiceName); + } + + public void load(@NotNull Element element) { + myMachineName = element.getAttributeValue(DOCKER_MACHINE_NAME); + myComposeFilePath = element.getAttributeValue(DOCKER_COMPOSE_FILE_PATH); + myComposeServiceName = element.getAttributeValue(DOCKER_COMPOSE_SERVICE_NAME); + myRemoteProjectPath = element.getAttributeValue(DOCKER_REMOTE_PROJECT_PATH); + } +} From 67d2bb22871e27974c8c8a2668cd6f92f9f31221 Mon Sep 17 00:00:00 2001 From: Alexander Koshevoy Date: Fri, 15 Jan 2016 11:19:07 +0300 Subject: [PATCH 2/2] PY-17573 DockerCredentialsHolder extended to hold Compose properties --- .../remote/DockerCredentialsHolder.java | 62 ++++++++++++++++--- .../RemoteConnectionCredentialsWrapper.java | 15 ++++- 2 files changed, 68 insertions(+), 9 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/remote/DockerCredentialsHolder.java b/platform/platform-impl/src/com/intellij/remote/DockerCredentialsHolder.java index 2ea73e504b9d..c0515ac87d24 100644 --- a/platform/platform-impl/src/com/intellij/remote/DockerCredentialsHolder.java +++ b/platform/platform-impl/src/com/intellij/remote/DockerCredentialsHolder.java @@ -18,6 +18,7 @@ package com.intellij.remote; import com.intellij.openapi.util.text.StringUtil; import org.jdom.Element; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; /** * @author Alexander Koshevoy @@ -28,12 +29,19 @@ public class DockerCredentialsHolder { public static final String DOCKER_CONTAINER_NAME = "DOCKER_CONTAINER_NAME"; public static final String DOCKER_REMOTE_PROJECT_PATH = "DOCKER_REMOTE_PROJECT_PATH"; + public static final String DOCKER_COMPOSE_FILE_PATH = "DOCKER_COMPOSE_FILE_PATH"; + public static final String DOCKER_COMPOSE_SERVICE_NAME = "DOCKER_COMPOSE_SERVICE_NAME"; + private String myMachineName; private String myImageName; private String myContainerName; + private String myComposeFilePath; + + private String myComposeServiceName; + private String myRemoteProjectPath; public DockerCredentialsHolder() { @@ -49,6 +57,20 @@ public class DockerCredentialsHolder { myRemoteProjectPath = remoteProjectPath; } + public DockerCredentialsHolder(String machineName, + String composeFilePath, + String composeServiceName, + String imageName, + String containerName, + String remoteProjectPath) { + myMachineName = machineName; + myComposeFilePath = composeFilePath; + myComposeServiceName = composeServiceName; + myImageName = imageName; + myContainerName = containerName; + myRemoteProjectPath = remoteProjectPath; + } + public String getMachineName() { return myMachineName; } @@ -65,21 +87,47 @@ public class DockerCredentialsHolder { return myRemoteProjectPath; } + public String getComposeFilePath() { + return myComposeFilePath; + } + + public String getComposeServiceName() { + return myComposeServiceName; + } + public void save(@NotNull Element element) { - if (StringUtil.isNotEmpty(myMachineName)) { - element.setAttribute(DOCKER_MACHINE_NAME, myMachineName); - } - element.setAttribute(DOCKER_IMAGE_NAME, myImageName); - if (StringUtil.isNotEmpty(myContainerName)) { - element.setAttribute(DOCKER_CONTAINER_NAME, myContainerName); - } + setAttributeIfNotEmpty(element, DOCKER_MACHINE_NAME, myMachineName); + setAttributeIfNotEmpty(element, DOCKER_IMAGE_NAME, myImageName); + setAttributeIfNotEmpty(element, DOCKER_CONTAINER_NAME, myContainerName); + setAttributeIfNotEmpty(element, DOCKER_COMPOSE_FILE_PATH, myComposeFilePath); + setAttributeIfNotEmpty(element, DOCKER_COMPOSE_SERVICE_NAME, myComposeServiceName); element.setAttribute(DOCKER_REMOTE_PROJECT_PATH, myRemoteProjectPath); } + private static void setAttributeIfNotEmpty(@NotNull Element element, @NotNull String attribute, @Nullable String value) { + if (StringUtil.isNotEmpty(value)) { + element.setAttribute(attribute, value); + } + } + public void load(@NotNull Element element) { myMachineName = element.getAttributeValue(DOCKER_MACHINE_NAME); myImageName = element.getAttributeValue(DOCKER_IMAGE_NAME); myContainerName = element.getAttributeValue(DOCKER_CONTAINER_NAME); + myComposeFilePath = element.getAttributeValue(DOCKER_COMPOSE_FILE_PATH); + myComposeServiceName = element.getAttributeValue(DOCKER_COMPOSE_SERVICE_NAME); myRemoteProjectPath = element.getAttributeValue(DOCKER_REMOTE_PROJECT_PATH); } + + public boolean isDockerComposeCredentials() { + return myComposeFilePath != null; + } + + @NotNull + public static DockerCredentialsHolder newDockerComposeCredentials(@Nullable String machineName, + @Nullable String composeFilePath, + @Nullable String composeServiceName, + @Nullable String remoteProjectPath) { + return new DockerCredentialsHolder(machineName, composeFilePath, composeServiceName, null, null, remoteProjectPath); + } } diff --git a/platform/platform-impl/src/com/intellij/remote/RemoteConnectionCredentialsWrapper.java b/platform/platform-impl/src/com/intellij/remote/RemoteConnectionCredentialsWrapper.java index 7cbac5774097..7898c4f88504 100644 --- a/platform/platform-impl/src/com/intellij/remote/RemoteConnectionCredentialsWrapper.java +++ b/platform/platform-impl/src/com/intellij/remote/RemoteConnectionCredentialsWrapper.java @@ -185,7 +185,13 @@ public class RemoteConnectionCredentialsWrapper { @Override public void docker(@NotNull DockerCredentialsHolder cred) { // TODO [Docker] review - String name = StringUtil.isNotEmpty(cred.getContainerName()) ? cred.getContainerName() : cred.getImageName(); + String name; + if (cred.isDockerComposeCredentials()) { + name = cred.getComposeFilePath() + ":" + cred.getComposeServiceName(); + } + else { + name = StringUtil.isNotEmpty(cred.getContainerName()) ? cred.getContainerName() : cred.getImageName(); + } result.set(DOCKER_PREFIX + name + "/"); } }); @@ -270,7 +276,12 @@ public class RemoteConnectionCredentialsWrapper { public void docker(@NotNull DockerCredentialsHolder credentials) { String containerName = StringUtil.isNotEmpty(credentials.getContainerName()) ? credentials.getContainerName() + " " : ""; - result.set("Docker " + containerName + "(" + credentials.getImageName() + ")"); + if (credentials.isDockerComposeCredentials()) { + result.set("Docker Compose " + credentials.getComposeFilePath() + ":" + credentials.getComposeServiceName()); + } + else { + result.set("Docker " + containerName + "(" + credentials.getImageName() + ")"); + } } });