]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/Cpptasks/net/sf/antcontrib/cpptasks/userdefine/UserDefineDef.java
f17edcf4ae87dc36110f3e750fbf8897d97bc58a
[mirror_edk2.git] / Tools / Source / Cpptasks / net / sf / antcontrib / cpptasks / userdefine / UserDefineDef.java
1 /*
2 *
3 * Copyright 2002-2006 The Ant-Contrib project
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17 package net.sf.antcontrib.cpptasks.userdefine;
18
19 import java.io.BufferedReader;
20 import java.io.File;
21 import java.io.FileReader;
22 import java.util.Vector;
23
24 import org.apache.tools.ant.BuildException;
25 import org.apache.tools.ant.Project;
26 import org.apache.tools.ant.types.FileList;
27 import org.apache.tools.ant.types.FileSet;
28
29 import sun.nio.cs.ext.TIS_620;
30
31 import net.sf.antcontrib.cpptasks.ProcessorDef;
32 import net.sf.antcontrib.cpptasks.types.AslcompilerArgument;
33 import net.sf.antcontrib.cpptasks.types.ConditionalPath;
34 import net.sf.antcontrib.cpptasks.types.IncludePath;
35 import net.sf.antcontrib.cpptasks.types.LibrarySet;
36
37 public class UserDefineDef extends ProcessorDef{
38
39 public UserDefineDef () {}
40
41 private String type = "CC";
42 private String includepathDelimiter;
43
44 private File outdir;
45 private File workdir;
46
47 private String inputSuffix;
48 private String outputSuffix;
49
50 private Vector<IncludePath> includePaths= new Vector<IncludePath>();
51 private Vector<FileList> fileSetList = new Vector<FileList>();
52
53 /**
54 * New adding for support GCC toolchain.
55 * Most of those only have one value for example :
56 * entryPoint, mapFile, pdbFile, define those as element because
57 * if attribut too much the command line is not good-lookinng.
58 */
59
60 private Vector<UserDefineElement> includeFiles = new Vector<UserDefineElement>();
61 private Vector<UserDefineElement> outPutFiles = new Vector<UserDefineElement>();
62 private Vector<UserDefineElement> subSystem = new Vector<UserDefineElement>();
63 private Vector<UserDefineElement> entryPoint = new Vector<UserDefineElement>();
64 private Vector<UserDefineElement> map = new Vector<UserDefineElement>();
65 private Vector<UserDefineElement> pdb = new Vector<UserDefineElement>();
66 private Vector<LibrarySet> libSet = new Vector<LibrarySet>();
67
68 public void execute() throws org.apache.tools.ant.BuildException {
69 throw new org.apache.tools.ant.BuildException(
70 "Not an actual task, but looks like one for documentation purposes");
71 }
72
73
74 public void addConfiguredArgument(UserDefineArgument arg) {
75 if (isReference()) {
76 throw noChildrenAllowed();
77 }
78 addConfiguredProcessorArg(arg);
79 }
80
81 /**
82 * Creates an include path.
83 */
84 public IncludePath createIncludePath() {
85 Project p = getProject();
86 if (p == null) {
87 throw new java.lang.IllegalStateException("project must be set");
88 }
89 if (isReference()) {
90 throw noChildrenAllowed();
91 }
92 IncludePath path = new IncludePath(p);
93 includePaths.addElement(path);
94 return path;
95 }
96
97
98 /**
99 * Add a <includepath> if specify the file attribute
100 *
101 * @throws BuildException
102 * if the specify file not exist
103 */
104 protected void loadFile(Vector activePath, File file) throws BuildException {
105 FileReader fileReader;
106 BufferedReader in;
107 String str;
108 if (!file.exists()) {
109 throw new BuildException("The file " + file + " is not existed");
110 }
111 try {
112 fileReader = new FileReader(file);
113 in = new BufferedReader(fileReader);
114 while ((str = in.readLine()) != null) {
115 if (str.trim() == "") {
116 continue;
117 }
118 str = getProject().replaceProperties(str);
119 activePath.addElement(str.trim());
120 }
121 } catch (Exception e) {
122 throw new BuildException(e.getMessage());
123 }
124 }
125
126 /**
127 * Returns the specific include path.
128 */
129 public String[] getActiveIncludePaths() {
130 if (isReference()) {
131 return ((UserDefineDef) getCheckedRef(UserDefineDef.class,
132 "UserDefineDef")).getActiveIncludePaths();
133 }
134 return getActivePaths(includePaths);
135 }
136
137 private String[] getActivePaths(Vector paths) {
138 Project p = getProject();
139 if (p == null) {
140 throw new java.lang.IllegalStateException("project not set");
141 }
142 Vector activePaths = new Vector(paths.size());
143 for (int i = 0; i < paths.size(); i++) {
144 ConditionalPath path = (ConditionalPath) paths.elementAt(i);
145 if (path.isActive(p)) {
146 if (path.getFile() == null) {
147 String[] pathEntries = path.list();
148 for (int j = 0; j < pathEntries.length; j++) {
149 activePaths.addElement(pathEntries[j]);
150 }
151 } else {
152 loadFile(activePaths, path.getFile());
153 }
154 }
155 }
156 String[] pathNames = new String[activePaths.size()];
157 activePaths.copyInto(pathNames);
158 return pathNames;
159 }
160
161 public String getIncludepathDelimiter() {
162 if (isReference()) {
163 return ((UserDefineDef) getCheckedRef(UserDefineDef.class,
164 "UserDefineDef")).getIncludepathDelimiter();
165 }
166 return includepathDelimiter;
167 }
168
169 public void setIncludepathDelimiter(String includepathDelimiter) {
170 if (isReference()) {
171 throw tooManyAttributes();
172 }
173 this.includepathDelimiter = includepathDelimiter;
174 }
175
176 public String getInputSuffix() {
177 if (isReference()) {
178 return ((UserDefineDef) getCheckedRef(UserDefineDef.class,
179 "UserDefineDef")).getInputSuffix();
180 }
181 return inputSuffix;
182 }
183
184 public void setInputSuffix(String inputSuffix) {
185 if (isReference()) {
186 throw tooManyAttributes();
187 }
188 this.inputSuffix = inputSuffix;
189 }
190
191 public File getOutdir() {
192 if (isReference()) {
193 return ((UserDefineDef) getCheckedRef(UserDefineDef.class,
194 "UserDefineDef")).getOutdir();
195 }
196 return outdir;
197 }
198
199 public void setOutdir(File outdir) {
200 if (isReference()) {
201 throw tooManyAttributes();
202 }
203 this.outdir = outdir;
204 }
205
206 public String getOutputSuffix() {
207 if (isReference()) {
208 return ((UserDefineDef) getCheckedRef(UserDefineDef.class,
209 "UserDefineDef")).getOutputSuffix();
210 }
211 return outputSuffix;
212 }
213
214 public void setOutputSuffix(String outputSuffix) {
215 if (isReference()) {
216 throw tooManyAttributes();
217 }
218 this.outputSuffix = outputSuffix;
219 }
220
221 public String getType() {
222 if (isReference()) {
223 return ((UserDefineDef) getCheckedRef(UserDefineDef.class,
224 "UserDefineDef")).getType();
225 }
226 return type;
227 }
228
229 public void setType(String type) {
230 if (isReference()) {
231 throw tooManyAttributes();
232 }
233 this.type = type;
234 }
235
236 public File getWorkdir() {
237 if (isReference()) {
238 return ((UserDefineDef) getCheckedRef(UserDefineDef.class,
239 "UserDefineDef")).getWorkdir();
240 }
241 return workdir;
242 }
243
244 public void setWorkdir(File workdir) {
245 if (isReference()) {
246 throw tooManyAttributes();
247 }
248 this.workdir = workdir;
249 }
250
251 /**
252 * Add an libSet.
253 */
254 public LibrarySet createLibset() {
255 if (isReference()){
256 throw noChildrenAllowed();
257 }
258 LibrarySet lib = new LibrarySet();
259 libSet.addElement(lib);
260 return lib;
261 }
262
263 public String getLibSetString(){
264 String libString = null;
265 for (int i = 0; i < libSet.size(); i++){
266 String[] libList = libSet.get(i).getLibs();
267 for (int j = 0; j < libList.length; j++){
268 libString = libString + libList[j] + " ";
269 }
270 }
271 return libString;
272 }
273
274 public Vector<LibrarySet> getLibSet(){
275 return this.libSet;
276 }
277
278 /**
279 * Add map element
280 */
281 public void addMap(UserDefineElement mapElement){
282 if (isReference()){
283 throw noChildrenAllowed();
284 }else{
285 this.map.addElement(mapElement);
286 }
287 }
288
289 public Vector<UserDefineElement> getMap (){
290 return this.map;
291 }
292
293 public String getMapvalue (){
294 if (this.map.size() > 0){
295 /*
296 * If user set more than one map use the first one.
297 */
298 return this.map.get(0).value;
299 }
300 return null;
301
302 }
303 public String getMapFlag(){
304 if (this.map.size() > 0){
305 /*
306 * If user set more than one map use the first one.
307 */
308 return this.map.get(0).flag;
309 }
310 return null;
311 }
312 /**
313 * Add pdb element
314 */
315 public void addPdb(UserDefineElement pdbElement){
316 if (isReference()){
317 throw noChildrenAllowed();
318 }
319 this.pdb.addElement(pdbElement);
320 }
321
322 public Vector<UserDefineElement> getPdb(){
323 return this.pdb;
324 }
325 public String getPdbvalue (){
326 if (this.pdb.size() > 0){
327 /*
328 * If user set more than one pdb use the first one.
329 *
330 */
331 return this.pdb.get(0).value;
332 }
333 return null;
334
335 }
336 public String getPdbFlag(){
337 if (this.pdb.size() > 0){
338 /*
339 * If user set more than one pdb use the first one.
340 */
341 return this.pdb.get(0).flag;
342 }
343 return null;
344 }
345
346 /**
347 * add entryPoint element.
348 */
349 public void addEntryPoint(UserDefineElement entryPointElement){
350 if (isReference()){
351 throw noChildrenAllowed();
352 }
353 this.entryPoint.addElement(entryPointElement);
354 }
355
356 public Vector<UserDefineElement> getEntryPoint(){
357 return this.entryPoint;
358 }
359
360 public String getEntryPointvalue (){
361 if (this.entryPoint.size() > 0){
362 /*
363 * If user set more than one entryPoint use the first one.
364 */
365 return this.entryPoint.get(0).value;
366 }
367 return null;
368
369 }
370 public String getEntryPointFlag(){
371 if (this.entryPoint.size() > 0){
372 /*
373 * If user set more than one entry point use the first one.
374 */
375 return this.entryPoint.get(0).flag;
376 }
377 return null;
378 }
379
380 /**
381 * Add subSystem element.
382 */
383 public void addSubSystem (UserDefineElement subSystem){
384 if (isReference()){
385 throw noChildrenAllowed();
386 }
387 this.subSystem.addElement(subSystem);
388 }
389 public Vector<UserDefineElement> getSubSystem (){
390 return this.subSystem;
391 }
392
393 public String getSubSystemvalue (){
394 if (this.subSystem.size() > 0){
395 /*
396 * If user set more than one subsystem use the first one.
397 */
398 return this.subSystem.get(0).value;
399 }
400 return null;
401
402 }
403 public String getSubSystemFlag(){
404 if (this.subSystem.size() > 0){
405 /*
406 * If user set more than one subsystem use the first one.
407 */
408 return this.subSystem.get(0).flag;
409 }
410 return null;
411 }
412 /**
413 * Add includeFile element
414 */
415 public void addIncludeFile (UserDefineElement includeFile){
416 if (isReference()){
417 throw noChildrenAllowed();
418 }
419 this.includeFiles.addElement(includeFile);
420 }
421 public Vector<UserDefineElement> getIncludeFiles(){
422 return this.includeFiles;
423 }
424
425 public String getIncludeFile (){
426 if (this.includeFiles.size() > 0){
427 /*
428 * If user set more than one map use the first one.
429 */
430 return this.includeFiles.get(0).value;
431 }
432 return null;
433
434 }
435 public String getIncludeFileFlag(){
436 if (this.includeFiles.size() > 0){
437 /*
438 * If user set more than one map use the first one.
439 */
440 return this.includeFiles.get(0).flag;
441 }
442 return null;
443 }
444
445 /**
446 * Add OutputFile element
447 */
448 public void addOutputFile (UserDefineElement outPutFile){
449 if (isReference()){
450 throw noChildrenAllowed();
451 }
452 this.outPutFiles.addElement(outPutFile);
453 }
454
455 public Vector<UserDefineElement> getOutputFiles(){
456 return this.outPutFiles;
457 }
458
459 public String getOutputFile (){
460 if (this.outPutFiles.size() > 0){
461 /*
462 * If user set more than one map use the first one.
463 */
464 return this.outPutFiles.get(0).value;
465 }
466 return null;
467
468 }
469 public String getOutPutFlag(){
470 if (this.outPutFiles.size() > 0){
471 /*
472 * If user set more than one map use the first one.
473 */
474 return this.outPutFiles.get(0).flag;
475 }
476 return null;
477 }
478
479 /**
480 * Add fileSet list
481 */
482 public void addFileList(FileList fileSet){
483 this.fileSetList.addElement(fileSet);
484 }
485
486 public Vector<String> getFileList(){
487 Project p = getProject();
488 Vector<String> fileListVector = new Vector<String>();
489 for (int i = 0; i < this.fileSetList.size(); i++){
490 String[] tempStrList = this.fileSetList.get(i).getFiles(p);
491 for (int j = 0; j < tempStrList.length; j++){
492 fileListVector .addElement(tempStrList[j]);
493 }
494 }
495 return fileListVector;
496 }
497 }