]> git.proxmox.com Git - mirror_edk2.git/blobdiff - Tools/Java/Source/FrameworkTasks/org/tianocore/framework/tasks/VfrCompilerTask.java
Restructuring for better separation of Tool packages.
[mirror_edk2.git] / Tools / Java / Source / FrameworkTasks / org / tianocore / framework / tasks / VfrCompilerTask.java
diff --git a/Tools/Java/Source/FrameworkTasks/org/tianocore/framework/tasks/VfrCompilerTask.java b/Tools/Java/Source/FrameworkTasks/org/tianocore/framework/tasks/VfrCompilerTask.java
new file mode 100644 (file)
index 0000000..5897bd2
--- /dev/null
@@ -0,0 +1,215 @@
+/** @file\r
+This file is to define an ANT task which wraps VfrCompile.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 java.io.IOException;\r
+import java.util.ArrayList;\r
+import java.util.List;\r
+\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
+\r
+import org.tianocore.common.logger.EdkLog;\r
+\r
+/**\r
+ VfrcompilerTask Task Class\r
+  class member \r
+      -createListFile  : create an output IFR listing file.\r
+      -outPutDir       : deposit all output files to directory OutputDir (default=cwd)\r
+      -createIfrBinFile: create an IFR HII pack file\r
+      -vfrFile         : name of the input VFR script file\r
+      -processArg      : c processer argument\r
+      -includepathList : add IncPath to the search path for VFR included files\r
+ **/\r
+public class VfrCompilerTask extends Task implements EfiDefine {\r
+    private static String toolName = "VfrCompile";\r
+\r
+    private ToolArg createListFile = new ToolArg();\r
+    private ToolArg createIfrBinFile = new ToolArg();\r
+    private ToolArg processerArg = new ToolArg();\r
+    private FileArg vfrFile = new FileArg();\r
+    private IncludePath includepathList = new IncludePath();\r
+    private FileArg outPutDir = new FileArg(" -od ", ".");\r
+    private String dllPath = "";\r
+\r
+    /**\r
+     get class member of createList file\r
+\r
+     @returns file name of createList\r
+     **/\r
+    public boolean getCreateListFile() {\r
+        return this.createListFile.getValue().length() > 0;\r
+    }\r
+\r
+    /**\r
+     set class member of createList file\r
+\r
+     @param     createListFile  if createList string equal "on" set '-l' flag\r
+     **/\r
+    public void setCreateListFile(boolean createListFile) {\r
+        if (createListFile) {\r
+            this.createListFile.setArg(" -", "l");\r
+        }\r
+    }\r
+\r
+    /**\r
+     get output dir \r
+\r
+     @returns name of output dir\r
+     **/\r
+    public String getOutPutDir() {\r
+        return this.outPutDir.getValue();\r
+    }\r
+\r
+    /**\r
+     set class member of outPutDir\r
+\r
+     @param     outPutDir   The directory name for ouput file\r
+     **/\r
+    public void setOutPutDir(String outPutDir) {\r
+        this.outPutDir.setArg(" -od ", outPutDir);\r
+    }\r
+\r
+\r
+    /**\r
+     get class member of ifrBinFile\r
+\r
+     @return file name of ifrBinFile\r
+     **/\r
+    public boolean getCreateIfrBinFile() {\r
+        return this.createIfrBinFile.getValue().length() > 0;\r
+    }\r
+\r
+    /**\r
+     set class member of ifrBinFile \r
+\r
+     @param     createIfrBinFile    The flag to specify if the IFR binary file should\r
+                                    be generated or not\r
+     */\r
+    public void setCreateIfrBinFile(boolean createIfrBinFile) {\r
+        if (createIfrBinFile) {\r
+            this.createIfrBinFile.setArg(" -", "ibin");\r
+        }\r
+    }\r
+\r
+    /**\r
+     get class member of vfrFile\r
+\r
+     @returns name of vfrFile\r
+     **/\r
+    public String getVfrFile() {\r
+        return this.vfrFile.getValue();\r
+    }\r
+\r
+    /**\r
+     set class member of vfrFile \r
+\r
+     @param     vfrFile The name of VFR file\r
+     **/\r
+    public void setVfrFile(String vfrFile) {\r
+        this.vfrFile.setArg(" ", vfrFile);\r
+    }\r
+\r
+    /**\r
+     add includePath in includepath List \r
+\r
+     @param     includepath The IncludePath object which represents include path\r
+     **/\r
+    public void addConfiguredIncludepath(IncludePath includepath){\r
+        this.includepathList.insert(includepath);\r
+    }\r
+\r
+    /**\r
+     get class member of processerArg\r
+\r
+     @returns processer argument\r
+     **/\r
+    public String getProcesserArg() {\r
+        return this.processerArg.getValue();\r
+    }\r
+\r
+\r
+    /**\r
+     set class member of processerArg\r
+\r
+     @param     processerArg    The processor argument\r
+     */\r
+    public void setProcesserArg(String processerArg) {\r
+        this.processerArg.setArg(" -ppflag ", processerArg);\r
+    }\r
+\r
+    public void setDllPath(String dllPath) {\r
+        this.dllPath = dllPath;\r
+    }\r
+\r
+    /**\r
+     The standard execute method of ANT task.\r
+     **/\r
+    public void execute() throws BuildException {\r
+        Project project = this.getProject();\r
+        String  toolPath= project.getProperty("env.FRAMEWORK_TOOLS_PATH");\r
+        String  command;\r
+        if (toolPath == null) {\r
+            command = toolName;\r
+        } else {\r
+            command = toolPath + File.separator + toolName;\r
+        }\r
+\r
+        String argument = "" + createIfrBinFile\r
+                             + processerArg  \r
+                             + includepathList\r
+                             + outPutDir\r
+                             + createListFile\r
+                             + vfrFile;\r
+        try {\r
+            ///\r
+            /// constructs the command-line\r
+            ///\r
+            Commandline commandLine = new Commandline();\r
+            commandLine.setExecutable(command);\r
+            commandLine.createArgument().setLine(argument);\r
+\r
+            ///\r
+            /// configures the Execute object\r
+            ///\r
+            LogStreamHandler streamHandler = new LogStreamHandler(this,\r
+                                                                  Project.MSG_INFO,\r
+                                                                  Project.MSG_WARN);\r
+\r
+            Execute runner = new Execute(streamHandler,null);\r
+            runner.setAntRun(project);            \r
+            runner.setCommandline(commandLine.getCommandline());\r
+            runner.setWorkingDirectory(new File(outPutDir.getValue())); \r
+            runner.setEnvironment(new String[]{"PATH", dllPath});\r
+            \r
+            EdkLog.log(this, EdkLog.EDK_VERBOSE, Commandline.toString(commandLine.getCommandline()));\r
+            EdkLog.log(this, vfrFile.toFileList());\r
+\r
+            int returnVal = runner.execute();\r
+            if (EFI_SUCCESS == returnVal) {\r
+                EdkLog.log(this, EdkLog.EDK_VERBOSE, "VfrCompile succeeded!");\r
+            } else {\r
+                EdkLog.log(this, "ERROR = " + Integer.toHexString(returnVal));\r
+                throw new BuildException("VfrCompile failed!");\r
+            }\r
+        } catch (IOException e) {\r
+            throw new BuildException(e.getMessage());\r
+        }\r
+    }\r
+}\r