View Javadoc

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    private ErrorCode errorCode = null;
32    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    public static final ErrorCode TEST_CODE = new ErrorCode(EXCEPTION_PREFIX + "00000");
38  
39    public static final ErrorCode NO_IMPLEMENTING_CLASS = new ErrorCode(EXCEPTION_PREFIX + "00001");
40  
41    public static final ErrorCode UNKNOWN_COMMAND = new ErrorCode(EXCEPTION_PREFIX + "00029");
42    /*** The command is invalid. The command could not be created. */
43    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    public static ErrorCode MISSING_OPTION = new ErrorCode(EXCEPTION_PREFIX + "00031");
46    /*** Argument for a command option is missing. */
47    public static ErrorCode MISSING_ARGUMENT = new ErrorCode(EXCEPTION_PREFIX + "00032");
48    /*** Argument for a command option is invalid. */
49    public static ErrorCode INVALID_ARGUMENT = new ErrorCode(EXCEPTION_PREFIX + "00033");
50    /*** Invalid option. */
51    public static final ErrorCode INVALID_OPTION = new ErrorCode(EXCEPTION_PREFIX + "00034");
52    /*** No arguments required. More of a warning really. */
53    public static final ErrorCode NO_OPTIONS_REQUIRED = new ErrorCode(EXCEPTION_PREFIX + "00035");;
54    /*** The build of a module failed. */
55    public static final ErrorCode BUILD_FAILED = new ErrorCode(EXCEPTION_PREFIX + "00040");
56    /*** The build of a module failed. */
57    public static final ErrorCode BUILD_FAILED_TOO_MANY_MISSING_DEPENDENCIES = new ErrorCode(EXCEPTION_PREFIX + "00046");
58    /*** The test of a module failed. */
59    public static final ErrorCode TEST_FAILED = new ErrorCode(EXCEPTION_PREFIX + "00050");
60    /*** Generating the test report failed. */
61    public static final ErrorCode TEST_REPORT_FAILED = new ErrorCode(EXCEPTION_PREFIX + "00052");
62    /*** The test of a module failed. */
63    public static final ErrorCode CLEAN_MODULE_FAILED = new ErrorCode(EXCEPTION_PREFIX + "00060");
64    /*** The test of a module failed. */
65    public static final ErrorCode CLEAN_ALL_FAILED = new ErrorCode(EXCEPTION_PREFIX + "00063");
66    /*** The packaging of a module failed. */
67    public static final ErrorCode PACKAGE_FAILED = new ErrorCode(EXCEPTION_PREFIX + "00070");
68    /*** The packaging of a module failed. */
69    public static final ErrorCode PACKAGE_FAILED_NOTHING_TO_PACKAGE = new ErrorCode(EXCEPTION_PREFIX + "00074");
70    /*** The packaging of a module failed. */
71    public static final ErrorCode PACKAGE_FAILED_NO_APPLICATION_XML = new ErrorCode(EXCEPTION_PREFIX + "00071");
72    /*** The packaging of a module failed. */
73    public static final ErrorCode PACKAGE_FAILED_INVALID_APPLICATION_XML = new ErrorCode(EXCEPTION_PREFIX + "00072");
74    /*** The packaging of a module failed. */
75    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    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    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    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    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     * <ul>
90     *   <li/>the dependency is a sourcemodule dependency and the jar it refers to has not been built.
91     *   <li/>the dependency is a jar dependency and the artifact is not available in the Maven repository locally.
92     * </ul>
93     */
94    public static final ErrorCode DEPENDENCY_DOES_NOT_EXIST = new ErrorCode(EXCEPTION_PREFIX + "00044");
95  
96    public static final ErrorCode DEPENDENCY_FILE_INVALID = new ErrorCode(EXCEPTION_PREFIX + "00047");
97    /*** <code>src/java</code> (the default directory for a module where java sources are located) is missing. */
98    public static final ErrorCode NO_SRC_DIR = new ErrorCode(EXCEPTION_PREFIX + "00045");
99    /*** <code>test/java</code> (the default directory for a module where test java sources are located) is missing. */
100   public static final ErrorCode NO_TEST_DIR = new ErrorCode(EXCEPTION_PREFIX + "00051");
101 
102   public static final ErrorCode UNCOMMITTED_NEW_FILES = new ErrorCode(EXCEPTION_PREFIX + "00055");
103 
104   public static final ErrorCode UNCOMMITTED_CHANGED_FILES = new ErrorCode(EXCEPTION_PREFIX + "00056");
105 
106   public static final ErrorCode UNCOMMITTED_REMOVED_FILES = new ErrorCode(EXCEPTION_PREFIX + "00057");
107   /*** <code>build/&lt;module&gt;</code> (the default directory for a module where built files are located) is missing. */
108   public static final ErrorCode NO_MODULE_BUILD_DIR = new ErrorCode(EXCEPTION_PREFIX + "00061");
109   /*** <code>build</code> (the default directory where built files are located) is missing. */
110   public static final ErrorCode NO_BUILD_DIR = new ErrorCode(EXCEPTION_PREFIX + "00062");
111 
112   public static final ErrorCode MODULE_VERSION_ERROR = new ErrorCode(EXCEPTION_PREFIX + "00064");
113 
114   public static final ErrorCode TEST_WARNING = new ErrorCode(EXCEPTION_PREFIX + "00100");
115 
116   public static final ErrorCode BUILD_WARNING = new ErrorCode(EXCEPTION_PREFIX + "00101");
117   /*** Thrown when a module is not working and the user wants to stop work on it. */
118   public static final ErrorCode INVALID_STATE_MODULE_NOT_WORKING = new ErrorCode(EXCEPTION_PREFIX + "00102");
119 
120   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   public static final ErrorCode INVALID_LOCATION_TYPE = new ErrorCode(EXCEPTION_PREFIX + "00104");
123   /*** The working context could not be initialized. */
124   public static final ErrorCode CANNOT_INITIALIZE_WORKING_CONTEXT = new ErrorCode(EXCEPTION_PREFIX + "00105");
125   /*** A module is encountered with state WORKING. This is not allowed when creating a release manifest. */
126   public static final ErrorCode MODULE_CANNOT_BE_WORKING_FOR_RELEASE_MANIFEST = new ErrorCode(EXCEPTION_PREFIX + "00106");
127   /*** Configuration for working context is invalid. */
128   public static final ErrorCode INVALID_WORKING_CONTEXT_CONFIGURATION = new ErrorCode(EXCEPTION_PREFIX + "00107");
129 
130   public CommandException(ErrorCode errorCode) {
131     this(errorCode, null);
132   }
133 
134   public CommandException(Throwable t, ErrorCode errorCode) {
135     this(t, errorCode, null);
136   }
137 
138   public CommandException(ErrorCode errorCode, Object[] messageArguments) {
139     super();
140     this.errorCode = errorCode;
141     this.messageArguments = messageArguments;
142   }
143 
144   public CommandException(Throwable t, ErrorCode errorCode, Object[] messageArguments) {
145     super(t);
146     this.errorCode = errorCode;
147     this.messageArguments = messageArguments;
148   }
149 
150   public String getMessage() {
151     if (messageArguments != null && messageArguments.length > 0) {
152       errorCode.setMessageArguments(messageArguments);
153     }
154     return getErrorCode().getErrorMessage();
155   }
156 
157   /***
158    * Gets the exceptions' {@link nl.toolforge.karma.core.ErrorCode}.
159    * @return
160    */
161   public final ErrorCode getErrorCode() {
162     return errorCode;
163   }
164 
165   public final Object[] getMessageArguments() {
166     return messageArguments;
167   }
168 
169 }