]> git.proxmox.com Git - mirror_edk2.git/blobdiff - Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/GenSectionTask.java
Modify GenFfsFileTask.
[mirror_edk2.git] / Tools / Source / FrameworkTasks / org / tianocore / framework / tasks / GenSectionTask.java
index bb477f031e2f518302b2578e764becc015f08a5c..4cd7a96cdbd76fc71dd2e0ea72cf5e2dcebf8418 100644 (file)
@@ -31,36 +31,46 @@ import org.apache.tools.ant.taskdefs.LogStreamHandler;
 import org.apache.tools.ant.types.Commandline;\r
 import org.tianocore.common.logger.EdkLog;\r
 \r
-public class GenSectionTask extends Task implements EfiDefine, Section,FfsTypes {\r
-    ///\r
-    /// inputfile name\r
-    ///\r
-    private String inputFile = "";\r
-    ///\r
-    /// \r
-    /// \r
-    private String inputFileName = "";\r
-    ///\r
-    /// outputfile name\r
-    ///\r
-    private String outputFile = "";\r
-    ///\r
-    /// section type\r
-    ///\r
-    private String sectionType = "";\r
-    ///\r
-    /// version number\r
-    ///\r
-    private String versionNum = "";\r
-    ///\r
-    /// interface string\r
-    ///\r
-    private String interfaceString = "";\r
-    ///\r
-    /// Section file list\r
-    ///\r
+public class GenSectionTask extends Task implements EfiDefine, Section, FfsTypes {\r
+    //\r
+    // Tool name\r
+    // \r
+    private final static String toolName = "GenSection";\r
+    //\r
+    // inputfile name\r
+    //\r
+    private FileArg inputFile = new FileArg();\r
+\r
+    //\r
+    // outputfile name\r
+    //\r
+    private FileArg outputFile = new FileArg();\r
+\r
+    //\r
+    // section type\r
+    //\r
+    private ToolArg sectionType = new ToolArg();\r
+\r
+    //\r
+    // version number\r
+    //\r
+    private ToolArg versionNum = new ToolArg();\r
+\r
+    //\r
+    // interface string\r
+    //\r
+    private ToolArg interfaceString = new ToolArg();\r
+\r
+    //\r
+    // Section file list\r
+    //\r
     private List<Section> sectFileList = new ArrayList<Section>();\r
-   \r
+\r
+    //\r
+    // flag indicated the <tool> element\r
+    //\r
+    private boolean haveTool = false;\r
+\r
     /**\r
       execute\r
       \r
@@ -77,15 +87,14 @@ public class GenSectionTask extends Task implements EfiDefine, Section,FfsTypes
         //\r
         String path = project.getProperty("env.FRAMEWORK_TOOLS_PATH");\r
         if (path == null) {\r
-            command = "GenSection";\r
+            command = toolName;\r
         } else {\r
-            command = path + "/" + "GenSection";\r
+            command = path + File.separator + toolName;\r
         }\r
         //\r
         // argument of tools\r
         //\r
-        String argument = inputFile + outputFile + " -s "+ sectionType + versionNum\r
-                + interfaceString;\r
+        String argument = "" + inputFile + outputFile + sectionType + versionNum + interfaceString;\r
         //\r
         // return value of gensection execution\r
         //\r
@@ -103,17 +112,19 @@ public class GenSectionTask extends Task implements EfiDefine, Section,FfsTypes
             runner.setAntRun(project);\r
             runner.setCommandline(cmdline.getCommandline());\r
 \r
-            EdkLog.log(this, EdkLog.EDK_INFO, inputFileName);\r
-            EdkLog.log(this, EdkLog.EDK_DEBUG, Commandline.toString(cmdline.getCommandline()));\r
+            EdkLog.log(this, inputFile.toFileList() + versionNum.getValue() \r
+                + interfaceString.getValue() + " => " + outputFile.toFileList());\r
+            EdkLog.log(this, EdkLog.EDK_VERBOSE, Commandline.toString(cmdline.getCommandline()));\r
+\r
             revl = runner.execute();\r
             if (EFI_SUCCESS == revl) {\r
-                log("GenSection succeeded!", Project.MSG_VERBOSE);\r
+                EdkLog.log(this, EdkLog.EDK_VERBOSE, toolName + " succeeded!");\r
             } else {\r
                 //\r
                 // command execution fail\r
                 //\r
-                log("ERROR = " + Integer.toHexString(revl));\r
-                throw new BuildException("GenSection failed!");\r
+                EdkLog.log(this, EdkLog.EDK_INFO, "ERROR = " + Integer.toHexString(revl));\r
+                throw new BuildException(toolName + " failed!");\r
             }\r
         } catch (Exception e) {\r
             throw new BuildException(e.getMessage());\r
@@ -128,7 +139,7 @@ public class GenSectionTask extends Task implements EfiDefine, Section,FfsTypes
       @return                    name of input file\r
     **/\r
     public String getInputFile() {\r
-        return this.inputFile;\r
+        return this.inputFile.getValue();\r
     }\r
 \r
     /**\r
@@ -139,8 +150,7 @@ public class GenSectionTask extends Task implements EfiDefine, Section,FfsTypes
       @param inputFile            name of input file\r
     **/\r
     public void setInputFile(String inputFile) {\r
-        this.inputFileName = (new File(inputFile)).getName();\r
-        this.inputFile = " -i " + inputFile;\r
+        this.inputFile.setArg(" -i ", inputFile);\r
     }\r
 \r
     /**\r
@@ -151,7 +161,7 @@ public class GenSectionTask extends Task implements EfiDefine, Section,FfsTypes
       @return                      name of output file\r
     **/\r
     public String getOutputFile() {\r
-        return this.outputFile;\r
+        return this.outputFile.getValue();\r
     }\r
 \r
     /**\r
@@ -161,7 +171,7 @@ public class GenSectionTask extends Task implements EfiDefine, Section,FfsTypes
       @param  outputFile            name of output file\r
     **/\r
     public void setOutputfile(String outputFile) {\r
-        this.outputFile = " -o " + outputFile;\r
+        this.outputFile.setArg(" -o ", outputFile);\r
     }\r
 \r
     /**\r
@@ -172,7 +182,7 @@ public class GenSectionTask extends Task implements EfiDefine, Section,FfsTypes
       @return                        sectoin type\r
     **/\r
     public String getSectionType() {\r
-        return this.sectionType;\r
+        return this.sectionType.getValue();\r
     }\r
 \r
     /**\r
@@ -183,7 +193,7 @@ public class GenSectionTask extends Task implements EfiDefine, Section,FfsTypes
       @param sectionType              section type\r
     **/\r
     public void setSectionType(String sectionType) {\r
-        this.sectionType = sectionType;\r
+        this.sectionType.setArg(" -s ", sectionType);\r
     }\r
 \r
     /**\r
@@ -193,7 +203,7 @@ public class GenSectionTask extends Task implements EfiDefine, Section,FfsTypes
       @return                         version number\r
     **/\r
     public String getVersionNum() {\r
-        return this.versionNum;\r
+        return this.versionNum.getValue();\r
     }\r
 \r
     /**\r
@@ -203,7 +213,7 @@ public class GenSectionTask extends Task implements EfiDefine, Section,FfsTypes
       @param versionNum               version number\r
     **/\r
     public void setVersionNum(String versionNum) {\r
-        this.versionNum = " -v " + versionNum;\r
+        this.versionNum.setArg(" -v ", versionNum);\r
     }\r
 \r
     /**\r
@@ -213,7 +223,7 @@ public class GenSectionTask extends Task implements EfiDefine, Section,FfsTypes
       @return                         interface string\r
     **/\r
     public String getInterfaceString() {\r
-        return this.interfaceString;\r
+        return this.interfaceString.getValue();\r
     }\r
 \r
     /**\r
@@ -223,7 +233,7 @@ public class GenSectionTask extends Task implements EfiDefine, Section,FfsTypes
       @param interfaceString            interface string\r
     **/\r
     public void setInterfaceString(String interfaceString) {\r
-        this.interfaceString = " -a " + "\"" + interfaceString + "\"";\r
+        this.interfaceString.setArg(" -a ", "\"" + interfaceString + "\"");\r
     }\r
     \r
     /**\r
@@ -246,6 +256,7 @@ public class GenSectionTask extends Task implements EfiDefine, Section,FfsTypes
     **/\r
     public void addTool(Tool tool) {\r
         this.sectFileList.add(tool);\r
+        this.haveTool = true;\r
     }\r
     \r
     /**\r
@@ -260,111 +271,113 @@ public class GenSectionTask extends Task implements EfiDefine, Section,FfsTypes
     \r
     public void toBuffer(DataOutputStream buffer){\r
         //\r
-        //  Search SectionList find earch section and call it's \r
-        //  ToBuffer function.\r
+        // Search SectionList find earch section and call it's\r
+        // ToBuffer function.\r
         //\r
-        if (this.sectionType.equalsIgnoreCase("EFI_SECTION_COMPRESSION")){\r
-            Section    sect;\r
-            \r
+        if (this.sectionType.getValue().equalsIgnoreCase(\r
+                "EFI_SECTION_COMPRESSION")\r
+                && !this.haveTool) {\r
+            Section sect;\r
+\r
             //\r
-            //  Get section file in compress node.\r
+            // Get section file in compress node.\r
             //\r
-            try{\r
-                ByteArrayOutputStream bo = new ByteArrayOutputStream ();\r
-                DataOutputStream Do = new DataOutputStream (bo);\r
-                \r
+            try {\r
+                ByteArrayOutputStream bo = new ByteArrayOutputStream();\r
+                DataOutputStream Do = new DataOutputStream(bo);\r
+\r
                 //\r
-                //  Get each section which under the compress {};\r
-                //  And add it is contains to File;\r
+                // Get each section which under the compress {};\r
+                // And add it is contains to File;\r
                 //\r
                 Iterator SectionIter = this.sectFileList.iterator();\r
-                while (SectionIter.hasNext()){\r
-                    sect = (Section)SectionIter.next();\r
-                    \r
+                while (SectionIter.hasNext()) {\r
+                    sect = (Section) SectionIter.next();\r
+\r
                     //\r
-                    //  Call each section class's toBuffer function.\r
+                    // Call each section class's toBuffer function.\r
                     //\r
                     try {\r
                         sect.toBuffer(Do);\r
-                    }\r
-                    catch (BuildException e) {\r
+                    } catch (BuildException e) {\r
                         System.out.print(e.getMessage());\r
-                        throw new BuildException ("Compress.toBuffer failed at section");\r
-                    }    \r
-                                \r
+                        throw new BuildException(\r
+                                "Compress.toBuffer failed at section");\r
+                    } finally {\r
+                        if (Do != null){\r
+                            Do.close();\r
+                        }\r
+                    }\r
                 }\r
-                Do.close();    \r
-                \r
                 //\r
-                //  Call compress\r
+                // Call compress\r
                 //\r
                 byte[] fileBuffer = bo.toByteArray();\r
-                Compress myCompress = new Compress(fileBuffer, fileBuffer.length);            \r
-                \r
-                //\r
-                //  Add Compress header\r
-                //\r
-                CompressHeader Ch        = new CompressHeader();\r
-                Ch.SectionHeader.Size[0] = (byte)((myCompress.outputBuffer.length +\r
-                                                   Ch.GetSize()) &\r
-                                                   0xff\r
-                                                  );\r
-                Ch.SectionHeader.Size[1] = (byte)(((myCompress.outputBuffer.length + \r
-                                                    Ch.GetSize())&\r
-                                                   0xff00) >> 8\r
-                                                  );\r
-                Ch.SectionHeader.Size[2] = (byte)(((myCompress.outputBuffer.length + \r
-                                                    Ch.GetSize()) & \r
-                                                   0xff0000) >> 16\r
-                                                 );\r
-                Ch.SectionHeader.type    = (byte) EFI_SECTION_COMPRESSION;\r
-                \r
-                //\r
-                //  Note: The compressName was not efsfective now. Using the\r
-                //  EFI_STANDARD_COMPRSSION for compressType .\r
-                //  That is follow old Genffsfile tools. Some code will be added for \r
-                //  the different compressName;\r
-                //\r
-                Ch.UncompressLen         = fileBuffer.length;\r
-                Ch.CompressType          = EFI_STANDARD_COMPRESSION; \r
-                \r
-                //\r
-                //  Change header struct to byte buffer\r
-                //\r
-                byte [] headerBuffer = new byte[Ch.GetSize()];\r
-                Ch.StructToBuffer(headerBuffer);\r
-                \r
-                //\r
-                //  First add CompressHeader to Buffer, then add Compress data.\r
-                //\r
-                buffer.write (headerBuffer);\r
-                buffer.write(myCompress.outputBuffer);            \r
-                    \r
-                //\r
-                //  Buffer 4 Byte aligment \r
-                //\r
-                int size = Ch.GetSize() + myCompress.outputBuffer.length;\r
-                \r
-                while ((size & 0x03) != 0){\r
-                    size ++;\r
-                    buffer.writeByte(0);\r
+\r
+                synchronized (CompressSection.semaphore) {\r
+                    Compress myCompress = new Compress(fileBuffer,\r
+                            fileBuffer.length);\r
+\r
+                    //\r
+                    // Add Compress header\r
+                    //\r
+                    CompressHeader Ch = new CompressHeader();\r
+                    Ch.SectionHeader.Size[0] = (byte) ((myCompress.outputBuffer.length + Ch\r
+                            .GetSize()) & 0xff);\r
+                    Ch.SectionHeader.Size[1] = (byte) (((myCompress.outputBuffer.length + Ch\r
+                            .GetSize()) & 0xff00) >> 8);\r
+                    Ch.SectionHeader.Size[2] = (byte) (((myCompress.outputBuffer.length + Ch\r
+                            .GetSize()) & 0xff0000) >> 16);\r
+                    Ch.SectionHeader.type = (byte) EFI_SECTION_COMPRESSION;\r
+\r
+                    //\r
+                    // Note: The compressName was not efsfective now. Using the\r
+                    // EFI_STANDARD_COMPRSSION for compressType .\r
+                    // That is follow old Genffsfile tools. Some code will be\r
+                    // added for\r
+                    // the different compressName;\r
+                    //\r
+                    Ch.UncompressLen = fileBuffer.length;\r
+                    Ch.CompressType = EFI_STANDARD_COMPRESSION;\r
+\r
+                    //\r
+                    // Change header struct to byte buffer\r
+                    //\r
+                    byte[] headerBuffer = new byte[Ch.GetSize()];\r
+                    Ch.StructToBuffer(headerBuffer);\r
+\r
+                    //\r
+                    // First add CompressHeader to Buffer, then add Compress\r
+                    // data.\r
+                    //\r
+                    buffer.write(headerBuffer);\r
+                    buffer.write(myCompress.outputBuffer);\r
+\r
+                    //\r
+                    // Buffer 4 Byte aligment\r
+                    //\r
+                    int size = Ch.GetSize() + myCompress.outputBuffer.length;\r
+\r
+                    while ((size & 0x03) != 0) {\r
+                        size++;\r
+                        buffer.writeByte(0);\r
+                    }\r
                 }\r
-            }\r
-            catch (Exception e){\r
+            } catch (Exception e) {\r
                 throw new BuildException("compress.toBuffer failed!\n");\r
-            }    \r
+            } \r
         } else {\r
             Section sect;\r
             Iterator sectionIter = this.sectFileList.iterator();\r
             while (sectionIter.hasNext()) {\r
-                sect = (Section)sectionIter.next(); \r
+                sect = (Section) sectionIter.next();\r
                 try {\r
                     //\r
-                    //  The last section don't need 4 byte ffsAligment.\r
+                    // The last section don't need 4 byte ffsAligment.\r
                     //\r
                     sect.toBuffer(buffer);\r
                 } catch (Exception e) {\r
-                    throw new BuildException (e.getMessage());\r
+                    throw new BuildException(e.getMessage());\r
                 }\r
             }\r
         }\r