]>
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 | |
17 | package org.tianocore.build.pcd.action;\r | |
18 | \r | |
19 | import org.apache.tools.ant.Task;\r | |
20 | import org.tianocore.build.pcd.exception.BuildActionException;\r | |
21 | \r | |
22 | /** BuildAction is the parent class for all action related to ant Task. This class will\r | |
23 | define some common utility functionality, such as logMsg, warningMsg..etc.\r | |
24 | **/\r | |
25 | abstract class BuildAction extends Task {\r | |
26 | ///\r | |
27 | /// Original message level before this action. This value will \r | |
28 | /// be restored when quit this action.\r | |
29 | ///\r | |
30 | private int originalMessageLevel;\r | |
31 | \r | |
32 | /**\r | |
33 | checkParameter function check all parameter valid.\r | |
34 | \r | |
35 | This function will be overrided by child class.\r | |
36 | **/\r | |
37 | abstract void checkParameter() throws BuildActionException;\r | |
38 | \r | |
39 | /**\r | |
40 | performAction is to execute the detail action.\r | |
41 | \r | |
42 | This function will be overrided by child class.\r | |
43 | **/\r | |
44 | abstract void performAction() throws BuildActionException;\r | |
45 | \r | |
46 | /**\r | |
47 | setMessageLevel function set current message for task instance object.\r | |
48 | \r | |
49 | The message should be restored when this action exit.\r | |
50 | \r | |
51 | @param messageLevel The message level for this action.\r | |
52 | **/\r | |
53 | public void setMessageLevel(int messageLevel) {\r | |
54 | originalMessageLevel = ActionMessage.messageLevel;\r | |
55 | ActionMessage.messageLevel = messageLevel;\r | |
56 | }\r | |
57 | \r | |
58 | /**\r | |
59 | logMsg function provide common log information functionality for all \r | |
60 | PCD tool extends from ANT task class.\r | |
61 | \r | |
62 | This function will use the log function in Ant task class.\r | |
63 | \r | |
64 | @param action The class object who want log information.\r | |
65 | @param logStr The string contains log information.\r | |
66 | **/\r | |
67 | public static void logMsg(Object action, String logStr) {\r | |
68 | //\r | |
69 | // Comment following code because in console debug environment, we can't \r | |
70 | // get Project instance.\r | |
71 | //((Task) action).log(errorText, Project.MSG_INFO);\r | |
72 | //\r | |
73 | System.out.println(logStr);\r | |
74 | }\r | |
75 | \r | |
76 | /**\r | |
77 | warningMsg function provide common warning information functionality for all \r | |
78 | PCD tool.\r | |
79 | \r | |
80 | This function will dispatch message to special class such as BuildAction\r | |
81 | Class, Entity Class etc.\r | |
82 | \r | |
83 | @param action The class object who want warn information.\r | |
84 | @param warningStr The string contains warning information.\r | |
85 | **/ \r | |
86 | public static void warningMsg(Object action, String warningStr) {\r | |
87 | //\r | |
88 | // Comment following code because in console debug environment, we can't \r | |
89 | // get Project instance.\r | |
90 | //((Task) action).log(warningText, Project.MSG_WARN);\r | |
91 | //\r | |
92 | System.out.println(warningStr);\r | |
93 | }\r | |
94 | \r | |
95 | /**\r | |
96 | execute function is the main flow for all build action class.\r | |
97 | \r | |
98 | This workflow will be:\r | |
99 | 1) Check paramet of this action.\r | |
100 | 2) Perform the child class action function.\r | |
101 | 3) Restore the message level.\r | |
102 | \r | |
103 | @throws BuildActionException\r | |
104 | **/ \r | |
105 | public void execute() throws BuildActionException {\r | |
106 | checkParameter();\r | |
107 | performAction();\r | |
108 | \r | |
109 | //\r | |
110 | // Restore orignal message level when exist the action.\r | |
111 | //\r | |
112 | ActionMessage.messageLevel = originalMessageLevel;\r | |
113 | }\r | |
114 | }\r |