]>
Commit | Line | Data |
---|---|---|
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 | |
16 | import java.io.File;\r | |
17 | \r | |
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 | |
25 | import org.tianocore.common.logger.EdkLog;\r | |
26 | \r | |
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 | |
37 | \r | |
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 | |
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 | |
57 | String path = project.getProperty("env.FRAMEWORK_TOOLS_PATH");\r | |
58 | String command;\r | |
59 | if (path == null) {\r | |
60 | command = toolName;\r | |
61 | } else {\r | |
62 | command = path + File.separator + toolName;\r | |
63 | }\r | |
64 | ///\r | |
65 | /// argument of SetStamp tool\r | |
66 | ///\r | |
67 | String argument = "" + peFile + timeFile;\r | |
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 | |
84 | runner.setWorkingDirectory(new File(outputDir));\r | |
85 | \r | |
86 | EdkLog.log(this, EdkLog.EDK_VERBOSE, Commandline.toString(commandLine.getCommandline()));\r | |
87 | EdkLog.log(this, peFile.toFileList() + " < " + timeFile.toFileList());\r | |
88 | \r | |
89 | returnVal = runner.execute();\r | |
90 | if (EFI_SUCCESS == returnVal) {\r | |
91 | EdkLog.log(this, EdkLog.EDK_VERBOSE, toolName + " succeeded!");\r | |
92 | } else {\r | |
93 | ///\r | |
94 | /// command execution fail\r | |
95 | ///\r | |
96 | EdkLog.log(this, "ERROR = " + Integer.toHexString(returnVal));\r | |
97 | throw new BuildException(toolName + " failed!");\r | |
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 | |
110 | this.peFile.setArg(" ", peFile);\r | |
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 | |
119 | return this.peFile.getValue();\r | |
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 | |
128 | this.timeFile.setArg(" ", timeFile);\r | |
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 | |
137 | return this.timeFile.getValue();\r | |
138 | }\r | |
139 | \r | |
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 | |
162 | }\r |