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
;
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
,
42 ConnectionSettingsImpl connectionSettings
= new ConnectionSettingsImpl(settings
.HOST
,
44 proxySettings
.USE_PROXY
,
45 proxySettings
.PROXY_HOST
,
46 proxySettings
.PROXY_PORT
,
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());
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;
67 return Integer
.parseInt(port
);
69 catch (NumberFormatException e
) {
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
,
81 if (extConfiguration
.USE_INTERNAL_SSH_IMPLEMENTATION
) {
82 return createSshConnection(settings
, sshConfiguration
, proxySettings
,
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
,
94 proxySettings
.USE_PROXY
,
95 proxySettings
.PROXY_HOST
,
96 proxySettings
.PROXY_PORT
,
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('\\', '/');