WEB-22114 Node.js Remote Interpreter plugin breaks possibility to manage Node versions in Run Configuration

(cherry picked from commit cb6a72f)
This commit is contained in:
irengrig
2016-07-29 13:11:36 +02:00
committed by irengrig
parent 32c695966e
commit 84ffb21f00
5 changed files with 160 additions and 0 deletions
@@ -30,6 +30,7 @@ public abstract class CredentialsType<T> {
public static final Key<VagrantBasedCredentialsHolder> VAGRANT_BASED_CREDENTIALS = Key.create("VAGRANT_BASED_CREDENTIALS");
public static final Key<WebDeploymentCredentialsHolder> WEB_DEPLOYMENT_BASED_CREDENTIALS = Key.create("WEB_DEPLOYMENT_BASED_CREDENTIALS");
public static final Key<RemoteCredentialsHolder> PLAIN_SSH_CREDENTIALS = Key.create("PLAIN_SSH_CREDENTIALS");
public static final Key<UnknownCredentialsHolder> UNKNOWN_CREDENTIALS = Key.create("PLAIN_SSH_CREDENTIALS");
public static final CredentialsType<RemoteCredentialsHolder> SSH_HOST
= new CredentialsType<RemoteCredentialsHolder>("SSH Credentials", RemoteCredentialsHolder.SSH_PREFIX) {
@@ -87,6 +88,23 @@ public abstract class CredentialsType<T> {
}
};
public static final CredentialsType<UnknownCredentialsHolder> UNKNOWN = new CredentialsType<UnknownCredentialsHolder>("Unknown", "") {
@Override
public Key<UnknownCredentialsHolder> 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;
@@ -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();
}
@@ -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);
}
}
@@ -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<String, String> 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<String, String> getAttributes() {
return myAttributes;
}
public void save(@NotNull Element element) {
for (Map.Entry<String, String> 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;
}
}
@@ -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<UnknownCredentialsHolder> {
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);
}
}