]>
Commit | Line | Data |
---|---|---|
878ddf1f | 1 | /** @file\r |
2 | BuildAction class.\r | |
3 | \r | |
4 | BuildAction is the parent class for all action related to ant Task. This class will\r | |
5 | define some common utility functionality, such as logMsg, warningMsg..etc.\r | |
6 | \r | |
7 | Copyright (c) 2006, Intel Corporation\r | |
8 | All rights reserved. This program and the accompanying materials\r | |
9 | are licensed and made available under the terms and conditions of the BSD License\r | |
10 | which accompanies this distribution. The full text of the license may be found at\r | |
11 | http://opensource.org/licenses/bsd-license.php\r | |
12 | \r | |
13 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
14 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
15 | \r | |
16 | **/\r | |
d14ebb43 | 17 | package org.tianocore.pcd.action;\r |
878ddf1f | 18 | \r |
19 | import org.apache.tools.ant.Task;\r | |
3d52de13 | 20 | import org.apache.tools.ant.Project;\r |
d14ebb43 | 21 | import org.tianocore.pcd.exception.BuildActionException;\r |
878ddf1f | 22 | \r |
23 | /** BuildAction is the parent class for all action related to ant Task. This class will\r | |
24 | define some common utility functionality, such as logMsg, warningMsg..etc.\r | |
25 | **/\r | |
d14ebb43 | 26 | public abstract class BuildAction extends Task {\r |
878ddf1f | 27 | ///\r |
28 | /// Original message level before this action. This value will \r | |
29 | /// be restored when quit this action.\r | |
30 | ///\r | |
31 | private int originalMessageLevel;\r | |
32 | \r | |
33 | /**\r | |
34 | checkParameter function check all parameter valid.\r | |
35 | \r | |
36 | This function will be overrided by child class.\r | |
37 | **/\r | |
d14ebb43 | 38 | public abstract void checkParameter() throws BuildActionException;\r |
878ddf1f | 39 | \r |
40 | /**\r | |
41 | performAction is to execute the detail action.\r | |
42 | \r | |
43 | This function will be overrided by child class.\r | |
44 | **/\r | |
d14ebb43 | 45 | public abstract void performAction() throws BuildActionException;\r |
878ddf1f | 46 | \r |
47 | /**\r | |
48 | setMessageLevel function set current message for task instance object.\r | |
49 | \r | |
50 | The message should be restored when this action exit.\r | |
51 | \r | |
52 | @param messageLevel The message level for this action.\r | |
53 | **/\r | |
54 | public void setMessageLevel(int messageLevel) {\r | |
55 | originalMessageLevel = ActionMessage.messageLevel;\r | |
56 | ActionMessage.messageLevel = messageLevel;\r | |
57 | }\r | |
58 | \r | |
59 | /**\r | |
60 | logMsg function provide common log information functionality for all \r | |
61 | PCD tool extends from ANT task class.\r | |
62 | \r | |
63 | This function will use the log function in Ant task class.\r | |
64 | \r | |
65 | @param action The class object who want log information.\r | |
66 | @param logStr The string contains log information.\r | |
67 | **/\r | |
68 | public static void logMsg(Object action, String logStr) {\r | |
11eb278a | 69 | try { \r |
70 | ((Task) action).log(logStr, Project.MSG_INFO);\r | |
71 | } catch (Exception exp) {\r | |
72 | }\r | |
878ddf1f | 73 | }\r |
74 | \r | |
75 | /**\r | |
76 | warningMsg function provide common warning information functionality for all \r | |
77 | PCD tool.\r | |
78 | \r | |
79 | This function will dispatch message to special class such as BuildAction\r | |
80 | Class, Entity Class etc.\r | |
81 | \r | |
82 | @param action The class object who want warn information.\r | |
83 | @param warningStr The string contains warning information.\r | |
84 | **/ \r | |
85 | public static void warningMsg(Object action, String warningStr) {\r | |
3d52de13 | 86 | ((Task) action).log(warningStr, Project.MSG_WARN);\r |
878ddf1f | 87 | }\r |
88 | \r | |
89 | /**\r | |
90 | execute function is the main flow for all build action class.\r | |
91 | \r | |
92 | This workflow will be:\r | |
93 | 1) Check paramet of this action.\r | |
94 | 2) Perform the child class action function.\r | |
95 | 3) Restore the message level.\r | |
96 | \r | |
97 | @throws BuildActionException\r | |
98 | **/ \r | |
99 | public void execute() throws BuildActionException {\r | |
100 | checkParameter();\r | |
101 | performAction();\r | |
102 | \r | |
103 | //\r | |
104 | // Restore orignal message level when exist the action.\r | |
105 | //\r | |
106 | ActionMessage.messageLevel = originalMessageLevel;\r | |
107 | }\r | |
108 | }\r |