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