]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Java/Source/FrameworkTasks/org/tianocore/framework/tasks/SetStampTask.java
- Fixed EDKT240. Now the Blank.pad file for alignment purpose will no longer be needed.
[mirror_edk2.git] / Tools / Java / Source / FrameworkTasks / org / tianocore / framework / tasks / SetStampTask.java
1 /** @file
2 This file is to define an ANT task to wrap setstamp.exe tool
3
4 Copyright (c) 2006, Intel Corporation
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 **/
14 package org.tianocore.framework.tasks;
15
16 import java.io.File;
17
18 import org.apache.tools.ant.BuildException;
19 import org.apache.tools.ant.Project;
20 import org.apache.tools.ant.Task;
21 import org.apache.tools.ant.taskdefs.Execute;
22 import org.apache.tools.ant.taskdefs.LogStreamHandler;
23 import org.apache.tools.ant.types.Commandline;
24
25 import org.tianocore.common.logger.EdkLog;
26
27 /**
28 Class SetStampTask is a wrap class for setstamp.exe.
29 **/
30 public class SetStampTask extends Task implements EfiDefine {
31 /**
32 SetStamp Task Class
33 class member
34 -peFile : file of PE
35 -timeFile: Txt file of time
36 **/
37
38 private static String toolName = "SetStamp";
39
40 private FileArg peFile = new FileArg();
41
42 private FileArg timeFile = new FileArg();
43
44 private String outputDir = ".";
45
46 /**
47 assemble tool command line & execute tool command line
48
49 @throws BuildException
50 **/
51 public void execute() throws BuildException {
52
53 Project project = this.getOwningTarget().getProject();
54 ///
55 /// absolute path of edk tools
56 ///
57 String path = project.getProperty("env.FRAMEWORK_TOOLS_PATH");
58 String command;
59 if (path == null) {
60 command = toolName;
61 } else {
62 command = path + File.separator + toolName;
63 }
64 ///
65 /// argument of SetStamp tool
66 ///
67 String argument = "" + peFile + timeFile;
68 ///
69 /// reture value of SetStamp execution
70 ///
71 int returnVal = -1;
72
73 try {
74 Commandline commandLine = new Commandline();
75 commandLine.setExecutable(command);
76 commandLine.createArgument().setLine(argument);
77
78 LogStreamHandler streamHandler = new LogStreamHandler(this,
79 Project.MSG_INFO, Project.MSG_WARN);
80
81 Execute runner = new Execute(streamHandler, null);
82 runner.setAntRun(project);
83 runner.setCommandline(commandLine.getCommandline());
84 runner.setWorkingDirectory(new File(outputDir));
85
86 EdkLog.log(this, EdkLog.EDK_VERBOSE, Commandline.toString(commandLine.getCommandline()));
87 EdkLog.log(this, peFile.toFileList() + " < " + timeFile.toFileList());
88
89 returnVal = runner.execute();
90 if (EFI_SUCCESS == returnVal) {
91 EdkLog.log(this, EdkLog.EDK_VERBOSE, toolName + " succeeded!");
92 } else {
93 ///
94 /// command execution fail
95 ///
96 EdkLog.log(this, "ERROR = " + Integer.toHexString(returnVal));
97 throw new BuildException(toolName + " failed!");
98 }
99 } catch (Exception e) {
100 throw new BuildException(e.getMessage());
101 }
102 }
103
104 /**
105 set operation of class member "peFile"
106
107 @param peFile name of PE File
108 **/
109 public void setPeFile(String peFile) {
110 this.peFile.setArg(" ", peFile);
111 }
112
113 /**
114 get operation of class member "peFile"
115
116 @return peFile name of PE file
117 **/
118 public String getPeFile() {
119 return this.peFile.getValue();
120 }
121
122 /**
123 set operation of class member "timeFile"
124
125 @param timeFile name of time file
126 **/
127 public void setTimeFile(String timeFile) {
128 this.timeFile.setArg(" ", timeFile);
129 }
130
131 /**
132 get class member "timeFile"
133
134 @returns name of time file
135 **/
136 public String getTimeFile() {
137 return this.timeFile.getValue();
138 }
139
140 /**
141 getOutputDir
142
143 This function is to get class member "outputDir"
144
145 @return outputDir string of output directory.
146 **/
147 public String getOutputDir() {
148 return outputDir;
149 }
150
151 /**
152 setOutputDir
153
154 This function is to set class member "outputDir"
155
156 @param outputDir
157 string of output directory.
158 **/
159 public void setOutputDir(String outputDir) {
160 this.outputDir = outputDir;
161 }
162 }