summaryrefslogtreecommitdiff
path: root/Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/EfiRomTask.java
diff options
context:
space:
mode:
authorjwang36 <jwang36@6f19259b-4bc3-4df7-8a09-765794883524>2006-09-14 08:35:38 +0000
committerjwang36 <jwang36@6f19259b-4bc3-4df7-8a09-765794883524>2006-09-14 08:35:38 +0000
commit0fdb42ac4675ac888d7cfb3f29f68c342f47b9e9 (patch)
treebbee647c25f3f44c8b46b9b128c6486a941e9a02 /Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/EfiRomTask.java
parent39e5e412f910a30858d2feffdb69326ae088ee4c (diff)
downloadedk2-0fdb42ac4675ac888d7cfb3f29f68c342f47b9e9.zip
edk2-0fdb42ac4675ac888d7cfb3f29f68c342f47b9e9.tar.gz
edk2-0fdb42ac4675ac888d7cfb3f29f68c342f47b9e9.tar.bz2
1) Applied ToolArg and FileArg class to represent tool arguments
2) Unified the tool output message and exception handling 3) Cleaned the coding style 4) Removed used code git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@1535 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/EfiRomTask.java')
-rw-r--r--Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/EfiRomTask.java520
1 files changed, 244 insertions, 276 deletions
diff --git a/Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/EfiRomTask.java b/Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/EfiRomTask.java
index 7eb9878..caa7747 100644
--- a/Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/EfiRomTask.java
+++ b/Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/EfiRomTask.java
@@ -23,92 +23,95 @@ import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
-import org.apache.tools.ant.Task;
-import org.apache.tools.ant.Project;
import org.apache.tools.ant.BuildException;
-
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.Task;
import org.tianocore.common.logger.EdkLog;
+import org.apache.tools.ant.taskdefs.Execute;
+import org.apache.tools.ant.taskdefs.LogStreamHandler;
+import org.apache.tools.ant.types.Commandline;
+
+import com.sun.org.apache.bcel.internal.generic.NEW;
/**
- * SecFixupTask class.
- *
- * SecFixupTask is used to call SecFixup.exe to fix up sec image.
- */
+ SecFixupTask class.
+
+ SecFixupTask is used to call SecFixup.exe to fix up sec image.
+ **/
public class EfiRomTask extends Task implements EfiDefine {
- ///
- /// tool name
- ///
- private final String toolName = "EfiRom";
-
- ///
- /// Flash default file
- ///
- private String verbose = "";
-
- ///
- /// Flash device
- ///
- private String venderId = "";
-
- ///
- /// Flash device Image
- ///
- private String deviceId = "";
-
- ///
- /// MCI file
- ///
- private String outputFile = "";
-
- ///
- /// MCO file
- ///
- private List<Input> binaryFileList = new ArrayList<Input>();
-
- ///
- /// Efi PE32 image file
- ///
- private List<Input> pe32FileList = new ArrayList<Input>();
-
- ///
- /// Compress efi PE32 image file
- ///
- private List<Input> pe32ComprFileList = new ArrayList<Input>();
-
- ///
- /// Hex class code in the PCI data strutor header
- ///
- private String classCode = "";
-
- ///
- /// Hex revision in the PCI data header.
- ///
- private String revision = "";
-
- ///
- /// Dump the headers of an existing option rom image.
- ///
- private String dump = "";
-
-
- ///
- /// output directory
- ///
+ //
+ // tool name
+ //
+ private final static String toolName = "EfiRom";
+
+ //
+ // Flash default file
+ //
+ private ToolArg verbose = new ToolArg();
+
+ //
+ // Flash device
+ //
+ private ToolArg venderId = new ToolArg();
+
+ //
+ // Flash device Image
+ //
+ private ToolArg deviceId = new ToolArg();
+
+ //
+ // output file
+ //
+ private FileArg outputFile = new FileArg();
+
+ //
+ // binary file
+ //
+ private Input binaryFileList = new Input();
+
+ //
+ // Efi PE32 image file
+ //
+ private Input pe32FileList = new Input();
+
+ //
+ // Compress efi PE32 image file
+ //
+ private Input pe32ComprFileList = new Input();
+
+ //
+ // Hex class code in the PCI data strutor header
+ //
+ private ToolArg classCode = new ToolArg();
+
+ //
+ // Hex revision in the PCI data header.
+ //
+ private ToolArg revision = new ToolArg();
+
+ //
+ // Dump the headers of an existing option rom image.
+ //
+ private ToolArg dump = new ToolArg();
+
+ //
+ // output directory
+ //
private String outputDir = ".";
-
- ///
- /// command and argument list
- ///
+ //
+ // command and argument list
+ //
LinkedList<String> argList = new LinkedList<String>();
+
/**
- * execute
- *
- * EfiRomTask execute function is to assemble tool command line & execute
- * tool command line
- *
- * @throws BuidException
- */
+ execute
+
+ EfiRomTask execute function is to assemble tool command line & execute
+ tool command line
+
+ @throws BuidException
+ **/
public void execute() throws BuildException {
Project project = this.getOwningTarget().getProject();
@@ -121,294 +124,259 @@ public class EfiRomTask extends Task implements EfiDefine {
if (path == null) {
command = toolName;
} else {
- command = path + File.separatorChar + toolName;
+ command = path + File.separator + toolName;
}
- argList.addFirst(command);
- //
- // add microcode binary files
- //
- if (this.binaryFileList.size() > 0){
- argList.add("-b");
- Iterator binList = this.binaryFileList.iterator();
- while (binList.hasNext()){
- argList.addAll(((Input)binList.next()).getNameList());
- }
- }
+ String argument = "" + verbose + venderId + deviceId + dump + revision + classCode
+ + binaryFileList.toStringWithSinglepPrefix(" -b ")
+ + pe32FileList.toStringWithSinglepPrefix(" -e ")
+ + pe32ComprFileList.toStringWithSinglepPrefix(" -ec ")
+ + outputFile;
- //
- // add pe32 file
- //
- if (this.pe32FileList.size() > 0){
- argList.add("-e");
- Iterator pe32List = this.pe32FileList.iterator();
- while (pe32List.hasNext()){
- argList.addAll(((Input)pe32List.next()).getNameList());
- }
- }
+ try {
+ Commandline cmdline = new Commandline();
+ cmdline.setExecutable(command);
+ cmdline.createArgument().setLine(argument);
- //
- // add compressed pe32 file
- //
- if (this.pe32ComprFileList.size() > 0){
- argList.add("-ec");
- Iterator pe32ComprList = this.pe32ComprFileList.iterator();
- while (pe32ComprList.hasNext()){
- argList.addAll(((Input)pe32ComprList.next()).getNameList());
- }
- }
+ LogStreamHandler streamHandler = new LogStreamHandler(this,
+ Project.MSG_INFO, Project.MSG_WARN);
+ Execute runner = new Execute(streamHandler, null);
- EdkLog.log(this, EdkLog.EDK_VERBOSE, argList.toString().replaceAll(",",""));
- EdkLog.log(this, EdkLog.EDK_INFO, " ");
+ runner.setAntRun(project);
+ runner.setCommandline(cmdline.getCommandline());
+ runner.setWorkingDirectory(new File(outputDir));
- //
- // lauch the program
- //
- ProcessBuilder pb = new ProcessBuilder(argList);
- pb.directory(new File(outputDir));
- int exitCode = 0;
- try {
- Process cmdProc = pb.start();
- InputStreamReader cmdOut = new InputStreamReader(cmdProc.getInputStream());
- char[] buf = new char[1024];
+ EdkLog.log(this, EdkLog.EDK_VERBOSE, Commandline.toString(cmdline.getCommandline()));
+ EdkLog.log(this, EdkLog.EDK_INFO, binaryFileList.toFileList()
+ + pe32FileList.toFileList() + pe32ComprFileList.toFileList()
+ + " => " + outputFile.toFileList());
- exitCode = cmdProc.waitFor();
+ int exitCode = runner.execute();
if (exitCode != 0) {
- int len = cmdOut.read(buf, 0, 1024);
- EdkLog.log(EdkLog.EDK_INFO, new String(buf, 0, len));
+ //
+ // command execution fail
+ //
+ EdkLog.log(this, "ERROR = " + Integer.toHexString(exitCode));
+ throw new BuildException(toolName + " failed!");
} else {
- EdkLog.log(EdkLog.EDK_VERBOSE, "EfiRom succeeded!");
+ EdkLog.log(this, EdkLog.EDK_VERBOSE, toolName + " succeeded!");
}
} catch (Exception e) {
throw new BuildException(e.getMessage());
- } finally {
- if (exitCode != 0) {
- throw new BuildException("EfiRom failed!");
- }
}
}
/**
- * getVerbose
- *
- * This function is to get class member "verbose"
- *
- * @return verbose for verbose output.
- */
+ getVerbose
+
+ This function is to get class member "verbose"
+
+ @return verbose for verbose output.
+ **/
public String getVerbose() {
- return verbose;
+ return verbose.getValue();
}
/**
- * setVerbose
- *
- * This function is to set class member "verbose"
- *
- * @param verbose for verbose output.
- */
+ setVerbose
+
+ This function is to set class member "verbose"
+
+ @param verbose for verbose output.
+ **/
public void setVerbose(boolean verbose) {
if (verbose){
- this.verbose = "-p";
- argList.add(this.verbose);
+ this.verbose.setArg(" -", "p");
}
}
/**
- * getVenderId
- *
- * This function is to get class member "venderId"
- *
- * @return venderId String of venderId.
- */
+ getVenderId
+
+ This function is to get class member "venderId"
+
+ @return venderId String of venderId.
+ **/
public String getVenderId() {
- return venderId;
+ return venderId.getValue();
}
/**
- * setVenderId
- *
- * This function is to set class member "venderId"
- *
- * @param venderId String of venderId.
- */
- public void setVenderId(String VenderId) {
- this.venderId = VenderId;
- argList.add("-v");
- argList.add(this.venderId);
+ setVenderId
+
+ This function is to set class member "venderId"
+
+ @param venderId String of venderId.
+ **/
+ public void setVenderId(String venderId) {
+ this.venderId.setArg(" -v ", venderId);
}
/**
- * getDeviceId
- *
- * This function is to get class member "deviceId"
- *
- * @return deviceId String of device ID.
- */
+ getDeviceId
+
+ This function is to get class member "deviceId"
+
+ @return deviceId String of device ID.
+ **/
public String getDeviceId() {
- return this.deviceId;
+ return this.deviceId.getValue();
}
/**
- * setDeviceId
- *
- * This function is to set class member "deviceId"
- *
- * @param deviceId String of device ID.
- */
+ setDeviceId
+
+ This function is to set class member "deviceId"
+
+ @param deviceId String of device ID.
+ **/
public void setDeviceId(String deviceId) {
- this.deviceId = deviceId;
- argList.add("-d");
- argList.add(this.deviceId);
+ this.deviceId.setArg(" -d ", deviceId);
}
/**
- * getOutputFile
- *
- * This function is to get class member "outputFile"
- *
- * @return outputFile name of output directory.
- */
+ getOutputFile
+
+ This function is to get class member "outputFile"
+
+ @return outputFile name of output directory.
+ **/
public String getOutputFile() {
- return outputFile;
+ return outputFile.getValue();
}
/**
- * setOutputFile
- *
- * This function is to set class member "dscFile"
- *
- * @param outputFile name of DSC file
- */
+ setOutputFile
+
+ This function is to set class member "dscFile"
+
+ @param outputFile name of DSC file
+ **/
public void setOutputFile(String outputFile) {
- this.outputFile = outputFile;
-
+ this.outputFile.setArg(" -o ", outputFile);
}
/**
- * getClassCode
- *
- * This function is to get class member "classCode"
- *
- * @return fdImage name of class code file.
- */
+ getClassCode
+
+ This function is to get class member "classCode"
+
+ @return fdImage name of class code file.
+ **/
public String getClassCode() {
- return classCode;
+ return classCode.getValue();
}
/**
- * setclassCode
- *
- * This function is to set class member "classCode"
- *
- * @param fdImage name of class code file.
- */
+ setclassCode
+
+ This function is to set class member "classCode"
+
+ @param fdImage name of class code file.
+ **/
public void setclassCode(String classCode) {
- this.classCode = classCode;
- argList.add("-cc");
- argList.add(this.classCode);
+ this.classCode.setArg(" -cc ", classCode);
}
/**
- * getRevision
- *
- * This function is to get class member "revision".
- *
- * @return revision hex revision in the PDI data header.
- */
+ getRevision
+
+ This function is to get class member "revision".
+
+ @return revision hex revision in the PDI data header.
+ **/
public String getRevision() {
- return revision;
+ return revision.getValue();
}
/**
- * setRevision
- *
- * This function is to set class member "revision"
- *
- * @param revision hex revision in the PDI data header.
- */
+ setRevision
+
+ This function is to set class member "revision"
+
+ @param revision hex revision in the PDI data header.
+ **/
public void setRevision(String revision) {
- this.revision = revision;
- argList.add("-rev");
- argList.add(this.revision);
+ this.revision.setArg(" -rev ", revision);
}
/**
- * getFlashDeviceImage
- *
- * This function is to get class member "dump"
- *
- * @return flashDeviceImage name of flash device image
- */
+ getFlashDeviceImage
+
+ This function is to get class member "dump"
+
+ @return flashDeviceImage name of flash device image
+ **/
public String getDump() {
- return dump;
+ return dump.getValue();
}
/**
- * setFlashDeviceImage
- *
- * This function is to set class member "dump"
- *
- * @param flashDeviceImage name of flash device image
- */
+ setFlashDeviceImage
+
+ This function is to set class member "dump"
+
+ @param flashDeviceImage name of flash device image
+ **/
public void setDump(boolean dump) {
- if (dump){
- this.dump = "-dump";
- argList.add(this.dump);
+ if (dump) {
+ this.dump.setArg(" -", "dump");
}
}
/**
- * getOutputDir
- *
- * This function is to get class member "outputDir"
- *
- * @return outputDir string of output directory
- */
+ getOutputDir
+
+ This function is to get class member "outputDir"
+
+ @return outputDir string of output directory
+ **/
public String getOutputDir() {
return outputDir;
}
/**
- * setOutputDir
- *
- * This function is to set class member "outputDir"
- *
- * @param outputDir string of output directory
- */
+ setOutputDir
+
+ This function is to set class member "outputDir"
+
+ @param outputDir string of output directory
+ **/
public void setOutputDir(String outputDir) {
this.outputDir = outputDir;
}
+
/**
- * addBinaryFile
- *
- * This function is to add binary file to binaryFile list.
- *
- * @param binaryFile name of binary file.
- */
- public void addBinaryFile(Input binaryFile){
- this.binaryFileList.add(binaryFile);
+ addBinaryFile
+
+ This function is to add binary file to binaryFile list.
+
+ @param binaryFile name of binary file.
+ **/
+ public void addConfiguredBinaryFile(Input binaryFile){
+ this.binaryFileList.insert(binaryFile);
}
/**
- * addPe32File
- *
- * This function is to add pe32 file to pe32File list.
- *
- * @param pe32File name of pe32 file.
- */
- public void addPe32File(Input pe32File){
- this.pe32FileList.add(pe32File);
+ addPe32File
+
+ This function is to add pe32 file to pe32File list.
+
+ @param pe32File name of pe32 file.
+ **/
+ public void addConfiguredPe32File(Input pe32File){
+ this.pe32FileList.insert(pe32File);
}
/**
- * addPe32ComprFile
- *
- * This function os to add compressed pe32 file to pe32ComprFile list.
- *
- * @param pe32ComprFile name of compressed pe32 file.
- */
- public void addPe32ComprFile(Input pe32ComprFile){
- this.pe32ComprFileList.add(pe32ComprFile);
+ addPe32ComprFile
+
+ This function os to add compressed pe32 file to pe32ComprFile list.
+
+ @param pe32ComprFile name of compressed pe32 file.
+ **/
+ public void addConfiguredPe32ComprFile(Input pe32ComprFile){
+ this.pe32ComprFileList.insert(pe32ComprFile);
}
}