KickJava   Java API By Example, From Geeks To Geeks.

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


1 /**
2  * $Id: CallOnceTask.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 OnceTask}; usually defined as &lt;call&gt;.
45  * The CallOnceTask allows only &lt;propertyset&gt;, &lt;[copy]property&gt;, and
46  * &lt;[copy]reference&gt; declarations to be nested within it as fixture instructions
47  * for the child project.
48  * <p>
49  * <b>Example Usage:</b><pre>
50  * &lt;call steps="scrub,co,merge" failproperty="prepare.failed"&gt;
51  * &lt;property name="scrub.disable" value="false"/&gt;
52  * &lt;reference refid="copy.filters"/&gt;
53  * &lt/call&gt;
54  *
55  * &lt;call targets="--clobber,--checkout,--merge" failproperty="prepare.failed"&gt;
56  * &lt;property name="scrub.disable" value="false"/&gt;
57  * &lt;property name="start.time" variable="local.start.time"/&gt;
58  * &lt/call&gt;
59  *
60  * &lt;call macros="scrub,co,merge"&gt;
61  * &lt;attribute name="project" value="${subproject}"/&gt;
62  * &lt;property name="scrub.disable" value="false"/&gt;
63  * &lt;/call&gt;
64  * </pre>
65  *
66  * @since JWare/AntX 0.4
67  * @author ssmc, &copy;2004 <a HREF="http://www.jware.info">iDare&nbsp;Media,&nbsp;Inc.</a>
68  * @version 0.5
69  * @.safety single
70  * @.group api,infra
71  **/

72
73 public final class CallOnceTask extends OnceTask
74 {
75     /**
76      * Initializes a new CallOnceTask instance.
77      **/

78     public CallOnceTask()
79     {
80         super(AntX.flow+"call");
81     }
82
83
84
85     /**
86      * Initializes a new helper CallOnceTask instance.
87      * @param iam CV-label (non-null)
88      **/

89     public CallOnceTask(String JavaDoc iam)
90     {
91         super(iam);
92     }
93
94
95 // ---------------------------------------------------------------------------------------
96
// Unique Script-facing Parameters:
97
// ---------------------------------------------------------------------------------------
98

99     /**
100      * Adds a new fixture overlay property to this task.
101      * This property is automatically passed to each target's
102      * environment as it is executed.
103      * @param param initialized property (non-null)
104      * @since JWare/AntX 0.4
105      **/

106     public void addProperty(CopyPropertyTask param)
107     {
108         require_(param!=null,"addProperty- nonzro item");
109         getParametersKeeper().addParameter(param);
110     }
111
112
113
114     /**
115      * Adds a new fixture overlay property set to this task. The
116      * properties named by the property set are automatically
117      * copied to each target's environment before it is executed.
118      * @param param property set information (non-null)
119      * @since JWare/AntX 0.4
120      **/

121     public void addPropertySet(PropertySet param)
122     {
123         require_(param!=null,"addPropertySet- nonzro item");
124         getParametersKeeper().addParameter(param);
125     }
126
127
128     /**
129      * Adds a new configuration reference to this task. This
130      * reference is automatically copied to each target's
131      * environment as each is executed.
132      * @param param reference information (non-null)
133      * @since JWare/AntX 0.4
134      **/

135     public void addReference(CopyReferenceTask param)
136     {
137         require_(param!=null,"addReference- nonzro item");
138         getParametersKeeper().addParameter(param);
139     }
140
141
142
143     /**
144      * Adds a new macro attribute default value to this task.
145      * This attribute is automatically passed to ,em>each</em>
146      * macro when it is executed.
147      * @param attr initialized macro attribute (non-null)
148      * @since JWare/AntX 0.5
149      * @throws BuildException if this caller is not setup for macros.
150      **/

151     public void addConfiguredAttribute(InnerNameValuePair attr)
152     {
153         require_(attr!=null,"addAttribute- nonzro item");
154         if (getMacroNamesList()==null) {
155             String JavaDoc err = getAntXMsg("flow.attritem.formacros");
156             log(err,Project.MSG_ERR);
157             throw new BuildException(err,getLocation());
158         }
159         getParametersKeeper().addParameter(attr);
160     }
161
162
163
164     /**
165      * Instructs this task what kinds of fixture informaton
166      * should be passed to the child project. By default only
167      * properties are passed on.
168      * @since JWare/AntX 0.4
169      **/

170     public void setPassthru(FixturePassthru passthru)
171     {
172         require_(passthru!=null,"setPassthru- nonzro option");
173         m_passthru = FixturePassthru.from(passthru.getIndex());//NB:normalize
174
}
175
176
177
178     /**
179      * Returns the fixture passthru setting to be used when this
180      * caller runs its targets. Never returns <i>null</i>;
181      * will return <span class="src">PROPERTIES</span> if
182      * not set explicitly.
183      * @since JWare/AntX 0.4
184      **/

185     public final FixturePassthru getPassthruOption()
186     {
187         return m_passthru;
188     }
189
190
191
192     /**
193      * Sets this task's list of steps. These steps will be
194      * called in order from a partitioned child project
195      * when this task is executed.
196      * @param setOfStepNames the comma-delimited list of names
197      * @since JWare/AntX 0.4
198      **/

199     public void setSteps(String JavaDoc setOfStepNames)
200     {
201         require_(!Tk.isWhitespace(setOfStepNames),
202                  "setStps- nonwspc list");
203         m_stepNames = setOfStepNames;
204     }
205
206
207     /**
208      * Returns this task's comma-delimited list of step names.
209      * Will return <i>null</i> if never set. By default, all
210      * steps must exist within the same target as this task.
211      * @since JWare/AntX 0.4
212      **/

213     public String JavaDoc getStepNamesList()
214     {
215         return m_stepNames;
216     }
217
218
219
220     /**
221      * Sets this task's list of targets. These targets will
222      * be called in order from a partitioned child project
223      * when this task is executed.
224      * @param setOfTargetNames the comma-delimited list of names
225      * @since JWare/AntX 0.4
226      **/

227     public void setTargets(String JavaDoc setOfTargetNames)
228     {
229         require_(!Tk.isWhitespace(setOfTargetNames),
230                  "setTrgs- nonwspc list");
231         m_targetNames = setOfTargetNames;
232     }
233
234
235     /**
236      * Returns this task's comma-delimited list of target names.
237      * Will return <i>null</i> if never set.
238      * @since JWare/AntX 0.4
239      **/

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

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

272     public String JavaDoc getMacroNamesList()
273     {
274         return m_macroNames;
275     }
276
277
278
279     /**
280      * Tells this tasks to execute items locally (within current
281      * project).
282      * @param Xmodestring either "local" or "isolated"
283      * @since JWare/AntX 0.4
284      **/

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

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