annotate src/org/tmatesoft/hg/repo/HgLookup.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 6526d8adbc0f
children a483b2b68a2e
rev   line source
74
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
1 /*
578
f97e81d13190 Throw exception if repository encountered is too old for Hg4J
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 526
diff changeset
2 * Copyright (c) 2010-2013 TMate Software Ltd
74
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
3 *
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
4 * This program is free software; you can redistribute it and/or modify
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
5 * it under the terms of the GNU General Public License as published by
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
6 * the Free Software Foundation; version 2 of the License.
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
7 *
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
8 * This program is distributed in the hope that it will be useful,
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
11 * GNU General Public License for more details.
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
12 *
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
13 * For information on how to redistribute this software under
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
14 * the terms of a license other than GNU General Public License
102
a3a2e5deb320 Updated contact address to support@hg4j.com
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 95
diff changeset
15 * contact TMate Software at support@hg4j.com
2
08db726a0fb7 Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
16 */
74
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
17 package org.tmatesoft.hg.repo;
2
08db726a0fb7 Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
18
456
909306e412e2 Refactor LogFacility and SessionContext, better API for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 431
diff changeset
19 import static org.tmatesoft.hg.util.LogFacility.Severity.Warn;
909306e412e2 Refactor LogFacility and SessionContext, better API for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 431
diff changeset
20
2
08db726a0fb7 Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
21 import java.io.File;
698
822f3a83ff57 in, out and clone tests pass for ssh repositories. Infrastructure to decouple HgRemoteRepository from specific Connector implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
22 import java.io.InputStream;
822f3a83ff57 in, out and clone tests pass for ssh repositories. Infrastructure to decouple HgRemoteRepository from specific Connector implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
23 import java.net.URI;
822f3a83ff57 in, out and clone tests pass for ssh repositories. Infrastructure to decouple HgRemoteRepository from specific Connector implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
24 import java.net.URISyntaxException;
170
71ddbf8603e8 Initial clone: populate given directory from a bundle. Everything but remote server access is there, albeit prototype code style
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 169
diff changeset
25 import java.net.URL;
698
822f3a83ff57 in, out and clone tests pass for ssh repositories. Infrastructure to decouple HgRemoteRepository from specific Connector implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
26 import java.net.URLStreamHandler;
822f3a83ff57 in, out and clone tests pass for ssh repositories. Infrastructure to decouple HgRemoteRepository from specific Connector implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
27 import java.net.URLStreamHandlerFactory;
148
1a7a9a20e1f9 Exceptions, javadoc. Initial cancel and progress support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
28
181
cd3371670f0b Refactor incoming and outgoing code to be shared with RepositoryComparator. Placeholders for in/out commands. Refactor common remote lookup code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
29 import org.tmatesoft.hg.core.HgBadArgumentException;
628
6526d8adbc0f Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 622
diff changeset
30 import org.tmatesoft.hg.core.HgIOException;
423
9c9c442b5f2e Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 357
diff changeset
31 import org.tmatesoft.hg.core.HgRepositoryNotFoundException;
295
981f9f50bb6c Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 215
diff changeset
32 import org.tmatesoft.hg.core.SessionContext;
981f9f50bb6c Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 215
diff changeset
33 import org.tmatesoft.hg.internal.BasicSessionContext;
181
cd3371670f0b Refactor incoming and outgoing code to be shared with RepositoryComparator. Placeholders for in/out commands. Refactor common remote lookup code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
34 import org.tmatesoft.hg.internal.ConfigFile;
169
8c8e3f372fa1 Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 151
diff changeset
35 import org.tmatesoft.hg.internal.DataAccessProvider;
698
822f3a83ff57 in, out and clone tests pass for ssh repositories. Infrastructure to decouple HgRemoteRepository from specific Connector implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
36 import org.tmatesoft.hg.internal.Experimental;
578
f97e81d13190 Throw exception if repository encountered is too old for Hg4J
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 526
diff changeset
37 import org.tmatesoft.hg.internal.RequiresFile;
503
0bd2d0441d8f Add lookup of remote paths from repository's .hg/hgrc, respect default (origin)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 492
diff changeset
38 import org.tmatesoft.hg.repo.HgRepoConfig.PathsSection;
2
08db726a0fb7 Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
39
08db726a0fb7 Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
40 /**
148
1a7a9a20e1f9 Exceptions, javadoc. Initial cancel and progress support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
41 * Utility methods to find Mercurial repository at a given location
74
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
42 *
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
43 * @author Artem Tikhomirov
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 49
diff changeset
44 * @author TMate Software Ltd.
2
08db726a0fb7 Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
45 */
618
7c0d2ce340b8 Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 578
diff changeset
46 public class HgLookup implements SessionContext.Source {
2
08db726a0fb7 Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
47
181
cd3371670f0b Refactor incoming and outgoing code to be shared with RepositoryComparator. Placeholders for in/out commands. Refactor common remote lookup code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
48 private ConfigFile globalCfg;
295
981f9f50bb6c Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 215
diff changeset
49 private SessionContext sessionContext;
981f9f50bb6c Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 215
diff changeset
50
981f9f50bb6c Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 215
diff changeset
51 public HgLookup() {
981f9f50bb6c Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 215
diff changeset
52 }
981f9f50bb6c Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 215
diff changeset
53
981f9f50bb6c Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 215
diff changeset
54 public HgLookup(SessionContext ctx) {
981f9f50bb6c Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 215
diff changeset
55 sessionContext = ctx;
981f9f50bb6c Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 215
diff changeset
56 }
181
cd3371670f0b Refactor incoming and outgoing code to be shared with RepositoryComparator. Placeholders for in/out commands. Refactor common remote lookup code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
57
423
9c9c442b5f2e Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 357
diff changeset
58 public HgRepository detectFromWorkingDir() throws HgRepositoryNotFoundException {
2
08db726a0fb7 Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
59 return detect(System.getProperty("user.dir"));
08db726a0fb7 Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
60 }
08db726a0fb7 Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
61
423
9c9c442b5f2e Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 357
diff changeset
62 public HgRepository detect(String location) throws HgRepositoryNotFoundException {
95
bcd31a4c638a Lookup to HgLookup
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 74
diff changeset
63 return detect(new File(location));
bcd31a4c638a Lookup to HgLookup
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 74
diff changeset
64 }
bcd31a4c638a Lookup to HgLookup
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 74
diff changeset
65
578
f97e81d13190 Throw exception if repository encountered is too old for Hg4J
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 526
diff changeset
66 /**
f97e81d13190 Throw exception if repository encountered is too old for Hg4J
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 526
diff changeset
67 * Look up repository in specified location and above
f97e81d13190 Throw exception if repository encountered is too old for Hg4J
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 526
diff changeset
68 *
f97e81d13190 Throw exception if repository encountered is too old for Hg4J
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 526
diff changeset
69 * @param location where to look for .hg directory, never <code>null</code>
f97e81d13190 Throw exception if repository encountered is too old for Hg4J
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 526
diff changeset
70 * @return repository object, never <code>null</code>
f97e81d13190 Throw exception if repository encountered is too old for Hg4J
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 526
diff changeset
71 * @throws HgRepositoryNotFoundException if no repository found, or repository version is not supported
f97e81d13190 Throw exception if repository encountered is too old for Hg4J
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 526
diff changeset
72 */
423
9c9c442b5f2e Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 357
diff changeset
73 public HgRepository detect(File location) throws HgRepositoryNotFoundException {
492
e4eaa23e3442 Leave path as close as possible to one supplied by user. No need to keep it as canonical
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 483
diff changeset
74 File dir = location.getAbsoluteFile();
e4eaa23e3442 Leave path as close as possible to one supplied by user. No need to keep it as canonical
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 483
diff changeset
75 File repository;
e4eaa23e3442 Leave path as close as possible to one supplied by user. No need to keep it as canonical
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 483
diff changeset
76 do {
e4eaa23e3442 Leave path as close as possible to one supplied by user. No need to keep it as canonical
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 483
diff changeset
77 repository = new File(dir, ".hg");
e4eaa23e3442 Leave path as close as possible to one supplied by user. No need to keep it as canonical
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 483
diff changeset
78 if (repository.exists() && repository.isDirectory()) {
e4eaa23e3442 Leave path as close as possible to one supplied by user. No need to keep it as canonical
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 483
diff changeset
79 break;
2
08db726a0fb7 Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
80 }
492
e4eaa23e3442 Leave path as close as possible to one supplied by user. No need to keep it as canonical
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 483
diff changeset
81 repository = null;
e4eaa23e3442 Leave path as close as possible to one supplied by user. No need to keep it as canonical
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 483
diff changeset
82 dir = dir.getParentFile();
e4eaa23e3442 Leave path as close as possible to one supplied by user. No need to keep it as canonical
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 483
diff changeset
83
e4eaa23e3442 Leave path as close as possible to one supplied by user. No need to keep it as canonical
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 483
diff changeset
84 } while(dir != null);
e4eaa23e3442 Leave path as close as possible to one supplied by user. No need to keep it as canonical
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 483
diff changeset
85 if (repository == null) {
e4eaa23e3442 Leave path as close as possible to one supplied by user. No need to keep it as canonical
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 483
diff changeset
86 throw new HgRepositoryNotFoundException(String.format("Can't locate .hg/ directory of Mercurial repository in %s nor in parent dirs", location)).setLocation(location.getPath());
148
1a7a9a20e1f9 Exceptions, javadoc. Initial cancel and progress support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
87 }
628
6526d8adbc0f Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 622
diff changeset
88 try {
6526d8adbc0f Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 622
diff changeset
89 String repoPath = repository.getParentFile().getAbsolutePath();
6526d8adbc0f Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 622
diff changeset
90 HgRepository rv = new HgRepository(getSessionContext(), repoPath, repository);
6526d8adbc0f Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 622
diff changeset
91 int requiresFlags = rv.getImplHelper().getRequiresFlags();
6526d8adbc0f Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 622
diff changeset
92 if ((requiresFlags & RequiresFile.REVLOGV1) == 0) {
6526d8adbc0f Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 622
diff changeset
93 throw new HgRepositoryNotFoundException(String.format("%s: repository version is not supported (Mercurial <0.9?)", repoPath)).setLocation(location.getPath());
6526d8adbc0f Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 622
diff changeset
94 }
6526d8adbc0f Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 622
diff changeset
95 return rv;
6526d8adbc0f Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 622
diff changeset
96 } catch (HgRuntimeException ex) {
6526d8adbc0f Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 622
diff changeset
97 HgRepositoryNotFoundException e = new HgRepositoryNotFoundException("Failed to initialize Hg4J library").setLocation(location.getPath());
6526d8adbc0f Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 622
diff changeset
98 e.initCause(ex);
6526d8adbc0f Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 622
diff changeset
99 throw e;
578
f97e81d13190 Throw exception if repository encountered is too old for Hg4J
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 526
diff changeset
100 }
4
aa1912c70b36 Fix offset issue for inline revlogs. Commandline processing.
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 2
diff changeset
101 }
169
8c8e3f372fa1 Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 151
diff changeset
102
425
48f993aa2f41 FIXMEs: exceptions, javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 423
diff changeset
103 public HgBundle loadBundle(File location) throws HgRepositoryNotFoundException {
169
8c8e3f372fa1 Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 151
diff changeset
104 if (location == null || !location.canRead()) {
425
48f993aa2f41 FIXMEs: exceptions, javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 423
diff changeset
105 throw new HgRepositoryNotFoundException(String.format("Can't read file %s", location)).setLocation(String.valueOf(location));
169
8c8e3f372fa1 Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 151
diff changeset
106 }
618
7c0d2ce340b8 Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 578
diff changeset
107 return new HgBundle(getSessionContext(), new DataAccessProvider(getSessionContext()), location).link();
169
8c8e3f372fa1 Towards initial clone: refactor HgBundle to provide slightly higher-level structure of the bundle
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 151
diff changeset
108 }
181
cd3371670f0b Refactor incoming and outgoing code to be shared with RepositoryComparator. Placeholders for in/out commands. Refactor common remote lookup code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
109
cd3371670f0b Refactor incoming and outgoing code to be shared with RepositoryComparator. Placeholders for in/out commands. Refactor common remote lookup code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
110 /**
503
0bd2d0441d8f Add lookup of remote paths from repository's .hg/hgrc, respect default (origin)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 492
diff changeset
111 * Try to instantiate remote server using an immediate url or an url from configuration files
0bd2d0441d8f Add lookup of remote paths from repository's .hg/hgrc, respect default (origin)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 492
diff changeset
112 *
0bd2d0441d8f Add lookup of remote paths from repository's .hg/hgrc, respect default (origin)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 492
diff changeset
113 * @param key either URL or a key from configuration file that points to remote server; if <code>null</code> or empty string, default remote location of the supplied repository (if any) is looked up
0bd2d0441d8f Add lookup of remote paths from repository's .hg/hgrc, respect default (origin)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 492
diff changeset
114 * @param hgRepo optional local repository to get default or otherwise configured remote location
181
cd3371670f0b Refactor incoming and outgoing code to be shared with RepositoryComparator. Placeholders for in/out commands. Refactor common remote lookup code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
115 * @return an instance featuring access to remote repository, check {@link HgRemoteRepository#isInvalid()} before actually using it
cd3371670f0b Refactor incoming and outgoing code to be shared with RepositoryComparator. Placeholders for in/out commands. Refactor common remote lookup code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
116 * @throws HgBadArgumentException if anything is wrong with the remote server's URL
cd3371670f0b Refactor incoming and outgoing code to be shared with RepositoryComparator. Placeholders for in/out commands. Refactor common remote lookup code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
117 */
cd3371670f0b Refactor incoming and outgoing code to be shared with RepositoryComparator. Placeholders for in/out commands. Refactor common remote lookup code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
118 public HgRemoteRepository detectRemote(String key, HgRepository hgRepo) throws HgBadArgumentException {
698
822f3a83ff57 in, out and clone tests pass for ssh repositories. Infrastructure to decouple HgRemoteRepository from specific Connector implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
119 URI uri;
181
cd3371670f0b Refactor incoming and outgoing code to be shared with RepositoryComparator. Placeholders for in/out commands. Refactor common remote lookup code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
120 Exception toReport;
cd3371670f0b Refactor incoming and outgoing code to be shared with RepositoryComparator. Placeholders for in/out commands. Refactor common remote lookup code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
121 try {
698
822f3a83ff57 in, out and clone tests pass for ssh repositories. Infrastructure to decouple HgRemoteRepository from specific Connector implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
122 uri = new URI(key);
181
cd3371670f0b Refactor incoming and outgoing code to be shared with RepositoryComparator. Placeholders for in/out commands. Refactor common remote lookup code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
123 toReport = null;
698
822f3a83ff57 in, out and clone tests pass for ssh repositories. Infrastructure to decouple HgRemoteRepository from specific Connector implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
124 } catch (URISyntaxException ex) {
822f3a83ff57 in, out and clone tests pass for ssh repositories. Infrastructure to decouple HgRemoteRepository from specific Connector implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
125 uri = null;
181
cd3371670f0b Refactor incoming and outgoing code to be shared with RepositoryComparator. Placeholders for in/out commands. Refactor common remote lookup code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
126 toReport = ex;
cd3371670f0b Refactor incoming and outgoing code to be shared with RepositoryComparator. Placeholders for in/out commands. Refactor common remote lookup code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
127 }
698
822f3a83ff57 in, out and clone tests pass for ssh repositories. Infrastructure to decouple HgRemoteRepository from specific Connector implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
128 if (uri == null) {
503
0bd2d0441d8f Add lookup of remote paths from repository's .hg/hgrc, respect default (origin)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 492
diff changeset
129 String server = null;
0bd2d0441d8f Add lookup of remote paths from repository's .hg/hgrc, respect default (origin)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 492
diff changeset
130 if (hgRepo != null && !hgRepo.isInvalid()) {
0bd2d0441d8f Add lookup of remote paths from repository's .hg/hgrc, respect default (origin)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 492
diff changeset
131 PathsSection ps = hgRepo.getConfiguration().getPaths();
622
4e6179bde4fc Update to comply with Java 1.5 target
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 618
diff changeset
132 server = key == null || key.trim().length() == 0 ? ps.getDefault() : ps.getString(key, null); // XXX Java 1.5 isEmpty()
503
0bd2d0441d8f Add lookup of remote paths from repository's .hg/hgrc, respect default (origin)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 492
diff changeset
133 } else if (key == null || key.trim().length() == 0) {
0bd2d0441d8f Add lookup of remote paths from repository's .hg/hgrc, respect default (origin)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 492
diff changeset
134 throw new HgBadArgumentException("Can't look up empty key in a global configuration", null);
0bd2d0441d8f Add lookup of remote paths from repository's .hg/hgrc, respect default (origin)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 492
diff changeset
135 }
0bd2d0441d8f Add lookup of remote paths from repository's .hg/hgrc, respect default (origin)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 492
diff changeset
136 if (server == null) {
0bd2d0441d8f Add lookup of remote paths from repository's .hg/hgrc, respect default (origin)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 492
diff changeset
137 server = getGlobalConfig().getSection("paths").get(key);
0bd2d0441d8f Add lookup of remote paths from repository's .hg/hgrc, respect default (origin)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 492
diff changeset
138 }
181
cd3371670f0b Refactor incoming and outgoing code to be shared with RepositoryComparator. Placeholders for in/out commands. Refactor common remote lookup code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
139 if (server == null) {
cd3371670f0b Refactor incoming and outgoing code to be shared with RepositoryComparator. Placeholders for in/out commands. Refactor common remote lookup code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
140 throw new HgBadArgumentException(String.format("Can't find server %s specification in the config", key), toReport);
cd3371670f0b Refactor incoming and outgoing code to be shared with RepositoryComparator. Placeholders for in/out commands. Refactor common remote lookup code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
141 }
cd3371670f0b Refactor incoming and outgoing code to be shared with RepositoryComparator. Placeholders for in/out commands. Refactor common remote lookup code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
142 try {
698
822f3a83ff57 in, out and clone tests pass for ssh repositories. Infrastructure to decouple HgRemoteRepository from specific Connector implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
143 uri = new URI(server);
822f3a83ff57 in, out and clone tests pass for ssh repositories. Infrastructure to decouple HgRemoteRepository from specific Connector implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
144 } catch (URISyntaxException ex) {
181
cd3371670f0b Refactor incoming and outgoing code to be shared with RepositoryComparator. Placeholders for in/out commands. Refactor common remote lookup code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
145 throw new HgBadArgumentException(String.format("Found %s server spec in the config, but failed to initialize with it", key), ex);
cd3371670f0b Refactor incoming and outgoing code to be shared with RepositoryComparator. Placeholders for in/out commands. Refactor common remote lookup code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
146 }
cd3371670f0b Refactor incoming and outgoing code to be shared with RepositoryComparator. Placeholders for in/out commands. Refactor common remote lookup code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
147 }
698
822f3a83ff57 in, out and clone tests pass for ssh repositories. Infrastructure to decouple HgRemoteRepository from specific Connector implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
148 return detectRemote(uri);
181
cd3371670f0b Refactor incoming and outgoing code to be shared with RepositoryComparator. Placeholders for in/out commands. Refactor common remote lookup code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
149 }
cd3371670f0b Refactor incoming and outgoing code to be shared with RepositoryComparator. Placeholders for in/out commands. Refactor common remote lookup code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
150
698
822f3a83ff57 in, out and clone tests pass for ssh repositories. Infrastructure to decouple HgRemoteRepository from specific Connector implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
151 /**
822f3a83ff57 in, out and clone tests pass for ssh repositories. Infrastructure to decouple HgRemoteRepository from specific Connector implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
152 * Detect remote repository
822f3a83ff57 in, out and clone tests pass for ssh repositories. Infrastructure to decouple HgRemoteRepository from specific Connector implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
153 * <p>Use of this method is discouraged, please use {@link #detectRemote(URI)} instead}
822f3a83ff57 in, out and clone tests pass for ssh repositories. Infrastructure to decouple HgRemoteRepository from specific Connector implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
154 *
822f3a83ff57 in, out and clone tests pass for ssh repositories. Infrastructure to decouple HgRemoteRepository from specific Connector implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
155 * @param url location of remote repository
822f3a83ff57 in, out and clone tests pass for ssh repositories. Infrastructure to decouple HgRemoteRepository from specific Connector implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
156 * @return instance to interact with remote repository
822f3a83ff57 in, out and clone tests pass for ssh repositories. Infrastructure to decouple HgRemoteRepository from specific Connector implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
157 * @throws HgBadArgumentException if location format is not a valid {@link URI}
822f3a83ff57 in, out and clone tests pass for ssh repositories. Infrastructure to decouple HgRemoteRepository from specific Connector implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
158 * @throws IllegalArgumentException if url is <code>null</code>
822f3a83ff57 in, out and clone tests pass for ssh repositories. Infrastructure to decouple HgRemoteRepository from specific Connector implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
159 */
295
981f9f50bb6c Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 215
diff changeset
160 public HgRemoteRepository detect(URL url) throws HgBadArgumentException {
171
2c3e96674e2a Towards outgoing changes - initial detection logic, get connected with remote repo stub
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 170
diff changeset
161 if (url == null) {
2c3e96674e2a Towards outgoing changes - initial detection logic, get connected with remote repo stub
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 170
diff changeset
162 throw new IllegalArgumentException();
2c3e96674e2a Towards outgoing changes - initial detection logic, get connected with remote repo stub
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 170
diff changeset
163 }
698
822f3a83ff57 in, out and clone tests pass for ssh repositories. Infrastructure to decouple HgRemoteRepository from specific Connector implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
164 try {
822f3a83ff57 in, out and clone tests pass for ssh repositories. Infrastructure to decouple HgRemoteRepository from specific Connector implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
165 return detectRemote(url.toURI());
822f3a83ff57 in, out and clone tests pass for ssh repositories. Infrastructure to decouple HgRemoteRepository from specific Connector implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
166 } catch (URISyntaxException ex) {
822f3a83ff57 in, out and clone tests pass for ssh repositories. Infrastructure to decouple HgRemoteRepository from specific Connector implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
167 throw new HgBadArgumentException(String.format("Bad remote repository location: %s", url), ex);
170
71ddbf8603e8 Initial clone: populate given directory from a bundle. Everything but remote server access is there, albeit prototype code style
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 169
diff changeset
168 }
698
822f3a83ff57 in, out and clone tests pass for ssh repositories. Infrastructure to decouple HgRemoteRepository from specific Connector implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
169 }
822f3a83ff57 in, out and clone tests pass for ssh repositories. Infrastructure to decouple HgRemoteRepository from specific Connector implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
170
822f3a83ff57 in, out and clone tests pass for ssh repositories. Infrastructure to decouple HgRemoteRepository from specific Connector implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
171 /**
822f3a83ff57 in, out and clone tests pass for ssh repositories. Infrastructure to decouple HgRemoteRepository from specific Connector implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
172 * Resolves location of remote repository.
822f3a83ff57 in, out and clone tests pass for ssh repositories. Infrastructure to decouple HgRemoteRepository from specific Connector implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
173 *
822f3a83ff57 in, out and clone tests pass for ssh repositories. Infrastructure to decouple HgRemoteRepository from specific Connector implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
174 * <p>Choice between {@link URI URIs} and {@link URL URLs} done in favor of former because they are purely syntactical,
822f3a83ff57 in, out and clone tests pass for ssh repositories. Infrastructure to decouple HgRemoteRepository from specific Connector implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
175 * while latter have semantics of {@link URL#openConnection() connection} establishing, which is not always possible.
822f3a83ff57 in, out and clone tests pass for ssh repositories. Infrastructure to decouple HgRemoteRepository from specific Connector implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
176 * E.g. one can't instantiate <code>new URL("ssh://localhost/")</code> as long as there's no local {@link URLStreamHandler}
822f3a83ff57 in, out and clone tests pass for ssh repositories. Infrastructure to decouple HgRemoteRepository from specific Connector implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
177 * for the protocol, which is the case for certain JREs out there. The way {@link URLStreamHandlerFactory URLStreamHandlerFactories}
822f3a83ff57 in, out and clone tests pass for ssh repositories. Infrastructure to decouple HgRemoteRepository from specific Connector implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
178 * are installed (static field/method) is quite fragile, and definitely not the one to rely on from a library's code (apps can carefully
822f3a83ff57 in, out and clone tests pass for ssh repositories. Infrastructure to decouple HgRemoteRepository from specific Connector implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
179 * do this, but library can't install own nor expect anyone outside there would do). Use of fake {@link URLStreamHandler} (fails to open
822f3a83ff57 in, out and clone tests pass for ssh repositories. Infrastructure to decouple HgRemoteRepository from specific Connector implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
180 * every connection) is possible, of course, although it seems to be less appropriate when there is alternative with {@link URI URIs}.
822f3a83ff57 in, out and clone tests pass for ssh repositories. Infrastructure to decouple HgRemoteRepository from specific Connector implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
181 *
822f3a83ff57 in, out and clone tests pass for ssh repositories. Infrastructure to decouple HgRemoteRepository from specific Connector implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
182 * @param uriRemote remote repository location
822f3a83ff57 in, out and clone tests pass for ssh repositories. Infrastructure to decouple HgRemoteRepository from specific Connector implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
183 * @return instance to interact with remote repository
822f3a83ff57 in, out and clone tests pass for ssh repositories. Infrastructure to decouple HgRemoteRepository from specific Connector implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
184 * @throws HgBadArgumentException
822f3a83ff57 in, out and clone tests pass for ssh repositories. Infrastructure to decouple HgRemoteRepository from specific Connector implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
185 */
822f3a83ff57 in, out and clone tests pass for ssh repositories. Infrastructure to decouple HgRemoteRepository from specific Connector implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
186 public HgRemoteRepository detectRemote(URI uriRemote) throws HgBadArgumentException {
822f3a83ff57 in, out and clone tests pass for ssh repositories. Infrastructure to decouple HgRemoteRepository from specific Connector implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
187 RemoteDescriptor rd = getSessionContext().getRemoteDescriptor(uriRemote);
822f3a83ff57 in, out and clone tests pass for ssh repositories. Infrastructure to decouple HgRemoteRepository from specific Connector implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
188 if (rd == null) {
822f3a83ff57 in, out and clone tests pass for ssh repositories. Infrastructure to decouple HgRemoteRepository from specific Connector implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
189 throw new HgBadArgumentException(String.format("Unsupported remote repository location:%s", uriRemote), null);
822f3a83ff57 in, out and clone tests pass for ssh repositories. Infrastructure to decouple HgRemoteRepository from specific Connector implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
190 }
822f3a83ff57 in, out and clone tests pass for ssh repositories. Infrastructure to decouple HgRemoteRepository from specific Connector implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
191 return new HgRemoteRepository(getSessionContext(), rd);
170
71ddbf8603e8 Initial clone: populate given directory from a bundle. Everything but remote server access is there, albeit prototype code style
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 169
diff changeset
192 }
181
cd3371670f0b Refactor incoming and outgoing code to be shared with RepositoryComparator. Placeholders for in/out commands. Refactor common remote lookup code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
193
cd3371670f0b Refactor incoming and outgoing code to be shared with RepositoryComparator. Placeholders for in/out commands. Refactor common remote lookup code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
194 private ConfigFile getGlobalConfig() {
cd3371670f0b Refactor incoming and outgoing code to be shared with RepositoryComparator. Placeholders for in/out commands. Refactor common remote lookup code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
195 if (globalCfg == null) {
618
7c0d2ce340b8 Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 578
diff changeset
196 globalCfg = new ConfigFile(getSessionContext());
295
981f9f50bb6c Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 215
diff changeset
197 try {
981f9f50bb6c Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 215
diff changeset
198 globalCfg.addLocation(new File(System.getProperty("user.home"), ".hgrc"));
628
6526d8adbc0f Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 622
diff changeset
199 } catch (HgIOException ex) {
295
981f9f50bb6c Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 215
diff changeset
200 // XXX perhaps, makes sense to let caller/client know that we've failed to read global config?
618
7c0d2ce340b8 Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 578
diff changeset
201 getSessionContext().getLog().dump(getClass(), Warn, ex, null);
295
981f9f50bb6c Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 215
diff changeset
202 }
181
cd3371670f0b Refactor incoming and outgoing code to be shared with RepositoryComparator. Placeholders for in/out commands. Refactor common remote lookup code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
203 }
cd3371670f0b Refactor incoming and outgoing code to be shared with RepositoryComparator. Placeholders for in/out commands. Refactor common remote lookup code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
204 return globalCfg;
cd3371670f0b Refactor incoming and outgoing code to be shared with RepositoryComparator. Placeholders for in/out commands. Refactor common remote lookup code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 172
diff changeset
205 }
295
981f9f50bb6c Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 215
diff changeset
206
618
7c0d2ce340b8 Refactor approach how content finds it way down to a commit revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 578
diff changeset
207 public SessionContext getSessionContext() {
295
981f9f50bb6c Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 215
diff changeset
208 if (sessionContext == null) {
431
12f668401613 FIXMEs: awkward API refactored, what need to be internal got hidden; public aspects got captured in slim interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 425
diff changeset
209 sessionContext = new BasicSessionContext(null);
295
981f9f50bb6c Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 215
diff changeset
210 }
981f9f50bb6c Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 215
diff changeset
211 return sessionContext;
981f9f50bb6c Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 215
diff changeset
212 }
698
822f3a83ff57 in, out and clone tests pass for ssh repositories. Infrastructure to decouple HgRemoteRepository from specific Connector implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
213
822f3a83ff57 in, out and clone tests pass for ssh repositories. Infrastructure to decouple HgRemoteRepository from specific Connector implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
214
822f3a83ff57 in, out and clone tests pass for ssh repositories. Infrastructure to decouple HgRemoteRepository from specific Connector implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
215 /**
822f3a83ff57 in, out and clone tests pass for ssh repositories. Infrastructure to decouple HgRemoteRepository from specific Connector implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
216 * Session context ({@link SessionContext#getRemoteDescriptor(URI)} gives descriptor of remote when asked.
822f3a83ff57 in, out and clone tests pass for ssh repositories. Infrastructure to decouple HgRemoteRepository from specific Connector implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
217 */
822f3a83ff57 in, out and clone tests pass for ssh repositories. Infrastructure to decouple HgRemoteRepository from specific Connector implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
218 @Experimental(reason="Work in progress")
822f3a83ff57 in, out and clone tests pass for ssh repositories. Infrastructure to decouple HgRemoteRepository from specific Connector implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
219 public interface RemoteDescriptor {
822f3a83ff57 in, out and clone tests pass for ssh repositories. Infrastructure to decouple HgRemoteRepository from specific Connector implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
220 URI getURI();
822f3a83ff57 in, out and clone tests pass for ssh repositories. Infrastructure to decouple HgRemoteRepository from specific Connector implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
221 Authenticator getAuth();
822f3a83ff57 in, out and clone tests pass for ssh repositories. Infrastructure to decouple HgRemoteRepository from specific Connector implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
222 }
822f3a83ff57 in, out and clone tests pass for ssh repositories. Infrastructure to decouple HgRemoteRepository from specific Connector implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
223
822f3a83ff57 in, out and clone tests pass for ssh repositories. Infrastructure to decouple HgRemoteRepository from specific Connector implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
224 @Experimental(reason="Work in progress")
822f3a83ff57 in, out and clone tests pass for ssh repositories. Infrastructure to decouple HgRemoteRepository from specific Connector implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
225 public interface Authenticator {
822f3a83ff57 in, out and clone tests pass for ssh repositories. Infrastructure to decouple HgRemoteRepository from specific Connector implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
226 public void authenticate(RemoteDescriptor remote, AuthMethod authMethod);
822f3a83ff57 in, out and clone tests pass for ssh repositories. Infrastructure to decouple HgRemoteRepository from specific Connector implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
227 }
822f3a83ff57 in, out and clone tests pass for ssh repositories. Infrastructure to decouple HgRemoteRepository from specific Connector implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
228
822f3a83ff57 in, out and clone tests pass for ssh repositories. Infrastructure to decouple HgRemoteRepository from specific Connector implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
229 /**
822f3a83ff57 in, out and clone tests pass for ssh repositories. Infrastructure to decouple HgRemoteRepository from specific Connector implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
230 * Clients do not implement this interface, instead, they invoke appropriate authentication method
822f3a83ff57 in, out and clone tests pass for ssh repositories. Infrastructure to decouple HgRemoteRepository from specific Connector implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
231 * once they got user input
822f3a83ff57 in, out and clone tests pass for ssh repositories. Infrastructure to decouple HgRemoteRepository from specific Connector implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
232 */
822f3a83ff57 in, out and clone tests pass for ssh repositories. Infrastructure to decouple HgRemoteRepository from specific Connector implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
233 @Experimental(reason="Work in progress")
822f3a83ff57 in, out and clone tests pass for ssh repositories. Infrastructure to decouple HgRemoteRepository from specific Connector implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
234 public interface AuthMethod {
822f3a83ff57 in, out and clone tests pass for ssh repositories. Infrastructure to decouple HgRemoteRepository from specific Connector implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
235 public void noCredentials() throws AuthFailedException;
822f3a83ff57 in, out and clone tests pass for ssh repositories. Infrastructure to decouple HgRemoteRepository from specific Connector implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
236 public boolean supportsPassword();
822f3a83ff57 in, out and clone tests pass for ssh repositories. Infrastructure to decouple HgRemoteRepository from specific Connector implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
237 public void withPassword(String username, byte[] password) throws AuthFailedException;
822f3a83ff57 in, out and clone tests pass for ssh repositories. Infrastructure to decouple HgRemoteRepository from specific Connector implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
238 public boolean supportsPublicKey();
822f3a83ff57 in, out and clone tests pass for ssh repositories. Infrastructure to decouple HgRemoteRepository from specific Connector implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
239 public void withPublicKey(String username, InputStream publicKey, String passphrase) throws AuthFailedException;
822f3a83ff57 in, out and clone tests pass for ssh repositories. Infrastructure to decouple HgRemoteRepository from specific Connector implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
240 public boolean supportsCertificate();
822f3a83ff57 in, out and clone tests pass for ssh repositories. Infrastructure to decouple HgRemoteRepository from specific Connector implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
241 public void withCertificate() throws AuthFailedException;
822f3a83ff57 in, out and clone tests pass for ssh repositories. Infrastructure to decouple HgRemoteRepository from specific Connector implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
242 }
822f3a83ff57 in, out and clone tests pass for ssh repositories. Infrastructure to decouple HgRemoteRepository from specific Connector implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
243
822f3a83ff57 in, out and clone tests pass for ssh repositories. Infrastructure to decouple HgRemoteRepository from specific Connector implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
244 @SuppressWarnings("serial")
822f3a83ff57 in, out and clone tests pass for ssh repositories. Infrastructure to decouple HgRemoteRepository from specific Connector implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
245 public class AuthFailedException extends Exception /*XXX HgRemoteException?*/ {
822f3a83ff57 in, out and clone tests pass for ssh repositories. Infrastructure to decouple HgRemoteRepository from specific Connector implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
246 public AuthFailedException(String message, Throwable cause) {
822f3a83ff57 in, out and clone tests pass for ssh repositories. Infrastructure to decouple HgRemoteRepository from specific Connector implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
247 super(message, cause);
822f3a83ff57 in, out and clone tests pass for ssh repositories. Infrastructure to decouple HgRemoteRepository from specific Connector implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
248 }
822f3a83ff57 in, out and clone tests pass for ssh repositories. Infrastructure to decouple HgRemoteRepository from specific Connector implementation
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
249 }
2
08db726a0fb7 Shaping out low-level Hg structures
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
250 }