comparison src/org/tmatesoft/hg/internal/remote/SshConnector.java @ 698:822f3a83ff57

in, out and clone tests pass for ssh repositories. Infrastructure to decouple HgRemoteRepository from specific Connector implementation
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Tue, 06 Aug 2013 21:18:33 +0200
parents 24f4efedc9d5
children a483b2b68a2e
comparison
equal deleted inserted replaced
697:24f4efedc9d5 698:822f3a83ff57
26 import java.io.IOException; 26 import java.io.IOException;
27 import java.io.InputStream; 27 import java.io.InputStream;
28 import java.io.InputStreamReader; 28 import java.io.InputStreamReader;
29 import java.io.OutputStream; 29 import java.io.OutputStream;
30 import java.io.SequenceInputStream; 30 import java.io.SequenceInputStream;
31 import java.net.URL; 31 import java.net.URI;
32 import java.util.ArrayList; 32 import java.util.ArrayList;
33 import java.util.Collection; 33 import java.util.Collection;
34 import java.util.Collections; 34 import java.util.Collections;
35 import java.util.List; 35 import java.util.List;
36 36
52 * @author Artem Tikhomirov 52 * @author Artem Tikhomirov
53 * @author TMate Software Ltd. 53 * @author TMate Software Ltd.
54 */ 54 */
55 public class SshConnector implements Connector { 55 public class SshConnector implements Connector {
56 private SessionContext sessionCtx; 56 private SessionContext sessionCtx;
57 private URL url; 57 private URI uri;
58 private Connection conn; 58 private Connection conn;
59 private Session session; 59 private Session session;
60 private int sessionUse; 60 private int sessionUse;
61 61
62 private StreamGobbler remoteErr, remoteOut; 62 private StreamGobbler remoteErr, remoteOut;
63 private OutputStream remoteIn; 63 private OutputStream remoteIn;
64 64
65 public void init(URL url, SessionContext sessionContext, Object globalConfig) throws HgRuntimeException { 65 public void init(URI uri, SessionContext sessionContext, Object globalConfig) throws HgRuntimeException {
66 sessionCtx = sessionContext; 66 sessionCtx = sessionContext;
67 this.url = url; 67 this.uri = uri;
68 } 68 }
69 69
70 public void connect() throws HgRemoteConnectionException, HgRuntimeException { 70 public void connect() throws HgRemoteConnectionException, HgRuntimeException {
71 try { 71 try {
72 conn = new Connection(url.getHost(), url.getPort() == -1 ? 22 : url.getPort()); 72 conn = new Connection(uri.getHost(), uri.getPort() == -1 ? 22 : uri.getPort());
73 conn.connect(); 73 conn.connect();
74 } catch (IOException ex) { 74 } catch (IOException ex) {
75 throw new HgRemoteConnectionException("Failed to establish connection"); 75 throw new HgRemoteConnectionException("Failed to establish connection");
76 } 76 }
77 try { 77 try {
99 sessionUse++; 99 sessionUse++;
100 return; 100 return;
101 } 101 }
102 try { 102 try {
103 session = conn.openSession(); 103 session = conn.openSession();
104 final String path = url.getPath(); 104 final String path = uri.getPath();
105 session.execCommand(String.format("hg -R %s serve --stdio", path.charAt(0) == '/' ? path.substring(1) : path)); 105 session.execCommand(String.format("hg -R %s serve --stdio", path.charAt(0) == '/' ? path.substring(1) : path));
106 remoteErr = new StreamGobbler(session.getStderr()); 106 remoteErr = new StreamGobbler(session.getStderr());
107 remoteOut = new StreamGobbler(session.getStdout()); 107 remoteOut = new StreamGobbler(session.getStdout());
108 remoteIn = session.getStdin(); 108 remoteIn = session.getStdin();
109 sessionUse = 1; 109 sessionUse = 1;
121 } 121 }
122 forceSessionClose(); 122 forceSessionClose();
123 } 123 }
124 124
125 public String getServerLocation() { 125 public String getServerLocation() {
126 return url.toString(); // FIXME 126 return uri.toString(); // FIXME
127 } 127 }
128 128
129 public String getCapabilities() throws HgRemoteConnectionException { 129 public String getCapabilities() throws HgRemoteConnectionException {
130 try { 130 try {
131 consume(remoteOut); 131 consume(remoteOut);