a59598a529b0791fb765c532fde2e2d240c7582a
[mirror_edk2.git] / Tools / 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 org.apache.tools.ant.BuildException;
17 import org.apache.tools.ant.Project;
18 import org.apache.tools.ant.Task;
19 import org.apache.tools.ant.taskdefs.Execute;
20 import org.apache.tools.ant.taskdefs.LogStreamHandler;
21 import org.apache.tools.ant.types.Commandline;
22
23 /**
24 Class SetStampTask is a wrap class for setstamp.exe.
25 **/
26 public class SetStampTask extends Task implements EfiDefine {
27 /**
28 SetStamp Task Class
29 class member
30 -peFile : file of PE
31 -timeFile: Txt file of time
32 **/
33
34 private String peFile = "";
35
36 private String timeFile = "";
37
38 /**
39 assemble tool command line & execute tool command line
40
41 @throws BuildException
42 **/
43 public void execute() throws BuildException {
44
45 Project project = this.getOwningTarget().getProject();
46 ///
47 /// absolute path of edk tools
48 ///
49 String path = project.getProperty("env.FRAMEWORK_TOOLS_PATH");
50 String command;
51 if (path == null) {
52 command = "SetStamp";
53 } else {
54 command = path + "/" + "SetStamp";
55 }
56 ///
57 /// argument of SetStamp tool
58 ///
59 String argument = peFile + timeFile;
60 ///
61 /// reture value of SetStamp execution
62 ///
63 int returnVal = -1;
64
65 try {
66 Commandline commandLine = new Commandline();
67 commandLine.setExecutable(command);
68 commandLine.createArgument().setLine(argument);
69
70 LogStreamHandler streamHandler = new LogStreamHandler(this,
71 Project.MSG_INFO, Project.MSG_WARN);
72
73 Execute runner = new Execute(streamHandler, null);
74 runner.setAntRun(project);
75 runner.setCommandline(commandLine.getCommandline());
76
77 System.out.println(Commandline.toString(commandLine
78 .getCommandline()));
79
80 returnVal = runner.execute();
81 if (EFI_SUCCESS == returnVal) {
82 ///
83 /// command execution success
84 ///
85 System.out.println("SetStamp execute succeeded!");
86 } else {
87 ///
88 /// command execution fail
89 ///
90 System.out.println("SetStamp failed. (error="
91 + Integer.toHexString(returnVal) + ")");
92 throw new BuildException("SetStamp failed. (error="
93 + Integer.toHexString(returnVal) + ")");
94 }
95 } catch (Exception e) {
96 throw new BuildException(e.getMessage());
97 }
98 }
99
100 /**
101 set operation of class member "peFile"
102
103 @param peFile name of PE File
104 **/
105 public void setPeFile(String peFile) {
106 this.peFile = " " + peFile;
107 }
108
109 /**
110 get operation of class member "peFile"
111
112 @return peFile name of PE file
113 **/
114 public String getPeFile() {
115 return this.peFile;
116 }
117
118 /**
119 set operation of class member "timeFile"
120
121 @param timeFile name of time file
122 **/
123 public void setTimeFile(String timeFile) {
124 this.timeFile = " " + timeFile;
125 }
126
127 /**
128 get class member "timeFile"
129
130 @returns name of time file
131 **/
132 public String getTimeFile() {
133 return this.timeFile;
134 }
135
136 }