3 * Copyright 2002-2006 The Ant-Contrib project
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package net
.sf
.antcontrib
.cpptasks
.userdefine
;
19 import java
.io
.BufferedReader
;
21 import java
.io
.FileReader
;
22 import java
.util
.Vector
;
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
;
29 import sun
.nio
.cs
.ext
.TIS_620
;
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
;
37 public class UserDefineDef
extends ProcessorDef
{
39 public UserDefineDef () {}
41 private String type
= "CC";
42 private String includepathDelimiter
;
47 private String inputSuffix
;
48 private String outputSuffix
;
50 private Vector
<IncludePath
> includePaths
= new Vector
<IncludePath
>();
51 private Vector
<FileList
> fileSetList
= new Vector
<FileList
>();
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.
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
>();
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");
74 public void addConfiguredArgument(UserDefineArgument arg
) {
76 throw noChildrenAllowed();
78 addConfiguredProcessorArg(arg
);
82 * Creates an include path.
84 public IncludePath
createIncludePath() {
85 Project p
= getProject();
87 throw new java
.lang
.IllegalStateException("project must be set");
90 throw noChildrenAllowed();
92 IncludePath path
= new IncludePath(p
);
93 includePaths
.addElement(path
);
99 * Add a <includepath> if specify the file attribute
101 * @throws BuildException
102 * if the specify file not exist
104 protected void loadFile(Vector activePath
, File file
) throws BuildException
{
105 FileReader fileReader
;
108 if (!file
.exists()) {
109 throw new BuildException("The file " + file
+ " is not existed");
112 fileReader
= new FileReader(file
);
113 in
= new BufferedReader(fileReader
);
114 while ((str
= in
.readLine()) != null) {
115 if (str
.trim() == "") {
118 str
= getProject().replaceProperties(str
);
119 activePath
.addElement(str
.trim());
121 } catch (Exception e
) {
122 throw new BuildException(e
.getMessage());
127 * Returns the specific include path.
129 public String
[] getActiveIncludePaths() {
131 return ((UserDefineDef
) getCheckedRef(UserDefineDef
.class,
132 "UserDefineDef")).getActiveIncludePaths();
134 return getActivePaths(includePaths
);
137 private String
[] getActivePaths(Vector paths
) {
138 Project p
= getProject();
140 throw new java
.lang
.IllegalStateException("project not set");
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
]);
152 loadFile(activePaths
, path
.getFile());
156 String
[] pathNames
= new String
[activePaths
.size()];
157 activePaths
.copyInto(pathNames
);
161 public String
getIncludepathDelimiter() {
163 return ((UserDefineDef
) getCheckedRef(UserDefineDef
.class,
164 "UserDefineDef")).getIncludepathDelimiter();
166 return includepathDelimiter
;
169 public void setIncludepathDelimiter(String includepathDelimiter
) {
171 throw tooManyAttributes();
173 this.includepathDelimiter
= includepathDelimiter
;
176 public String
getInputSuffix() {
178 return ((UserDefineDef
) getCheckedRef(UserDefineDef
.class,
179 "UserDefineDef")).getInputSuffix();
184 public void setInputSuffix(String inputSuffix
) {
186 throw tooManyAttributes();
188 this.inputSuffix
= inputSuffix
;
191 public File
getOutdir() {
193 return ((UserDefineDef
) getCheckedRef(UserDefineDef
.class,
194 "UserDefineDef")).getOutdir();
199 public void setOutdir(File outdir
) {
201 throw tooManyAttributes();
203 this.outdir
= outdir
;
206 public String
getOutputSuffix() {
208 return ((UserDefineDef
) getCheckedRef(UserDefineDef
.class,
209 "UserDefineDef")).getOutputSuffix();
214 public void setOutputSuffix(String outputSuffix
) {
216 throw tooManyAttributes();
218 this.outputSuffix
= outputSuffix
;
221 public String
getType() {
223 return ((UserDefineDef
) getCheckedRef(UserDefineDef
.class,
224 "UserDefineDef")).getType();
229 public void setType(String type
) {
231 throw tooManyAttributes();
236 public File
getWorkdir() {
238 return ((UserDefineDef
) getCheckedRef(UserDefineDef
.class,
239 "UserDefineDef")).getWorkdir();
244 public void setWorkdir(File workdir
) {
246 throw tooManyAttributes();
248 this.workdir
= workdir
;
254 public LibrarySet
createLibset() {
256 throw noChildrenAllowed();
258 LibrarySet lib
= new LibrarySet();
259 libSet
.addElement(lib
);
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
] + " ";
274 public Vector
<LibrarySet
> getLibSet(){
281 public void addMap(UserDefineElement mapElement
){
283 throw noChildrenAllowed();
285 this.map
.addElement(mapElement
);
289 public Vector
<UserDefineElement
> getMap (){
293 public String
getMapvalue (){
294 if (this.map
.size() > 0){
296 * If user set more than one map use the first one.
298 return this.map
.get(0).value
;
303 public String
getMapFlag(){
304 if (this.map
.size() > 0){
306 * If user set more than one map use the first one.
308 return this.map
.get(0).flag
;
315 public void addPdb(UserDefineElement pdbElement
){
317 throw noChildrenAllowed();
319 this.pdb
.addElement(pdbElement
);
322 public Vector
<UserDefineElement
> getPdb(){
325 public String
getPdbvalue (){
326 if (this.pdb
.size() > 0){
328 * If user set more than one pdb use the first one.
331 return this.pdb
.get(0).value
;
336 public String
getPdbFlag(){
337 if (this.pdb
.size() > 0){
339 * If user set more than one pdb use the first one.
341 return this.pdb
.get(0).flag
;
347 * add entryPoint element.
349 public void addEntryPoint(UserDefineElement entryPointElement
){
351 throw noChildrenAllowed();
353 this.entryPoint
.addElement(entryPointElement
);
356 public Vector
<UserDefineElement
> getEntryPoint(){
357 return this.entryPoint
;
360 public String
getEntryPointvalue (){
361 if (this.entryPoint
.size() > 0){
363 * If user set more than one entryPoint use the first one.
365 return this.entryPoint
.get(0).value
;
370 public String
getEntryPointFlag(){
371 if (this.entryPoint
.size() > 0){
373 * If user set more than one entry point use the first one.
375 return this.entryPoint
.get(0).flag
;
381 * Add subSystem element.
383 public void addSubSystem (UserDefineElement subSystem
){
385 throw noChildrenAllowed();
387 this.subSystem
.addElement(subSystem
);
389 public Vector
<UserDefineElement
> getSubSystem (){
390 return this.subSystem
;
393 public String
getSubSystemvalue (){
394 if (this.subSystem
.size() > 0){
396 * If user set more than one subsystem use the first one.
398 return this.subSystem
.get(0).value
;
403 public String
getSubSystemFlag(){
404 if (this.subSystem
.size() > 0){
406 * If user set more than one subsystem use the first one.
408 return this.subSystem
.get(0).flag
;
413 * Add includeFile element
415 public void addIncludeFile (UserDefineElement includeFile
){
417 throw noChildrenAllowed();
419 this.includeFiles
.addElement(includeFile
);
421 public Vector
<UserDefineElement
> getIncludeFiles(){
422 return this.includeFiles
;
425 public String
getIncludeFile (){
426 if (this.includeFiles
.size() > 0){
428 * If user set more than one map use the first one.
430 return this.includeFiles
.get(0).value
;
435 public String
getIncludeFileFlag(){
436 if (this.includeFiles
.size() > 0){
438 * If user set more than one map use the first one.
440 return this.includeFiles
.get(0).flag
;
446 * Add OutputFile element
448 public void addOutputFile (UserDefineElement outPutFile
){
450 throw noChildrenAllowed();
452 this.outPutFiles
.addElement(outPutFile
);
455 public Vector
<UserDefineElement
> getOutputFiles(){
456 return this.outPutFiles
;
459 public String
getOutputFile (){
460 if (this.outPutFiles
.size() > 0){
462 * If user set more than one map use the first one.
464 return this.outPutFiles
.get(0).value
;
469 public String
getOutPutFlag(){
470 if (this.outPutFiles
.size() > 0){
472 * If user set more than one map use the first one.
474 return this.outPutFiles
.get(0).flag
;
482 public void addFileList(FileList fileSet
){
483 this.fileSetList
.addElement(fileSet
);
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
]);
495 return fileListVector
;