Coverage Report - net.sf.statsvn.output.SvnConfigurationOptions
 
Classes in this File Line Coverage Branch Coverage Complexity
SvnConfigurationOptions
42%
46/109
17%
4/24
1.346
 
 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: 2005/03/20 19:12:25 $
 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  124
 
 49  
         private static final int DEFAULT_NUMBER_THREADS = 25;
 50  124
 
 51  4
         private static String cacheDir = "";
 52  124
 
 53  4
         private static final String DEFAULT_CACHE_DIR = System.getProperty("user.home") + FileUtils.getDirSeparator() + ".statsvn" + FileUtils.getDirSeparator();
 54  124
 
 55  4
         private static String svnUsername = null;
 56  124
 
 57  4
         private static String svnPassword = null;
 58  124
 
 59  4
         private static TaskLogger taskLogger = new JavaUtilTaskLogger();
 60  124
 
 61  4
         private static int numberSvnDiffThreads = DEFAULT_NUMBER_THREADS;
 62  124
 
 63  4
         private static long thresholdInMsToUseConcurrency = DEFAULT_THRESHOLD_MS_FOR_CONCURRENCY;
 64  124
 
 65  4
         private static boolean dump = false;
 66  124
 
 67  4
         private static boolean anonymize = false;
 68  
 
 69  128
         private static String tagsDirectory = "/tags/";
 70  
 
 71  
         // use the newer diff. will be overridden if this is not possible. 
 72  4
         private static boolean useLegacyDiff = false;
 73  
 
 74  
         private static ISvnProcessor processor;
 75  0
 
 76  4
     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  0
         private SvnConfigurationOptions() {
 83  0
         }
 84  58
 
 85  
         /**
 86  
          * Returns the cacheDir.
 87  
          * 
 88  
          * @return String output Directory
 89  
          */
 90  
         public static String getCacheDir() {
 91  2
                 return cacheDir;
 92  
         }
 93  
 
 94  
         /**
 95  
          * Sets the cacheDir.
 96  29
          * 
 97  29
          * @param cacheDir
 98  
          *            The cacheDir to set
 99  29
          * @throws ConfigurationException
 100  29
          *             if the cache directory cannot be created
 101  0
          */
 102  
         public static void setCacheDir(String cacheDir) throws ConfigurationException {
 103  30
                 if (!cacheDir.endsWith(FileUtils.getDirSeparator())) {
 104  30
                         cacheDir += FileUtils.getDefaultDirSeparator();
 105  
                 }
 106  1
                 final File cDir = new File(cacheDir);
 107  1
                 if (!cDir.exists() && !cDir.mkdirs()) {
 108  0
                         throw new ConfigurationException("Can't create cache directory: " + cacheDir);
 109  
                 }
 110  1
                 SvnConfigurationOptions.cacheDir = cacheDir;
 111  1
         }
 112  
 
 113  0
         /**
 114  0
          * Sets the cacheDir to the DEFAULT_CACHE_DIR
 115  
          * 
 116  
          * @throws ConfigurationException
 117  0
          *             if the cache directory cannot be created
 118  
          */
 119  
         public static void setCacheDirToDefault() throws ConfigurationException {
 120  0
                 setCacheDir(DEFAULT_CACHE_DIR);
 121  0
         }
 122  
 
 123  
         public static File getCheckedOutDirectoryAsFile() {
 124  0
                 return new File(FileUtils.getPathWithoutEndingSlash(ConfigurationOptions.getCheckedOutDirectory()) + FileUtils.getDirSeparator());
 125  
         }
 126  
 
 127  
         /**
 128  
          * @return Returns the svnPassword.
 129  
          */
 130  
         public static String getSvnPassword() {
 131  0
                 return svnPassword;
 132  0
         }
 133  0
 
 134  
         /**
 135  
          * @param svnPassword
 136  
          *            The svnPassword to set.
 137  
          */
 138  
         public static void setSvnPassword(final String svnPassword) {
 139  0
                 SvnConfigurationOptions.svnPassword = svnPassword;
 140  0
         }
 141  
 
 142  
         /**
 143  
          * @return Returns the svnUsername.
 144  
          */
 145  
         public static String getSvnUsername() {
 146  0
                 return svnUsername;
 147  0
         }
 148  0
 
 149  
         /**
 150  
          * @param svnUsername
 151  
          *            The svnUsername to set.
 152  
          */
 153  
         public static void setSvnUsername(final String svnUsername) {
 154  227517
                 SvnConfigurationOptions.svnUsername = svnUsername;
 155  0
         }
 156  
 
 157  
         /**
 158  
          * @return the taskLogger
 159  
          */
 160  
         public static TaskLogger getTaskLogger() {
 161  7836
                 return taskLogger;
 162  0
         }
 163  0
 
 164  
         /**
 165  
          * @param taskLogger
 166  
          *            the taskLogger to set
 167  
          */
 168  
         public static void setTaskLogger(final TaskLogger taskLogger) {
 169  116
                 SvnConfigurationOptions.taskLogger = taskLogger;
 170  0
         }
 171  
 
 172  
         /**
 173  
          * @return the numberSvnDiffThreads
 174  
          */
 175  
         public static int getNumberSvnDiffThreads() {
 176  4
                 return numberSvnDiffThreads;
 177  0
         }
 178  0
 
 179  
         /**
 180  
          * @param numberSvnDiffThreads
 181  
          *            the numberSvnDiffThreads to set
 182  
          */
 183  
         public static void setNumberSvnDiffThreads(final int numberSvnDiffThreads) {
 184  0
                 SvnConfigurationOptions.numberSvnDiffThreads = numberSvnDiffThreads;
 185  0
         }
 186  
 
 187  
         /**
 188  
          * @return the thresholdInMsToUseConcurrency
 189  
          */
 190  
         public static long getThresholdInMsToUseConcurrency() {
 191  0
                 return thresholdInMsToUseConcurrency;
 192  0
         }
 193  0
 
 194  
         /**
 195  
          * @param thresholdInMsToUseConcurrency
 196  0
          *            the thresholdInMsToUseConcurrency to set
 197  0
          */
 198  
         public static void setThresholdInMsToUseConcurrency(final long thresholdToUseConcurrency) {
 199  0
                 SvnConfigurationOptions.thresholdInMsToUseConcurrency = thresholdToUseConcurrency;
 200  29
         }
 201  
 
 202  
         public static void setDumpContent(final boolean dumpContent) {
 203  0
                 dump = dumpContent;
 204  0
         }
 205  0
 
 206  
         public static boolean isDumpContent() {
 207  1
                 return dump;
 208  161074
         }
 209  
 
 210  
         public static void setAnonymize(final boolean bAnon) {
 211  0
                 anonymize = bAnon;
 212  0
         }
 213  
 
 214  
         public static boolean isAnonymize() {
 215  5551
                 return anonymize;
 216  0
         }
 217  0
 
 218  0
         /**
 219  
          * Following request 1692245, add option -tags-dir to the command line.
 220  
          */
 221  0
         public static void setTagsDirectory(final String tagsDir) {
 222  0
                 if (tagsDir != null) {
 223  0
                         tagsDirectory = tagsDir.replace('\\', '/');
 224  0
                         if (!tagsDirectory.endsWith("/")) {
 225  0
                                 tagsDirectory = tagsDir + "/";
 226  
                         }
 227  157122
                 }
 228  0
         }
 229  
 
 230  
         /**
 231  
          * Following request 1692245, add option -tags-dir to the command line.
 232  
          */
 233  
         public static String getTagsDirectory() {
 234  5418
                 return tagsDirectory;
 235  
         }
 236  58
 
 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  2
                 return useLegacyDiff;
 244  
         }
 245  0
 
 246  0
         /**
 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  0
                 useLegacyDiff = isLegacy;
 253  0
         }
 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  0
         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  0
         useSvnKit = isSvnKit;
 271  0
     }
 272  
 
 273  
         public static ISvnProcessor getProcessor()
 274  
         {
 275  0
             if (processor==null) {
 276  0
                 if (isUsingSVNKit()) {
 277  
                     try {
 278  0
                     processor = new SvnKitProcessor();
 279  0
                     } catch (NoClassDefFoundError ex)
 280  
                     {
 281  0
                         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  0
                         throw ex;
 283  0
                     }
 284  
                 }
 285  
                 else
 286  0
                     processor = new SvnCommandLineProcessor();
 287  
             }
 288  0
             return processor;
 289  
                 
 290  
         }
 291  
 
 292  
 }