]> git.proxmox.com Git - mirror_edk2.git/blobdiff - Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/StrGatherTask.java
Changed spelling to manifest
[mirror_edk2.git] / Tools / Source / FrameworkTasks / org / tianocore / framework / tasks / StrGatherTask.java
index c136f15511f9ed004b732dfa1b0b0b071b6f4525..541e96f54f785b2b0f06d4a14c5e892138a82243 100644 (file)
@@ -13,13 +13,14 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 **/\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
@@ -43,58 +44,63 @@ import org.apache.tools.ant.types.Commandline;
       -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
@@ -108,30 +114,22 @@ public class StrGatherTask extends Task implements EfiDefine {
         ///\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
@@ -148,22 +146,29 @@ public class StrGatherTask extends Task implements EfiDefine {
 \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
@@ -176,7 +181,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
@@ -185,7 +190,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
@@ -194,7 +199,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
@@ -207,17 +212,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
@@ -227,7 +232,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
@@ -236,7 +241,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
@@ -245,7 +250,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
@@ -254,7 +259,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
@@ -262,8 +267,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
@@ -271,9 +276,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
@@ -282,8 +287,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
@@ -292,9 +297,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
@@ -303,8 +308,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
@@ -313,9 +318,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
@@ -325,7 +330,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
@@ -334,7 +339,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
@@ -343,7 +348,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
@@ -352,7 +357,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
@@ -361,7 +366,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
@@ -370,7 +375,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
@@ -379,7 +384,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
@@ -388,7 +393,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
@@ -397,7 +402,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
@@ -406,7 +411,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
@@ -415,7 +420,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
@@ -424,7 +429,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
@@ -432,8 +437,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
@@ -441,8 +446,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
@@ -450,8 +455,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
@@ -460,68 +465,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
+    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