summaryrefslogtreecommitdiff
path: root/platform/platform-impl/src/com/intellij/remotesdk/RemoteSdkDataBuilder.java
blob: c1e9a822a0626e0b70d7f2fcf8d267a4e70ee31c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/*
 * Copyright 2000-2013 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.remotesdk;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

/**
 * @author traff
 */
public class RemoteSdkDataBuilder {
  private String myInterpreterPath = null;
  private String myHelpersPath = null;
  private RemoteCredentials myRemoteCredentials = null;
  private String myHelpersDefaultDirName = ".idea_helpers";


  public RemoteSdkData build() {
    RemoteSdkData result = new RemoteSdkDataHolder(myHelpersDefaultDirName);

    if (myRemoteCredentials != null) {
      copyCredentials(myRemoteCredentials, result);
    }

    if (myInterpreterPath != null) {
      result.setInterpreterPath(myInterpreterPath);
    }

    if (myHelpersPath != null) {
      result.setHelpersPath(myHelpersPath);
    }

    return result;
  }


  public static void copyRemoteSdkData(@NotNull RemoteSdkData data, @NotNull RemoteSdkData copyTo) {
    copyCredentials(data, copyTo);

    copyTo.setInterpreterPath(data.getInterpreterPath());
    copyTo.setHelpersPath(data.getHelpersPath());

    copyTo.setHelpersVersionChecked(data.isHelpersVersionChecked());
    copyTo.setRemoteRoots(data.getRemoteRoots());
  }

  public static void copyCredentials(RemoteCredentials data, MutableRemoteCredentials copyTo) {
    copyTo.setHost(data.getHost());
    copyTo.setPort(data.getPort());
    copyTo.setAnonymous(data.isAnonymous());
    copyTo.setUserName(data.getUserName());
    copyTo.setPassword(data.getPassword());
    copyTo.setPrivateKeyFile(data.getPrivateKeyFile());
    copyTo.setKnownHostsFile(data.getKnownHostsFile());
    copyTo.setPassphrase(data.getPassphrase());
    copyTo.setUseKeyPair(data.isUseKeyPair());

    copyTo.setStorePassword(data.isStorePassword());
    copyTo.setStorePassphrase(data.isStorePassphrase());
  }

  public RemoteSdkDataBuilder withCredentials(@Nullable RemoteCredentials remoteCredentials) {
    myRemoteCredentials = remoteCredentials;
    return this;
  }

  public RemoteSdkDataBuilder withInterpreterPath(String interpreterPath) {
    myInterpreterPath = interpreterPath;
    return this;
  }
}