Coverage report

  %line %branch
nl.toolforge.karma.core.cmd.CommandException
96% 
100% 

 1  
 /*
 2  
 Karma core - Core of the Karma application
 3  
 Copyright (C) 2004  Toolforge <www.toolforge.nl>
 4  
 
 5  
 This library is free software; you can redistribute it and/or
 6  
 modify it under the terms of the GNU Lesser General Public
 7  
 License as published by the Free Software Foundation; either
 8  
 version 2.1 of the License, or (at your option) any later version.
 9  
 
 10  
 This library is distributed in the hope that it will be useful,
 11  
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 12  
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 13  
 Lesser General Public License for more details.
 14  
 
 15  
 You should have received a copy of the GNU Lesser General Public
 16  
 License along with this library; if not, write to the Free Software
 17  
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 18  
 */
 19  
 package nl.toolforge.karma.core.cmd;
 20  
 
 21  
 import nl.toolforge.karma.core.ErrorCode;
 22  
 
 23  
 /**
 24  
  * Exceptions thrown during the execution of a command.
 25  
  *
 26  
  * @author D.A. Smedes
 27  
  * @version $Id:
 28  
  */
 29  
 public class CommandException extends Exception {
 30  
 
 31  78
   private ErrorCode errorCode = null;
 32  78
   private Object[] messageArguments = null;
 33  
 
 34  
   public static final String EXCEPTION_PREFIX = "CMD-";
 35  
 
 36  
   /** Not to be used for business logic. Needed for testing. */
 37  26
   public static final ErrorCode TEST_CODE = new ErrorCode(EXCEPTION_PREFIX + "00000");
 38  
 
 39  26
   public static final ErrorCode NO_IMPLEMENTING_CLASS = new ErrorCode(EXCEPTION_PREFIX + "00001");
 40  
 
 41  26
   public static final ErrorCode UNKNOWN_COMMAND = new ErrorCode(EXCEPTION_PREFIX + "00029");
 42  
   /** The command is invalid. The command could not be created. */
 43  26
   public static final ErrorCode INVALID_COMMAND = new ErrorCode(EXCEPTION_PREFIX + "00030");
 44  
   /** A required option (see &lt;required&gt;-attributes for options in <code>commands.xml</code>. */
 45  26
   public static ErrorCode MISSING_OPTION = new ErrorCode(EXCEPTION_PREFIX + "00031");
 46  
   /** Argument for a command option is missing. */
 47  26
   public static ErrorCode MISSING_ARGUMENT = new ErrorCode(EXCEPTION_PREFIX + "00032");
 48  
   /** Argument for a command option is invalid. */
 49  26
   public static ErrorCode INVALID_ARGUMENT = new ErrorCode(EXCEPTION_PREFIX + "00033");
 50  
   /** Invalid option. */
 51  26
   public static final ErrorCode INVALID_OPTION = new ErrorCode(EXCEPTION_PREFIX + "00034");
 52  
   /** No arguments required. More of a warning really. */
 53  26
   public static final ErrorCode NO_OPTIONS_REQUIRED = new ErrorCode(EXCEPTION_PREFIX + "00035");;
 54  
   /** The build of a module failed. */
 55  26
   public static final ErrorCode BUILD_FAILED = new ErrorCode(EXCEPTION_PREFIX + "00040");
 56  
   /** The build of a module failed. */
 57  26
   public static final ErrorCode BUILD_FAILED_TOO_MANY_MISSING_DEPENDENCIES = new ErrorCode(EXCEPTION_PREFIX + "00046");
 58  
   /** The test of a module failed. */
 59  26
   public static final ErrorCode TEST_FAILED = new ErrorCode(EXCEPTION_PREFIX + "00050");
 60  
   /** Generating the test report failed. */
 61  26
   public static final ErrorCode TEST_REPORT_FAILED = new ErrorCode(EXCEPTION_PREFIX + "00052");
 62  
   /** The test of a module failed. */
 63  26
   public static final ErrorCode CLEAN_MODULE_FAILED = new ErrorCode(EXCEPTION_PREFIX + "00060");
 64  
   /** The test of a module failed. */
 65  26
   public static final ErrorCode CLEAN_ALL_FAILED = new ErrorCode(EXCEPTION_PREFIX + "00063");
 66  
   /** The packaging of a module failed. */
 67  26
   public static final ErrorCode PACKAGE_FAILED = new ErrorCode(EXCEPTION_PREFIX + "00070");
 68  
   /** The packaging of a module failed. */
 69  26
   public static final ErrorCode PACKAGE_FAILED_NOTHING_TO_PACKAGE = new ErrorCode(EXCEPTION_PREFIX + "00074");
 70  
   /** The packaging of a module failed. */
 71  26
   public static final ErrorCode PACKAGE_FAILED_NO_APPLICATION_XML = new ErrorCode(EXCEPTION_PREFIX + "00071");
 72  
   /** The packaging of a module failed. */
 73  26
   public static final ErrorCode PACKAGE_FAILED_INVALID_APPLICATION_XML = new ErrorCode(EXCEPTION_PREFIX + "00072");
 74  
   /** The packaging of a module failed. */
 75  26
   public static final ErrorCode PACKAGE_FAILED_WRONG_MODULE_TYPE = new ErrorCode(EXCEPTION_PREFIX + "00073");
 76  
   /** When the manifest is a development manifest and the module is STATIC. Not allowed to start work on this module. */
 77  26
   public static final ErrorCode START_WORK_NOT_ALLOWED_ON_STATIC_MODULE = new ErrorCode(EXCEPTION_PREFIX + "00041");
 78  
   /** When the module is not (a descendant of) <code>BaseModule</code>. Not allowed to start work on this module. */
 79  26
   public static final ErrorCode MODULE_TYPE_MUST_BE_BASEMODULE = new ErrorCode(EXCEPTION_PREFIX + "00042");
 80  
   /** Promote command is not allowed on static and dynamic modules. */
 81  15
   public static final ErrorCode PROMOTE_ONLY_ALLOWED_ON_WORKING_MODULE = new ErrorCode(EXCEPTION_PREFIX + "00043");
 82  
   /** Promote command is not allowed on static and dynamic modules. */
 83  10
   public static final ErrorCode PROMOTE_WITH_INCREASE_MAJOR_VERSION_NOT_ALLOWED_ON_RELEASE_MANIFEST = new ErrorCode(EXCEPTION_PREFIX + "00075");
 84  
 
 85  
 
 86  
   /**
 87  
    * <p>The dependency that is referenced does not exists. This could happen when:
 88  
    *
 89  11
    * <ul>
 90  
    *   <li/>the dependency is a sourcemodule dependency and the jar it refers to has not been built.
 91  11
    *   <li/>the dependency is a jar dependency and the artifact is not available in the Maven repository locally.
 92  5
    * </ul>
 93  11
    */
 94  15
   public static final ErrorCode DEPENDENCY_DOES_NOT_EXIST = new ErrorCode(EXCEPTION_PREFIX + "00044");
 95  11
 
 96  15
   public static final ErrorCode DEPENDENCY_FILE_INVALID = new ErrorCode(EXCEPTION_PREFIX + "00047");
 97  11
   /** <code>src/java</code> (the default directory for a module where java sources are located) is missing. */
 98  15
   public static final ErrorCode NO_SRC_DIR = new ErrorCode(EXCEPTION_PREFIX + "00045");
 99  11
   /** <code>test/java</code> (the default directory for a module where test java sources are located) is missing. */
 100  15
   public static final ErrorCode NO_TEST_DIR = new ErrorCode(EXCEPTION_PREFIX + "00051");
 101  11
 
 102  15
   public static final ErrorCode UNCOMMITTED_NEW_FILES = new ErrorCode(EXCEPTION_PREFIX + "00055");
 103  11
 
 104  15
   public static final ErrorCode UNCOMMITTED_CHANGED_FILES = new ErrorCode(EXCEPTION_PREFIX + "00056");
 105  11
 
 106  15
   public static final ErrorCode UNCOMMITTED_REMOVED_FILES = new ErrorCode(EXCEPTION_PREFIX + "00057");
 107  11
   /** <code>build/&lt;module&gt;</code> (the default directory for a module where built files are located) is missing. */
 108  15
   public static final ErrorCode NO_MODULE_BUILD_DIR = new ErrorCode(EXCEPTION_PREFIX + "00061");
 109  11
   /** <code>build</code> (the default directory where built files are located) is missing. */
 110  15
   public static final ErrorCode NO_BUILD_DIR = new ErrorCode(EXCEPTION_PREFIX + "00062");
 111  11
 
 112  15
   public static final ErrorCode MODULE_VERSION_ERROR = new ErrorCode(EXCEPTION_PREFIX + "00064");
 113  11
 
 114  15
   public static final ErrorCode TEST_WARNING = new ErrorCode(EXCEPTION_PREFIX + "00100");
 115  11
 
 116  15
   public static final ErrorCode BUILD_WARNING = new ErrorCode(EXCEPTION_PREFIX + "00101");
 117  11
   /** Thrown when a module is not working and the user wants to stop work on it. */
 118  15
   public static final ErrorCode INVALID_STATE_MODULE_NOT_WORKING = new ErrorCode(EXCEPTION_PREFIX + "00102");
 119  11
 
 120  15
   public static final ErrorCode MODULE_NOT_LOCAL = new ErrorCode(EXCEPTION_PREFIX + "00103");
 121  
   /** The location type is invalid. Happens when another type of location is required than is specified. */
 122  26
   public static final ErrorCode INVALID_LOCATION_TYPE = new ErrorCode(EXCEPTION_PREFIX + "00104");
 123  11
   /** The working context could not be initialized. */
 124  10
   public static final ErrorCode CANNOT_INITIALIZE_WORKING_CONTEXT = new ErrorCode(EXCEPTION_PREFIX + "00105");
 125  5
   /** A module is encountered with state WORKING. This is not allowed when creating a release manifest. */
 126  12
   public static final ErrorCode MODULE_CANNOT_BE_WORKING_FOR_RELEASE_MANIFEST = new ErrorCode(EXCEPTION_PREFIX + "00106");
 127  3
   /** Configuration for working context is invalid. */
 128  8
   public static final ErrorCode INVALID_WORKING_CONTEXT_CONFIGURATION = new ErrorCode(EXCEPTION_PREFIX + "00107");
 129  2
 
 130  35
   public CommandException(ErrorCode errorCode) {
 131  38
     this(errorCode, null);
 132  38
   }
 133  48
 
 134  15
   public CommandException(Throwable t, ErrorCode errorCode) {
 135  24
     this(t, errorCode, null);
 136  24
   }
 137  15
 
 138  15
   public CommandException(ErrorCode errorCode, Object[] messageArguments) {
 139  21
     super();
 140  21
     this.errorCode = errorCode;
 141  15
     this.messageArguments = messageArguments;
 142  48
   }
 143  22
 
 144  
   public CommandException(Throwable t, ErrorCode errorCode, Object[] messageArguments) {
 145  48
     super(t);
 146  10
     this.errorCode = errorCode;
 147  9
     this.messageArguments = messageArguments;
 148  21
   }
 149  6
 
 150  13
   public String getMessage() {
 151  15
     if (messageArguments != null && messageArguments.length > 0) {
 152  16
       errorCode.setMessageArguments(messageArguments);
 153  33
     }
 154  15
     return getErrorCode().getErrorMessage();
 155  
   }
 156  15
 
 157  
   /**
 158  9
    * Gets the exceptions' {@link nl.toolforge.karma.core.ErrorCode}.
 159  
    * @return
 160  6
    */
 161  
   public final ErrorCode getErrorCode() {
 162  15
     return errorCode;
 163  
   }
 164  
 
 165  
   public final Object[] getMessageArguments() {
 166  0
     return messageArguments;
 167  
   }
 168  
 
 169  
 }

This report is generated by jcoverage, Maven and Maven JCoverage Plugin.