| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| RepositoryConfiguration |
|
| 1.0;1 | ||||
| RepositoryConfiguration$CachePolicy |
|
| 1.0;1 |
| 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 | 24 | public class RepositoryConfiguration { |
| 41 | ||
| 42 | static { | |
| 43 | 1 | String hgBin = System.getProperty("com.aragost.javahg.hgbin"); |
| 44 | 1 | if (Strings.isNullOrEmpty(hgBin)) { |
| 45 | 1 | hgBin = "hg"; |
| 46 | } | |
| 47 | 1 | 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 | 1 | protected static final Charset DEFAULT_ENCODING = Charset.forName("UTF-8"); |
| 56 | ||
| 57 | /** | |
| 58 | * Mercurial repository encoding. Default is UTF-8. | |
| 59 | */ | |
| 60 | 24 | 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 | 1 | public static final RepositoryConfiguration DEFAULT = new RepositoryConfiguration(); |
| 67 | ||
| 68 | 6 | public enum CachePolicy { |
| 69 | 1 | STRONG, SOFT, WEAK, NONE |
| 70 | }; | |
| 71 | ||
| 72 | /** | |
| 73 | * The Mercurial executable | |
| 74 | */ | |
| 75 | 24 | 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 | 24 | private String hgrcPath = ""; |
| 84 | ||
| 85 | /** | |
| 86 | * How should Changesets be cached | |
| 87 | */ | |
| 88 | 24 | 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 | 24 | 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 | 24 | private int stderrBufferSize = 1024; |
| 103 | ||
| 104 | /** | |
| 105 | * Extensions to enable. | |
| 106 | */ | |
| 107 | 24 | 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 | 24 | 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 | 24 | 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 | 24 | 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 | 24 | private boolean enablePendingChangesets = false; |
| 135 | ||
| 136 | /** | |
| 137 | * Environment variables to set before starting command servers | |
| 138 | */ | |
| 139 | 24 | private final Map<String, String> environment = new HashMap<String, String>(); |
| 140 | ||
| 141 | public boolean isEnablePendingChangesets(){ | |
| 142 | 216 | return enablePendingChangesets; |
| 143 | } | |
| 144 | ||
| 145 | public void setEnablePendingChangesets(boolean enablePendingChangesets){ | |
| 146 | 0 | this.enablePendingChangesets = enablePendingChangesets; |
| 147 | 0 | } |
| 148 | ||
| 149 | public String getHgBin() { | |
| 150 | 439 | return hgBin; |
| 151 | } | |
| 152 | ||
| 153 | public void setHgBin(String hgBin) { | |
| 154 | 0 | this.hgBin = hgBin; |
| 155 | 0 | } |
| 156 | ||
| 157 | public String getHgrcPath() { | |
| 158 | 220 | return hgrcPath; |
| 159 | } | |
| 160 | ||
| 161 | public void setHgrcPath(String hgrcPath) { | |
| 162 | 18 | this.hgrcPath = hgrcPath; |
| 163 | 18 | } |
| 164 | ||
| 165 | public CachePolicy getCachePolicy() { | |
| 166 | 218 | return cachePolicy; |
| 167 | } | |
| 168 | ||
| 169 | public void setCachePolicy(CachePolicy cachePolicy) { | |
| 170 | 3 | this.cachePolicy = cachePolicy; |
| 171 | 3 | } |
| 172 | ||
| 173 | public CodingErrorAction getCodingErrorAction() { | |
| 174 | 5894 | return codingErrorAction; |
| 175 | } | |
| 176 | ||
| 177 | public void setCodingErrorAction(CodingErrorAction codingErrorAction) { | |
| 178 | 0 | this.codingErrorAction = codingErrorAction; |
| 179 | 0 | } |
| 180 | ||
| 181 | public int getStderrBufferSize() { | |
| 182 | 217 | return stderrBufferSize; |
| 183 | } | |
| 184 | ||
| 185 | public void setStderrBufferSize(int stderrBufferSize) { | |
| 186 | 1 | this.stderrBufferSize = stderrBufferSize; |
| 187 | 1 | } |
| 188 | ||
| 189 | public Collection<Class<? extends MercurialExtension>> getExtensionClasses() { | |
| 190 | 216 | return extensionClasses; |
| 191 | } | |
| 192 | ||
| 193 | public void setExtensionClasses(Collection<Class<? extends MercurialExtension>> extensionClasses) { | |
| 194 | 0 | this.extensionClasses = extensionClasses; |
| 195 | 0 | } |
| 196 | ||
| 197 | public void addExtension(Class<? extends MercurialExtension> extClass) { | |
| 198 | 5 | this.extensionClasses.add(extClass); |
| 199 | 5 | } |
| 200 | ||
| 201 | public void removeExtension(Class<? extends MercurialExtension> extClass) { | |
| 202 | 0 | this.extensionClasses.remove(extClass); |
| 203 | 0 | } |
| 204 | ||
| 205 | public Charset getEncoding(){ | |
| 206 | 218 | return encoding; |
| 207 | } | |
| 208 | ||
| 209 | public void setEncoding(Charset encoding){ | |
| 210 | 0 | this.encoding = encoding; |
| 211 | 0 | } |
| 212 | ||
| 213 | /** | |
| 214 | * @return The maximum number of command server processes to use. Default is 1. | |
| 215 | */ | |
| 216 | public int getConcurrency() { | |
| 217 | 212 | 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 | 1 | this.concurrency = concurrency; |
| 228 | 1 | } |
| 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 | 1987 | 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 | 0 | this.commandWaitTimeoutSeconds = seconds; |
| 250 | 0 | } |
| 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 | 222 | 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 | 1 | this.serverIdleTimeSeconds = seconds; |
| 270 | 1 | } |
| 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 | 3808 | 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 | 0 | this.sshBin = sshBin; |
| 288 | 0 | } |
| 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 | 216 | return this.environment; |
| 297 | } | |
| 298 | } |