KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > idaremedia > antx > flowcontrol > call > CallForEachTask


1 /**
2  * $Id: CallForEachTask.java 180 2007-03-15 12:56:38Z ssmc $
3  * Copyright 2004 iDare Media, Inc. All rights reserved.
4  *
5  * Originally written by iDare Media, Inc. for release into the public domain. This
6  * library, source form and binary form, is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public License (LGPL) as published
8  * by the Free Software Foundation; either version 2.1 of the License, or (at your option)
9  * any later version.<p>
10  *
11  * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
12  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13  * See the GNU LGPL for more details.<p>
14  *
15  * You should have received a copy of the GNU Lesser General Public License along with this
16  * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite
17  * 330, Boston, MA 02111-1307 USA. The GNU LGPL can be found online at
18  * http://www.fsf.org/copyleft/lesser.html<p>
19  *
20  * This product has been influenced by several projects within the open-source community.
21  * The JWare developers wish to acknowledge the open-source community's support. For more
22  * information regarding the open-source products used within JWare, please visit the
23  * JWare website.
24  *----------------------------------------------------------------------------------------*
25  * WEBSITE- http://www.jware.info EMAIL- inquiries@jware.info
26  *----------------------------------------------------------------------------------------*
27  **/

28
29 package com.idaremedia.antx.flowcontrol.call;
30
31 import org.apache.tools.ant.BuildException;
32 import org.apache.tools.ant.Project;
33 import org.apache.tools.ant.types.PropertySet;
34
35 import com.idaremedia.antx.AntX;
36 import com.idaremedia.antx.helpers.InnerNameValuePair;
37 import com.idaremedia.antx.helpers.Tk;
38 import com.idaremedia.antx.parameters.ExecutionMode;
39 import com.idaremedia.antx.parameters.FixturePassthru;
40 import com.idaremedia.antx.solo.CopyPropertyTask;
41 import com.idaremedia.antx.solo.CopyReferenceTask;
42
43 /**
44  * The public task definition of {@linkplain ForEachTask}; usually defined as
45  * &lt;callforeach&gt;. The CallForEachTask allows only &lt;propertyset&gt;,
46  * &lt;[copy]property&gt;, and &lt;[copy]reference&gt; declarations to be nested
47  * within it as fixture instructions for the child projects.
48  * <p>
49  * <b>Example Usage:</b><pre>
50  * &lt;do unlessTrue="co.disable"&gt;
51  * &lt;callforeach i="module.name" list="${modules}" mode="local"
52  * targets="clobber,checkout,merge"/&gt;
53  * &lt;/do&gt;
54  *
55  * &lt;do iftrue="scm.enable"&gt;
56  * &lt;callforeach i="_file" files="module.files" steps="checkin,tag,delete"/&gt;
57  * &lt;/do&gt;
58  *
59  * &lt;callforeach i="_response" in="400,403" targets="check-server1,check-server2"/&gt;
60  *
61  * &lt;urls id="serverlist"&gt;...&lt;/urls&gt;
62  * &lt;callforeach i="_server" items="serverlist" targets="check-http-alive"/&gt;
63  *
64  * &lt;callforeach i="_packagename" infile="/tmp/package.list"
65  * targets="-preprocess,-javadoc,-scrub"/&gt;
66  *
67  * &lt;do unless="no.jars.verify"&gt;
68  * &lt;callforeach i="_candidate" path="${build.classpath}" targets="verify-jar"/&gt;
69  * &lt;/do&gt;
70  *
71  * &lt;do iftrue="scm.enable"&gt;
72  * &lt;callforeach i="_file" files="module.files" macros="checkin,tag,delete"/&gt;
73  * &lt;/do&gt;
74  * </pre>
75  *
76  * @since JWare/AntX 0.4
77  * @author ssmc, &copy;2004 <a HREF="http://www.jware.info">iDare&nbsp;Media,&nbsp;Inc.</a>
78  * @version 0.5
79  * @.safety single
80  * @.group api,infra
81  **/

82
83 public final class CallForEachTask extends ForEachTask
84 {
85     /**
86      * Initializes a new CallForEachTask instance.
87      **/

88     public CallForEachTask()
89     {
90         super(AntX.flow+"foreach");
91     }
92
93
94
95     /**
96      * Initializes a new helper CallForEachTask instance.
97      * @param iam CV-label (non-null)
98      **/

99     public CallForEachTask(String JavaDoc iam)
100     {
101         super(iam);
102     }
103
104
105 // ---------------------------------------------------------------------------------------
106
// Unique Script-facing Parameters:
107
// ---------------------------------------------------------------------------------------
108

109     /**
110      * Adds a new fixture overlay property to this task.
111      * This property is automatically passed to each target's
112      * environment as it is executed.
113      * @param param initialized property (non-null)
114      * @since JWare/AntX 0.4
115      **/

116     public void addProperty(CopyPropertyTask param)
117     {
118         require_(param!=null,"addProperty- nonzro item");
119         getParametersKeeper().addParameter(param);
120     }
121
122
123
124     /**
125      * Adds a new fixture overlay property set to this task. The
126      * properties named by the property set are automatically
127      * copied to each target's environment before it is executed.
128      * @param param property set information (non-null)
129      * @since JWare/AntX 0.4
130      **/

131     public void addPropertySet(PropertySet param)
132     {
133         require_(param!=null,"addPropertySet- nonzro item");
134         getParametersKeeper().addParameter(param);
135     }
136
137
138     /**
139      * Adds a new configuration reference to this task. This
140      * reference is automatically copied to each target's
141      * environment as each is executed.
142      * @param param reference information (non-null)
143      * @since JWare/AntX 0.4
144      **/

145     public void addReference(CopyReferenceTask param)
146     {
147         require_(param!=null,"addReference- nonzro item");
148         getParametersKeeper().addParameter(param);
149     }
150
151
152
153     /**
154      * Adds a new macro attribute default value to this task.
155      * This attribute is automatically passed to ,em>each</em>
156      * macro when it is executed.
157      * @param attr initialized macro attribute (non-null)
158      * @since JWare/AntX 0.5
159      * @throws BuildException if this caller is not setup for macros.
160      **/

161     public void addConfiguredAttribute(InnerNameValuePair attr)
162     {
163         require_(attr!=null,"addAttribute- nonzro item");
164         if (getMacroNamesList()==null) {
165             String JavaDoc err = getAntXMsg("flow.attritem.formacros");
166             log(err,Project.MSG_ERR);
167             throw new BuildException(err,getLocation());
168         }
169         getParametersKeeper().addParameter(attr);
170     }
171
172
173
174     /**
175      * Instructs this task what kinds of fixture informaton
176      * should be passed to the child project. By default only
177      * properties are passed on.
178      * @since JWare/AntX 0.4
179      **/

180     public void setPassthru(FixturePassthru passthru)
181     {
182         require_(passthru!=null,"setPassthru- nonzro option");
183         m_passthru = FixturePassthru.from(passthru.getIndex());//NB:normalize
184
}
185
186
187
188     /**
189      * Returns the fixture passthru setting to be used when this
190      * caller runs its targets. Never returns <i>null</i>;
191      * will return <span class="src">PROPERTIES</span> if
192      * not set explicitly.
193      * @since JWare/AntX 0.4
194      **/

195     public final FixturePassthru getPassthruOption()
196     {
197         return m_passthru;
198     }
199
200
201
202     /**
203      * Sets this task's list of steps. These steps will be
204      * called in order from a partitioned child project
205      * when this task is executed.
206      * @param setOfStepNames the comma-delimited list of names
207      **/

208     public void setSteps(String JavaDoc setOfStepNames)
209     {
210         require_(!Tk.isWhitespace(setOfStepNames),
211                  "setStps- nonwspc list");
212         m_stepNames = setOfStepNames;
213     }
214
215
216     /**
217      * Returns this task's comma-delimited list of step names.
218      * Will return <i>null</i> if never set. By default, all
219      * steps must exist within the same target as this task.
220      **/

221     public String JavaDoc getStepNamesList()
222     {
223         return m_stepNames;
224     }
225
226
227
228     /**
229      * Sets this task's list of targets. These targets will
230      * be called in order from a partitioned child project
231      * when this task is executed.
232      * @param setOfTargetNames the comma-delimited list of names
233      **/

234     public void setTargets(String JavaDoc setOfTargetNames)
235     {
236         require_(!Tk.isWhitespace(setOfTargetNames),
237                  "setTrgs- nonwspc list");
238         m_targetNames = setOfTargetNames;
239     }
240
241
242     /**
243      * Returns this task's comma-delimited list of target names.
244      * Will return <i>null</i> if never set.
245      **/

246     public String JavaDoc getTargetNamesList()
247     {
248         return m_targetNames;
249     }
250
251
252
253     /**
254      * Sets this task's list of macros. These macros will be
255      * called in order from the current project's partition when
256      * this task is executed.
257      * @param setOfMacroNames the comma-delimited list of macros
258      * @since JWare/AntX 0.5
259      * @.sideeffect Will default mode to "local" if not set.
260      **/

261     public void setMacros(String JavaDoc setOfMacroNames)
262     {
263         require_(!Tk.isWhitespace(setOfMacroNames),
264                  "setMacros- nonwspc list");
265         m_macroNames = setOfMacroNames;
266         if (!m_modeInited) {
267             setMode(ExecutionMode.LOCAL.getValue());
268         }
269     }
270
271
272     /**
273      * Returns this task's comma-delimited list of macro names.
274      * Will return <i>null</i> if never set. By default, all
275      * macros must exist within the same project as this task.
276      * @since JWare/AntX 0.5
277      **/

278     public String JavaDoc getMacroNamesList()
279     {
280         return m_macroNames;
281     }
282
283
284
285     /**
286      * Tells this tasks to execute items locally (within current
287      * project).
288      * @param Xmodestring either "local" or "isolated"
289      * @since JWare/AntX 0.4
290      **/

291     public void setMode(String JavaDoc Xmodestring)
292     {
293         require_(Xmodestring!=null,"setMode- nonzro string");
294         m_Xmode = ExecutionMode.from(Xmodestring,m_Xmode);
295     }
296
297
298
299     /**
300      * Returns this task's execution mode. Never returns <i>null</i>;
301      * will return <span class="src">ISOLATED</span> if never set.
302      * @since JWare/AntX 0.4
303      **/

304     public ExecutionMode getMode()
305     {
306         return m_Xmode;
307     }
308
309
310
311     //Required sequence of steps (can be specified by subclass "later")
312
//Default way of specifying a set of steps is using a comma-delimited list
313
//in "steps" or "targets" attribute.
314
private String JavaDoc m_stepNames;
315     private String JavaDoc m_targetNames;
316     private String JavaDoc m_macroNames;
317     private FixturePassthru m_passthru = FixturePassthru.PROPERTIES;/* NB: Ant dflt */
318     private ExecutionMode m_Xmode= ExecutionMode.ISOLATED;
319     private boolean m_modeInited;
320 }
321
322 /* end-of-CallForEachTask.java */
323
Popular Tags