]>
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 | |
509693cc | 22 | import java.util.Iterator;\r |
23 | import java.util.LinkedHashSet;\r | |
24 | import java.util.Set;\r | |
878ddf1f | 25 | import java.util.Vector;\r |
26 | \r | |
27 | import org.apache.tools.ant.BuildException;\r | |
28 | import org.apache.tools.ant.Project;\r | |
878ddf1f | 29 | \r |
30 | import net.sf.antcontrib.cpptasks.ProcessorDef;\r | |
878ddf1f | 31 | import net.sf.antcontrib.cpptasks.types.ConditionalPath;\r |
32 | import net.sf.antcontrib.cpptasks.types.IncludePath;\r | |
33 | import net.sf.antcontrib.cpptasks.types.LibrarySet;\r | |
34 | \r | |
35 | public class UserDefineDef extends ProcessorDef{\r | |
36 | \r | |
37 | public UserDefineDef () {}\r | |
38 | \r | |
39 | private String type = "CC";\r | |
509693cc | 40 | \r |
41 | private String family = "MSFT";\r | |
42 | \r | |
43 | private String cmd;\r | |
44 | \r | |
878ddf1f | 45 | private String includepathDelimiter;\r |
46 | \r | |
509693cc | 47 | private String outputDelimiter;\r |
48 | \r | |
878ddf1f | 49 | private File workdir;\r |
878ddf1f | 50 | \r |
509693cc | 51 | private Vector includePaths= new Vector();\r |
878ddf1f | 52 | \r |
509693cc | 53 | private String outputFile;\r |
54 | \r | |
55 | private Vector _libset = new Vector();\r | |
878ddf1f | 56 | \r |
509693cc | 57 | public void addLibset(LibrarySet libset) {\r |
58 | if (isReference()) {\r | |
59 | throw noChildrenAllowed();\r | |
60 | }\r | |
61 | if (libset == null) {\r | |
62 | throw new NullPointerException("libset");\r | |
63 | }\r | |
64 | \r | |
65 | _libset.add(libset);\r | |
66 | }\r | |
878ddf1f | 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 | |
509693cc | 176 | public String getType() {\r |
878ddf1f | 177 | if (isReference()) {\r |
178 | return ((UserDefineDef) getCheckedRef(UserDefineDef.class,\r | |
509693cc | 179 | "UserDefineDef")).getType();\r |
878ddf1f | 180 | }\r |
509693cc | 181 | return type;\r |
878ddf1f | 182 | }\r |
183 | \r | |
509693cc | 184 | public void setType(String type) {\r |
878ddf1f | 185 | if (isReference()) {\r |
186 | throw tooManyAttributes();\r | |
187 | }\r | |
509693cc | 188 | this.type = type;\r |
878ddf1f | 189 | }\r |
190 | \r | |
509693cc | 191 | public String getCmd() {\r |
192 | return cmd;\r | |
878ddf1f | 193 | }\r |
194 | \r | |
509693cc | 195 | public void setCmd(String cmd) {\r |
878ddf1f | 196 | if (isReference()) {\r |
197 | throw tooManyAttributes();\r | |
198 | }\r | |
509693cc | 199 | this.cmd = cmd;\r |
878ddf1f | 200 | }\r |
201 | \r | |
509693cc | 202 | public String getFamily() {\r |
203 | return family;\r | |
878ddf1f | 204 | }\r |
205 | \r | |
509693cc | 206 | public void setFamily(String family) {\r |
878ddf1f | 207 | if (isReference()) {\r |
208 | throw tooManyAttributes();\r | |
209 | }\r | |
509693cc | 210 | this.family = family;\r |
878ddf1f | 211 | }\r |
212 | \r | |
509693cc | 213 | public String getOutputFile() {\r |
214 | return outputFile;\r | |
878ddf1f | 215 | }\r |
216 | \r | |
509693cc | 217 | public void setOutputFile(String outputFile) {\r |
878ddf1f | 218 | if (isReference()) {\r |
219 | throw tooManyAttributes();\r | |
220 | }\r | |
509693cc | 221 | this.outputFile = outputFile;\r |
878ddf1f | 222 | }\r |
223 | \r | |
224 | public File getWorkdir() {\r | |
878ddf1f | 225 | return workdir;\r |
226 | }\r | |
227 | \r | |
228 | public void setWorkdir(File workdir) {\r | |
229 | if (isReference()) {\r | |
230 | throw tooManyAttributes();\r | |
231 | }\r | |
232 | this.workdir = workdir;\r | |
233 | }\r | |
509693cc | 234 | \r |
235 | public String[] get_libset() {\r | |
236 | Set libs = new LinkedHashSet();\r | |
237 | Iterator iter = _libset.iterator();\r | |
238 | while (iter.hasNext()) {\r | |
239 | LibrarySet librarySet = (LibrarySet)iter.next();\r | |
240 | File basedir = librarySet.getDir(getProject());\r | |
241 | String[] libStrArray = librarySet.getLibs();\r | |
242 | for (int i = 0 ; i < libStrArray.length; i ++) {\r | |
243 | if (basedir != null) {\r | |
244 | File libFile = new File(libStrArray[i]);\r | |
245 | if (libFile.isAbsolute()) {\r | |
246 | libs.add(libFile.getPath());\r | |
247 | }\r | |
248 | else {\r | |
249 | libs.add(basedir.getPath() + File.separatorChar + libFile.getPath());\r | |
250 | }\r | |
251 | }\r | |
252 | else {\r | |
253 | libs.add(libStrArray[i]);\r | |
254 | }\r | |
878ddf1f | 255 | }\r |
256 | }\r | |
509693cc | 257 | return (String[])libs.toArray(new String[libs.size()]);\r |
878ddf1f | 258 | }\r |
509693cc | 259 | \r |
260 | public String getOutputDelimiter() {\r | |
261 | return outputDelimiter;\r | |
878ddf1f | 262 | }\r |
509693cc | 263 | \r |
264 | public void setOutputDelimiter(String outputDelimiter) {\r | |
265 | this.outputDelimiter = outputDelimiter;\r | |
878ddf1f | 266 | }\r |
509693cc | 267 | \r |
878ddf1f | 268 | }\r |