--- /dev/null
+/** @file\r
+This file is to define an ANT task which wraps StrGather.exe tool.\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.framework.tasks;\r
+\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.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
+ class memberg\r
+ -commandType : command type [parse/scan/dump] \r
+ -baseName : base name of component \r
+ -verbose : level of verbose [all/read/write]\r
+ -outputDatabase : file name of output database file\r
+ -databaseList : file name list of database files\r
+ -inputFileList : file name list of input files\r
+ -newDatabase : whether to need new database [ture/false]\r
+ -unquotedString : whether to unquoted strings are used [ture/false]\r
+ -includePathList: path list of include paths\r
+ -ignoreNotFound : whether to ignore a given STRING_TOKEN(STR) is not found in database [ture/false]\r
+ -skipExtList : skip scan of files with extension name\r
+ -outputString : write string data to filename \r
+ -outputDefines : write string defines to filename \r
+ -outputUnicode : dump database to unicode file filename\r
+ -lang : only dump for the language \r
+ -indirectionFile: specify an indirection file\r
+ -outputHpk : create an HII export pack of the strings\r
+ **/\r
+public class StrGatherTask extends Task implements EfiDefine {\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 ToolArg baseName = new ToolArg();\r
+\r
+ //\r
+ // "all/read/write"\r
+ //\r
+ private ToolArg verbose = new ToolArg();\r
+\r
+ private FileArg outputDatabase = new FileArg();\r
+\r
+ private Database databaseList = new Database();\r
+\r
+ private InputFile inputFileList = new InputFile();\r
+\r
+ //\r
+ // parse options newDatabase -- "ture/false" unquoteString -- "ture/false"\r
+ //\r
+ private ToolArg newDatabase = new ToolArg();\r
+\r
+ private ToolArg unquotedString = new ToolArg();\r
+\r
+ private IncludePath includePathList = new IncludePath();\r
+\r
+ //\r
+ // scan options ignoreNotFound -- "ture/false"\r
+ //\r
+ private ToolArg ignoreNotFound = new ToolArg();\r
+\r
+ private SkipExt skipExtList = new SkipExt();\r
+\r
+ //\r
+ // dump options\r
+ //\r
+ private ToolArg outputString = new ToolArg();\r
+\r
+ private ToolArg outputDefines = new ToolArg();\r
+\r
+ private ToolArg outputUnicode = new ToolArg();\r
+\r
+ private ToolArg lang = new ToolArg();\r
+\r
+ private FileArg indirectionFile = new FileArg();\r
+\r
+ private FileArg outputHpk = new FileArg();\r
+\r
+ //\r
+ // global variable\r
+ //\r
+ static private Project project;\r
+\r
+ /**\r
+ assemble tool command line & execute tool command line\r
+ \r
+ @throws BuildException\r
+ **/\r
+ public void execute() throws BuildException {\r
+\r
+ project = this.getOwningTarget().getProject();\r
+ ///\r
+ /// absolute path of efi tools\r
+ ///\r
+ String path = project.getProperty("env.FRAMEWORK_TOOLS_PATH"); \r
+ String command;\r
+ if (path == null) {\r
+ command = toolName;\r
+ } else {\r
+ command = path + File.separator + toolName;\r
+ }\r
+\r
+ ///\r
+ /// assemble argument\r
+ ///\r
+ String argument = "" + commandType + verbose + databaseList + baseName\r
+ + outputDatabase + includePathList + newDatabase + unquotedString\r
+ + skipExtList + ignoreNotFound + outputString + outputDefines\r
+ + outputUnicode + lang + indirectionFile + outputHpk\r
+ + inputFileList;\r
+ ///\r
+ /// return value of fwimage execution\r
+ ///\r
+ int revl = -1;\r
+\r
+ try {\r
+ Commandline cmdline = new Commandline();\r
+ cmdline.setExecutable(command);\r
+ cmdline.createArgument().setLine(argument);\r
+\r
+ LogStreamHandler streamHandler = new LogStreamHandler(this,\r
+ Project.MSG_INFO, Project.MSG_WARN);\r
+ Execute runner = new Execute(streamHandler, null);\r
+\r
+ runner.setAntRun(project);\r
+ runner.setCommandline(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
+ EdkLog.log(this, EdkLog.EDK_VERBOSE, toolName + " succeeded!");\r
+ } else {\r
+ ///\r
+ /// command execution fail\r
+ ///\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
+ }\r
+ }\r
+\r
+ /**\r
+ get class member "commandType"\r
+ \r
+ @returns commandType parameter\r
+ **/\r
+ public String getCommandType() {\r
+ return this.commandType.getValue();\r
+ }\r
+\r
+ /**\r
+ set class member ""\r
+ \r
+ @param commandType type of strgather command [parse/scan/dump]\r
+ **/\r
+ public void setCommandType(String commandType) {\r
+ this.commandType.setArg(" -", commandType);\r
+ }\r
+\r
+ /**\r
+ get class member "verbose"\r
+ \r
+ @returns verbose parameter\r
+ **/\r
+ public String getVerbose() {\r
+ return this.verbose.getValue();\r
+ }\r
+\r
+ /**\r
+ set class member "verbose"\r
+ \r
+ @param verbose verbose level [all/read/write]\r
+ **/\r
+ public void setVerbose(String verbose) {\r
+ if (verbose.equals("all")) {\r
+ ///\r
+ /// for verbose output\r
+ ///\r
+ this.verbose.setArg(" -", "v");\r
+ } else if (verbose.equals("read")) {\r
+ ///\r
+ /// for verbose output when reading database\r
+ ///\r
+ this.verbose.setArg(" -", "vdbr");\r
+ } else if (verbose.equals("write")) {\r
+ ///\r
+ /// for verbose output when writing database\r
+ ///\r
+ this.verbose.setArg(" -", "vdbw");\r
+ }\r
+ }\r
+\r
+ /**\r
+ get class member baseName\r
+ \r
+ @returns baseName parameter\r
+ **/\r
+ public String getBaseName() {\r
+ return this.baseName.getValue();\r
+ }\r
+\r
+ /**\r
+ set class member baseName\r
+ \r
+ @param baseName name of the output files of .c and .h\r
+ **/\r
+ public void setBaseName(String baseName) {\r
+ this.baseName.setArg(" -bn ", baseName);\r
+ }\r
+\r
+ /**\r
+ get class member "outputDatabase"\r
+ \r
+ @returns outputDatabase parameter\r
+ **/\r
+ public String getOutputDatabase() {\r
+ return this.outputDatabase.getValue();\r
+ }\r
+\r
+ /**\r
+ set class member "outputDatabase"\r
+ \r
+ @param outputDatabase filename of output database file\r
+ **/\r
+ public void setOutputDatabase(String outputDatabase) {\r
+ this.outputDatabase.setArg(" -od ", outputDatabase);\r
+ }\r
+\r
+ /**\r
+ get class member "newDatabase"\r
+ \r
+ @returns newDatabase parameter\r
+ **/\r
+ public boolean getNewDatabse() {\r
+ return this.newDatabase.getPrefix().length() > 0;\r
+ }\r
+\r
+ /**\r
+ set class member "newDatabase"\r
+ \r
+ @param newDatabase whether to not read in existing database file\r
+ **/\r
+ public void setNewDatabase(boolean newDatabase) {\r
+ if (newDatabase) {\r
+ this.newDatabase.setArg(" -", "newdb");\r
+ }\r
+ }\r
+\r
+ /**\r
+ get class member "unquotedString"\r
+ \r
+ @returns unquotedString parameter\r
+ **/\r
+ public boolean getUnquotedString() {\r
+ return this.unquotedString.getValue().length() > 0;\r
+ }\r
+\r
+ /**\r
+ set class member "unquotedString"\r
+ \r
+ @param unquotedString :\r
+ whether to indicate that unquoted strings are used\r
+ **/\r
+ public void setUnquotedString(boolean unquotedString) {\r
+ if (unquotedString) {\r
+ this.unquotedString.setArg(" -", "uqs");\r
+ }\r
+ }\r
+\r
+ /**\r
+ get class member "ignoreNotFound"\r
+ \r
+ @returns ignoreNotFound parameter\r
+ **/\r
+ public boolean getIgnoreNotFound() {\r
+ return this.ignoreNotFound.getValue().length() > 0;\r
+ }\r
+\r
+ /**\r
+ set class member "ignoreNotFound"\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(boolean ignoreNotFound) {\r
+ if (ignoreNotFound) {\r
+ this.ignoreNotFound.setArg(" -", "ignorenotfound");\r
+ }\r
+ }\r
+\r
+ /**\r
+ get class member "outputString"\r
+ \r
+ @returns outputString parameter\r
+ **/\r
+ public String getOutputString() {\r
+ return this.outputString.getValue();\r
+ }\r
+\r
+ /**\r
+ set class member "outputString"\r
+ \r
+ @param outputString filename of string data file\r
+ **/\r
+ public void setOutputString(String outputString) {\r
+ this.outputString.setArg(" -oc ", outputString);\r
+ }\r
+\r
+ /**\r
+ get class member "outputDefines"\r
+ \r
+ @returns outputDefines parameter\r
+ **/\r
+ public String getOutputDefines() {\r
+ return this.outputDefines.getValue();\r
+ }\r
+\r
+ /**\r
+ set class member "outputDefines"\r
+ \r
+ @param outputDefines filename of string defines file\r
+ **/\r
+ public void setOutputDefines(String outputDefines) {\r
+ this.outputDefines.setArg(" -oh ", outputDefines);\r
+ }\r
+\r
+ /**\r
+ get class member "outputUnicode"\r
+ \r
+ @returns outputUnicode parameter\r
+ **/\r
+ public String getOutputUnicode() {\r
+ return this.outputUnicode.getValue();\r
+ }\r
+\r
+ /**\r
+ set class member "outputUnicode"\r
+ \r
+ @param outputUnicode filename of unicode file to be dumped database\r
+ **/\r
+ public void setOutputUnicode(String outputUnicode) {\r
+ this.outputUnicode.setArg(" -ou ", outputUnicode);\r
+ }\r
+\r
+ /**\r
+ get class member "lang"\r
+ \r
+ @returns lang parameter\r
+ **/\r
+ public String getLang() {\r
+ return this.lang.getValue();\r
+ }\r
+\r
+ /**\r
+ set class member "lang"\r
+ \r
+ @param lang language of dump\r
+ **/\r
+ public void setLang(String lang) {\r
+ this.lang.setArg(" -lang ", lang);\r
+ }\r
+\r
+ /**\r
+ get class member "indirectionFile"\r
+ \r
+ @returns indirectionFile parameter\r
+ **/\r
+ public String getIndirectionFile() {\r
+ return this.indirectionFile.getValue();\r
+ }\r
+\r
+ /**\r
+ set class member "indirectionFile"\r
+ \r
+ @param indirectionFile filename of indirection file\r
+ **/\r
+ public void setIndirectionFile(String indirectionFile) {\r
+ this.indirectionFile.setArg(" -if ", indirectionFile);\r
+ }\r
+\r
+ /**\r
+ get class member "outputHpk"\r
+ \r
+ @returns outputHpk parameter\r
+ **/\r
+ public String getOutputHpk() {\r
+ return this.outputHpk.getValue();\r
+ }\r
+\r
+ /**\r
+ set class member "outputHpk"\r
+ \r
+ @param outputHpk filename of output HII export pack of the strings\r
+ **/\r
+ public void setOutputHpk(String outputHpk) {\r
+ this.outputHpk.setArg(" -hpk ", outputHpk);\r
+ }\r
+\r
+ /**\r
+ add a skipExt element into list\r
+ \r
+ @param skipExt skipExt element\r
+ **/\r
+ public void addConfiguredSkipext(SkipExt skipExt) {\r
+ this.skipExtList.insert(skipExt);\r
+ };\r
+\r
+ /**\r
+ add a includePath element into list\r
+ \r
+ @param includePath includePath element\r
+ **/\r
+ public void addConfiguredIncludepath(IncludePath includePath) {\r
+ this.includePathList.insert(includePath);\r
+ };\r
+\r
+ /**\r
+ add a inputFile element into list\r
+ \r
+ @param inputFile inputFile element\r
+ **/\r
+ public void addConfiguredInputfile(InputFile inputFile) {\r
+ this.inputFileList.insert(inputFile);\r
+ };\r
+\r
+ /**\r
+ add a database element into list\r
+ \r
+ @param database :\r
+ database element\r
+ **/\r
+ public void addConfiguredDatabase(Database database) {\r
+ this.databaseList.insert(database);\r
+ }\r
+}\r