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.statcvs.output;
24  
25  import java.io.BufferedReader;
26  import java.io.File;
27  import java.io.FileInputStream;
28  import java.io.FileNotFoundException;
29  import java.io.FileReader;
30  import java.io.IOException;
31  import java.io.InputStream;
32  import java.net.MalformedURLException;
33  import java.net.URL;
34  import java.util.ArrayList;
35  import java.util.Collection;
36  import java.util.Properties;
37  import java.util.regex.Pattern;
38  import java.util.regex.PatternSyntaxException;
39  
40  import net.sf.statcvs.pages.MarkupSyntax;
41  import net.sf.statcvs.util.FilePatternMatcher;
42  import net.sf.statcvs.util.FileUtils;
43  import net.sf.statcvs.weblinks.bugs.BugTracker;
44  import net.sf.statcvs.weblinks.bugs.Bugzilla;
45  import net.sf.statcvs.weblinks.bugs.Mantis;
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  public class ConfigurationOptions {
58  
59      private static final String LOGGING_CONFIG_DEFAULT = "logging.properties";
60      private static final String LOGGING_CONFIG_VERBOSE = "logging-verbose.properties";
61      private static final String LOGGING_CONFIG_DEBUG = "logging-debug.properties";
62  
63      private static String logFileName = null;
64      private static String checkedOutDirectory = null;
65      private static String projectName = null;
66      private static String outputDir = "";
67      private static String loggingProperties = LOGGING_CONFIG_DEFAULT;
68      private static String notesFile = null;
69      private static String notes = null;
70  
71      private static FilePatternMatcher includePattern = null;
72      private static FilePatternMatcher excludePattern = null;
73  
74      private static Collection nonDeveloperLogins = new ArrayList();
75  
76      private static CssHandler cssHandler = new DefaultCssHandler("statcvs.css");
77      private static WebRepositoryIntegration webRepository = null;
78      private static Pattern symbolicNamesPattern;
79  
80      private static BugTracker webBugTracker = BugTracker.NO_BUG_TRACKER;
81      private static String outputFormat = "html";
82      private static Properties properties = new Properties();
83  
84      
85  
86  
87  
88      public static CssHandler getCssHandler() {
89          return cssHandler;
90      }
91  
92      
93  
94  
95  
96      public static String getProjectName() {
97          return projectName;
98      }
99  
100     
101 
102 
103 
104     public static String getCheckedOutDirectory() {
105         return checkedOutDirectory;
106     }
107 
108     
109 
110 
111 
112     public static String getLogFileName() {
113         return logFileName;
114     }
115 
116     
117 
118 
119 
120     public static String getOutputDir() {
121         return outputDir;
122     }
123 
124     
125 
126 
127 
128 
129     public static String getNotes() {
130         return notes;
131     }
132 
133     
134 
135 
136 
137 
138     public static WebRepositoryIntegration getWebRepository() {
139         return webRepository;
140     }
141 
142     
143 
144 
145 
146 
147     public static void setCheckedOutDirectory(final String checkedOutDirectory) throws ConfigurationException {
148         final File directory = new File(checkedOutDirectory);
149         if (!directory.exists() || !directory.isDirectory()) {
150             throw new ConfigurationException("directory does not exist: " + checkedOutDirectory);
151         }
152         ConfigurationOptions.checkedOutDirectory = checkedOutDirectory;
153     }
154 
155     
156 
157 
158 
159 
160 
161 
162 
163 
164 
165 
166     public static void setCssFile(final String cssFile) throws ConfigurationException {
167         try {
168             final URL url = new URL(cssFile);
169             if (!url.getProtocol().equals("http")) {
170                 throw new ConfigurationException("Only HTTP URLs or local files allowed for -css");
171             }
172             cssHandler = new UrlCssHandler(url);
173         } catch (final MalformedURLException isLocalFile) {
174             cssHandler = new LocalFileCssHandler(cssFile);
175         }
176         cssHandler.checkForMissingResources();
177     }
178 
179     
180 
181 
182 
183 
184     public static void setLogFileName(final String logFileName) throws ConfigurationException {
185         final File inputFile = new File(logFileName);
186         if (!inputFile.exists()) {
187             throw new ConfigurationException("Specified logfile not found: " + logFileName);
188         }
189         ConfigurationOptions.logFileName = logFileName;
190     }
191 
192     
193 
194 
195 
196 
197     public static void setOutputDir(String outputDir) throws ConfigurationException {
198         if (!outputDir.endsWith(FileUtils.getDirSeparator())) {
199             outputDir += FileUtils.getDefaultDirSeparator();
200         }
201         final File outDir = new File(outputDir);
202         if (!outDir.exists() && !outDir.mkdirs()) {
203             throw new ConfigurationException("Can't create output directory: " + outputDir);
204         }
205         ConfigurationOptions.outputDir = outputDir;
206     }
207 
208     
209 
210 
211 
212 
213 
214 
215 
216     public static void setNotesFile(final String notesFile) throws ConfigurationException {
217         final File f = new File(notesFile);
218         if (!f.exists()) {
219             throw new ConfigurationException("Notes file not found: " + notesFile);
220         }
221         if (!f.canRead()) {
222             throw new ConfigurationException("Can't read notes file: " + notesFile);
223         }
224         ConfigurationOptions.notesFile = notesFile;
225         try {
226             notes = readNotesFile();
227         } catch (final IOException e) {
228             throw new ConfigurationException(e.getMessage());
229         }
230     }
231 
232     
233 
234 
235 
236 
237 
238     public static void setViewCvsURL(final String url) {
239         ConfigurationOptions.webRepository = new ViewCvsIntegration(url);
240     }
241 
242     
243 
244 
245 
246 
247 
248 
249     public static void setCvswebURL(final String url) {
250         ConfigurationOptions.webRepository = new CvswebIntegration(url);
251     }
252 
253     
254 
255 
256 
257 
258 
259     public static void setChoraURL(final String url) {
260         ConfigurationOptions.webRepository = new ChoraIntegration(url);
261     }
262 
263     
264 
265 
266 
267 
268 
269     public static void setJCVSWebURL(final String url) {
270         ConfigurationOptions.webRepository = new JCVSWebIntegration(url);
271     }
272 
273     
274 
275 
276 
277 
278 
279 
280 
281     public static void setViewVcURL(final String url) {
282         ConfigurationOptions.webRepository = new ViewVcIntegration(url);
283     }
284 
285     
286 
287 
288 
289 
290 
291 
292 
293     public static void setViewTracURL(final String url) {
294         ConfigurationOptions.webRepository = new TracIntegration(url);
295     }
296 
297     
298 
299 
300 
301     public static void setProjectName(final String projectName) {
302         ConfigurationOptions.projectName = projectName;
303     }
304 
305     
306 
307 
308 
309     public static String getLoggingProperties() {
310         return loggingProperties;
311     }
312 
313     
314 
315 
316     public static void setVerboseLogging() {
317         ConfigurationOptions.loggingProperties = LOGGING_CONFIG_VERBOSE;
318     }
319 
320     
321 
322 
323     public static void setDebugLogging() {
324         ConfigurationOptions.loggingProperties = LOGGING_CONFIG_DEBUG;
325     }
326 
327     private static String readNotesFile() throws IOException {
328         BufferedReader r = null;
329         final StringBuffer result = new StringBuffer();
330         try {
331             r = new BufferedReader(new FileReader(notesFile));
332             String line = r.readLine();
333             while (line != null) {
334                 result.append(line);
335                 line = r.readLine();
336             }
337         } finally {
338             if (r != null) {
339                 r.close();
340             }
341         }
342         return result.toString();
343     }
344 
345     
346 
347 
348 
349 
350 
351 
352     public static void setIncludePattern(final String patternList) {
353         includePattern = new FilePatternMatcher(patternList);
354     }
355 
356     
357 
358 
359 
360 
361 
362 
363     public static void setExcludePattern(final String patternList) {
364         excludePattern = new FilePatternMatcher(patternList);
365     }
366 
367     
368 
369 
370     public static FilePatternMatcher getExcludePattern() {
371         return excludePattern;
372     }
373 
374     
375 
376 
377     public static FilePatternMatcher getIncludePattern() {
378         return includePattern;
379     }
380 
381     public static void setSymbolicNamesPattern(final String symbolicNamesPattern) throws ConfigurationException {
382         try {
383             ConfigurationOptions.symbolicNamesPattern = Pattern.compile(symbolicNamesPattern);
384         } catch (final PatternSyntaxException e) {
385             throw new ConfigurationException("Invalid regular expression for tags: " + e.getLocalizedMessage());
386         }
387     }
388 
389     public static Pattern getSymbolicNamesPattern() {
390         return symbolicNamesPattern;
391     }
392 
393     public static void setBugzillaUrl(final String bugzillaUrl) {
394         ConfigurationOptions.webBugTracker = new Bugzilla(bugzillaUrl);
395     }
396 
397     public static void setMantisUrl(final String mantisUrl) {
398         ConfigurationOptions.webBugTracker = new Mantis(mantisUrl);
399     }
400 
401     public static BugTracker getWebBugtracker() {
402         return ConfigurationOptions.webBugTracker;
403     }
404 
405     public static void setOutputFormat(final String outputFormat) throws ConfigurationException {
406         if (!"html".equals(outputFormat) && !"xdoc".equals(outputFormat) && !"xml".equals(outputFormat)) {
407             throw new ConfigurationException("Invalid output format, use only 'html', 'xdoc' or 'xml'");
408         }
409         ConfigurationOptions.outputFormat = outputFormat;
410     }
411 
412     public static String getOutputFormat() {
413         return outputFormat;
414     }
415 
416     public static MarkupSyntax getMarkupSyntax() {
417         if ("xdoc".equals(outputFormat)) {
418             return ReportConfig.XDOC;
419         } else if ("xml".equals(outputFormat)) {
420             return ReportConfig.XML;
421         }
422         return ReportConfig.HTML;
423     }
424 
425     public static void setWebRepositoryIntegration(final WebRepositoryIntegration webRepo) {
426         webRepository = webRepo;
427     }
428 
429     
430 
431 
432 
433     public static void setDefaultCssFile(final String cssName) {
434         cssHandler = new DefaultCssHandler(cssName);
435     }
436 
437     
438 
439 
440 
441 
442 
443     public static void addNonDeveloperLogin(final String loginName) {
444         nonDeveloperLogins.add(loginName);
445     }
446 
447     
448 
449 
450 
451     public static Collection getNonDeveloperLogins() {
452         return nonDeveloperLogins;
453     }
454 
455     
456 
457 
458 
459     public static void setConfigFile(final String propertiesFilename) throws ConfigurationException {
460         if (propertiesFilename != null) {
461             InputStream is = null;
462             try {
463                 is = new FileInputStream(propertiesFilename);
464                 properties.load(is);
465             } catch (final FileNotFoundException e) {
466                 throw new ConfigurationException("Unable to find the configuration file " + propertiesFilename);
467             } catch (final IOException e) {
468                 throw new ConfigurationException("Problem reading the configuration file " + propertiesFilename);
469             } finally {
470                 if (is != null) {
471                     try {
472                         is.close();
473                     } catch (final IOException e) {
474                         throw new ConfigurationException("Problem closing stream to the configuration file " + propertiesFilename);
475                     }
476                 }
477             }
478         }
479     }
480 
481     
482 
483 
484 
485     public static Properties getConfigProperties() {
486         return properties;
487     }
488 }