]> git.proxmox.com Git - mirror_edk2.git/blobdiff - Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/ModifyInfTask.java
Add ModifyInftask in FrameworkTask.
[mirror_edk2.git] / Tools / Source / FrameworkTasks / org / tianocore / framework / tasks / ModifyInfTask.java
diff --git a/Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/ModifyInfTask.java b/Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/ModifyInfTask.java
new file mode 100644 (file)
index 0000000..1339d0b
--- /dev/null
@@ -0,0 +1,238 @@
+/** @file\r
+ ModifyInfTask class.\r
+\r
+ ModifyInfTask is used to call Modify.exe to generate inf file.\r
\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
+\r
+import org.apache.tools.ant.Task;\r
+import org.apache.tools.ant.Project;\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.logger.EdkLog;\r
+\r
+/**\r
+  ModifyInfTask class.\r
+\r
+  ModifyInfTask is used to call Modify.exe to generate inf file.\r
+**/\r
+public class ModifyInfTask extends Task implements EfiDefine {\r
+    ///\r
+    /// tool name\r
+    ///\r
+    private String toolName = "ModifyInf";\r
+    \r
+    ///\r
+    /// input FV inf file\r
+    ///\r
+    private String inputFVInfFileName = "";\r
+\r
+    ///\r
+    /// output FV inf file\r
+    ///\r
+    private String outputFVInfFileName = "";\r
+\r
+    ///\r
+    /// pattern string\r
+    ///\r
+    private String patternStr = "";\r
+\r
+       ///\r
+       ///  Output dir\r
+       /// \r
+       private String outputDir = "";\r
+   \r
+    /**\r
+     * execute\r
+     * \r
+     * ModifyInfTask execute function is to assemble tool command line & execute\r
+     * tool command line\r
+     * \r
+     * @throws BuidException\r
+     */\r
+    public void execute() throws BuildException {\r
+\r
+        Project project = this.getOwningTarget().getProject();\r
+        //\r
+        // set Logger\r
+        //\r
+        FrameworkLogger logger = new FrameworkLogger(project, "modifytask");\r
+        EdkLog.setLogLevel(project.getProperty("env.LOGLEVEL"));\r
+        EdkLog.setLogger(logger);\r
+        //\r
+        // absolute path of efi tools\r
+        //\r
+        String path = project.getProperty("env.FRAMEWORK_TOOLS_PATH");\r
+        String command;\r
+        String argument;\r
+        if (path == null) {\r
+            command = toolName;\r
+        } else {\r
+            command = path + File.separatorChar + toolName;\r
+        }\r
+        //\r
+        // argument of tools\r
+        //\r
+               File file = new File(outputFVInfFileName);\r
+        if (!file.isAbsolute() && (!this.outputDir.equalsIgnoreCase(""))) {\r
+                       argument = this.inputFVInfFileName +\r
+                                      this.outputDir + \r
+                                          File.separatorChar +\r
+                                          this.outputFVInfFileName +\r
+                                          this.patternStr;\r
+               } else {\r
+                       argument = this.inputFVInfFileName + \r
+                                      this.outputFVInfFileName +\r
+                                      this.patternStr;\r
+               }\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
+            // Set debug log information.\r
+            //\r
+            EdkLog.log(EdkLog.EDK_INFO, Commandline.toString(cmdline\r
+                    .getCommandline()));\r
+\r
+            revl = runner.execute();\r
+\r
+            if (EFI_SUCCESS == revl) {\r
+                //\r
+                // command execution success\r
+                //\r
+                EdkLog.log(EdkLog.EDK_INFO, "ModifyInfTask succeeded!");\r
+            } else {\r
+                //\r
+                // command execution fail\r
+                //\r
+                EdkLog.log(EdkLog.EDK_ERROR, "ModifyInfTask failed. (error="\r
+                        + Integer.toHexString(revl) + ")");\r
+                throw new BuildException("ModifyInfTask failed. (error="\r
+                        + Integer.toHexString(revl) + ")");\r
+\r
+            }\r
+        } catch (Exception e) {\r
+            throw new BuildException(e.getMessage());\r
+        }\r
+    }\r
+\r
+    /**\r
+     * getinputFVInfFileName\r
+     * \r
+     * This function is to get class member "inputFVInfFileName".\r
+     * \r
+     * @return string of input inf file name.\r
+     */\r
+    public String getinputFVInfFileName() {\r
+        return this.inputFVInfFileName;\r
+    }\r
+\r
+    /**\r
+     * setinputFVInfFileName\r
+     * \r
+     * This function is to set class member "inputFVInfFileName".\r
+     * \r
+     * @param inputFile\r
+     *            string of input inf file name.\r
+     */\r
+    public void setinputFVInfFileName(String inputFVInfFileName) {\r
+        this.inputFVInfFileName = inputFVInfFileName + " ";\r
+    }\r
+\r
+    /**\r
+     * getoutputFVInfFileName\r
+     * \r
+     * This function is to get class member "outputFVInfFileName"\r
+     * \r
+     * @return outputFVInfFileName string of output inf file name.\r
+     */\r
+    public String getoutputFVInfFileName() {\r
+        return this.outputFVInfFileName;\r
+    }\r
+\r
+    /**\r
+     * setoutputFVInfFileName\r
+     * \r
+     * This function is to set class member "outputFVInfFileName"\r
+     * \r
+     * @param outputFVInfFileName\r
+     *            string of output  inf file name.\r
+     */\r
+    public void setoutputFVInfFileName(String outputFVInfFileName) {\r
+        this.outputFVInfFileName = outputFVInfFileName  + " ";\r
+    }\r
+\r
+    /**\r
+     * getpatternStr\r
+     * \r
+     * This function is to get class member "patternStr"\r
+     * \r
+     * @return patternStr string of pattern.\r
+     */\r
+    public String getpatternStr() {\r
+        return this.patternStr;\r
+    }\r
+\r
+    /**\r
+     * setpatternStr\r
+     * \r
+     * This function is to set class member "patternStr"\r
+     * \r
+     * @param patternStr\r
+     *            string of patternStr.\r
+     */\r
+    public void setpatternStr(String patternStr) {\r
+        this.patternStr = "[" + patternStr + "]";\r
+    }\r
+\r
+       /**\r
+     * getoutputDir\r
+     * \r
+     * This function is to get class member "outputDir"\r
+     * \r
+     * @return outputDir string of output directory.\r
+     */\r
+    public String getoutputDir() {\r
+        return this.outputDir;\r
+    }\r
+\r
+    /**\r
+     * setoutputDir\r
+     * \r
+     * This function is to set class member "outputDir"\r
+     * \r
+     * @param patternStr\r
+     *            string of output directory.\r
+     */\r
+    public void setoutputDir(String outputDir) {\r
+        this.outputDir = outputDir;\r
+    }\r
+}\r