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