Coverage Report - net.sf.statsvn.util.svnkit.SvnKitInfo
 
Classes in this File Line Coverage Branch Coverage Complexity
SvnKitInfo
0%
0/24
0%
0/6
1.778
SvnKitInfo$SvnKitInfoHandler
0%
0/4
0%
0/6
1.778
 
 1  
 package net.sf.statsvn.util.svnkit;
 2  
 
 3  
 import java.io.File;
 4  
 import java.io.IOException;
 5  
 
 6  
 import net.sf.statcvs.input.LogSyntaxException;
 7  
 import net.sf.statsvn.output.SvnConfigurationOptions;
 8  
 import net.sf.statsvn.util.ISvnProcessor;
 9  
 import net.sf.statsvn.util.SvnInfoUtils;
 10  
 import net.sf.statsvn.util.SvnVersionMismatchException;
 11  
 
 12  
 import org.tmatesoft.svn.core.SVNDepth;
 13  
 import org.tmatesoft.svn.core.SVNException;
 14  
 import org.tmatesoft.svn.core.wc.SVNClientManager;
 15  
 import org.tmatesoft.svn.core.wc.xml.SVNXMLInfoHandler;
 16  
 import org.xml.sax.Attributes;
 17  
 
 18  
 /**
 19  
  * 
 20  
  * Performs svn info using svnkit. 
 21  
  * 
 22  
  * @author jkealey, yogesh
 23  
  *
 24  
  */
 25  
 public class SvnKitInfo extends SvnInfoUtils {
 26  
 
 27  
     protected static class SvnKitInfoHandler extends SvnInfoUtils.SvnInfoHandler {
 28  
 
 29  
         public SvnKitInfoHandler(SvnInfoUtils infoUtils) {
 30  0
             super(infoUtils);
 31  0
         }
 32  
 
 33  
         protected boolean isRootFolder(Attributes attributes) {
 34  0
             String path = attributes.getValue("path");
 35  
             // . is never returned by SvnKit, it appears. 
 36  0
             return (path.equals(".") || new File(path).equals(((SvnKitInfo) getInfoUtils()).getCheckoutDirectory()))
 37  
                     && attributes.getValue("kind").equals("dir");
 38  
         }
 39  
 
 40  
     }
 41  
 
 42  
     public SvnKitInfo(ISvnProcessor processor) {
 43  0
         super(processor);
 44  0
     }
 45  
 
 46  
     /**
 47  
      * Verifies that the "svn info" command can return the repository root
 48  
      * (info available in svn >= 1.3.0)
 49  
      * 
 50  
      * @throws SvnVersionMismatchException
 51  
      *             if <tt>svn info</tt> failed to provide a non-empty repository root
 52  
      */
 53  
     public synchronized void checkRepoRootAvailable() throws SvnVersionMismatchException {
 54  
 
 55  
         try {
 56  0
             loadInfo(true);
 57  0
             if (getRootUrl() != null)
 58  0
                 return;
 59  0
         } catch (Exception e) {
 60  0
             SvnConfigurationOptions.getTaskLogger().info(e.getMessage());
 61  0
         }
 62  
 
 63  0
         throw new SvnVersionMismatchException(SVN_REPO_ROOT_NOTFOUND);
 64  
     }
 65  
 
 66  
     public File getCheckoutDirectory() {
 67  0
         return getSvnKitProcessor().getCheckoutDirectory();
 68  
     }
 69  
 
 70  
     public SVNClientManager getManager() {
 71  0
         return getSvnKitProcessor().getManager();
 72  
     }
 73  
 
 74  
     public SvnKitProcessor getSvnKitProcessor() {
 75  0
         return (SvnKitProcessor) getProcessor();
 76  
     }
 77  
 
 78  
     protected void handleSvnException(SVNException ex) throws IOException {
 79  0
         String msg = "svn info " + ex.getMessage();
 80  0
         SvnConfigurationOptions.getTaskLogger().error(msg);
 81  0
         throw new IOException(msg);
 82  
     }
 83  
 
 84  
     /**
 85  
      * Loads the information from svn info if needed.
 86  
      * 
 87  
      * @param bRootOnly
 88  
      *            load only the root?
 89  
      * @throws LogSyntaxException
 90  
      *             if the format of the svn info is invalid
 91  
      * @throws IOException
 92  
      *             if we can't read from the response stream.
 93  
      */
 94  
     protected void loadInfo(final boolean bRootOnly) throws LogSyntaxException, IOException {
 95  0
         if (isQueryNeeded(true /*bRootOnly*/)) {
 96  0
             clearCache();
 97  
 
 98  
             try {
 99  0
                 SVNXMLInfoHandler handler = new SVNXMLInfoHandler(new SvnKitInfoHandler(this));
 100  0
                 handler.setTargetPath(getCheckoutDirectory());
 101  0
                 getManager().getWCClient().doInfo(getCheckoutDirectory(), null, null, SVNDepth.fromRecurse(!bRootOnly), null,
 102  
                         handler);
 103  0
             } catch (SVNException e) {
 104  0
                 handleSvnException(e);
 105  0
             }
 106  
         }
 107  0
     }
 108  
 
 109  
 }