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