Coverage Report - net.sf.statsvn.util.SvnStartupUtils
 
Classes in this File Line Coverage Branch Coverage Complexity
SvnStartupUtils
0%
0/69
0%
0/32
4.25
 
 1  
 package net.sf.statsvn.util;
 2  
 
 3  
 import java.io.IOException;
 4  
 import java.io.InputStream;
 5  
 import java.io.InputStreamReader;
 6  
 import java.util.regex.Matcher;
 7  
 import java.util.regex.Pattern;
 8  
 
 9  
 import net.sf.statcvs.util.LookaheadReader;
 10  
 import net.sf.statsvn.output.SvnConfigurationOptions;
 11  
 
 12  
 /**
 13  
  * Utility class that verifies if the correct version of subversion is used.
 14  
  * 
 15  
  * @author Jean-Philippe Daigle <jpdaigle@softwareengineering.ca>
 16  
  * 
 17  
  * @version $Id: SvnStartupUtils.java 394 2009-08-10 20:08:46Z jkealey $
 18  
  */
 19  
 public class SvnStartupUtils implements ISvnVersionProcessor {
 20  
         private static final String SVN_VERSION_COMMAND = "svn --version";
 21  
 
 22  
         public static final String SVN_MINIMUM_VERSION = "1.3.0";
 23  
 
 24  
         public static final String SVN_MINIMUM_VERSION_DIFF_PER_REV = "1.4.0";
 25  
 
 26  
         private static final String SVN_VERSION_LINE_PATTERN = ".* [0-9]+\\.[0-9]+\\.[0-9]+.*";
 27  
 
 28  
         private static final String SVN_VERSION_PATTERN = "[0-9]+\\.[0-9]+\\.[0-9]+";
 29  
 
 30  
 
 31  
     protected ISvnProcessor processor;
 32  
 
 33  
     /**
 34  
      * Invokes various calls needed during StatSVN's startup, including the svn version command line.   
 35  
      */
 36  0
     public SvnStartupUtils(ISvnProcessor processor) {
 37  0
         this.processor = processor;
 38  0
     }
 39  
 
 40  0
     protected ISvnProcessor getProcessor() {
 41  0
         return processor;
 42  
     }
 43  
 
 44  
         /* (non-Javadoc)
 45  
      * @see net.sf.statsvn.util.IVersionProcessor#checkSvnVersionSufficient()
 46  
      */
 47  
         public synchronized String checkSvnVersionSufficient() throws SvnVersionMismatchException {
 48  0
                 ProcessUtils pUtils = null;
 49  
                 try {
 50  
 
 51  0
                         pUtils = ProcessUtils.call(SVN_VERSION_COMMAND);
 52  0
                         final InputStream istream = pUtils.getInputStream();
 53  0
                         final LookaheadReader reader = new LookaheadReader(new InputStreamReader(istream));
 54  
 
 55  0
                         while (reader.hasNextLine()) {
 56  0
                                 final String line = reader.nextLine();
 57  0
                                 if (line.matches(SVN_VERSION_LINE_PATTERN)) {
 58  
                                         // We have our version line
 59  0
                                         final Pattern pRegex = Pattern.compile(SVN_VERSION_PATTERN);
 60  0
                                         final Matcher m = pRegex.matcher(line);
 61  0
                                         if (m.find()) {
 62  0
                                                 final String versionString = line.substring(m.start(), m.end());
 63  0
 
 64  0
                                                 // we perform a simple string comparison against the version numbers
 65  0
                                                 if (versionString.compareTo(SVN_MINIMUM_VERSION) >= 0) {
 66  0
                                                         return versionString; // success
 67  
                                                 } else {
 68  0
                                                         throw new SvnVersionMismatchException(versionString, SVN_MINIMUM_VERSION);
 69  0
                                                 }
 70  0
                                         }
 71  
                                 }
 72  0
                         }
 73  
 
 74  0
                         if (pUtils.hasErrorOccured()) {
 75  0
                                 throw new IOException(pUtils.getErrorMessage());
 76  0
                         }
 77  0
                 } catch (final IOException e) {
 78  0
                         SvnConfigurationOptions.getTaskLogger().info(e.getMessage());
 79  0
                 } catch (final RuntimeException e) {
 80  0
                         SvnConfigurationOptions.getTaskLogger().info(e.getMessage());
 81  0
                 } finally {
 82  0
                         if (pUtils != null) {
 83  0
                                 try {
 84  0
                                         pUtils.close();
 85  0
                                 } catch (final IOException e) {
 86  0
                                         SvnConfigurationOptions.getTaskLogger().info(e.getMessage());
 87  0
                                 }
 88  0
                         }
 89  0
                 }
 90  0
 
 91  0
                 throw new SvnVersionMismatchException();
 92  
         }
 93  0
 
 94  
         /* (non-Javadoc)
 95  0
      * @see net.sf.statsvn.util.IVersionProcessor#checkDiffPerRevPossible(java.lang.String)
 96  
      */
 97  
         public synchronized boolean checkDiffPerRevPossible(final String version) {
 98  
                 // we perform a simple string comparison against the version numbers
 99  0
                 return version.compareTo(SVN_MINIMUM_VERSION_DIFF_PER_REV) >= 0;
 100  
         }
 101  
 }