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