comparison src/org/tmatesoft/hg/core/HgRepoFacade.java @ 148:1a7a9a20e1f9

Exceptions, javadoc. Initial cancel and progress support
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Wed, 23 Feb 2011 22:36:28 +0100
parents b9700740553a
children cd3371670f0b
comparison
equal deleted inserted replaced
147:a05145db4d0c 148:1a7a9a20e1f9
21 import org.tmatesoft.hg.repo.HgRepository; 21 import org.tmatesoft.hg.repo.HgRepository;
22 import org.tmatesoft.hg.repo.HgLookup; 22 import org.tmatesoft.hg.repo.HgLookup;
23 23
24 /** 24 /**
25 * Starting point for the library. 25 * Starting point for the library.
26 * <p>Sample use:
27 * <pre>
28 * HgRepoFacade f = new HgRepoFacade();
29 * f.initFrom(System.getenv("whatever.repo.location"));
30 * HgStatusCommand statusCmd = f.createStatusCommand();
31 * HgStatusCommand.Handler handler = ...;
32 * statusCmd.execute(handler);
33 * </pre>
26 * 34 *
27 * @author Artem Tikhomirov 35 * @author Artem Tikhomirov
28 * @author TMate Software Ltd. 36 * @author TMate Software Ltd.
29 */ 37 */
30 public class HgRepoFacade { 38 public class HgRepoFacade {
31 private HgRepository repo; 39 private HgRepository repo;
32 40
33 public HgRepoFacade() { 41 public HgRepoFacade() {
34 } 42 }
35 43
44 /**
45 * @param hgRepo
46 * @return true on successful initialization
47 * @throws IllegalArgumentException when argument is null
48 */
36 public boolean init(HgRepository hgRepo) { 49 public boolean init(HgRepository hgRepo) {
37 if (hgRepo == null) { 50 if (hgRepo == null) {
38 throw new IllegalArgumentException(); 51 throw new IllegalArgumentException();
39 } 52 }
40 repo = hgRepo; 53 repo = hgRepo;
41 return !repo.isInvalid(); 54 return !repo.isInvalid();
42 } 55 }
43 56
44 public boolean init() throws Exception /*FIXME RepoInitException*/ { 57 /**
58 * Tries to find repository starting from the current working directory.
59 * @return <code>true</code> if found valid repository
60 * @throws HgException in case of errors during repository initialization
61 */
62 public boolean init() throws HgException {
45 repo = new HgLookup().detectFromWorkingDir(); 63 repo = new HgLookup().detectFromWorkingDir();
46 return repo != null && !repo.isInvalid(); 64 return repo != null && !repo.isInvalid();
47 } 65 }
48 66
49 public boolean initFrom(File repoLocation) throws Exception { 67 /**
50 repo = new HgLookup().detect(repoLocation.getCanonicalPath()); 68 * Looks up Mercurial repository starting from specified location and up to filesystem root.
69 *
70 * @param repoLocation path to any folder within structure of a Mercurial repository.
71 * @return <code>true</code> if found valid repository
72 * @throws HgException if there are errors accessing specified location
73 * @throws IllegalArgumentException if argument is <code>null</code>
74 */
75 public boolean initFrom(File repoLocation) throws HgException {
76 if (repoLocation == null) {
77 throw new IllegalArgumentException();
78 }
79 repo = new HgLookup().detect(repoLocation);
51 return repo != null && !repo.isInvalid(); 80 return repo != null && !repo.isInvalid();
52 } 81 }
53 82
54 public HgRepository getRepository() { 83 public HgRepository getRepository() {
55 if (repo == null) { 84 if (repo == null) {