Fix EDKT256: using unified logging mechanism in PcdAutogen tools.
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@1626 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
@@ -1,126 +0,0 @@
|
||||
/** @file
|
||||
ActionMessage class.
|
||||
|
||||
ActionMessage class take over all message for loging and waning. This class should
|
||||
dispatch message into different class according to instance class type.
|
||||
|
||||
Copyright (c) 2006, Intel Corporation
|
||||
All rights reserved. This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the BSD License
|
||||
which accompanies this distribution. The full text of the license may be found at
|
||||
http://opensource.org/licenses/bsd-license.php
|
||||
|
||||
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
|
||||
**/
|
||||
package org.tianocore.pcd.action;
|
||||
|
||||
import org.apache.tools.ant.Task;
|
||||
|
||||
/** ActionMessage class take over all message for loging and waning. This class
|
||||
should dispatch message into different Action class according to instance
|
||||
class type.
|
||||
**/
|
||||
public class ActionMessage {
|
||||
///
|
||||
/// Macro definition for NULL messge level.
|
||||
/// In this meessage level, all message will be hidden.
|
||||
///
|
||||
public final static int NULL_MESSAGE_LEVEL = 0;
|
||||
|
||||
///
|
||||
/// Macro definition for Log messge level.
|
||||
/// In this message level, Only log information will be shown.
|
||||
///
|
||||
public final static int LOG_MESSAGE_LEVEL = 1;
|
||||
|
||||
///
|
||||
/// Macro definition for Warning message level.
|
||||
/// In this message level, log and waning message will be shown.
|
||||
///
|
||||
public final static int WARNING_MESSAGE_LEVEL = 2;
|
||||
|
||||
///
|
||||
/// Macro definition for Debug mesage level.
|
||||
/// In this message level, log, warning, debug message will be shown.
|
||||
///
|
||||
public final static int DEBUG_MESSAGE_LEVEL = 3;
|
||||
|
||||
///
|
||||
/// Macor definition for MAX message level.
|
||||
/// In this message level, all message will be shown.
|
||||
///
|
||||
public final static int MAX_MESSAGE_LEVEL = 4;
|
||||
|
||||
///
|
||||
/// Current message level. It will control all message output for PCD tool.
|
||||
///
|
||||
public static int messageLevel = NULL_MESSAGE_LEVEL;
|
||||
|
||||
/**
|
||||
Log() function provide common log information functionality for all
|
||||
PCD tool includes all function
|
||||
|
||||
This function will dispatch message to special class such as BuildAction
|
||||
Class, Entity Class etc.
|
||||
|
||||
@param thisClass The class object who want log information.
|
||||
@param logStr The string contains log information.
|
||||
**/
|
||||
public static void log(Object thisClass, String logStr) {
|
||||
if(messageLevel < LOG_MESSAGE_LEVEL) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(thisClass instanceof Task) {
|
||||
BuildAction.logMsg(thisClass, "$$LOG$$:" + logStr);
|
||||
} else {
|
||||
System.out.println("$$LOG$$:" + logStr);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Warning() function provide common warning information functionality for all
|
||||
PCD tool.
|
||||
|
||||
This function will dispatch message to special class such as BuildAction
|
||||
Class, Entity Class etc.
|
||||
|
||||
@param thisClass The class object who want warn information.
|
||||
@param warningStr The string contains warning information.
|
||||
**/
|
||||
public static void warning(Object thisClass, String warningStr) {
|
||||
if(messageLevel < WARNING_MESSAGE_LEVEL) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(thisClass instanceof Task) {
|
||||
BuildAction.warningMsg(thisClass, "**WARNING**:" + warningStr);
|
||||
} else {
|
||||
System.out.println("**WARNING**:" + warningStr);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Debug() function provide common Debug information functionality for all
|
||||
PCD tool.
|
||||
|
||||
This function will dispatch message to special class such as BuildAction
|
||||
Class, Entity Class etc.
|
||||
|
||||
@param thisClass The class object who want Debug information.
|
||||
@param debugStr The string contains Debug information.
|
||||
**/
|
||||
public static void debug(Object thisClass, String debugStr) {
|
||||
if(messageLevel < DEBUG_MESSAGE_LEVEL) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(thisClass instanceof Task) {
|
||||
BuildAction.logMsg(thisClass, "%%DEBUG%%:" + debugStr);
|
||||
} else {
|
||||
System.out.println("%%DEBUG%%:" + debugStr);
|
||||
}
|
||||
}
|
||||
}
|
@@ -44,48 +44,6 @@ public abstract class BuildAction extends Task {
|
||||
**/
|
||||
public abstract void performAction() throws BuildActionException;
|
||||
|
||||
/**
|
||||
setMessageLevel function set current message for task instance object.
|
||||
|
||||
The message should be restored when this action exit.
|
||||
|
||||
@param messageLevel The message level for this action.
|
||||
**/
|
||||
public void setMessageLevel(int messageLevel) {
|
||||
originalMessageLevel = ActionMessage.messageLevel;
|
||||
ActionMessage.messageLevel = messageLevel;
|
||||
}
|
||||
|
||||
/**
|
||||
logMsg function provide common log information functionality for all
|
||||
PCD tool extends from ANT task class.
|
||||
|
||||
This function will use the log function in Ant task class.
|
||||
|
||||
@param action The class object who want log information.
|
||||
@param logStr The string contains log information.
|
||||
**/
|
||||
public static void logMsg(Object action, String logStr) {
|
||||
try {
|
||||
((Task) action).log(logStr, Project.MSG_INFO);
|
||||
} catch (Exception exp) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
warningMsg function provide common warning information functionality for all
|
||||
PCD tool.
|
||||
|
||||
This function will dispatch message to special class such as BuildAction
|
||||
Class, Entity Class etc.
|
||||
|
||||
@param action The class object who want warn information.
|
||||
@param warningStr The string contains warning information.
|
||||
**/
|
||||
public static void warningMsg(Object action, String warningStr) {
|
||||
((Task) action).log(warningStr, Project.MSG_WARN);
|
||||
}
|
||||
|
||||
/**
|
||||
execute function is the main flow for all build action class.
|
||||
|
||||
@@ -99,10 +57,5 @@ public abstract class BuildAction extends Task {
|
||||
public void execute() throws BuildActionException {
|
||||
checkParameter();
|
||||
performAction();
|
||||
|
||||
//
|
||||
// Restore orignal message level when exist the action.
|
||||
//
|
||||
ActionMessage.messageLevel = originalMessageLevel;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user