diff src/org/tmatesoft/hg/repo/HgRemoteRepository.java @ 181:cd3371670f0b

Refactor incoming and outgoing code to be shared with RepositoryComparator. Placeholders for in/out commands. Refactor common remote lookup code
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Tue, 12 Apr 2011 19:10:38 +0200
parents da426c2fe1ec
children ec1820f64d2b
line wrap: on
line diff
--- a/src/org/tmatesoft/hg/repo/HgRemoteRepository.java	Wed Apr 06 03:08:05 2011 +0200
+++ b/src/org/tmatesoft/hg/repo/HgRemoteRepository.java	Tue Apr 12 19:10:38 2011 +0200
@@ -46,6 +46,7 @@
 import javax.net.ssl.TrustManager;
 import javax.net.ssl.X509TrustManager;
 
+import org.tmatesoft.hg.core.HgBadArgumentException;
 import org.tmatesoft.hg.core.HgBadStateException;
 import org.tmatesoft.hg.core.HgException;
 import org.tmatesoft.hg.core.Nodeid;
@@ -63,9 +64,9 @@
 	private final URL url;
 	private final SSLContext sslContext;
 	private final String authInfo;
-	private final boolean debug = Boolean.FALSE.booleanValue();
+	private final boolean debug = Boolean.parseBoolean(System.getProperty("hg4j.remote.debug"));
 
-	HgRemoteRepository(URL url) throws HgException {
+	HgRemoteRepository(URL url) throws HgBadArgumentException {
 		if (url == null) {
 			throw new IllegalArgumentException();
 		}
@@ -86,7 +87,7 @@
 				};
 				sslContext.init(null, new TrustManager[] { new TrustEveryone() }, null);
 			} catch (Exception ex) {
-				throw new HgException(ex);
+				throw new HgBadArgumentException("Can't initialize secure connection", ex);
 			}
 		} else {
 			sslContext = null;
@@ -109,6 +110,28 @@
 		}
 	}
 	
+	public boolean isInvalid() throws HgException {
+		// say hello to server, check response
+		if (Boolean.FALSE.booleanValue()) {
+			throw HgRepository.notImplemented();
+		}
+		return false; // FIXME
+	}
+
+	/**
+	 * @return human-readable address of the server, without user credentials or any other security information
+	 */
+	public String getLocation() {
+		if (url.getUserInfo() == null) {
+			return url.toExternalForm();
+		}
+		if (url.getPort() != -1) {
+			return String.format("%s://%s:%d%s", url.getProtocol(), url.getHost(), url.getPort(), url.getPath());
+		} else {
+			return String.format("%s://%s%s", url.getProtocol(), url.getHost(), url.getPath());
+		}
+	}
+
 	public List<Nodeid> heads() throws HgException {
 		try {
 			URL u = new URL(url, url.getPath() + "?cmd=heads");