Mercurial > hg4j
comparison hg4j/src/main/java/org/tmatesoft/hg/core/HgRepoFacade.java @ 213:6ec4af642ba8 gradle
Project uses Gradle for build - actual changes
author | Alexander Kitaev <kitaev@gmail.com> |
---|---|
date | Tue, 10 May 2011 10:52:53 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
212:edb2e2829352 | 213:6ec4af642ba8 |
---|---|
1 /* | |
2 * Copyright (c) 2011 TMate Software Ltd | |
3 * | |
4 * This program is free software; you can redistribute it and/or modify | |
5 * it under the terms of the GNU General Public License as published by | |
6 * the Free Software Foundation; version 2 of the License. | |
7 * | |
8 * This program is distributed in the hope that it will be useful, | |
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
11 * GNU General Public License for more details. | |
12 * | |
13 * For information on how to redistribute this software under | |
14 * the terms of a license other than GNU General Public License | |
15 * contact TMate Software at support@hg4j.com | |
16 */ | |
17 package org.tmatesoft.hg.core; | |
18 | |
19 import java.io.File; | |
20 | |
21 import org.tmatesoft.hg.repo.HgRepository; | |
22 import org.tmatesoft.hg.repo.HgLookup; | |
23 | |
24 /** | |
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> | |
34 * | |
35 * @author Artem Tikhomirov | |
36 * @author TMate Software Ltd. | |
37 */ | |
38 public class HgRepoFacade { | |
39 private HgRepository repo; | |
40 | |
41 public HgRepoFacade() { | |
42 } | |
43 | |
44 /** | |
45 * @param hgRepo | |
46 * @return true on successful initialization | |
47 * @throws IllegalArgumentException when argument is null | |
48 */ | |
49 public boolean init(HgRepository hgRepo) { | |
50 if (hgRepo == null) { | |
51 throw new IllegalArgumentException(); | |
52 } | |
53 repo = hgRepo; | |
54 return !repo.isInvalid(); | |
55 } | |
56 | |
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 { | |
63 repo = new HgLookup().detectFromWorkingDir(); | |
64 return repo != null && !repo.isInvalid(); | |
65 } | |
66 | |
67 /** | |
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); | |
80 return repo != null && !repo.isInvalid(); | |
81 } | |
82 | |
83 public HgRepository getRepository() { | |
84 if (repo == null) { | |
85 throw new IllegalStateException("Call any of #init*() methods first first"); | |
86 } | |
87 return repo; | |
88 } | |
89 | |
90 public HgLogCommand createLogCommand() { | |
91 return new HgLogCommand(repo/*, getCommandContext()*/); | |
92 } | |
93 | |
94 public HgStatusCommand createStatusCommand() { | |
95 return new HgStatusCommand(repo/*, getCommandContext()*/); | |
96 } | |
97 | |
98 public HgCatCommand createCatCommand() { | |
99 return new HgCatCommand(repo); | |
100 } | |
101 | |
102 public HgManifestCommand createManifestCommand() { | |
103 return new HgManifestCommand(repo); | |
104 } | |
105 | |
106 public HgOutgoingCommand createOutgoingCommand() { | |
107 return new HgOutgoingCommand(repo); | |
108 } | |
109 | |
110 public HgIncomingCommand createIncomingCommand() { | |
111 return new HgIncomingCommand(repo); | |
112 } | |
113 } |