1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package net.sf.statsvn.output;
24
25 import java.io.File;
26
27 import net.sf.statcvs.output.ConfigurationException;
28 import net.sf.statcvs.output.ConfigurationOptions;
29 import net.sf.statcvs.util.FileUtils;
30 import net.sf.statsvn.util.ISvnProcessor;
31 import net.sf.statsvn.util.JavaUtilTaskLogger;
32 import net.sf.statsvn.util.SvnCommandLineProcessor;
33 import net.sf.statsvn.util.TaskLogger;
34 import net.sf.statsvn.util.svnkit.SvnKitProcessor;
35
36 /**
37 * Class for storing all command line parameters. The parameters are set by the
38 * {@link net.sf.statsvn.Main#main} method. Interested classes can read all
39 * parameter values from here.
40 *
41 * @todo Should be moved to more appropriate package and made non-public
42 *
43 * @author jentzsch
44 * @version $Id: ConfigurationOptions.java,v 1.17 2005/03/20 19:12:25 squig Exp $
45 */
46 public final class SvnConfigurationOptions {
47 private static final int DEFAULT_THRESHOLD_MS_FOR_CONCURRENCY = 2000;
48
49 private static final int DEFAULT_NUMBER_THREADS = 25;
50
51 private static String cacheDir = "";
52
53 private static final String DEFAULT_CACHE_DIR = System.getProperty("user.home") + FileUtils.getDirSeparator() + ".statsvn" + FileUtils.getDirSeparator();
54
55 private static String svnUsername = null;
56
57 private static String svnPassword = null;
58
59 private static TaskLogger taskLogger = new JavaUtilTaskLogger();
60
61 private static int numberSvnDiffThreads = DEFAULT_NUMBER_THREADS;
62
63 private static long thresholdInMsToUseConcurrency = DEFAULT_THRESHOLD_MS_FOR_CONCURRENCY;
64
65 private static boolean dump = false;
66
67 private static boolean anonymize = false;
68
69 private static String tagsDirectory = "/tags/";
70
71
72 private static boolean useLegacyDiff = false;
73
74 private static ISvnProcessor processor;
75
76 private static boolean useSvnKit = false;
77
78 /**
79 * A utility class (only static methods) should be final and have a private
80 * constructor.
81 */
82 private SvnConfigurationOptions() {
83 }
84
85 /**
86 * Returns the cacheDir.
87 *
88 * @return String output Directory
89 */
90 public static String getCacheDir() {
91 return cacheDir;
92 }
93
94 /**
95 * Sets the cacheDir.
96 *
97 * @param cacheDir
98 * The cacheDir to set
99 * @throws ConfigurationException
100 * if the cache directory cannot be created
101 */
102 public static void setCacheDir(String cacheDir) throws ConfigurationException {
103 if (!cacheDir.endsWith(FileUtils.getDirSeparator())) {
104 cacheDir += FileUtils.getDefaultDirSeparator();
105 }
106 final File cDir = new File(cacheDir);
107 if (!cDir.exists() && !cDir.mkdirs()) {
108 throw new ConfigurationException("Can't create cache directory: " + cacheDir);
109 }
110 SvnConfigurationOptions.cacheDir = cacheDir;
111 }
112
113 /**
114 * Sets the cacheDir to the DEFAULT_CACHE_DIR
115 *
116 * @throws ConfigurationException
117 * if the cache directory cannot be created
118 */
119 public static void setCacheDirToDefault() throws ConfigurationException {
120 setCacheDir(DEFAULT_CACHE_DIR);
121 }
122
123 public static File getCheckedOutDirectoryAsFile() {
124 return new File(FileUtils.getPathWithoutEndingSlash(ConfigurationOptions.getCheckedOutDirectory()) + FileUtils.getDirSeparator());
125 }
126
127 /**
128 * @return Returns the svnPassword.
129 */
130 public static String getSvnPassword() {
131 return svnPassword;
132 }
133
134 /**
135 * @param svnPassword
136 * The svnPassword to set.
137 */
138 public static void setSvnPassword(final String svnPassword) {
139 SvnConfigurationOptions.svnPassword = svnPassword;
140 }
141
142 /**
143 * @return Returns the svnUsername.
144 */
145 public static String getSvnUsername() {
146 return svnUsername;
147 }
148
149 /**
150 * @param svnUsername
151 * The svnUsername to set.
152 */
153 public static void setSvnUsername(final String svnUsername) {
154 SvnConfigurationOptions.svnUsername = svnUsername;
155 }
156
157 /**
158 * @return the taskLogger
159 */
160 public static TaskLogger getTaskLogger() {
161 return taskLogger;
162 }
163
164 /**
165 * @param taskLogger
166 * the taskLogger to set
167 */
168 public static void setTaskLogger(final TaskLogger taskLogger) {
169 SvnConfigurationOptions.taskLogger = taskLogger;
170 }
171
172 /**
173 * @return the numberSvnDiffThreads
174 */
175 public static int getNumberSvnDiffThreads() {
176 return numberSvnDiffThreads;
177 }
178
179 /**
180 * @param numberSvnDiffThreads
181 * the numberSvnDiffThreads to set
182 */
183 public static void setNumberSvnDiffThreads(final int numberSvnDiffThreads) {
184 SvnConfigurationOptions.numberSvnDiffThreads = numberSvnDiffThreads;
185 }
186
187 /**
188 * @return the thresholdInMsToUseConcurrency
189 */
190 public static long getThresholdInMsToUseConcurrency() {
191 return thresholdInMsToUseConcurrency;
192 }
193
194 /**
195 * @param thresholdInMsToUseConcurrency
196 * the thresholdInMsToUseConcurrency to set
197 */
198 public static void setThresholdInMsToUseConcurrency(final long thresholdToUseConcurrency) {
199 SvnConfigurationOptions.thresholdInMsToUseConcurrency = thresholdToUseConcurrency;
200 }
201
202 public static void setDumpContent(final boolean dumpContent) {
203 dump = dumpContent;
204 }
205
206 public static boolean isDumpContent() {
207 return dump;
208 }
209
210 public static void setAnonymize(final boolean bAnon) {
211 anonymize = bAnon;
212 }
213
214 public static boolean isAnonymize() {
215 return anonymize;
216 }
217
218 /**
219 * Following request 1692245, add option -tags-dir to the command line.
220 */
221 public static void setTagsDirectory(final String tagsDir) {
222 if (tagsDir != null) {
223 tagsDirectory = tagsDir.replace('\\', '/');
224 if (!tagsDirectory.endsWith("/")) {
225 tagsDirectory = tagsDir + "/";
226 }
227 }
228 }
229
230 /**
231 * Following request 1692245, add option -tags-dir to the command line.
232 */
233 public static String getTagsDirectory() {
234 return tagsDirectory;
235 }
236
237 /**
238 * Should we use a one diff per-file-per-revision or should we use the newer one diff per-revision?
239 *
240 * @return true if legacy diff should be used.
241 */
242 public static boolean isLegacyDiff() {
243 return useLegacyDiff;
244 }
245
246 /**
247 * Should we use a one diff per-file-per-revision or should we use the newer one diff per-revision?
248 *
249 * @param isLegacy true if the legacy diff should be used.
250 */
251 public static void setLegacyDiff(final boolean isLegacy) {
252 useLegacyDiff = isLegacy;
253 }
254
255 /**
256 * Should we use svnkit to query the repository
257 *
258 * @return true if we should be using SVN kit.
259 */
260 public static boolean isUsingSVNKit() {
261 return useSvnKit;
262 }
263
264 /**
265 * Should we use svnkit to query the repository.
266 *
267 * @param isSvnKit true if we should use svnkit
268 */
269 public static void setUsingSvnKit(final boolean isSvnKit) {
270 useSvnKit = isSvnKit;
271 }
272
273 public static ISvnProcessor getProcessor()
274 {
275 if (processor==null) {
276 if (isUsingSVNKit()) {
277 try {
278 processor = new SvnKitProcessor();
279 } catch (NoClassDefFoundError ex)
280 {
281 getTaskLogger().error("Unable to find svnkit.jar and/or jna.jar in the same folder as statsvn.jar. Please copy these files and try again.");
282 throw ex;
283 }
284 }
285 else
286 processor = new SvnCommandLineProcessor();
287 }
288 return processor;
289
290 }
291
292 }