1 /*
2 * #%L
3 * JavaHg
4 * %%
5 * Copyright (C) 2011 aragost Trifork ag
6 * %%
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 * THE SOFTWARE.
24 * #L%
25 */
26 package com.aragost.javahg;
27
28 import java.nio.charset.CodingErrorAction;
29 import java.util.Collection;
30 import java.util.HashMap;
31 import java.util.Map;
32
33 import com.google.common.base.Strings;
34 import com.google.common.collect.Sets;
35 import java.nio.charset.Charset;
36
37 /**
38 * Settings for repository and underlying server process
39 */
40 public class RepositoryConfiguration {
41
42 static {
43 String hgBin = System.getProperty("com.aragost.javahg.hgbin");
44 if (Strings.isNullOrEmpty(hgBin)) {
45 hgBin = "hg";
46 }
47 DEFAULT_HG_BIN = hgBin;
48 }
49
50 private static final String DEFAULT_HG_BIN;
51
52 /**
53 * The default encoding for the repository
54 */
55 protected static final Charset DEFAULT_ENCODING = Charset.forName("UTF-8");
56
57 /**
58 * Mercurial repository encoding. Default is UTF-8.
59 */
60 private Charset encoding = DEFAULT_ENCODING;
61
62 /**
63 * The default configuration, used in case no explicit
64 * configuration is given to a {@link Repository}
65 */
66 public static final RepositoryConfiguration DEFAULT = new RepositoryConfiguration();
67
68 public enum CachePolicy {
69 STRONG, SOFT, WEAK, NONE
70 };
71
72 /**
73 * The Mercurial executable
74 */
75 private String hgBin = DEFAULT_HG_BIN;
76
77 /**
78 * The hgrc property file to use. If it is the empty string then
79 * no hgrc file is used, if it is null Mercurial uses its normal
80 * logic to determine the hgrc file. Otherwise it is the path to a
81 * file
82 */
83 private String hgrcPath = "";
84
85 /**
86 * How should Changesets be cached
87 */
88 private CachePolicy cachePolicy = CachePolicy.SOFT;
89
90 /**
91 * What to do if we encounter some decoding problems with the
92 * output from Mercurial
93 */
94 private CodingErrorAction codingErrorAction = CodingErrorAction.REPORT;
95
96 /**
97 * Size of buffer for stderr from Mercurial command server.
98 * <p>
99 * Most likely no reason to change this. Main reason it is
100 * configurable is so buffer overflow can be tested.
101 */
102 private int stderrBufferSize = 1024;
103
104 /**
105 * Extensions to enable.
106 */
107 private Collection<Class<? extends MercurialExtension>> extensionClasses = Sets.newHashSet();
108
109 /**
110 * The maximum number of command server processes to use. Default is 1.
111 */
112 private int concurrency = 1;
113
114 /**
115 * The maximum number of seconds to wait for a command server instance to
116 * become available. Default is 2 minutes.
117 */
118 private int commandWaitTimeoutSeconds = 120;
119
120 /**
121 * After a command server is idle for this many seconds the server pool may
122 * stop it. Default is {@link Integer#MAX_VALUE}.
123 */
124 private int serverIdleTimeSeconds = Integer.MAX_VALUE;
125
126 /**
127 * A custom SSH executable which should be used by Mercurial.
128 */
129 private String sshBin;
130
131 /**
132 * Enable access to pending changesets.
133 */
134 private boolean enablePendingChangesets = false;
135
136 /**
137 * Environment variables to set before starting command servers
138 */
139 private final Map<String, String> environment = new HashMap<String, String>();
140
141 public boolean isEnablePendingChangesets(){
142 return enablePendingChangesets;
143 }
144
145 public void setEnablePendingChangesets(boolean enablePendingChangesets){
146 this.enablePendingChangesets = enablePendingChangesets;
147 }
148
149 public String getHgBin() {
150 return hgBin;
151 }
152
153 public void setHgBin(String hgBin) {
154 this.hgBin = hgBin;
155 }
156
157 public String getHgrcPath() {
158 return hgrcPath;
159 }
160
161 public void setHgrcPath(String hgrcPath) {
162 this.hgrcPath = hgrcPath;
163 }
164
165 public CachePolicy getCachePolicy() {
166 return cachePolicy;
167 }
168
169 public void setCachePolicy(CachePolicy cachePolicy) {
170 this.cachePolicy = cachePolicy;
171 }
172
173 public CodingErrorAction getCodingErrorAction() {
174 return codingErrorAction;
175 }
176
177 public void setCodingErrorAction(CodingErrorAction codingErrorAction) {
178 this.codingErrorAction = codingErrorAction;
179 }
180
181 public int getStderrBufferSize() {
182 return stderrBufferSize;
183 }
184
185 public void setStderrBufferSize(int stderrBufferSize) {
186 this.stderrBufferSize = stderrBufferSize;
187 }
188
189 public Collection<Class<? extends MercurialExtension>> getExtensionClasses() {
190 return extensionClasses;
191 }
192
193 public void setExtensionClasses(Collection<Class<? extends MercurialExtension>> extensionClasses) {
194 this.extensionClasses = extensionClasses;
195 }
196
197 public void addExtension(Class<? extends MercurialExtension> extClass) {
198 this.extensionClasses.add(extClass);
199 }
200
201 public void removeExtension(Class<? extends MercurialExtension> extClass) {
202 this.extensionClasses.remove(extClass);
203 }
204
205 public Charset getEncoding(){
206 return encoding;
207 }
208
209 public void setEncoding(Charset encoding){
210 this.encoding = encoding;
211 }
212
213 /**
214 * @return The maximum number of command server processes to use. Default is 1.
215 */
216 public int getConcurrency() {
217 return concurrency;
218 }
219
220 /**
221 * The maximum number of command server processes to use. Default is 1.
222 *
223 * @param concurrency
224 * The maximum number of command server processes to use.
225 */
226 public void setConcurrency(int concurrency) {
227 this.concurrency = concurrency;
228 }
229
230 /**
231 * @return The maximum number of seconds to wait for a command server
232 * instance to become available. Default is 2 minutes.
233 */
234 public int getCommandWaitTimeout() {
235 return commandWaitTimeoutSeconds;
236 }
237
238 /**
239 * Set the maximum number of seconds to wait for a command server instance
240 * to become available. Default is 2 minutes.
241 *
242 * Note: this is not command execution timeout.
243 *
244 * @param seconds
245 * The amount of time to wait for a server to become available in
246 * seconds.
247 */
248 public void setCommandWaitTimeout(int seconds) {
249 this.commandWaitTimeoutSeconds = seconds;
250 }
251
252 /**
253 * After a command server is idle for this many seconds the server pool may
254 * stop it. Default is {@link Integer#MAX_VALUE}.
255 *
256 * @return The idle time for a server
257 */
258 public int getServerIdleTime() {
259 return this.serverIdleTimeSeconds;
260 }
261
262 /**
263 * After a command server is idle for this many seconds the server pool may
264 * stop it. Default is {@link Integer#MAX_VALUE}.
265 *
266 * @param seconds The idle time for a server
267 */
268 public void setServerIdleTime(int seconds) {
269 this.serverIdleTimeSeconds = seconds;
270 }
271
272 /**
273 * Returns the custom SSH executable which should be used by Mercurial.
274 *
275 * @return the custom SSH executable
276 */
277 public String getSshBin() {
278 return sshBin;
279 }
280
281 /**
282 * Sets the custom SSH executable which should be used by Mercurial.
283 *
284 * @param sshBin the custom SSH executable
285 */
286 public void setSshBin(String sshBin) {
287 this.sshBin = sshBin;
288 }
289
290 /**
291 * @return A map of custom environment variables that will be set when
292 * command servers are started.
293 */
294 public Map<String, String> getEnvironment()
295 {
296 return this.environment;
297 }
298 }