]>
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 | |
3d52de13 | 20 | import org.apache.tools.ant.Project;\r |
878ddf1f | 21 | import org.tianocore.build.pcd.exception.BuildActionException;\r |
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 | |
26 | abstract class BuildAction extends Task {\r | |
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 | |
38 | abstract void checkParameter() throws BuildActionException;\r | |
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 | |
45 | abstract void performAction() throws BuildActionException;\r | |
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 | |
3d52de13 | 69 | ((Task) action).log(logStr, Project.MSG_INFO);\r |
878ddf1f | 70 | }\r |
71 | \r | |
72 | /**\r | |
73 | warningMsg function provide common warning information functionality for all \r | |
74 | PCD tool.\r | |
75 | \r | |
76 | This function will dispatch message to special class such as BuildAction\r | |
77 | Class, Entity Class etc.\r | |
78 | \r | |
79 | @param action The class object who want warn information.\r | |
80 | @param warningStr The string contains warning information.\r | |
81 | **/ \r | |
82 | public static void warningMsg(Object action, String warningStr) {\r | |
3d52de13 | 83 | ((Task) action).log(warningStr, Project.MSG_WARN);\r |
878ddf1f | 84 | }\r |
85 | \r | |
86 | /**\r | |
87 | execute function is the main flow for all build action class.\r | |
88 | \r | |
89 | This workflow will be:\r | |
90 | 1) Check paramet of this action.\r | |
91 | 2) Perform the child class action function.\r | |
92 | 3) Restore the message level.\r | |
93 | \r | |
94 | @throws BuildActionException\r | |
95 | **/ \r | |
96 | public void execute() throws BuildActionException {\r | |
97 | checkParameter();\r | |
98 | performAction();\r | |
99 | \r | |
100 | //\r | |
101 | // Restore orignal message level when exist the action.\r | |
102 | //\r | |
103 | ActionMessage.messageLevel = originalMessageLevel;\r | |
104 | }\r | |
105 | }\r |