]> git.proxmox.com Git - mirror_edk2.git/blobdiff - Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/StrGatherTask.java
1) Changed ToolArg class to abstract generic arguments of a tool
[mirror_edk2.git] / Tools / Source / FrameworkTasks / org / tianocore / framework / tasks / StrGatherTask.java
index b84adf2525d25de9ebfbb769dd7f2d0c12312dca..a92f727376d37c7e3b378f582bd08639f7baf625 100644 (file)
@@ -22,6 +22,7 @@ import org.apache.tools.ant.Task;
 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
@@ -48,51 +49,51 @@ public class StrGatherTask extends Task implements EfiDefine {
     ///\r
     /// common options\r
     ///\r
-    private String commandType = "";\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
+    private ToolArg verbose = new ToolArg();\r
 \r
-    private String outputDatabase = "";\r
+    private FileArg outputDatabase = new FileArg();\r
 \r
-    private List<Database> databaseList = new ArrayList<Database>();\r
+    private Database databaseList = new Database();\r
 \r
-    private List<InputFile> inputFileList = new ArrayList<InputFile>();\r
+    private InputFile inputFileList = new InputFile();\r
 \r
     ///\r
     /// parse options newDatabase -- "ture/false" unquoteString -- "ture/false"\r
     ///\r
-    private String newDatabase = "";\r
+    private ToolArg newDatabase = new ToolArg();\r
 \r
-    private String unquotedString = "";\r
+    private ToolArg unquotedString = new ToolArg();\r
 \r
-    private List<IncludePath> includePathList = new ArrayList<IncludePath>();\r
+    private IncludePath includePathList = new IncludePath();\r
 \r
     ///\r
     /// scan options ignoreNotFound -- "ture/false"\r
     ///\r
-    private String ignoreNotFound = "";\r
+    private ToolArg ignoreNotFound = new ToolArg();\r
 \r
-    private List<SkipExt> skipExtList = new ArrayList<SkipExt>();\r
+    private SkipExt skipExtList = new SkipExt();\r
 \r
     ///\r
     /// dump options\r
     ///\r
-    private String outputString = "";\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
@@ -118,22 +119,14 @@ public class StrGatherTask extends Task implements EfiDefine {
             command = path + File.separator + "StrGather";\r
         }\r
 \r
-        ///\r
-        /// transfer nested elements into string\r
-        ///\r
-        String databases = list2Str(databaseList);\r
-        String skipExts = list2Str(skipExtList);\r
-        String includePaths = list2Str(includePathList);\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
@@ -151,16 +144,27 @@ public class StrGatherTask extends Task implements EfiDefine {
             runner.setAntRun(project);\r
             runner.setCommandline(cmdline.getCommandline());\r
 \r
-            log(Commandline.toString(cmdline.getCommandline()), Project.MSG_VERBOSE);\r
-            log(this.commandType.substring(2));\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
-                log("StrGather succeeded!", Project.MSG_VERBOSE);\r
+                EdkLog.log(this, EdkLog.EDK_VERBOSE, "StrGather succeeded!");\r
             } else {\r
                 ///\r
                 /// command execution fail\r
                 ///\r
-                log("ERROR = " + Integer.toHexString(revl));\r
+                EdkLog.log(this, "ERROR = " + Integer.toHexString(revl));\r
                 throw new BuildException("StrGather failed!");\r
             }\r
         } catch (Exception e) {\r
@@ -174,7 +178,7 @@ public class StrGatherTask extends Task implements EfiDefine {
      @returns commandType parameter\r
      **/\r
     public String getCommandType() {\r
-        return this.commandType;\r
+        return this.commandType.getValue();\r
     }\r
 \r
     /**\r
@@ -183,7 +187,7 @@ public class StrGatherTask extends Task implements EfiDefine {
      @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
@@ -192,7 +196,7 @@ public class StrGatherTask extends Task implements EfiDefine {
      @returns verbose parameter\r
      **/\r
     public String getVerbose() {\r
-        return this.verbose;\r
+        return this.verbose.getValue();\r
     }\r
 \r
     /**\r
@@ -205,17 +209,17 @@ public class StrGatherTask extends Task implements EfiDefine {
             ///\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
@@ -225,7 +229,7 @@ public class StrGatherTask extends Task implements EfiDefine {
      @returns baseName parameter\r
      **/\r
     public String getBaseName() {\r
-        return this.baseName;\r
+        return this.baseName.getValue();\r
     }\r
 \r
     /**\r
@@ -234,7 +238,7 @@ public class StrGatherTask extends Task implements EfiDefine {
      @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
@@ -243,7 +247,7 @@ public class StrGatherTask extends Task implements EfiDefine {
      @returns outputDatabase parameter\r
      **/\r
     public String getOutputDatabase() {\r
-        return this.outputDatabase;\r
+        return this.outputDatabase.getValue();\r
     }\r
 \r
     /**\r
@@ -252,7 +256,7 @@ public class StrGatherTask extends Task implements EfiDefine {
      @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
@@ -260,8 +264,8 @@ public class StrGatherTask extends Task implements EfiDefine {
      \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
@@ -269,9 +273,9 @@ public class StrGatherTask extends Task implements EfiDefine {
      \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
@@ -280,8 +284,8 @@ public class StrGatherTask extends Task implements EfiDefine {
      \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
@@ -290,9 +294,9 @@ public class StrGatherTask extends Task implements EfiDefine {
      @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
@@ -301,8 +305,8 @@ public class StrGatherTask extends Task implements EfiDefine {
      \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
@@ -311,9 +315,9 @@ public class StrGatherTask extends Task implements EfiDefine {
      @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
@@ -323,7 +327,7 @@ public class StrGatherTask extends Task implements EfiDefine {
      @returns outputString parameter\r
      **/\r
     public String getOutputString() {\r
-        return this.outputString;\r
+        return this.outputString.getValue();\r
     }\r
 \r
     /**\r
@@ -332,7 +336,7 @@ public class StrGatherTask extends Task implements EfiDefine {
      @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
@@ -341,7 +345,7 @@ public class StrGatherTask extends Task implements EfiDefine {
      @returns outputDefines parameter\r
      **/\r
     public String getOutputDefines() {\r
-        return this.outputDefines;\r
+        return this.outputDefines.getValue();\r
     }\r
 \r
     /**\r
@@ -350,7 +354,7 @@ public class StrGatherTask extends Task implements EfiDefine {
      @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
@@ -359,7 +363,7 @@ public class StrGatherTask extends Task implements EfiDefine {
      @returns outputUnicode parameter\r
      **/\r
     public String getOutputUnicode() {\r
-        return this.outputUnicode;\r
+        return this.outputUnicode.getValue();\r
     }\r
 \r
     /**\r
@@ -368,7 +372,7 @@ public class StrGatherTask extends Task implements EfiDefine {
      @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
@@ -377,7 +381,7 @@ public class StrGatherTask extends Task implements EfiDefine {
      @returns lang parameter\r
      **/\r
     public String getLang() {\r
-        return this.lang;\r
+        return this.lang.getValue();\r
     }\r
 \r
     /**\r
@@ -386,7 +390,7 @@ public class StrGatherTask extends Task implements EfiDefine {
      @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
@@ -395,7 +399,7 @@ public class StrGatherTask extends Task implements EfiDefine {
      @returns indirectionFile parameter\r
      **/\r
     public String getIndirectionFile() {\r
-        return this.indirectionFile;\r
+        return this.indirectionFile.getValue();\r
     }\r
 \r
     /**\r
@@ -404,7 +408,7 @@ public class StrGatherTask extends Task implements EfiDefine {
      @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
@@ -413,7 +417,7 @@ public class StrGatherTask extends Task implements EfiDefine {
      @returns outputHpk parameter\r
      **/\r
     public String getOutputHpk() {\r
-        return this.outputHpk;\r
+        return this.outputHpk.getValue();\r
     }\r
 \r
     /**\r
@@ -422,7 +426,7 @@ public class StrGatherTask extends Task implements EfiDefine {
      @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
@@ -430,8 +434,8 @@ public class StrGatherTask extends Task implements EfiDefine {
      \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
@@ -439,8 +443,8 @@ public class StrGatherTask extends Task implements EfiDefine {
      \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
@@ -448,8 +452,8 @@ public class StrGatherTask extends Task implements EfiDefine {
      \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
@@ -458,25 +462,7 @@ public class StrGatherTask extends Task implements EfiDefine {
      @param database :\r
                 database element\r
      **/\r
-    public void addDatabase(Database database) {\r
-        databaseList.add(database);\r
-    }\r
-\r
-    /**\r
-       Compose the content in each NestElement into a single string.\r
-\r
-       @param list  The NestElement list\r
-       \r
-       @return String\r
-     **/\r
-    private String list2Str(List list) {\r
-        int listLength = list.size();\r
-        String str = "";\r
-        for (int i = 0; i < listLength; ++i) {\r
-            NestElement e = (NestElement)list.get(i);\r
-            str += e.toString();\r
-        }\r
-\r
-        return str;\r
+    public void addConfiguredDatabase(Database database) {\r
+        this.databaseList.insert(database);\r
     }\r
 }\r