Coverage Report - net.sf.statcvs.output.ConfigurationOptions
 
Classes in this File Line Coverage Branch Coverage Complexity
ConfigurationOptions
10%
19/199
0%
0/70
1.829
 
 1  
 /*
 2  
     StatCvs - CVS statistics generation 
 3  
     Copyright (C) 2002  Lukasz Pekacki <lukasz@pekacki.de>
 4  
     http://statcvs.sf.net/
 5  
     
 6  
     This library is free software; you can redistribute it and/or
 7  
     modify it under the terms of the GNU Lesser General Public
 8  
     License as published by the Free Software Foundation; either
 9  
     version 2.1 of the License, or (at your option) any later version.
 10  
 
 11  
     This library is distributed in the hope that it will be useful,
 12  
     but WITHOUT ANY WARRANTY; without even the implied warranty of
 13  
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 14  
     Lesser General Public License for more details.
 15  
 
 16  
     You should have received a copy of the GNU Lesser General Public
 17  
     License along with this library; if not, write to the Free Software
 18  
     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 19  
     
 20  
         $RCSfile: ConfigurationOptions.java,v $
 21  
         $Date: 2008/04/17 15:02:01 $ 
 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  
  * Class for storing all command line parameters. The parameters
 49  
  * are set by the {@link net.sf.statcvs.Main#main} method. Interested classes
 50  
  * can read all parameter values from here.
 51  
  * 
 52  
  * TODO: Should be moved to more appropriate package and made non-public
 53  
  * 
 54  
  * @author jentzsch
 55  
  * @version $Id: ConfigurationOptions.java,v 1.33 2008/04/17 15:02:01 benoitx Exp $
 56  
  */
 57  0
 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  16
     private static String logFileName = null;
 64  16
     private static String checkedOutDirectory = null;
 65  16
     private static String projectName = null;
 66  16
     private static String outputDir = "";
 67  16
     private static String loggingProperties = LOGGING_CONFIG_DEFAULT;
 68  16
     private static String notesFile = null;
 69  16
     private static String notes = null;
 70  
 
 71  16
     private static FilePatternMatcher includePattern = null;
 72  16
     private static FilePatternMatcher excludePattern = null;
 73  
 
 74  16
     private static Collection nonDeveloperLogins = new ArrayList();
 75  
 
 76  16
     private static CssHandler cssHandler = new DefaultCssHandler("statcvs.css");
 77  16
     private static WebRepositoryIntegration webRepository = null;
 78  
     private static Pattern symbolicNamesPattern;
 79  
 
 80  16
     private static BugTracker webBugTracker = BugTracker.NO_BUG_TRACKER;
 81  16
     private static String outputFormat = "html";
 82  16
     private static Properties properties = new Properties();
 83  
 
 84  
     /**
 85  
      * returns the {@link CssHandler}
 86  
      * @return the CssHandler
 87  
      */
 88  
     public static CssHandler getCssHandler() {
 89  0
         return cssHandler;
 90  
     }
 91  
 
 92  
     /**
 93  
      * Method getProjectName.
 94  
      * @return String name of the project
 95  
      */
 96  
     public static String getProjectName() {
 97  0
         return projectName;
 98  
     }
 99  
 
 100  
     /**
 101  
      * Method getCheckedOutDirectory.
 102  
      * @return String name of the checked out directory
 103  
      */
 104  
     public static String getCheckedOutDirectory() {
 105  0
         return checkedOutDirectory;
 106  
     }
 107  
 
 108  
     /**
 109  
      * Method getLogfilename.
 110  
      * @return String name of the logfile to be parsed
 111  
      */
 112  
     public static String getLogFileName() {
 113  0
         return logFileName;
 114  
     }
 115  
 
 116  
     /**
 117  
      * Returns the outputDir.
 118  
      * @return String output Directory
 119  
      */
 120  
     public static String getOutputDir() {
 121  0
         return outputDir;
 122  
     }
 123  
 
 124  
     /**
 125  
      * Returns the report notes (from "-notes filename" switch) or <tt>null</tt>
 126  
      * if not specified
 127  
      * @return the report notes
 128  
      */
 129  
     public static String getNotes() {
 130  0
         return notes;
 131  
     }
 132  
 
 133  
     /**
 134  
      * Returns a {@link WebRepositoryIntegration} object if the user
 135  
      * has specified a URL to one. <tt>null</tt> otherwise.
 136  
      * @return the web repository
 137  
      */
 138  
     public static WebRepositoryIntegration getWebRepository() {
 139  0
         return webRepository;
 140  
     }
 141  
 
 142  
     /**
 143  
      * Sets the checkedOutDirectory.
 144  
      * @param checkedOutDirectory The checkedOutDirectory to set
 145  
      * @throws ConfigurationException if directory does not exist
 146  
      */
 147  
     public static void setCheckedOutDirectory(final String checkedOutDirectory) throws ConfigurationException {
 148  0
         final File directory = new File(checkedOutDirectory);
 149  0
         if (!directory.exists() || !directory.isDirectory()) {
 150  0
             throw new ConfigurationException("directory does not exist: " + checkedOutDirectory);
 151  
         }
 152  0
         ConfigurationOptions.checkedOutDirectory = checkedOutDirectory;
 153  0
     }
 154  
 
 155  
     /**
 156  
      * Sets the cssFile. Currently, the css file can be any local file or
 157  
      * a HTTP URL. If it is a local file, a copy will be included in the
 158  
      * output directory. If this method is never called, a default CSS file
 159  
      * will be generated in the output directory.
 160  
      *
 161  
      * @param cssFile The cssFile to set
 162  
      * @throws ConfigurationException if the specified CSS file can not be
 163  
      * accessed from local file system or from URL source, or if the specified
 164  
      * CSS file is local and does not exist
 165  
      */
 166  
     public static void setCssFile(final String cssFile) throws ConfigurationException {
 167  
         try {
 168  0
             final URL url = new URL(cssFile);
 169  0
             if (!url.getProtocol().equals("http")) {
 170  0
                 throw new ConfigurationException("Only HTTP URLs or local files allowed for -css");
 171  
             }
 172  0
             cssHandler = new UrlCssHandler(url);
 173  0
         } catch (final MalformedURLException isLocalFile) {
 174  0
             cssHandler = new LocalFileCssHandler(cssFile);
 175  0
         }
 176  0
         cssHandler.checkForMissingResources();
 177  0
     }
 178  
 
 179  
     /**
 180  
      * Sets the logFileName.
 181  
      * @param logFileName The logFileName to set
 182  
      * @throws ConfigurationException if the file does not exist
 183  
      */
 184  
     public static void setLogFileName(final String logFileName) throws ConfigurationException {
 185  0
         final File inputFile = new File(logFileName);
 186  0
         if (!inputFile.exists()) {
 187  0
             throw new ConfigurationException("Specified logfile not found: " + logFileName);
 188  
         }
 189  0
         ConfigurationOptions.logFileName = logFileName;
 190  0
     }
 191  
 
 192  
     /**
 193  
      * Sets the outputDir.
 194  
      * @param outputDir The outputDir to set
 195  
      * @throws ConfigurationException if the output directory cannot be created
 196  
      */
 197  
     public static void setOutputDir(String outputDir) throws ConfigurationException {
 198  0
         if (!outputDir.endsWith(FileUtils.getDirSeparator())) {
 199  0
             outputDir += FileUtils.getDefaultDirSeparator();
 200  
         }
 201  0
         final File outDir = new File(outputDir);
 202  0
         if (!outDir.exists() && !outDir.mkdirs()) {
 203  0
             throw new ConfigurationException("Can't create output directory: " + outputDir);
 204  
         }
 205  0
         ConfigurationOptions.outputDir = outputDir;
 206  0
     }
 207  
 
 208  
     /**
 209  
      * Sets the name of the notes file. The notes file will be included
 210  
      * on the index page of the output. It must contain a valid
 211  
      * block-level HTML fragment (for example
 212  
      * <tt>"&lt;p&gt;Some notes&lt;/p&gt;"</tt>) 
 213  
      * @param notesFile a local filename
 214  
      * @throws ConfigurationException if the file is not found or can't be read
 215  
      */
 216  
     public static void setNotesFile(final String notesFile) throws ConfigurationException {
 217  0
         final File f = new File(notesFile);
 218  0
         if (!f.exists()) {
 219  0
             throw new ConfigurationException("Notes file not found: " + notesFile);
 220  
         }
 221  0
         if (!f.canRead()) {
 222  0
             throw new ConfigurationException("Can't read notes file: " + notesFile);
 223  
         }
 224  0
         ConfigurationOptions.notesFile = notesFile;
 225  
         try {
 226  0
             notes = readNotesFile();
 227  0
         } catch (final IOException e) {
 228  0
             throw new ConfigurationException(e.getMessage());
 229  0
         }
 230  0
     }
 231  
 
 232  
     /**
 233  
      * Sets the URL to a <a href="http://viewcvs.sourceforge.net/">ViewCVS</a>
 234  
      * web-based CVS browser. This must be the URL at which the checked-out
 235  
      * module's root can be viewed in ViewCVS.
 236  
      * @param url URL to a ViewCVS repository
 237  
      */
 238  
     public static void setViewCvsURL(final String url) {
 239  0
         ConfigurationOptions.webRepository = new ViewCvsIntegration(url);
 240  0
     }
 241  
 
 242  
     /**
 243  
      * Sets the URL to a 
 244  
      * <a href="http://www.freebsd.org/projects/cvsweb.html">cvsweb</a>
 245  
      * web-based CVS browser. This must be the URL at which the checked-out
 246  
      * module's root can be viewed in cvsweb.
 247  
      * @param url URL to a cvsweb repository
 248  
      */
 249  
     public static void setCvswebURL(final String url) {
 250  0
         ConfigurationOptions.webRepository = new CvswebIntegration(url);
 251  0
     }
 252  
 
 253  
     /**
 254  
      * Sets the URL to a <a href="http://www.horde.org/chora/">Chora</a>
 255  
      * web-based CVS browser. This must be the URL at which the checked-out
 256  
      * module's root can be viewed in Chora.
 257  
      * @param url URL to a cvsweb repository
 258  
      */
 259  
     public static void setChoraURL(final String url) {
 260  0
         ConfigurationOptions.webRepository = new ChoraIntegration(url);
 261  0
     }
 262  
 
 263  
     /**
 264  
      * Sets the URL to a <a href="http://www.jcvs.org/jcvsweb/">JCVSWeb</a>
 265  
      * web-based CVS browser. This must be the URL at which the checked-out
 266  
      * module's root can be viewed in JCVSWeb.
 267  
      * @param url URL to a JCVSWeb repository
 268  
      */
 269  
     public static void setJCVSWebURL(final String url) {
 270  0
         ConfigurationOptions.webRepository = new JCVSWebIntegration(url);
 271  0
     }
 272  
 
 273  
     /**
 274  
      * Sets the URL to a <a href="http://www.viewvc.org/">ViewVC</a> web-based CVS/SVN browser. 
 275  
      * This must be the URL at which the checked-out module's
 276  
      * root can be viewed in ViewVC.
 277  
      * 
 278  
      * @param url
 279  
      *            URL to a ViewVC repository
 280  
      */
 281  
     public static void setViewVcURL(final String url) {
 282  0
         ConfigurationOptions.webRepository = new ViewVcIntegration(url);
 283  0
     }
 284  
 
 285  
     /**
 286  
      * Sets the URL to a <a href="http://trac.edgewall.org/wiki/TracBrowser">Trac</a> web-based SVN browser and issue tracking. 
 287  
      * This must be the URL at which the checked-out module's
 288  
      * root can be viewed in Trac 
 289  
      * 
 290  0
      * @param url
 291  0
      *            URL to a Trac website
 292  
      */
 293  
     public static void setViewTracURL(final String url) {
 294  0
         ConfigurationOptions.webRepository = new TracIntegration(url);
 295  0
     }
 296  
 
 297  
     /**
 298  0
      * Sets a project title to be used in the reports
 299  
      * @param projectName The project title to be used in the reports
 300  
      */
 301  
     public static void setProjectName(final String projectName) {
 302  0
         ConfigurationOptions.projectName = projectName;
 303  0
     }
 304  
 
 305  0
     /**
 306  0
      * Gets the name of the logging properties file
 307  
      * @return the name of the logging properties file
 308  
      */
 309  
     public static String getLoggingProperties() {
 310  0
         return loggingProperties;
 311  
     }
 312  0
 
 313  0
     /**
 314  
      * Sets the logging level to verbose
 315  
      */
 316  0
     public static void setVerboseLogging() {
 317  0
         ConfigurationOptions.loggingProperties = LOGGING_CONFIG_VERBOSE;
 318  0
     }
 319  0
 
 320  0
     /**
 321  0
      * Sets the logging level to debug
 322  0
      */
 323  0
     public static void setDebugLogging() {
 324  0
         ConfigurationOptions.loggingProperties = LOGGING_CONFIG_DEBUG;
 325  0
     }
 326  0
 
 327  0
     private static String readNotesFile() throws IOException {
 328  0
         BufferedReader r = null;
 329  0
         final StringBuffer result = new StringBuffer();
 330  0
         try {
 331  0
             r = new BufferedReader(new FileReader(notesFile));
 332  0
             String line = r.readLine();
 333  0
             while (line != null) {
 334  0
                 result.append(line);
 335  0
                 line = r.readLine();
 336  
             }
 337  
         } finally {
 338  0
             if (r != null) {
 339  0
                 r.close();
 340  
             }
 341  0
         }
 342  0
         return result.toString();
 343  
     }
 344  
 
 345  0
     /**
 346  0
      * Sets a file include pattern list. Only files matching one of the
 347  
      * patterns will be included in the analysis.
 348  
      * @param patternList a list of Ant-style wildcard patterns, seperated
 349  
      *                    by : or ;
 350  
      * @see net.sf.statcvs.util.FilePatternMatcher
 351  
      */
 352  0
     public static void setIncludePattern(final String patternList) {
 353  0
         includePattern = new FilePatternMatcher(patternList);
 354  0
     }
 355  
 
 356  
     /**
 357  
      * Sets a file exclude pattern list. Files matching any of the
 358  
      * patterns will be excluded from the analysis.
 359  0
      * @param patternList a list of Ant-style wildcard patterns, seperated
 360  
      *                    by : or ;
 361  
      * @see net.sf.statcvs.util.FilePatternMatcher
 362  
      */
 363  
     public static void setExcludePattern(final String patternList) {
 364  0
         excludePattern = new FilePatternMatcher(patternList);
 365  0
     }
 366  0
 
 367  0
     /**
 368  0
      * @return Returns the excludePattern.
 369  
      */
 370  
     public static FilePatternMatcher getExcludePattern() {
 371  0
         return excludePattern;
 372  0
     }
 373  0
 
 374  0
     /**
 375  0
      * @return Returns the includePattern.
 376  0
      */
 377  
     public static FilePatternMatcher getIncludePattern() {
 378  0
         return includePattern;
 379  0
     }
 380  0
 
 381  
     public static void setSymbolicNamesPattern(final String symbolicNamesPattern) throws ConfigurationException {
 382  0
         try {
 383  0
             ConfigurationOptions.symbolicNamesPattern = Pattern.compile(symbolicNamesPattern);
 384  0
         } catch (final PatternSyntaxException e) {
 385  0
             throw new ConfigurationException("Invalid regular expression for tags: " + e.getLocalizedMessage());
 386  0
         }
 387  0
     }
 388  0
 
 389  
     public static Pattern getSymbolicNamesPattern() {
 390  0
         return symbolicNamesPattern;
 391  0
     }
 392  
 
 393  
     public static void setBugzillaUrl(final String bugzillaUrl) {
 394  0
         ConfigurationOptions.webBugTracker = new Bugzilla(bugzillaUrl);
 395  0
     }
 396  
 
 397  0
     public static void setMantisUrl(final String mantisUrl) {
 398  0
         ConfigurationOptions.webBugTracker = new Mantis(mantisUrl);
 399  0
     }
 400  0
 
 401  2
     public static BugTracker getWebBugtracker() {
 402  0
         return ConfigurationOptions.webBugTracker;
 403  0
     }
 404  
 
 405  0
     public static void setOutputFormat(final String outputFormat) throws ConfigurationException {
 406  0
         if (!"html".equals(outputFormat) && !"xdoc".equals(outputFormat) && !"xml".equals(outputFormat)) {
 407  0
             throw new ConfigurationException("Invalid output format, use only 'html', 'xdoc' or 'xml'");
 408  0
         }
 409  0
         ConfigurationOptions.outputFormat = outputFormat;
 410  0
     }
 411  
 
 412  
     public static String getOutputFormat() {
 413  6
         return outputFormat;
 414  0
     }
 415  0
 
 416  0
     public static MarkupSyntax getMarkupSyntax() {
 417  0
         if ("xdoc".equals(outputFormat)) {
 418  0
             return ReportConfig.XDOC;
 419  0
         } else if ("xml".equals(outputFormat)) {
 420  0
             return ReportConfig.XML;
 421  
         }
 422  0
         return ReportConfig.HTML;
 423  0
     }
 424  
 
 425  0
     public static void setWebRepositoryIntegration(final WebRepositoryIntegration webRepo) {
 426  0
         webRepository = webRepo;
 427  0
     }
 428  
 
 429  
     /**
 430  
     * Allow change between css that are shipped with the tool.
 431  
     * @param cssName statcvs.css or objectlab-statcvs-xdoc.css
 432  0
     */
 433  0
     public static void setDefaultCssFile(final String cssName) {
 434  0
         cssHandler = new DefaultCssHandler(cssName);
 435  0
     }
 436  
 
 437  
     /**
 438  
      * Excludes a login name from charts and reports that compare
 439  
      * several developers. Useful to reduce the noise from admin
 440  0
      * accounts.
 441  0
      * @param loginName A login name
 442  0
      */
 443  
     public static void addNonDeveloperLogin(final String loginName) {
 444  0
         nonDeveloperLogins.add(loginName);
 445  0
     }
 446  0
 
 447  0
     /**
 448  0
      * Gets login names that should be excluded from charts and
 449  0
      * reports that compare several developers.
 450  
      */
 451  0
     public static Collection getNonDeveloperLogins() {
 452  0
         return nonDeveloperLogins;
 453  0
     }
 454  0
 
 455  0
     /**
 456  0
      * Set the config file that may contain user details.
 457  
      * @param propertiesFilename
 458  0
      */
 459  
     public static void setConfigFile(final String propertiesFilename) throws ConfigurationException {
 460  0
         if (propertiesFilename != null) {
 461  0
             InputStream is = null;
 462  0
             try {
 463  0
                 is = new FileInputStream(propertiesFilename);
 464  0
                 properties.load(is);
 465  0
             } catch (final FileNotFoundException e) {
 466  0
                 throw new ConfigurationException("Unable to find the configuration file " + propertiesFilename);
 467  0
             } catch (final IOException e) {
 468  0
                 throw new ConfigurationException("Problem reading the configuration file " + propertiesFilename);
 469  
             } finally {
 470  0
                 if (is != null) {
 471  
                     try {
 472  0
                         is.close();
 473  0
                     } catch (final IOException e) {
 474  25
                         throw new ConfigurationException("Problem closing stream to the configuration file " + propertiesFilename);
 475  0
                     }
 476  
                 }
 477  
             }
 478  
         }
 479  0
     }
 480  
 
 481  
     /**
 482  
      * The config properties.
 483  
      * @return
 484  
      */
 485  
     public static Properties getConfigProperties() {
 486  75
         return properties;
 487  
     }
 488  
 }