IDEA-25467 (CVS is set to Offline mode on project open) - integration to trunk
[fedora-idea.git] / plugins / cvs / cvs-core / src / com / intellij / cvsSupport2 / connections / CvsConnectionUtil.java
blob7f9e9d5d871d7bbd073ba58fa67c10c76f4e516e
1 /*
2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package com.intellij.cvsSupport2.connections;
19 import com.intellij.cvsSupport2.config.ExtConfiguration;
20 import com.intellij.cvsSupport2.config.ProxySettings;
21 import com.intellij.cvsSupport2.config.SshSettings;
22 import com.intellij.cvsSupport2.connections.ext.ExtConnection;
23 import com.intellij.cvsSupport2.connections.ssh.*;
24 import com.intellij.cvsSupport2.errorHandling.ErrorRegistry;
25 import org.netbeans.lib.cvsclient.connection.ConnectionSettings;
26 import org.netbeans.lib.cvsclient.connection.IConnection;
27 import org.netbeans.lib.cvsclient.connection.PServerConnection;
29 import java.io.File;
31 public class CvsConnectionUtil {
32 public static final int DEFAULT_PSERVER_PORT = 2401;
34 private CvsConnectionUtil() {
37 public static IConnection createSshConnection(final CvsRootData settings,
38 final SshSettings sshConfiguration,
39 final ProxySettings proxySettings,
40 final SSHPasswordProvider sshPasswordProvider,
41 final int timeout) {
42 ConnectionSettingsImpl connectionSettings = new ConnectionSettingsImpl(settings.HOST,
43 settings.PORT,
44 proxySettings.USE_PROXY,
45 proxySettings.PROXY_HOST,
46 proxySettings.PROXY_PORT,
47 timeout,
48 proxySettings.getType(),
49 proxySettings.getLogin(),
50 proxySettings.getPassword());
51 //final EmptyPool pool = EmptyPool.getInstance();
52 final ConnectionPoolI pool = SshConnectionPool.getInstance();
53 final SshAuthentication authentication;
54 if (sshConfiguration.USE_PPK) {
55 authentication = new SshPublicKeyAuthentication(new File(sshConfiguration.PATH_TO_PPK), settings.USER, sshPasswordProvider,
56 settings.getCvsRootAsString());
58 else {
59 authentication = new SshPasswordAuthentication(settings.USER, sshPasswordProvider, settings.getCvsRootAsString());
61 return pool.getConnection(settings.REPOSITORY, connectionSettings, authentication);
64 public static int getPort(final String port) {
65 if (port.length() == 0) return 22;
66 try {
67 return Integer.parseInt(port);
69 catch (NumberFormatException e) {
70 return 22;
74 public static IConnection createExtConnection(final CvsRootData settings,
75 final ExtConfiguration extConfiguration,
76 final SshSettings sshConfiguration,
77 final SSHPasswordProvider sshPasswordProvider,
78 final ProxySettings proxySettings,
79 final ErrorRegistry errorRegistry,
80 final int timeout) {
81 if (extConfiguration.USE_INTERNAL_SSH_IMPLEMENTATION) {
82 return createSshConnection(settings, sshConfiguration, proxySettings,
83 sshPasswordProvider,
84 timeout);
86 else {
87 return new ExtConnection(settings.HOST, settings.USER, settings.REPOSITORY, extConfiguration, errorRegistry);
91 public static IConnection createPServerConnection(CvsRootData root, ProxySettings proxySettings, final int timeout) {
92 ConnectionSettings connectionSettings = new ConnectionSettingsImpl(root.HOST,
93 root.PORT,
94 proxySettings.USE_PROXY,
95 proxySettings.PROXY_HOST,
96 proxySettings.PROXY_PORT,
97 timeout,
98 proxySettings.TYPE,
99 proxySettings.getLogin(),
100 proxySettings.getPassword());
102 return new PServerConnection(connectionSettings, root.USER, root.PASSWORD, adjustRepository(root));
105 public static String adjustRepository(CvsRootData root) {
106 if (root.REPOSITORY != null) {
107 return root.REPOSITORY.replace('\\', '/');
108 } else {
109 return null;