]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/FrameworkTasks/org/tianocore/framework/tasks/GenSectionTask.java
25328a12d87f7bd31bf0e5d06fb7909cfa18c36f
[mirror_edk2.git] / Tools / Source / FrameworkTasks / org / tianocore / framework / tasks / GenSectionTask.java
1 /** @file
2 GenSectionTask class.
3
4 GenSectionTask is to call GenSection.exe to generate Section.
5
6 Copyright (c) 2006, Intel Corporation
7 All rights reserved. This program and the accompanying materials
8 are licensed and made available under the terms and conditions of the BSD License
9 which accompanies this distribution. The full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php
11
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
14
15 **/
16
17 package org.tianocore.framework.tasks;
18
19 import java.io.File;
20
21 import org.apache.tools.ant.BuildException;
22 import org.apache.tools.ant.Project;
23 import org.apache.tools.ant.Task;
24 import org.apache.tools.ant.taskdefs.Execute;
25 import org.apache.tools.ant.taskdefs.LogStreamHandler;
26 import org.apache.tools.ant.types.Commandline;
27
28 public class GenSectionTask extends Task implements EfiDefine {
29 ///
30 /// inputfile name
31 ///
32 private String inputFile = "";
33 ///
34 ///
35 ///
36 private String inputFileName = "";
37 ///
38 /// outputfile name
39 ///
40 private String outputFile = "";
41 ///
42 /// section type
43 ///
44 private String sectionType = "";
45 ///
46 /// version number
47 ///
48 private String versionNum = "";
49 ///
50 /// interface string
51 ///
52 private String interfaceString = "";
53
54 /**
55 execute
56
57 GenSectionTaks execute is to assemble tool command line & execute tool
58 command line.
59
60 @throws BuildException
61 **/
62 public void execute() throws BuildException {
63 String command;
64 Project project = this.getOwningTarget().getProject();
65 //
66 // absolute path of efi tools
67 //
68 String path = project.getProperty("env.FRAMEWORK_TOOLS_PATH");
69 if (path == null) {
70 command = "GenSection";
71 } else {
72 command = path + "/" + "GenSection";
73 }
74 //
75 // argument of tools
76 //
77 String argument = inputFile + outputFile + sectionType + versionNum
78 + interfaceString;
79 //
80 // return value of gensection execution
81 //
82 int revl = -1;
83
84 try {
85 Commandline cmdline = new Commandline();
86 cmdline.setExecutable(command);
87 cmdline.createArgument().setLine(argument);
88
89 LogStreamHandler streamHandler = new LogStreamHandler(this,
90 Project.MSG_INFO, Project.MSG_WARN);
91 Execute runner = new Execute(streamHandler, null);
92
93 runner.setAntRun(project);
94 runner.setCommandline(cmdline.getCommandline());
95
96 log(inputFileName);
97 log(Commandline.toString(cmdline.getCommandline()), Project.MSG_VERBOSE);
98 revl = runner.execute();
99 if (EFI_SUCCESS == revl) {
100 log("gensection succeeded!", Project.MSG_VERBOSE);
101 } else {
102 //
103 // command execution fail
104 //
105 log("ERROR = " + Integer.toHexString(revl));
106 throw new BuildException("gensection failed!");
107 }
108 } catch (Exception e) {
109 throw new BuildException(e.getMessage());
110 }
111 }
112
113 /**
114 getInputFile
115
116 This function is to get class member "inputFile".
117
118 @return name of input file
119 **/
120 public String getInputFile() {
121 return this.inputFile;
122 }
123
124 /**
125 setInputFile
126
127 This function is to set class member "inputFile".
128
129 @param inputFile name of input file
130 **/
131 public void setInputFile(String inputFile) {
132 this.inputFileName = (new File(inputFile)).getName();
133 this.inputFile = " -i " + inputFile;
134 }
135
136 /**
137 getOutputFile
138
139 This function is to get class member "outputFile".
140
141 @return name of output file
142 **/
143 public String getOutputFile() {
144 return this.outputFile;
145 }
146
147 /**
148 setOutputfile
149
150 This function is to set class member "outputFile".
151 @param outputFile name of output file
152 **/
153 public void setOutputfile(String outputFile) {
154 this.outputFile = " -o " + outputFile;
155 }
156
157 /**
158 getSectionType
159
160 This function is to get class member "sectionType".
161
162 @return sectoin type
163 **/
164 public String getSectionType() {
165 return this.sectionType;
166 }
167
168 /**
169 setSectionType
170
171 This function is to set class member "sectionType".
172
173 @param sectionType section type
174 **/
175 public void setSectionType(String sectionType) {
176 this.sectionType = " -s " + sectionType;
177 }
178
179 /**
180 getVersionNum
181
182 This function is to get class member "versionNum".
183 @return version number
184 **/
185 public String getVersionNum() {
186 return this.versionNum;
187 }
188
189 /**
190 setVersionNume
191
192 This function is to set class member "versionNum".
193 @param versionNum version number
194 **/
195 public void setVersionNum(String versionNum) {
196 this.versionNum = " -v " + versionNum;
197 }
198
199 /**
200 getInterfaceString
201
202 This function is to get class member "interfaceString".
203 @return interface string
204 **/
205 public String getInterfaceString() {
206 return this.interfaceString;
207 }
208
209 /**
210 setInterfaceString
211
212 This funcion is to set class member "interfaceString".
213 @param interfaceString interface string
214 **/
215 public void setInterfaceString(String interfaceString) {
216 this.interfaceString = " -a " + "\"" + interfaceString + "\"";
217 }
218 }