**/\r
package org.tianocore.framework.tasks;\r
\r
-import java.util.*;\r
+import java.io.File;\r
+import org.apache.tools.ant.BuildException;\r
import org.apache.tools.ant.Project;\r
import org.apache.tools.ant.Task;\r
-import org.apache.tools.ant.BuildException;\r
import org.apache.tools.ant.taskdefs.Execute;\r
import org.apache.tools.ant.taskdefs.LogStreamHandler;\r
import org.apache.tools.ant.types.Commandline;\r
+import org.tianocore.common.logger.EdkLog;\r
\r
/**\r
StrGather Task Class\r
-outputHpk : create an HII export pack of the strings\r
**/\r
public class StrGatherTask extends Task implements EfiDefine {\r
- ///\r
- /// common options\r
- ///\r
- private String commandType = "";\r
+ //\r
+ // Tool name\r
+ // \r
+ private static String toolName = "StrGather";\r
+\r
+ //\r
+ // common options\r
+ //\r
+ private ToolArg commandType = new ToolArg();\r
\r
- private String baseName = "";\r
+ private ToolArg baseName = new ToolArg();\r
\r
- ///\r
- /// "all/read/write"\r
- ///\r
- private String verbose = "";\r
+ //\r
+ // "all/read/write"\r
+ //\r
+ private ToolArg verbose = new ToolArg();\r
\r
- private String outputDatabase = "";\r
+ private FileArg outputDatabase = new FileArg();\r
\r
- private List<Object> databaseList = new ArrayList<Object>();\r
+ private Database databaseList = new Database();\r
\r
- private List<Object> inputFileList = new ArrayList<Object>();\r
+ private InputFile inputFileList = new InputFile();\r
\r
- ///\r
- /// parse options newDatabase -- "ture/false" unquoteString -- "ture/false"\r
- ///\r
- private String newDatabase = "";\r
+ //\r
+ // parse options newDatabase -- "ture/false" unquoteString -- "ture/false"\r
+ //\r
+ private ToolArg newDatabase = new ToolArg();\r
\r
- private String unquotedString = "";\r
+ private ToolArg unquotedString = new ToolArg();\r
\r
- private List<Object> includePathList = new ArrayList<Object>();\r
+ private IncludePath includePathList = new IncludePath();\r
\r
- ///\r
- /// scan options ignoreNotFound -- "ture/false"\r
- ///\r
- private String ignoreNotFound = "";\r
+ //\r
+ // scan options ignoreNotFound -- "ture/false"\r
+ //\r
+ private ToolArg ignoreNotFound = new ToolArg();\r
\r
- private List<Object> skipExtList = new ArrayList<Object>();\r
+ private SkipExt skipExtList = new SkipExt();\r
\r
- ///\r
- /// dump options\r
- ///\r
- private String outputString = "";\r
+ //\r
+ // dump options\r
+ //\r
+ private ToolArg outputString = new ToolArg();\r
\r
- private String outputDefines = "";\r
+ private ToolArg outputDefines = new ToolArg();\r
\r
- private String outputUnicode = "";\r
+ private ToolArg outputUnicode = new ToolArg();\r
\r
- private String lang = "";\r
+ private ToolArg lang = new ToolArg();\r
\r
- private String indirectionFile = "";\r
+ private FileArg indirectionFile = new FileArg();\r
\r
- private String outputHpk = "";\r
+ private FileArg outputHpk = new FileArg();\r
\r
- ///\r
- /// global variable\r
- ///\r
+ //\r
+ // global variable\r
+ //\r
static private Project project;\r
\r
/**\r
///\r
/// absolute path of efi tools\r
///\r
- String path = project.getProperty("env.Framework_Tools_Path"); \r
+ String path = project.getProperty("env.FRAMEWORK_TOOLS_PATH"); \r
String command;\r
if (path == null) {\r
- command = "StrGather";\r
+ command = toolName;\r
} else {\r
- command = path + "/" + "StrGather";\r
+ command = path + File.separator + toolName;\r
}\r
\r
- ///\r
- /// transfer nested elements into string\r
- ///\r
- String databases = list2Str(databaseList, "-db");\r
- String skipExts = list2Str(skipExtList, "-skipext");\r
- String includePaths = list2Str(includePathList, "-I");\r
- String inputFiles = list2Str(inputFileList, "");\r
-\r
///\r
/// assemble argument\r
///\r
- String argument = commandType + verbose + databases + baseName\r
- + outputDatabase + includePaths + newDatabase + unquotedString\r
- + skipExts + ignoreNotFound + outputString + outputDefines\r
+ String argument = "" + commandType + verbose + databaseList + baseName\r
+ + outputDatabase + includePathList + newDatabase + unquotedString\r
+ + skipExtList + ignoreNotFound + outputString + outputDefines\r
+ outputUnicode + lang + indirectionFile + outputHpk\r
- + inputFiles;\r
+ + inputFileList;\r
///\r
/// return value of fwimage execution\r
///\r
\r
runner.setAntRun(project);\r
runner.setCommandline(cmdline.getCommandline());\r
- System.out.println(Commandline.toString(cmdline.getCommandline()));\r
+\r
+ String cmdType = getCommandType();\r
+ if (cmdType.equalsIgnoreCase("parse")) {\r
+ EdkLog.log(this, "(parse) " + inputFileList.toFileList() + " => " \r
+ + databaseList.toFileList());\r
+ } else if (cmdType.equalsIgnoreCase("scan")) {\r
+ EdkLog.log(this, "(scan) " + databaseList.toFileList() + " => " \r
+ + outputDatabase.toFileList());\r
+ } else {\r
+ EdkLog.log(this, "(dump) " + databaseList.toFileList() + " => " \r
+ + outputDefines.toFileList() + outputString.toFileList() + outputHpk.toFileList());\r
+ }\r
+ EdkLog.log(this, EdkLog.EDK_VERBOSE, Commandline.toString(cmdline.getCommandline()));\r
\r
revl = runner.execute();\r
if (EFI_SUCCESS == revl) {\r
- ///\r
- /// command execution success\r
- ///\r
- System.out.println("strgather succeeded!");\r
+ EdkLog.log(this, EdkLog.EDK_VERBOSE, toolName + " succeeded!");\r
} else {\r
///\r
/// command execution fail\r
///\r
- System.out.println("strgather failed. (error="\r
- + Integer.toHexString(revl) + ")");\r
- throw new BuildException("strgather failed. (error="\r
- + Integer.toHexString(revl) + ")");\r
+ EdkLog.log(this, "ERROR = " + Integer.toHexString(revl));\r
+ throw new BuildException(toolName + " failed!");\r
}\r
} catch (Exception e) {\r
throw new BuildException(e.getMessage());\r
@returns commandType parameter\r
**/\r
public String getCommandType() {\r
- return this.commandType;\r
+ return this.commandType.getValue();\r
}\r
\r
/**\r
@param commandType type of strgather command [parse/scan/dump]\r
**/\r
public void setCommandType(String commandType) {\r
- this.commandType = " -" + commandType;\r
+ this.commandType.setArg(" -", commandType);\r
}\r
\r
/**\r
@returns verbose parameter\r
**/\r
public String getVerbose() {\r
- return this.verbose;\r
+ return this.verbose.getValue();\r
}\r
\r
/**\r
///\r
/// for verbose output\r
///\r
- this.verbose = " -v ";\r
+ this.verbose.setArg(" -", "v");\r
} else if (verbose.equals("read")) {\r
///\r
/// for verbose output when reading database\r
///\r
- this.verbose = " -vdbr ";\r
+ this.verbose.setArg(" -", "vdbr");\r
} else if (verbose.equals("write")) {\r
///\r
/// for verbose output when writing database\r
///\r
- this.verbose = " -vdbw ";\r
+ this.verbose.setArg(" -", "vdbw");\r
}\r
}\r
\r
@returns baseName parameter\r
**/\r
public String getBaseName() {\r
- return this.baseName;\r
+ return this.baseName.getValue();\r
}\r
\r
/**\r
@param baseName name of the output files of .c and .h\r
**/\r
public void setBaseName(String baseName) {\r
- this.baseName = " -bn " + baseName;\r
+ this.baseName.setArg(" -bn ", baseName);\r
}\r
\r
/**\r
@returns outputDatabase parameter\r
**/\r
public String getOutputDatabase() {\r
- return this.outputDatabase;\r
+ return this.outputDatabase.getValue();\r
}\r
\r
/**\r
@param outputDatabase filename of output database file\r
**/\r
public void setOutputDatabase(String outputDatabase) {\r
- this.outputDatabase = " -od " + outputDatabase;\r
+ this.outputDatabase.setArg(" -od ", outputDatabase);\r
}\r
\r
/**\r
\r
@returns newDatabase parameter\r
**/\r
- public String getNewDatabse() {\r
- return this.newDatabase;\r
+ public boolean getNewDatabse() {\r
+ return this.newDatabase.getPrefix().length() > 0;\r
}\r
\r
/**\r
\r
@param newDatabase whether to not read in existing database file\r
**/\r
- public void setNewDatabase(String newDatabase) {\r
- if (newDatabase.equals("true")) {\r
- this.newDatabase = " -newdb ";\r
+ public void setNewDatabase(boolean newDatabase) {\r
+ if (newDatabase) {\r
+ this.newDatabase.setArg(" -", "newdb");\r
}\r
}\r
\r
\r
@returns unquotedString parameter\r
**/\r
- public String getUnquotedString() {\r
- return this.unquotedString;\r
+ public boolean getUnquotedString() {\r
+ return this.unquotedString.getValue().length() > 0;\r
}\r
\r
/**\r
@param unquotedString :\r
whether to indicate that unquoted strings are used\r
**/\r
- public void setUnquotedString(String unquotedString) {\r
- if (unquotedString.equals("true")) {\r
- this.unquotedString = " -uqs ";\r
+ public void setUnquotedString(boolean unquotedString) {\r
+ if (unquotedString) {\r
+ this.unquotedString.setArg(" -", "uqs");\r
}\r
}\r
\r
\r
@returns ignoreNotFound parameter\r
**/\r
- public String getIgnoreNotFound() {\r
- return this.ignoreNotFound;\r
+ public boolean getIgnoreNotFound() {\r
+ return this.ignoreNotFound.getValue().length() > 0;\r
}\r
\r
/**\r
@param ignoreNotFound whether to ignore if a given STRING_TOKEN(STR) \r
is not found in the database\r
**/\r
- public void setIgnoreNotFound(String ignoreNotFound) {\r
- if (ignoreNotFound.equals("true")) {\r
- this.ignoreNotFound = " -ignorenotfound ";\r
+ public void setIgnoreNotFound(boolean ignoreNotFound) {\r
+ if (ignoreNotFound) {\r
+ this.ignoreNotFound.setArg(" -", "ignorenotfound");\r
}\r
}\r
\r
@returns outputString parameter\r
**/\r
public String getOutputString() {\r
- return this.outputString;\r
+ return this.outputString.getValue();\r
}\r
\r
/**\r
@param outputString filename of string data file\r
**/\r
public void setOutputString(String outputString) {\r
- this.outputString = " -oc " + outputString;\r
+ this.outputString.setArg(" -oc ", outputString);\r
}\r
\r
/**\r
@returns outputDefines parameter\r
**/\r
public String getOutputDefines() {\r
- return this.outputDefines;\r
+ return this.outputDefines.getValue();\r
}\r
\r
/**\r
@param outputDefines filename of string defines file\r
**/\r
public void setOutputDefines(String outputDefines) {\r
- this.outputDefines = " -oh " + outputDefines;\r
+ this.outputDefines.setArg(" -oh ", outputDefines);\r
}\r
\r
/**\r
@returns outputUnicode parameter\r
**/\r
public String getOutputUnicode() {\r
- return this.outputUnicode;\r
+ return this.outputUnicode.getValue();\r
}\r
\r
/**\r
@param outputUnicode filename of unicode file to be dumped database\r
**/\r
public void setOutputUnicode(String outputUnicode) {\r
- this.outputUnicode = " -ou " + outputUnicode;\r
+ this.outputUnicode.setArg(" -ou ", outputUnicode);\r
}\r
\r
/**\r
@returns lang parameter\r
**/\r
public String getLang() {\r
- return this.lang;\r
+ return this.lang.getValue();\r
}\r
\r
/**\r
@param lang language of dump\r
**/\r
public void setLang(String lang) {\r
- this.lang = " -lang " + lang;\r
+ this.lang.setArg(" -lang ", lang);\r
}\r
\r
/**\r
@returns indirectionFile parameter\r
**/\r
public String getIndirectionFile() {\r
- return this.indirectionFile;\r
+ return this.indirectionFile.getValue();\r
}\r
\r
/**\r
@param indirectionFile filename of indirection file\r
**/\r
public void setIndirectionFile(String indirectionFile) {\r
- this.indirectionFile = " -if " + indirectionFile;\r
+ this.indirectionFile.setArg(" -if ", indirectionFile);\r
}\r
\r
/**\r
@returns outputHpk parameter\r
**/\r
public String getOutputHpk() {\r
- return this.outputHpk;\r
+ return this.outputHpk.getValue();\r
}\r
\r
/**\r
@param outputHpk filename of output HII export pack of the strings\r
**/\r
public void setOutputHpk(String outputHpk) {\r
- this.outputHpk = " -hpk " + outputHpk;\r
+ this.outputHpk.setArg(" -hpk ", outputHpk);\r
}\r
\r
/**\r
\r
@param skipExt skipExt element\r
**/\r
- public void addSkipext(SkipExt skipExt) {\r
- skipExtList.add(skipExt);\r
+ public void addConfiguredSkipext(SkipExt skipExt) {\r
+ this.skipExtList.insert(skipExt);\r
};\r
\r
/**\r
\r
@param includePath includePath element\r
**/\r
- public void addIncludepath(IncludePath includePath) {\r
- includePathList.add(includePath);\r
+ public void addConfiguredIncludepath(IncludePath includePath) {\r
+ this.includePathList.insert(includePath);\r
};\r
\r
/**\r
\r
@param inputFile inputFile element\r
**/\r
- public void addInputfile(InputFile inputFile) {\r
- inputFileList.add(inputFile);\r
+ public void addConfiguredInputfile(InputFile inputFile) {\r
+ this.inputFileList.insert(inputFile);\r
};\r
\r
/**\r
@param database :\r
database element\r
**/\r
- public void addDatabase(Database database) {\r
- databaseList.add(database);\r
+ public void addConfiguredDatabase(Database database) {\r
+ this.databaseList.insert(database);\r
}\r
-\r
- /**\r
- transfer List to String\r
- \r
- @param list nested element list\r
- @param tag interval tag of parameter\r
-\r
- @returns string line of parameters\r
- **/\r
- private String list2Str(List list, String tag) {\r
- ///\r
- /// string line for return\r
- ///\r
- String paraStr = "";\r
- ///\r
- /// nested element in list\r
- ///\r
- NestElement element;\r
- ///\r
- /// iterator of nested element list\r
- ///\r
- Iterator elementIter = list.iterator();\r
- ///\r
- /// string parameter list\r
- ///\r
- List<Object> strList = new ArrayList<Object>();\r
-\r
- while (elementIter.hasNext()) {\r
- element = (NestElement) elementIter.next();\r
- if (null != element.getFile()) {\r
- ///\r
- /// nested element include file\r
- ///\r
- FileParser.loadFile(project, strList, element.getFile(), tag);\r
- } \r
-\r
- if (element.getName().length() > 0) {\r
- ///\r
- /// nested element include name \r
- ///\r
- paraStr = paraStr + " " + element.getName();\r
- }\r
-\r
- List<String> nameList = element.getList();\r
- if (nameList.size() > 0) {\r
- Iterator nameIter = nameList.iterator();\r
- while (nameIter.hasNext()) {\r
- paraStr = paraStr + " " + tag + " " + (String)nameIter.next();\r
- }\r
- }\r
- }\r
- ///\r
- /// iterator of string parameter list\r
- ///\r
- Iterator strIter = strList.iterator();\r
- while (strIter.hasNext()) {\r
- paraStr = paraStr + " " + strIter.next();\r
- }\r
- return paraStr;\r
- }\r
-\r
}\r