From 84ffb21f008c4d9c2bc40ee52ed57df623c60cd7 Mon Sep 17 00:00:00 2001 From: irengrig Date: Fri, 29 Jul 2016 11:41:28 +0200 Subject: [PATCH] WEB-22114 Node.js Remote Interpreter plugin breaks possibility to manage Node versions in Run Configuration (cherry picked from commit cb6a72f) --- .../com/intellij/remote/CredentialsType.java | 18 ++++ .../RemoteConnectionCredentialsWrapper.java | 3 + .../remote/ext/CredentialsManagerImpl.java | 4 + .../remote/ext/UnknownCredentialsHolder.java | 86 +++++++++++++++++++ .../UnknownTypeRemoteCredentialHandler.java | 49 +++++++++++ 5 files changed, 160 insertions(+) create mode 100644 platform/platform-impl/src/com/intellij/remote/ext/UnknownCredentialsHolder.java create mode 100644 platform/platform-impl/src/com/intellij/remote/ext/UnknownTypeRemoteCredentialHandler.java diff --git a/platform/platform-impl/src/com/intellij/remote/CredentialsType.java b/platform/platform-impl/src/com/intellij/remote/CredentialsType.java index 43e09f02b057..ddfdb7415232 100644 --- a/platform/platform-impl/src/com/intellij/remote/CredentialsType.java +++ b/platform/platform-impl/src/com/intellij/remote/CredentialsType.java @@ -30,6 +30,7 @@ public abstract class CredentialsType { public static final Key VAGRANT_BASED_CREDENTIALS = Key.create("VAGRANT_BASED_CREDENTIALS"); public static final Key WEB_DEPLOYMENT_BASED_CREDENTIALS = Key.create("WEB_DEPLOYMENT_BASED_CREDENTIALS"); public static final Key PLAIN_SSH_CREDENTIALS = Key.create("PLAIN_SSH_CREDENTIALS"); + public static final Key UNKNOWN_CREDENTIALS = Key.create("PLAIN_SSH_CREDENTIALS"); public static final CredentialsType SSH_HOST = new CredentialsType("SSH Credentials", RemoteCredentialsHolder.SSH_PREFIX) { @@ -87,6 +88,23 @@ public abstract class CredentialsType { } }; + public static final CredentialsType UNKNOWN = new CredentialsType("Unknown", "") { + @Override + public Key getCredentialsKey() { + return UNKNOWN_CREDENTIALS; + } + + @Override + public RemoteCredentialsHandler getHandler(UnknownCredentialsHolder credentials) { + return new UnknownTypeRemoteCredentialHandler(credentials); + } + + @Override + public UnknownCredentialsHolder createCredentials() { + return new UnknownCredentialsHolder(); + } + }; + private final String myName; private final String myPrefix; diff --git a/platform/platform-impl/src/com/intellij/remote/RemoteConnectionCredentialsWrapper.java b/platform/platform-impl/src/com/intellij/remote/RemoteConnectionCredentialsWrapper.java index 5a714e0856fb..ef79dbd25832 100644 --- a/platform/platform-impl/src/com/intellij/remote/RemoteConnectionCredentialsWrapper.java +++ b/platform/platform-impl/src/com/intellij/remote/RemoteConnectionCredentialsWrapper.java @@ -21,6 +21,7 @@ import com.intellij.openapi.util.UserDataHolderBase; import com.intellij.remote.ext.CredentialsCase; import com.intellij.remote.ext.CredentialsManager; import com.intellij.remote.ext.RemoteCredentialsHandler; +import com.intellij.remote.ext.UnknownCredentialsHolder; import org.jdom.Element; import org.jetbrains.annotations.NotNull; @@ -82,6 +83,8 @@ public class RemoteConnectionCredentialsWrapper { return Pair.create(credentials, type); } } + final UnknownCredentialsHolder credentials = CredentialsType.UNKNOWN.getCredentials(myCredentialsTypeHolder); + if (credentials != null) return Pair.create(credentials, CredentialsType.UNKNOWN); throw unknownConnectionType(); } diff --git a/platform/platform-impl/src/com/intellij/remote/ext/CredentialsManagerImpl.java b/platform/platform-impl/src/com/intellij/remote/ext/CredentialsManagerImpl.java index 58c59c2cfac7..08741c8392bf 100644 --- a/platform/platform-impl/src/com/intellij/remote/ext/CredentialsManagerImpl.java +++ b/platform/platform-impl/src/com/intellij/remote/ext/CredentialsManagerImpl.java @@ -48,7 +48,11 @@ public class CredentialsManagerImpl extends CredentialsManager { Object credentials = type.createCredentials(); type.getHandler(credentials).load(element); data.setCredentials(type.getCredentialsKey(), credentials); + return; } } + final UnknownCredentialsHolder credentials = CredentialsType.UNKNOWN.createCredentials(); + credentials.setInterpreterPath(interpreterPath); + data.setCredentials(CredentialsType.UNKNOWN_CREDENTIALS, credentials); } } diff --git a/platform/platform-impl/src/com/intellij/remote/ext/UnknownCredentialsHolder.java b/platform/platform-impl/src/com/intellij/remote/ext/UnknownCredentialsHolder.java new file mode 100644 index 000000000000..8fdfd437e14b --- /dev/null +++ b/platform/platform-impl/src/com/intellij/remote/ext/UnknownCredentialsHolder.java @@ -0,0 +1,86 @@ +/* + * Copyright 2000-2016 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.ext; + +import org.jdom.Attribute; +import org.jdom.Element; +import org.jetbrains.annotations.NotNull; + +import java.util.HashMap; +import java.util.Map; + +/** + * @author Irina.Chernushina on 7/29/2016. + */ +public class UnknownCredentialsHolder { + private String myInterpreterPath; + @NotNull + private final Map myAttributes = new HashMap<>(); + + public UnknownCredentialsHolder(String interpreterPath) { + myInterpreterPath = interpreterPath; + } + + public UnknownCredentialsHolder() { + myInterpreterPath = ""; + } + + public String getInterpreterPath() { + return myInterpreterPath; + } + + public void setInterpreterPath(String interpreterPath) { + myInterpreterPath = interpreterPath; + } + + @NotNull + public Map getAttributes() { + return myAttributes; + } + + public void save(@NotNull Element element) { + for (Map.Entry entry : myAttributes.entrySet()) { + element.setAttribute(entry.getKey(), entry.getValue()); + } + } + + public void load(@NotNull Element element) { + myAttributes.clear(); + for (Attribute attribute : element.getAttributes()) { + myAttributes.put(attribute.getName(), attribute.getValue()); + } + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + UnknownCredentialsHolder holder = (UnknownCredentialsHolder)o; + + if (myInterpreterPath != null ? !myInterpreterPath.equals(holder.myInterpreterPath) : holder.myInterpreterPath != null) return false; + if (!myAttributes.equals(holder.myAttributes)) return false; + + return true; + } + + @Override + public int hashCode() { + int result = myInterpreterPath != null ? myInterpreterPath.hashCode() : 0; + result = 31 * result + myAttributes.hashCode(); + return result; + } +} diff --git a/platform/platform-impl/src/com/intellij/remote/ext/UnknownTypeRemoteCredentialHandler.java b/platform/platform-impl/src/com/intellij/remote/ext/UnknownTypeRemoteCredentialHandler.java new file mode 100644 index 000000000000..aa898d48160e --- /dev/null +++ b/platform/platform-impl/src/com/intellij/remote/ext/UnknownTypeRemoteCredentialHandler.java @@ -0,0 +1,49 @@ +/* + * Copyright 2000-2016 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.ext; + +import org.jdom.Element; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * @author Irina.Chernushina on 7/29/2016. + */ +public class UnknownTypeRemoteCredentialHandler extends RemoteCredentialsHandlerBase { + public UnknownTypeRemoteCredentialHandler(UnknownCredentialsHolder credentials) { + super(credentials); + } + + @Override + public String getId() { + return getCredentials().getInterpreterPath(); + } + + @Override + public void save(@NotNull Element rootElement) { + getCredentials().save(rootElement); + } + + @Override + public String getPresentableDetails(String interpreterPath) { + return getId(); + } + + @Override + public void load(@Nullable Element rootElement) { + getCredentials().load(rootElement); + } +}