]> git.proxmox.com Git - mirror_edk2.git/blobdiff - 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
diff --git a/Tools/Source/PcdTools/org/tianocore/pcd/action/BuildAction.java b/Tools/Source/PcdTools/org/tianocore/pcd/action/BuildAction.java
new file mode 100644 (file)
index 0000000..98068d9
--- /dev/null
@@ -0,0 +1,105 @@
+/** @file\r
+  BuildAction class.\r
+\r
+  BuildAction is the parent class for all action related to ant Task. This class will\r
+  define some common utility functionality, such as logMsg, warningMsg..etc.\r
\r
+Copyright (c) 2006, Intel Corporation\r
+All rights reserved. This program and the accompanying materials\r
+are licensed and made available under the terms and conditions of the BSD License\r
+which accompanies this distribution.  The full text of the license may be found at\r
+http://opensource.org/licenses/bsd-license.php\r
\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+package org.tianocore.pcd.action;\r
+\r
+import org.apache.tools.ant.Task;\r
+import org.apache.tools.ant.Project;\r
+import org.tianocore.pcd.exception.BuildActionException;\r
+\r
+/** BuildAction is the parent class for all action related to ant Task. This class will\r
+    define some common utility functionality, such as logMsg, warningMsg..etc.\r
+**/\r
+public abstract class BuildAction extends Task {\r
+    ///\r
+    /// Original message level before this action. This value will \r
+    /// be restored when quit this action.\r
+    ///\r
+    private int originalMessageLevel;\r
+\r
+    /**\r
+      checkParameter function check all parameter valid.\r
+\r
+      This function will be overrided by child class.\r
+    **/\r
+    public abstract void checkParameter() throws BuildActionException;\r
+\r
+    /**\r
+     performAction is to execute the detail action.\r
+      \r
+     This function will be overrided by child class.\r
+    **/\r
+    public abstract void performAction() throws BuildActionException;\r
+\r
+    /**\r
+      setMessageLevel function set current message for task instance object.\r
+\r
+      The message should be restored when this action exit.\r
+\r
+      @param messageLevel The message level for this action.\r
+    **/\r
+    public void setMessageLevel(int messageLevel) {\r
+        originalMessageLevel        = ActionMessage.messageLevel;\r
+        ActionMessage.messageLevel  = messageLevel;\r
+    }\r
+\r
+    /**\r
+      logMsg function provide common log information functionality for all \r
+      PCD tool extends from ANT task class.\r
+\r
+      This function will use the log function in Ant task class.\r
+     \r
+      @param action     The class object who want log information.\r
+      @param logStr     The string contains log information.\r
+    **/\r
+    public static void logMsg(Object action, String logStr) {\r
+        ((Task) action).log(logStr, Project.MSG_INFO);\r
+    }\r
+\r
+    /**\r
+      warningMsg function provide common warning information functionality for all \r
+      PCD tool.\r
+\r
+      This function will dispatch message to special class such as BuildAction\r
+      Class, Entity Class etc.\r
+     \r
+      @param action      The class object who want warn information.\r
+      @param warningStr  The string contains warning information.\r
+    **/  \r
+    public static void warningMsg(Object action, String warningStr) {\r
+        ((Task) action).log(warningStr, Project.MSG_WARN);\r
+    }\r
+\r
+    /**\r
+      execute function is the main flow for all build action class.\r
+\r
+      This workflow will be:\r
+      1) Check paramet of this action.\r
+      2) Perform the child class action function.\r
+      3) Restore the message level.\r
+     \r
+      @throws BuildActionException\r
+    **/  \r
+    public void execute() throws BuildActionException {\r
+        checkParameter();\r
+        performAction();\r
+\r
+        //\r
+        // Restore orignal message level when exist the action.\r
+        //\r
+        ActionMessage.messageLevel = originalMessageLevel;\r
+    }\r
+}\r