comparison src/org/tmatesoft/hg/repo/HgLookup.java @ 699:a483b2b68a2e

Provisional APIs and respective implementation for http, https and ssh remote repositories
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Thu, 08 Aug 2013 19:18:50 +0200
parents 822f3a83ff57
children
comparison
equal deleted inserted replaced
698:822f3a83ff57 699:a483b2b68a2e
17 package org.tmatesoft.hg.repo; 17 package org.tmatesoft.hg.repo;
18 18
19 import static org.tmatesoft.hg.util.LogFacility.Severity.Warn; 19 import static org.tmatesoft.hg.util.LogFacility.Severity.Warn;
20 20
21 import java.io.File; 21 import java.io.File;
22 import java.io.InputStream;
23 import java.net.URI; 22 import java.net.URI;
24 import java.net.URISyntaxException; 23 import java.net.URISyntaxException;
25 import java.net.URL; 24 import java.net.URL;
26 import java.net.URLStreamHandler; 25 import java.net.URLStreamHandler;
27 import java.net.URLStreamHandlerFactory; 26 import java.net.URLStreamHandlerFactory;
31 import org.tmatesoft.hg.core.HgRepositoryNotFoundException; 30 import org.tmatesoft.hg.core.HgRepositoryNotFoundException;
32 import org.tmatesoft.hg.core.SessionContext; 31 import org.tmatesoft.hg.core.SessionContext;
33 import org.tmatesoft.hg.internal.BasicSessionContext; 32 import org.tmatesoft.hg.internal.BasicSessionContext;
34 import org.tmatesoft.hg.internal.ConfigFile; 33 import org.tmatesoft.hg.internal.ConfigFile;
35 import org.tmatesoft.hg.internal.DataAccessProvider; 34 import org.tmatesoft.hg.internal.DataAccessProvider;
36 import org.tmatesoft.hg.internal.Experimental;
37 import org.tmatesoft.hg.internal.RequiresFile; 35 import org.tmatesoft.hg.internal.RequiresFile;
38 import org.tmatesoft.hg.repo.HgRepoConfig.PathsSection; 36 import org.tmatesoft.hg.repo.HgRepoConfig.PathsSection;
39 37
40 /** 38 /**
41 * Utility methods to find Mercurial repository at a given location 39 * Utility methods to find Mercurial repository at a given location
182 * @param uriRemote remote repository location 180 * @param uriRemote remote repository location
183 * @return instance to interact with remote repository 181 * @return instance to interact with remote repository
184 * @throws HgBadArgumentException 182 * @throws HgBadArgumentException
185 */ 183 */
186 public HgRemoteRepository detectRemote(URI uriRemote) throws HgBadArgumentException { 184 public HgRemoteRepository detectRemote(URI uriRemote) throws HgBadArgumentException {
187 RemoteDescriptor rd = getSessionContext().getRemoteDescriptor(uriRemote); 185 HgRemoteRepository.RemoteDescriptor rd = getSessionContext().getRemoteDescriptor(uriRemote);
188 if (rd == null) { 186 if (rd == null) {
189 throw new HgBadArgumentException(String.format("Unsupported remote repository location:%s", uriRemote), null); 187 throw new HgBadArgumentException(String.format("Unsupported remote repository location:%s", uriRemote), null);
190 } 188 }
191 return new HgRemoteRepository(getSessionContext(), rd); 189 return new HgRemoteRepository(getSessionContext(), rd);
192 } 190 }
208 if (sessionContext == null) { 206 if (sessionContext == null) {
209 sessionContext = new BasicSessionContext(null); 207 sessionContext = new BasicSessionContext(null);
210 } 208 }
211 return sessionContext; 209 return sessionContext;
212 } 210 }
213
214
215 /**
216 * Session context ({@link SessionContext#getRemoteDescriptor(URI)} gives descriptor of remote when asked.
217 */
218 @Experimental(reason="Work in progress")
219 public interface RemoteDescriptor {
220 URI getURI();
221 Authenticator getAuth();
222 }
223
224 @Experimental(reason="Work in progress")
225 public interface Authenticator {
226 public void authenticate(RemoteDescriptor remote, AuthMethod authMethod);
227 }
228
229 /**
230 * Clients do not implement this interface, instead, they invoke appropriate authentication method
231 * once they got user input
232 */
233 @Experimental(reason="Work in progress")
234 public interface AuthMethod {
235 public void noCredentials() throws AuthFailedException;
236 public boolean supportsPassword();
237 public void withPassword(String username, byte[] password) throws AuthFailedException;
238 public boolean supportsPublicKey();
239 public void withPublicKey(String username, InputStream publicKey, String passphrase) throws AuthFailedException;
240 public boolean supportsCertificate();
241 public void withCertificate() throws AuthFailedException;
242 }
243
244 @SuppressWarnings("serial")
245 public class AuthFailedException extends Exception /*XXX HgRemoteException?*/ {
246 public AuthFailedException(String message, Throwable cause) {
247 super(message, cause);
248 }
249 }
250 } 211 }