]>
Commit | Line | Data |
---|---|---|
878ddf1f | 1 | /*\r |
2 | * \r | |
3 | * Copyright 2002-2004 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;\r | |
18 | import java.io.BufferedReader;\r | |
19 | import java.io.File;\r | |
20 | import java.io.FileReader;\r | |
21 | import java.io.IOException;\r | |
22 | import java.lang.reflect.Method;\r | |
23 | import java.util.Vector;\r | |
24 | import net.sf.antcontrib.cpptasks.compiler.LinkType;\r | |
25 | import net.sf.antcontrib.cpptasks.compiler.Processor;\r | |
26 | import net.sf.antcontrib.cpptasks.compiler.ProcessorConfiguration;\r | |
27 | import net.sf.antcontrib.cpptasks.types.CommandLineArgument;\r | |
28 | import net.sf.antcontrib.cpptasks.types.ConditionalFileSet;\r | |
29 | import org.apache.tools.ant.BuildException;\r | |
30 | import org.apache.tools.ant.DirectoryScanner;\r | |
31 | import org.apache.tools.ant.Project;\r | |
32 | import org.apache.tools.ant.types.DataType;\r | |
33 | import org.apache.tools.ant.types.Environment;\r | |
34 | import org.apache.tools.ant.types.Reference;\r | |
35 | /**\r | |
36 | * An abstract compiler/linker definition.\r | |
37 | * \r | |
38 | * @author Curt Arnold\r | |
39 | */\r | |
40 | public abstract class ProcessorDef extends DataType {\r | |
41 | /**\r | |
42 | * Returns the equivalent Boolean object for the specified value\r | |
43 | * \r | |
44 | * Equivalent to Boolean.valueOf in JDK 1.4\r | |
45 | * \r | |
46 | * @param val\r | |
47 | * boolean value\r | |
48 | * @return Boolean.TRUE or Boolean.FALSE\r | |
49 | */\r | |
50 | protected static Boolean booleanValueOf(boolean val) {\r | |
51 | if (val) {\r | |
52 | return Boolean.TRUE;\r | |
53 | }\r | |
54 | return Boolean.FALSE;\r | |
55 | }\r | |
56 | /**\r | |
57 | * if true, targets will be built for debugging\r | |
58 | */\r | |
59 | private Boolean debug;\r | |
60 | private Environment env = null;\r | |
61 | /**\r | |
62 | * Reference for "extends" processor definition\r | |
63 | */\r | |
64 | private Reference extendsRef = null;\r | |
65 | /**\r | |
66 | * Name of property that must be present or definition will be ignored. May\r | |
67 | * be null.\r | |
68 | */\r | |
69 | private String ifProp;\r | |
70 | /**\r | |
71 | * if true, processor definition inherits values from containing <cc>\r | |
72 | * element\r | |
73 | */\r | |
74 | private boolean inherit;\r | |
75 | private Boolean libtool = null;\r | |
76 | protected boolean newEnvironment = false;\r | |
77 | /**\r | |
78 | * Processor.\r | |
79 | */\r | |
80 | private Processor processor;\r | |
81 | /**\r | |
82 | * Collection of <compilerarg>or <linkerarg>contained by definition\r | |
83 | */\r | |
84 | private final Vector processorArgs = new Vector();\r | |
85 | /**\r | |
86 | * Collection of <compilerparam>or <linkerparam>contained by definition\r | |
87 | */\r | |
88 | private final Vector processorParams = new Vector();\r | |
89 | /**\r | |
90 | * if true, all targets will be unconditionally rebuilt\r | |
91 | */\r | |
92 | private Boolean rebuild;\r | |
93 | /**\r | |
94 | * Collection of <fileset>contained by definition\r | |
95 | */\r | |
96 | private final Vector srcSets = new Vector();\r | |
97 | /**\r | |
98 | * Name of property that if present will cause definition to be ignored.\r | |
99 | * May be null.\r | |
100 | */\r | |
101 | private String unlessProp;\r | |
102 | /**\r | |
103 | * Constructor\r | |
104 | * \r | |
105 | */\r | |
106 | protected ProcessorDef() throws NullPointerException {\r | |
107 | inherit = true;\r | |
108 | }\r | |
109 | /**\r | |
110 | * Adds a <compilerarg>or <linkerarg>\r | |
111 | * \r | |
112 | * @param arg\r | |
113 | * command line argument, must not be null\r | |
114 | * @throws NullPointerException\r | |
115 | * if arg is null\r | |
116 | * @throws BuildException\r | |
117 | * if this definition is a reference\r | |
118 | */\r | |
119 | protected void addConfiguredProcessorArg(CommandLineArgument arg)\r | |
120 | throws NullPointerException, BuildException {\r | |
121 | if (arg == null) {\r | |
122 | throw new NullPointerException("arg");\r | |
123 | }\r | |
124 | if (isReference()) {\r | |
125 | throw noChildrenAllowed();\r | |
126 | }\r | |
127 | if(arg.getFile() == null ) {\r | |
128 | processorArgs.addElement(arg);\r | |
129 | }\r | |
130 | else {\r | |
131 | loadFile(arg.getFile());\r | |
132 | }\r | |
133 | }\r | |
134 | /**\r | |
135 | * Add a <compilerarg>or <linkerarg> if specify the file attribute\r | |
136 | * \r | |
137 | * @param arg\r | |
138 | * command line argument, must not be null\r | |
139 | * @throws BuildException\r | |
140 | * if the specify file not exist\r | |
141 | */\r | |
142 | protected void loadFile(File file)\r | |
143 | throws BuildException {\r | |
144 | FileReader fileReader;\r | |
145 | BufferedReader in;\r | |
146 | String str;\r | |
147 | if (! file.exists()){\r | |
148 | throw new BuildException("The file " + file + " is not existed");\r | |
149 | }\r | |
150 | try {\r | |
151 | fileReader = new FileReader(file);\r | |
152 | in = new BufferedReader(fileReader);\r | |
153 | while ( (str = in.readLine()) != null ){ \r | |
154 | if(str.trim() == ""){\r | |
155 | continue ;\r | |
156 | }\r | |
157 | str = getProject().replaceProperties(str);\r | |
158 | CommandLineArgument newarg = new CommandLineArgument();\r | |
159 | newarg.setValue(str.trim());\r | |
160 | processorArgs.addElement(newarg);\r | |
161 | }\r | |
162 | }\r | |
163 | catch(Exception e){\r | |
164 | throw new BuildException(e.getMessage());\r | |
165 | }\r | |
166 | }\r | |
167 | /**\r | |
168 | * Adds a <compilerarg>or <linkerarg>\r | |
169 | * \r | |
170 | * @param arg\r | |
171 | * command line argument, must not be null\r | |
172 | * @throws NullPointerException\r | |
173 | * if arg is null\r | |
174 | * @throws BuildException\r | |
175 | * if this definition is a reference\r | |
176 | */\r | |
177 | protected void addConfiguredProcessorParam(ProcessorParam param)\r | |
178 | throws NullPointerException, BuildException {\r | |
179 | if (param == null) {\r | |
180 | throw new NullPointerException("param");\r | |
181 | }\r | |
182 | if (isReference()) {\r | |
183 | throw noChildrenAllowed();\r | |
184 | }\r | |
185 | processorParams.addElement(param);\r | |
186 | }\r | |
187 | /**\r | |
188 | * Add an environment variable to the launched process.\r | |
189 | */\r | |
190 | public void addEnv(Environment.Variable var) {\r | |
191 | if (env == null) {\r | |
192 | env = new Environment();\r | |
193 | }\r | |
194 | env.addVariable(var);\r | |
195 | }\r | |
196 | /**\r | |
197 | * Adds a source file set.\r | |
198 | * \r | |
199 | * Files in these set will be processed by this configuration and will not\r | |
200 | * participate in the auction.\r | |
201 | * \r | |
202 | * @param srcSet\r | |
203 | * Fileset identifying files that should be processed by this\r | |
204 | * processor\r | |
205 | * @throws BuildException\r | |
206 | * if processor definition is a reference\r | |
207 | */\r | |
208 | public void addFileset(ConditionalFileSet srcSet) throws BuildException {\r | |
209 | if (isReference()) {\r | |
210 | throw noChildrenAllowed();\r | |
211 | }\r | |
212 | srcSet.setProject(getProject());\r | |
213 | srcSets.addElement(srcSet);\r | |
214 | }\r | |
215 | /**\r | |
216 | * Creates a configuration\r | |
217 | * \r | |
218 | * @param baseDef\r | |
219 | * reference to def from containing <cc>element, may be null\r | |
220 | * @return configuration\r | |
221 | * \r | |
222 | */\r | |
223 | public ProcessorConfiguration createConfiguration(CCTask task,\r | |
224 | LinkType linkType, ProcessorDef baseDef, TargetDef targetPlatform) {\r | |
225 | if (isReference()) {\r | |
226 | return ((ProcessorDef) getCheckedRef(ProcessorDef.class,\r | |
227 | "ProcessorDef")).createConfiguration(task, linkType,\r | |
228 | baseDef, targetPlatform);\r | |
229 | }\r | |
230 | ProcessorDef[] defaultProviders = getDefaultProviders(baseDef);\r | |
231 | Processor proc = getProcessor();\r | |
232 | return proc.createConfiguration(task, linkType, defaultProviders, this, targetPlatform);\r | |
233 | }\r | |
234 | /**\r | |
235 | * Prepares list of processor arguments ( <compilerarg>, <linkerarg>) that\r | |
236 | * are active for the current project settings.\r | |
237 | * \r | |
238 | * @return active compiler arguments\r | |
239 | */\r | |
240 | public CommandLineArgument[] getActiveProcessorArgs() {\r | |
241 | Project p = getProject();\r | |
242 | if (p == null) {\r | |
243 | throw new java.lang.IllegalStateException("project must be set");\r | |
244 | }\r | |
245 | if (isReference()) {\r | |
246 | return ((ProcessorDef) getCheckedRef(ProcessorDef.class,\r | |
247 | "ProcessorDef")).getActiveProcessorArgs();\r | |
248 | }\r | |
249 | Vector activeArgs = new Vector(processorArgs.size());\r | |
250 | for (int i = 0; i < processorArgs.size(); i++) {\r | |
251 | CommandLineArgument arg = (CommandLineArgument) processorArgs\r | |
252 | .elementAt(i);\r | |
253 | if (arg.isActive(p)) {\r | |
254 | activeArgs.addElement(arg);\r | |
255 | }\r | |
256 | }\r | |
257 | CommandLineArgument[] array = new CommandLineArgument[activeArgs.size()];\r | |
258 | activeArgs.copyInto(array);\r | |
259 | return array;\r | |
260 | }\r | |
261 | /**\r | |
262 | * Prepares list of processor arguments ( <compilerarg>, <linkerarg>) that\r | |
263 | * are active for the current project settings.\r | |
264 | * \r | |
265 | * @return active compiler arguments\r | |
266 | */\r | |
267 | public ProcessorParam[] getActiveProcessorParams() {\r | |
268 | Project p = getProject();\r | |
269 | if (p == null) {\r | |
270 | throw new java.lang.IllegalStateException("project must be set");\r | |
271 | }\r | |
272 | if (isReference()) {\r | |
273 | return ((ProcessorDef) getCheckedRef(ProcessorDef.class,\r | |
274 | "ProcessorDef")).getActiveProcessorParams();\r | |
275 | }\r | |
276 | Vector activeParams = new Vector(processorParams.size());\r | |
277 | for (int i = 0; i < processorParams.size(); i++) {\r | |
278 | ProcessorParam param = (ProcessorParam) processorParams\r | |
279 | .elementAt(i);\r | |
280 | if (param.isActive(p)) {\r | |
281 | activeParams.addElement(param);\r | |
282 | }\r | |
283 | }\r | |
284 | ProcessorParam[] array = new ProcessorParam[activeParams.size()];\r | |
285 | activeParams.copyInto(array);\r | |
286 | return array;\r | |
287 | }\r | |
288 | /**\r | |
289 | * Gets boolean indicating debug build\r | |
290 | * \r | |
291 | * @param defaultProviders\r | |
292 | * array of ProcessorDef's in descending priority\r | |
293 | * @param index\r | |
294 | * index to first element in array that should be considered\r | |
295 | * @return if true, built targets for debugging\r | |
296 | */\r | |
297 | public boolean getDebug(ProcessorDef[] defaultProviders, int index) {\r | |
298 | if (isReference()) {\r | |
299 | return ((ProcessorDef) getCheckedRef(ProcessorDef.class,\r | |
300 | "ProcessorDef")).getDebug(defaultProviders, index);\r | |
301 | }\r | |
302 | if (debug != null) {\r | |
303 | return debug.booleanValue();\r | |
304 | } else {\r | |
305 | if (defaultProviders != null && index < defaultProviders.length) {\r | |
306 | return defaultProviders[index].getDebug(defaultProviders,\r | |
307 | index + 1);\r | |
308 | }\r | |
309 | }\r | |
310 | return false;\r | |
311 | }\r | |
312 | /**\r | |
313 | * Creates an chain of objects which provide default values in descending\r | |
314 | * order of significance.\r | |
315 | * \r | |
316 | * @param baseDef\r | |
317 | * corresponding ProcessorDef from CCTask, will be last element\r | |
318 | * in array unless inherit = false\r | |
319 | * @return default provider array\r | |
320 | * \r | |
321 | */\r | |
322 | protected final ProcessorDef[] getDefaultProviders(ProcessorDef baseDef) {\r | |
323 | ProcessorDef extendsDef = getExtends();\r | |
324 | Vector chain = new Vector();\r | |
325 | while (extendsDef != null && !chain.contains(extendsDef)) {\r | |
326 | chain.addElement(extendsDef);\r | |
327 | extendsDef = extendsDef.getExtends();\r | |
328 | }\r | |
329 | if (baseDef != null && getInherit()) {\r | |
330 | chain.addElement(baseDef);\r | |
331 | }\r | |
332 | ProcessorDef[] defaultProviders = new ProcessorDef[chain.size()];\r | |
333 | chain.copyInto(defaultProviders);\r | |
334 | return defaultProviders;\r | |
335 | }\r | |
336 | /**\r | |
337 | * Gets the ProcessorDef specified by the extends attribute\r | |
338 | * \r | |
339 | * @return Base ProcessorDef, null if extends is not specified\r | |
340 | * @throws BuildException\r | |
341 | * if reference is not same type object\r | |
342 | */\r | |
343 | public ProcessorDef getExtends() throws BuildException {\r | |
344 | if (extendsRef != null) {\r | |
345 | Object obj = extendsRef.getReferencedObject(getProject());\r | |
346 | if (!getClass().isInstance(obj)) {\r | |
347 | throw new BuildException("Referenced object "\r | |
348 | + extendsRef.getRefId() + " not correct type, is "\r | |
349 | + obj.getClass().getName() + " should be "\r | |
350 | + getClass().getName());\r | |
351 | }\r | |
352 | return (ProcessorDef) obj;\r | |
353 | }\r | |
354 | return null;\r | |
355 | }\r | |
356 | /**\r | |
357 | * Gets the inherit attribute. If the inherit value is true, this processor\r | |
358 | * definition will inherit default values from the containing <cc>element.\r | |
359 | * \r | |
360 | * @return if true then properties from the containing <cc>element are\r | |
361 | * used.\r | |
362 | */\r | |
363 | public final boolean getInherit() {\r | |
364 | return inherit;\r | |
365 | }\r | |
366 | public boolean getLibtool() {\r | |
367 | if (libtool != null) {\r | |
368 | return libtool.booleanValue();\r | |
369 | }\r | |
370 | if (isReference()) {\r | |
371 | return ((ProcessorDef) getCheckedRef(ProcessorDef.class,\r | |
372 | "ProcessorDef")).getLibtool();\r | |
373 | }\r | |
374 | ProcessorDef extendsDef = getExtends();\r | |
375 | if (extendsDef != null) {\r | |
376 | return extendsDef.getLibtool();\r | |
377 | }\r | |
378 | return false;\r | |
379 | }\r | |
380 | /**\r | |
381 | * Obtains the appropriate processor (compiler, linker)\r | |
382 | * \r | |
383 | * @return processor\r | |
384 | */\r | |
385 | protected Processor getProcessor() {\r | |
386 | if (isReference()) {\r | |
387 | return ((ProcessorDef) getCheckedRef(ProcessorDef.class,\r | |
388 | "ProcessorDef")).getProcessor();\r | |
389 | }\r | |
390 | //\r | |
391 | // if a processor has not been explicitly set\r | |
392 | // then may be set by an extended definition\r | |
393 | if (processor == null) {\r | |
394 | ProcessorDef extendsDef = getExtends();\r | |
395 | if (extendsDef != null) {\r | |
396 | return extendsDef.getProcessor();\r | |
397 | }\r | |
398 | }\r | |
399 | return processor;\r | |
400 | }\r | |
401 | /**\r | |
402 | * Gets a boolean value indicating whether all targets must be rebuilt\r | |
403 | * regardless of dependency analysis.\r | |
404 | * \r | |
405 | * @param defaultProviders\r | |
406 | * array of ProcessorDef's in descending priority\r | |
407 | * @param index\r | |
408 | * index to first element in array that should be considered\r | |
409 | * @return true if all targets should be rebuilt.\r | |
410 | */\r | |
411 | public boolean getRebuild(ProcessorDef[] defaultProviders, int index) {\r | |
412 | if (isReference()) {\r | |
413 | return ((ProcessorDef) getCheckedRef(ProcessorDef.class,\r | |
414 | "ProcessorDef")).getRebuild(defaultProviders, index);\r | |
415 | }\r | |
416 | if (rebuild != null) {\r | |
417 | return rebuild.booleanValue();\r | |
418 | } else {\r | |
419 | if (defaultProviders != null && index < defaultProviders.length) {\r | |
420 | return defaultProviders[index].getRebuild(defaultProviders,\r | |
421 | index + 1);\r | |
422 | }\r | |
423 | }\r | |
424 | return false;\r | |
425 | }\r | |
426 | /**\r | |
427 | * Returns true if the processor definition contains embedded file set\r | |
428 | * definitions\r | |
429 | * \r | |
430 | * @return true if processor definition contains embedded filesets\r | |
431 | */\r | |
432 | public boolean hasFileSets() {\r | |
433 | if (isReference()) {\r | |
434 | return ((ProcessorDef) getCheckedRef(ProcessorDef.class,\r | |
435 | "ProcessorDef")).hasFileSets();\r | |
436 | }\r | |
437 | return srcSets.size() > 0;\r | |
438 | }\r | |
439 | /**\r | |
440 | * Determine if this def should be used.\r | |
441 | * \r | |
442 | * Definition will be active if the "if" variable (if specified) is set and\r | |
443 | * the "unless" variable (if specified) is not set and that all reference\r | |
444 | * or extended definitions are active\r | |
445 | * \r | |
446 | * @return true if processor is active\r | |
447 | * @throws IllegalStateException\r | |
448 | * if not properly initialized\r | |
449 | * @throws BuildException\r | |
450 | * if "if" or "unless" variable contains suspicious values\r | |
451 | * "false" or "no" which indicates possible confusion\r | |
452 | */\r | |
453 | public boolean isActive() throws BuildException, IllegalStateException {\r | |
454 | Project project = getProject();\r | |
455 | if (!CUtil.isActive(project, ifProp, unlessProp)) {\r | |
456 | return false;\r | |
457 | }\r | |
458 | if (isReference()) {\r | |
459 | if (!((ProcessorDef) getCheckedRef(ProcessorDef.class,\r | |
460 | "ProcessorDef")).isActive()) {\r | |
461 | return false;\r | |
462 | }\r | |
463 | }\r | |
464 | //\r | |
465 | // walk through any extended definitions\r | |
466 | //\r | |
467 | ProcessorDef[] defaultProviders = getDefaultProviders(null);\r | |
468 | for (int i = 0; i < defaultProviders.length; i++) {\r | |
469 | if (!defaultProviders[i].isActive()) {\r | |
470 | return false;\r | |
471 | }\r | |
472 | }\r | |
473 | return true;\r | |
474 | }\r | |
475 | /**\r | |
476 | * Sets the class name for the adapter. Use the "name" attribute when the\r | |
477 | * tool is supported.\r | |
478 | * \r | |
479 | * @param className\r | |
480 | * full class name\r | |
481 | * \r | |
482 | */\r | |
483 | public void setClassname(String className) throws BuildException {\r | |
484 | Object proc = null;\r | |
485 | try {\r | |
486 | Class implClass = ProcessorDef.class.getClassLoader().loadClass(\r | |
487 | className);\r | |
488 | try {\r | |
489 | Method getInstance = implClass.getMethod("getInstance",\r | |
490 | new Class[0]);\r | |
491 | proc = getInstance.invoke(null, new Object[0]);\r | |
492 | } catch (Exception ex) {\r | |
493 | proc = implClass.newInstance();\r | |
494 | }\r | |
495 | } catch (Exception ex) {\r | |
496 | throw new BuildException(ex);\r | |
497 | }\r | |
498 | setProcessor((Processor) proc);\r | |
499 | }\r | |
500 | /**\r | |
501 | * If set true, all targets will be built for debugging.\r | |
502 | * \r | |
503 | * @param debug\r | |
504 | * true if targets should be built for debugging\r | |
505 | * @throws BuildException\r | |
506 | * if processor definition is a reference\r | |
507 | */\r | |
508 | public void setDebug(boolean debug) throws BuildException {\r | |
509 | if (isReference()) {\r | |
510 | throw tooManyAttributes();\r | |
511 | }\r | |
512 | this.debug = booleanValueOf(debug);\r | |
513 | }\r | |
514 | /**\r | |
515 | * Sets a description of the current data type.\r | |
516 | */\r | |
517 | public void setDescription(String desc) {\r | |
518 | super.setDescription(desc);\r | |
519 | }\r | |
520 | /**\r | |
521 | * Specifies that this element extends the element with id attribute with a\r | |
522 | * matching value. The configuration will be constructed from the settings\r | |
523 | * of this element, element referenced by extends, and the containing cc\r | |
524 | * element.\r | |
525 | * \r | |
526 | * @param extendsRef\r | |
527 | * Reference to the extended processor definition.\r | |
528 | * @throws BuildException\r | |
529 | * if this processor definition is a reference\r | |
530 | */\r | |
531 | public void setExtends(Reference extendsRef) throws BuildException {\r | |
532 | if (isReference()) {\r | |
533 | throw tooManyAttributes();\r | |
534 | }\r | |
535 | this.extendsRef = extendsRef;\r | |
536 | }\r | |
537 | /**\r | |
538 | * Sets an id that can be used to reference this element.\r | |
539 | * \r | |
540 | * @param id\r | |
541 | * id\r | |
542 | */\r | |
543 | public void setId(String id) {\r | |
544 | //\r | |
545 | // this is actually accomplished by a different\r | |
546 | // mechanism, but we can document it\r | |
547 | //\r | |
548 | }\r | |
549 | /**\r | |
550 | * Sets the property name for the 'if' condition.\r | |
551 | * \r | |
552 | * The configuration will be ignored unless the property is defined.\r | |
553 | * \r | |
554 | * The value of the property is insignificant, but values that would imply\r | |
555 | * misinterpretation ("false", "no") will throw an exception when\r | |
556 | * evaluated.\r | |
557 | * \r | |
558 | * @param propName\r | |
559 | * name of property\r | |
560 | */\r | |
561 | public void setIf(String propName) {\r | |
562 | ifProp = propName;\r | |
563 | }\r | |
564 | /**\r | |
565 | * If inherit has the default value of true, defines, includes and other\r | |
566 | * settings from the containing <cc>element will be inherited.\r | |
567 | * \r | |
568 | * @param inherit\r | |
569 | * new value\r | |
570 | * @throws BuildException\r | |
571 | * if processor definition is a reference\r | |
572 | */\r | |
573 | public void setInherit(boolean inherit) throws BuildException {\r | |
574 | if (isReference()) {\r | |
575 | throw super.tooManyAttributes();\r | |
576 | }\r | |
577 | this.inherit = inherit;\r | |
578 | }\r | |
579 | /**\r | |
580 | * Set use of libtool.\r | |
581 | * \r | |
582 | * If set to true, the "libtool " will be prepended to the command line\r | |
583 | * \r | |
584 | * @param libtool\r | |
585 | * If true, use libtool.\r | |
586 | */\r | |
587 | public void setLibtool(boolean libtool) {\r | |
588 | if (isReference()) {\r | |
589 | throw tooManyAttributes();\r | |
590 | }\r | |
591 | this.libtool = booleanValueOf(libtool);\r | |
592 | }\r | |
593 | /**\r | |
594 | * Do not propagate old environment when new environment variables are\r | |
595 | * specified.\r | |
596 | */\r | |
597 | public void setNewenvironment(boolean newenv) {\r | |
598 | newEnvironment = newenv;\r | |
599 | }\r | |
600 | /**\r | |
601 | * Sets the processor\r | |
602 | * \r | |
603 | * @param processor\r | |
604 | * processor, may not be null.\r | |
605 | * @throws BuildException\r | |
606 | * if ProcessorDef is a reference\r | |
607 | * @throws NullPointerException\r | |
608 | * if processor is null\r | |
609 | */\r | |
610 | protected void setProcessor(Processor processor) throws BuildException,\r | |
611 | NullPointerException {\r | |
612 | if (processor == null) {\r | |
613 | throw new NullPointerException("processor");\r | |
614 | }\r | |
615 | if (isReference()) {\r | |
616 | throw super.tooManyAttributes();\r | |
617 | }\r | |
618 | if (env == null && !newEnvironment) {\r | |
619 | this.processor = processor;\r | |
620 | } else {\r | |
621 | this.processor = processor.changeEnvironment(newEnvironment, env);\r | |
622 | }\r | |
623 | }\r | |
624 | /**\r | |
625 | * If set true, all targets will be unconditionally rebuilt.\r | |
626 | * \r | |
627 | * @param rebuild\r | |
628 | * if true, rebuild all targets.\r | |
629 | * @throws BuildException\r | |
630 | * if processor definition is a reference\r | |
631 | */\r | |
632 | public void setRebuild(boolean rebuild) throws BuildException {\r | |
633 | if (isReference()) {\r | |
634 | throw tooManyAttributes();\r | |
635 | }\r | |
636 | this.rebuild = booleanValueOf(rebuild);\r | |
637 | }\r | |
638 | /**\r | |
639 | * Specifies that this element should behave as if the content of the\r | |
640 | * element with the matching id attribute was inserted at this location. If\r | |
641 | * specified, no other attributes or child content should be specified,\r | |
642 | * other than "if", "unless" and "description".\r | |
643 | * \r | |
644 | * @param ref\r | |
645 | * Reference to other element\r | |
646 | * \r | |
647 | */\r | |
648 | public void setRefid(org.apache.tools.ant.types.Reference ref) {\r | |
649 | super.setRefid(ref);\r | |
650 | }\r | |
651 | /**\r | |
652 | * Set the property name for the 'unless' condition.\r | |
653 | * \r | |
654 | * If named property is set, the configuration will be ignored.\r | |
655 | * \r | |
656 | * The value of the property is insignificant, but values that would imply\r | |
657 | * misinterpretation ("false", "no") of the behavior will throw an\r | |
658 | * exception when evaluated.\r | |
659 | * \r | |
660 | * @param propName\r | |
661 | * name of property\r | |
662 | */\r | |
663 | public void setUnless(String propName) {\r | |
664 | unlessProp = propName;\r | |
665 | }\r | |
666 | /**\r | |
667 | * This method calls the FileVistor's visit function for every file in the\r | |
668 | * processors definition\r | |
669 | * \r | |
670 | * @param visitor\r | |
671 | * object whose visit method is called for every file\r | |
672 | */\r | |
673 | public void visitFiles(FileVisitor visitor) {\r | |
674 | Project p = getProject();\r | |
675 | if (p == null) {\r | |
676 | throw new java.lang.IllegalStateException(\r | |
677 | "project must be set before this call");\r | |
678 | }\r | |
679 | if (isReference()) {\r | |
680 | ((ProcessorDef) getCheckedRef(ProcessorDef.class, "ProcessorDef"))\r | |
681 | .visitFiles(visitor);\r | |
682 | }\r | |
683 | //\r | |
684 | // if this processor extends another,\r | |
685 | // visit its files first\r | |
686 | //\r | |
687 | ProcessorDef extendsDef = getExtends();\r | |
688 | if (extendsDef != null) {\r | |
689 | extendsDef.visitFiles(visitor);\r | |
690 | }\r | |
691 | for (int i = 0; i < srcSets.size(); i++) {\r | |
692 | ConditionalFileSet srcSet = (ConditionalFileSet) srcSets\r | |
693 | .elementAt(i);\r | |
694 | if (srcSet.isActive()) {\r | |
695 | // Find matching source files\r | |
696 | DirectoryScanner scanner = srcSet.getDirectoryScanner(p);\r | |
697 | // Check each source file - see if it needs compilation\r | |
698 | String[] fileNames = scanner.getIncludedFiles();\r | |
699 | File parentDir = scanner.getBasedir();\r | |
700 | for (int j = 0; j < fileNames.length; j++) {\r | |
701 | String currentFile = fileNames[j];\r | |
702 | visitor.visit(parentDir, currentFile);\r | |
703 | }\r | |
704 | }\r | |
705 | }\r | |
706 | }\r | |
707 | public Vector getSrcSets() {\r | |
708 | if (isReference()) {\r | |
709 | return ((ProcessorDef) getCheckedRef(ProcessorDef.class,\r | |
710 | "ProcessorDef")).getSrcSets();\r | |
711 | }\r | |
712 | return srcSets;\r | |
713 | }\r | |
714 | }\r |