diff --git a/platform/platform-impl/src/com/intellij/remotesdk/RemoteCredentialsHolder.java b/platform/platform-impl/src/com/intellij/remotesdk/RemoteCredentialsHolder.java index d0e7e97902f2..1b5b4c311c70 100644 --- a/platform/platform-impl/src/com/intellij/remotesdk/RemoteCredentialsHolder.java +++ b/platform/platform-impl/src/com/intellij/remotesdk/RemoteCredentialsHolder.java @@ -18,6 +18,7 @@ package com.intellij.remotesdk; import com.intellij.openapi.util.PasswordUtil; import com.intellij.openapi.util.text.StringUtil; import com.intellij.util.xmlb.annotations.Transient; +import org.jdom.Element; import org.jetbrains.annotations.Nullable; /** @@ -204,7 +205,7 @@ public class RemoteCredentialsHolder implements MutableRemoteCredentials { } } - public void copyTo(RemoteSdkCredentials to) { + public void copyRemoteCredentialsTo(RemoteSdkCredentials to) { to.setHost(getHost()); to.setPort(getPort()); to.setAnonymous(isAnonymous()); @@ -216,4 +217,28 @@ public class RemoteCredentialsHolder implements MutableRemoteCredentials { to.setStorePassword(isStorePassword()); to.setStorePassphrase(isStorePassphrase()); } + + public void load(Element element) { + setHost(element.getAttributeValue(HOST)); + setPort(StringUtil.parseInt(element.getAttributeValue(PORT), 22)); + setAnonymous(StringUtil.parseBoolean(element.getAttributeValue(ANONYMOUS), false)); + setSerializedUserName(element.getAttributeValue(USERNAME)); + setSerializedPassword(element.getAttributeValue(PASSWORD)); + setPrivateKeyFile(StringUtil.nullize(element.getAttributeValue(PRIVATE_KEY_FILE))); + setKnownHostsFile(StringUtil.nullize(element.getAttributeValue(KNOWN_HOSTS_FILE))); + setSerializedPassphrase(element.getAttributeValue(PASSPHRASE)); + setUseKeyPair(StringUtil.parseBoolean(element.getAttributeValue(USE_KEY_PAIR), false)); + } + + public void save(Element rootElement) { + rootElement.setAttribute(HOST, StringUtil.notNullize(getHost())); + rootElement.setAttribute(PORT, Integer.toString(getPort())); + rootElement.setAttribute(ANONYMOUS, Boolean.toString(isAnonymous())); + rootElement.setAttribute(USERNAME, getSerializedUserName()); + rootElement.setAttribute(PASSWORD, getSerializedPassword()); + rootElement.setAttribute(PRIVATE_KEY_FILE, StringUtil.notNullize(getPrivateKeyFile())); + rootElement.setAttribute(KNOWN_HOSTS_FILE, StringUtil.notNullize(getKnownHostsFile())); + rootElement.setAttribute(PASSPHRASE, getSerializedPassphrase()); + rootElement.setAttribute(USE_KEY_PAIR, Boolean.toString(isUseKeyPair())); + } } diff --git a/platform/platform-impl/src/com/intellij/remotesdk/RemoteSdkCredentialsHolder.java b/platform/platform-impl/src/com/intellij/remotesdk/RemoteSdkCredentialsHolder.java index 37ee1df4b30c..07c1687d3231 100644 --- a/platform/platform-impl/src/com/intellij/remotesdk/RemoteSdkCredentialsHolder.java +++ b/platform/platform-impl/src/com/intellij/remotesdk/RemoteSdkCredentialsHolder.java @@ -1,11 +1,10 @@ package com.intellij.remotesdk; -import com.intellij.openapi.util.text.StringUtil; +import com.intellij.remotesdk2.RemoteSdkConnection; import org.jdom.Element; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.LinkedList; import java.util.List; /** @@ -13,11 +12,6 @@ import java.util.List; */ public class RemoteSdkCredentialsHolder extends RemoteCredentialsHolder implements RemoteSdkCredentials { public static final String SSH_PREFIX = "ssh://"; - private static final String INTERPRETER_PATH = "INTERPRETER_PATH"; - private static final String HELPERS_PATH = "HELPERS_PATH"; - private static final String REMOTE_ROOTS = "REMOTE_ROOTS"; - private static final String REMOTE_PATH = "REMOTE_PATH"; - private static final String INITIALIZED = "INITIALIZED"; @NotNull private final RemoteSdkPropertiesHolder myRemoteSdkProperties; @@ -143,64 +137,26 @@ public class RemoteSdkCredentialsHolder extends RemoteCredentialsHolder implemen public static boolean isRemoteSdk(@Nullable String path) { if (path != null) { - return path.startsWith(SSH_PREFIX); + return path.startsWith(SSH_PREFIX) || path.startsWith(RemoteSdkConnection.VAGRANT_PREFIX); } else { return false; } } - public void loadRemoteSdkCredentials(Element element) { - setHost(element.getAttributeValue(HOST)); - setPort(StringUtil.parseInt(element.getAttributeValue(PORT), 22)); - setAnonymous(StringUtil.parseBoolean(element.getAttributeValue(ANONYMOUS), false)); - setSerializedUserName(element.getAttributeValue(USERNAME)); - setSerializedPassword(element.getAttributeValue(PASSWORD)); - setPrivateKeyFile(StringUtil.nullize(element.getAttributeValue(PRIVATE_KEY_FILE))); - setKnownHostsFile(StringUtil.nullize(element.getAttributeValue(KNOWN_HOSTS_FILE))); - setSerializedPassphrase(element.getAttributeValue(PASSPHRASE)); - setUseKeyPair(StringUtil.parseBoolean(element.getAttributeValue(USE_KEY_PAIR), false)); - setInterpreterPath(StringUtil.nullize(element.getAttributeValue(INTERPRETER_PATH))); - setHelpersPath(StringUtil.nullize(element.getAttributeValue(HELPERS_PATH))); + @Override + public void load(Element element) { + super.load(element); - setRemoteRoots(loadStringsList(element, REMOTE_ROOTS, REMOTE_PATH)); - - setInitialized(StringUtil.parseBoolean(element.getAttributeValue(INITIALIZED), true)); + myRemoteSdkProperties.load(element); } - protected static List loadStringsList(Element element, String rootName, String attrName) { - final List paths = new LinkedList(); - if (element != null) { - @NotNull final List list = element.getChildren(rootName); - for (Object o : list) { - paths.add(((Element)o).getAttribute(attrName).getValue()); - } - } - return paths; - } + @Override + public void save(Element rootElement) { + super.save(rootElement); - public void saveRemoteSdkData(Element rootElement) { - rootElement.setAttribute(HOST, StringUtil.notNullize(getHost())); - rootElement.setAttribute(PORT, Integer.toString(getPort())); - rootElement.setAttribute(ANONYMOUS, Boolean.toString(isAnonymous())); - rootElement.setAttribute(USERNAME, getSerializedUserName()); - rootElement.setAttribute(PASSWORD, getSerializedPassword()); - rootElement.setAttribute(PRIVATE_KEY_FILE, StringUtil.notNullize(getPrivateKeyFile())); - rootElement.setAttribute(KNOWN_HOSTS_FILE, StringUtil.notNullize(getKnownHostsFile())); - rootElement.setAttribute(PASSPHRASE, getSerializedPassphrase()); - rootElement.setAttribute(USE_KEY_PAIR, Boolean.toString(isUseKeyPair())); - - rootElement.setAttribute(INTERPRETER_PATH, StringUtil.notNullize(getInterpreterPath())); - rootElement.setAttribute(HELPERS_PATH, StringUtil.notNullize(getHelpersPath())); - - rootElement.setAttribute(INITIALIZED, Boolean.toString(isInitialized())); - - for (String remoteRoot : getRemoteRoots()) { - final Element child = new Element(REMOTE_ROOTS); - child.setAttribute(REMOTE_PATH, remoteRoot); - rootElement.addContent(child); - } + myRemoteSdkProperties.save(rootElement); } @@ -273,8 +229,8 @@ public class RemoteSdkCredentialsHolder extends RemoteCredentialsHolder implemen '}'; } - public void copyTo(RemoteSdkCredentialsHolder to) { - super.copyTo(to); + public void copyRemoteSdkCredentialsTo(RemoteSdkCredentialsHolder to) { + super.copyRemoteCredentialsTo(to); myRemoteSdkProperties.copyTo(to.getRemoteSdkProperties()); } } diff --git a/platform/platform-impl/src/com/intellij/remotesdk/RemoteSdkPropertiesHolder.java b/platform/platform-impl/src/com/intellij/remotesdk/RemoteSdkPropertiesHolder.java index e9bdb81ecd0b..5b63720a5d50 100644 --- a/platform/platform-impl/src/com/intellij/remotesdk/RemoteSdkPropertiesHolder.java +++ b/platform/platform-impl/src/com/intellij/remotesdk/RemoteSdkPropertiesHolder.java @@ -15,6 +15,10 @@ */ package com.intellij.remotesdk; +import com.intellij.openapi.util.JDOMExternalizer; +import com.intellij.openapi.util.text.StringUtil; +import org.jdom.Element; + import java.util.ArrayList; import java.util.List; @@ -22,6 +26,12 @@ import java.util.List; * @author traff */ public class RemoteSdkPropertiesHolder implements RemoteSdkProperties { + private static final String INTERPRETER_PATH = "INTERPRETER_PATH"; + private static final String HELPERS_PATH = "HELPERS_PATH"; + private static final String REMOTE_ROOTS = "REMOTE_ROOTS"; + private static final String REMOTE_PATH = "REMOTE_PATH"; + private static final String INITIALIZED = "INITIALIZED"; + private String mySdkId; private String myInterpreterPath; @@ -121,4 +131,26 @@ public class RemoteSdkPropertiesHolder implements RemoteSdkProperties { copy.setInitialized(isInitialized()); } + + public void save(Element rootElement) { + rootElement.setAttribute(INTERPRETER_PATH, StringUtil.notNullize(getInterpreterPath())); + rootElement.setAttribute(HELPERS_PATH, StringUtil.notNullize(getHelpersPath())); + + rootElement.setAttribute(INITIALIZED, Boolean.toString(isInitialized())); + + for (String remoteRoot : getRemoteRoots()) { + final Element child = new Element(REMOTE_ROOTS); + child.setAttribute(REMOTE_PATH, remoteRoot); + rootElement.addContent(child); + } + } + + public void load(Element element) { + setInterpreterPath(StringUtil.nullize(element.getAttributeValue(INTERPRETER_PATH))); + setHelpersPath(StringUtil.nullize(element.getAttributeValue(HELPERS_PATH))); + + setRemoteRoots(JDOMExternalizer.loadStringsList(element, REMOTE_ROOTS, REMOTE_PATH)); + + setInitialized(StringUtil.parseBoolean(element.getAttributeValue(INITIALIZED), true)); + } } diff --git a/platform/platform-impl/src/com/intellij/remotesdk2/RemoteSdkConnection.java b/platform/platform-impl/src/com/intellij/remotesdk2/RemoteSdkConnection.java new file mode 100644 index 000000000000..21063c2baa9b --- /dev/null +++ b/platform/platform-impl/src/com/intellij/remotesdk2/RemoteSdkConnection.java @@ -0,0 +1,111 @@ +/* + * Copyright 2000-2014 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.remotesdk2; + +import com.intellij.openapi.util.Key; +import com.intellij.openapi.util.UserDataHolderBase; +import com.intellij.remotesdk.RemoteSdkCredentials; +import com.intellij.remotesdk.RemoteSdkCredentialsHolder; +import org.jdom.Element; +import org.jetbrains.annotations.NotNull; + +/** + * @author traff + */ +public class RemoteSdkConnection { + public static final String VAGRANT_PREFIX = "vagrant://"; + + public final Key VAGRANT_BASED_CREDENTIALS = Key.create("VAGRANT_BASED_CREDENTIALS"); + + public final Key PLAIN_SSH_CREDENTIALS = Key.create("PLAIN_SSH_CREDENTIALS"); + + private UserDataHolderBase myCredentialsTypeHolder = new UserDataHolderBase(); + + public void setVagrantConnectionType(VagrantBasedCredentialsHolder vagrantBasedCredentials) { + myCredentialsTypeHolder.putUserData(VAGRANT_BASED_CREDENTIALS, vagrantBasedCredentials); + } + + public void setPlainSshCredentials(T credentials) { + myCredentialsTypeHolder.putUserData(PLAIN_SSH_CREDENTIALS, credentials); + } + + public T getPlainSshCredentials() { + return myCredentialsTypeHolder.getUserData(PLAIN_SSH_CREDENTIALS); + } + + public VagrantBasedCredentialsHolder getVagrantCredentials() { + return myCredentialsTypeHolder.getUserData(VAGRANT_BASED_CREDENTIALS); + } + + public boolean isVagrantConnection() { + return getVagrantCredentials() != null; + } + + public boolean isPlainSshConnection() { + return getPlainSshCredentials() != null; + } + + + public Object getConnectionKey() { + if (isVagrantConnection()) { + return getVagrantCredentials(); + } + else if (isPlainSshConnection()) { + return getPlainSshCredentials(); + } + else { + throw unknownConnectionType(); + } + } + + public void save(Element rootElement) { + if (isVagrantConnection()) { + getVagrantCredentials().save(rootElement); + } + else if (isPlainSshConnection()) { + getPlainSshCredentials().save(rootElement); + } + else { + throw unknownConnectionType(); + } + } + + private static IllegalStateException unknownConnectionType() { + return new IllegalStateException(); //TODO + } + + public void copyTo(RemoteSdkConnection copy) { + copy.myCredentialsTypeHolder = new UserDataHolderBase(); + copy.setPlainSshCredentials(getPlainSshCredentials()); + copy.setVagrantConnectionType(getVagrantCredentials()); + } + + public String getId() { + if (isVagrantConnection()) { + @NotNull VagrantBasedCredentialsHolder cred = getVagrantCredentials(); + + return VAGRANT_PREFIX + cred.getVagrantFolder(); + } + else if (isPlainSshConnection()) { + RemoteSdkCredentials cred = getPlainSshCredentials(); + + return RemoteSdkCredentialsHolder.constructSshCredentialsSdkFullPath(cred); + } + else { + throw unknownConnectionType(); + } + } +} diff --git a/platform/platform-impl/src/com/intellij/remotesdk2/VagrantBasedCredentialsHolder.java b/platform/platform-impl/src/com/intellij/remotesdk2/VagrantBasedCredentialsHolder.java index 7133c12b1fd2..8e9d36f058d1 100644 --- a/platform/platform-impl/src/com/intellij/remotesdk2/VagrantBasedCredentialsHolder.java +++ b/platform/platform-impl/src/com/intellij/remotesdk2/VagrantBasedCredentialsHolder.java @@ -15,12 +15,15 @@ */ package com.intellij.remotesdk2; +import com.intellij.openapi.util.text.StringUtil; +import org.jdom.Element; import org.jetbrains.annotations.NotNull; /** * @author traff */ public class VagrantBasedCredentialsHolder { + private static final String VAGRANT_FOLDER = "VAGRANT_FOLDER"; private String myVagrantFolder; public VagrantBasedCredentialsHolder() { @@ -38,4 +41,12 @@ public class VagrantBasedCredentialsHolder { public String getVagrantFolder() { return myVagrantFolder; } + + public void load(Element element) { + setVagrantFolder(element.getAttributeValue(VAGRANT_FOLDER)); + } + + public void save(Element element) { + element.setAttribute(VAGRANT_FOLDER, getVagrantFolder()); + } } diff --git a/platform/util/src/com/intellij/openapi/util/JDOMExternalizer.java b/platform/util/src/com/intellij/openapi/util/JDOMExternalizer.java index 72dc236f0935..909c44db199b 100644 --- a/platform/util/src/com/intellij/openapi/util/JDOMExternalizer.java +++ b/platform/util/src/com/intellij/openapi/util/JDOMExternalizer.java @@ -19,6 +19,7 @@ import com.intellij.openapi.util.text.StringUtil; import com.intellij.util.ArrayUtil; import org.jdom.Element; import org.jetbrains.annotations.NonNls; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.*; @@ -104,4 +105,15 @@ public class JDOMExternalizer { } } } + + public static List loadStringsList(Element element, String rootName, String attrName) { + final List paths = new LinkedList(); + if (element != null) { + @NotNull final List list = element.getChildren(rootName); + for (Object o : list) { + paths.add(((Element)o).getAttribute(attrName).getValue()); + } + } + return paths; + } } \ No newline at end of file diff --git a/python/src/com/jetbrains/python/sdk/PythonSdkAdditionalData.java b/python/src/com/jetbrains/python/sdk/PythonSdkAdditionalData.java index c2680224e28a..8d7ea12aa5ac 100644 --- a/python/src/com/jetbrains/python/sdk/PythonSdkAdditionalData.java +++ b/python/src/com/jetbrains/python/sdk/PythonSdkAdditionalData.java @@ -35,6 +35,8 @@ import java.util.LinkedList; import java.util.List; import java.util.Set; +import static com.intellij.openapi.util.JDOMExternalizer.loadStringsList; + /** * @author traff */ @@ -181,16 +183,7 @@ public class PythonSdkAdditionalData implements SdkAdditionalData { return files; } - protected static List loadStringsList(Element element, String rootName, String attrName) { - final List paths = new LinkedList(); - if (element != null) { - @NotNull final List list = element.getChildren(rootName); - for (Object o : list) { - paths.add(((Element)o).getAttribute(attrName).getValue()); - } - } - return paths; - } + public Set getAddedPathFiles() { return getPathsAsVirtualFiles(myAddedPaths);