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