Coverage Report - com.aragost.javahg.UnknownCommandException
 
Classes in this File Line Coverage Branch Coverage Complexity
UnknownCommandException
90%
10/11
N/A
1.25
 
 1  
 package com.aragost.javahg;
 2  
 
 3  
 import com.aragost.javahg.internals.AbstractCommand;
 4  
 
 5  
 /**
 6  
  * Exception thrown when an attempt it made to execute a command that
 7  
  * the underlying Mercurial command server doesn't know.
 8  
  * <p>
 9  
  * Since Mercurial from time to time introduce new commands (e.g.
 10  
  * phase, graft), JavaHg implements these. But if you attempt to use
 11  
  * them against an older version of Mercurial you get this exception.
 12  
  * 
 13  
  */
 14  
 public class UnknownCommandException extends RuntimeException {
 15  
 
 16  
     private static final long serialVersionUID = 1L;
 17  
 
 18  
     // TODO Exceptions are Serializable, AbstractCommand not. So we
 19  
     // should not have it as a non-transient field.
 20  
     private final AbstractCommand command;
 21  
 
 22  
     public UnknownCommandException(AbstractCommand cmd) {
 23  1
         super(createMessage(cmd));
 24  1
         this.command = cmd;
 25  1
     }
 26  
 
 27  
     private static String createMessage(AbstractCommand cmd) {
 28  1
         HgVersion hgVersion = getHgVersion(cmd);
 29  1
         return "Mercurial command '" + cmd.getCommandName() + "' is not supported by Mercurial version: "
 30  
                 + hgVersion.getVersionString();
 31  
     }
 32  
 
 33  
     private static HgVersion getHgVersion(AbstractCommand cmd) {
 34  1
         HgVersion hgVersion = HgVersion.unknown();
 35  
         try {
 36  1
             hgVersion = cmd.getRepository().getHgVersion();
 37  0
         } catch (RuntimeException e) {
 38  
             // Something went wrong, but ignore this so we can create
 39  
             // this exception
 40  1
         }
 41  1
         return hgVersion;
 42  
     }
 43  
 
 44  
     public AbstractCommand getCommand() {
 45  1
         return command;
 46  
     }
 47  
 
 48  
 }