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
.Iterator
;
23 import java
.util
.LinkedHashSet
;
25 import java
.util
.Vector
;
27 import org
.apache
.tools
.ant
.BuildException
;
28 import org
.apache
.tools
.ant
.Project
;
30 import net
.sf
.antcontrib
.cpptasks
.ProcessorDef
;
31 import net
.sf
.antcontrib
.cpptasks
.types
.ConditionalPath
;
32 import net
.sf
.antcontrib
.cpptasks
.types
.IncludePath
;
33 import net
.sf
.antcontrib
.cpptasks
.types
.LibrarySet
;
35 public class UserDefineDef
extends ProcessorDef
{
37 public UserDefineDef () {}
39 private String type
= "CC";
41 private String family
= "MSFT";
45 private String includepathDelimiter
;
47 private String outputDelimiter
;
51 private Vector includePaths
= new Vector();
53 private String outputFile
;
55 private Vector _libset
= new Vector();
57 public void addLibset(LibrarySet libset
) {
59 throw noChildrenAllowed();
62 throw new NullPointerException("libset");
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
getType() {
178 return ((UserDefineDef
) getCheckedRef(UserDefineDef
.class,
179 "UserDefineDef")).getType();
184 public void setType(String type
) {
186 throw tooManyAttributes();
191 public String
getCmd() {
195 public void setCmd(String cmd
) {
197 throw tooManyAttributes();
202 public String
getFamily() {
206 public void setFamily(String family
) {
208 throw tooManyAttributes();
210 this.family
= family
;
213 public String
getOutputFile() {
217 public void setOutputFile(String outputFile
) {
219 throw tooManyAttributes();
221 this.outputFile
= outputFile
;
224 public File
getWorkdir() {
228 public void setWorkdir(File workdir
) {
230 throw tooManyAttributes();
232 this.workdir
= workdir
;
235 public String
[] get_libset() {
236 Set libs
= new LinkedHashSet();
237 Iterator iter
= _libset
.iterator();
238 while (iter
.hasNext()) {
239 LibrarySet librarySet
= (LibrarySet
)iter
.next();
240 File basedir
= librarySet
.getDir(getProject());
241 String
[] libStrArray
= librarySet
.getLibs();
242 for (int i
= 0 ; i
< libStrArray
.length
; i
++) {
243 if (basedir
!= null) {
244 File libFile
= new File(libStrArray
[i
]);
245 if (libFile
.isAbsolute()) {
246 libs
.add(libFile
.getPath());
249 libs
.add(basedir
.getPath() + File
.separatorChar
+ libFile
.getPath());
253 libs
.add(libStrArray
[i
]);
257 return (String
[])libs
.toArray(new String
[libs
.size()]);
260 public String
getOutputDelimiter() {
261 return outputDelimiter
;
264 public void setOutputDelimiter(String outputDelimiter
) {
265 this.outputDelimiter
= outputDelimiter
;