KickJava   Java API By Example, From Geeks To Geeks.

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


1 /**
2  * $Id: LocalTargetTask.java 186 2007-03-16 13:42:35Z 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 java.util.List JavaDoc;
32
33 import org.apache.tools.ant.BuildException;
34 import org.apache.tools.ant.Project;
35 import org.apache.tools.ant.types.PropertySet;
36
37 import com.idaremedia.antx.AntX;
38 import com.idaremedia.antx.AntXFixture;
39 import com.idaremedia.antx.helpers.Tk;
40 import com.idaremedia.antx.solo.CopyPropertyTask;
41
42 /**
43  * Task that will execute a set of targets <em>within</em> the enclosing project. A
44  * new subproject is not created and any modifications to the fixture are seen. The
45  * named targets are <em>not</em> checked for duplication (directly or indirectly).
46  * This task is fairly straightforwardd: it just executes the targets <em>in the order
47  * you list them</em>. If you would like to execute the named targets in their own
48  * partitioned space, use the {@linkplain CallOnceTask}.
49  * <p>
50  * If at least one of the named targets does not exist in the enclosing project,
51  * <em>no</em> targets are run and a build exception is thrown.
52  * <p>
53  * <b>Example Usage:</b><pre>
54  * &lt;callinline targets="--init_a,--init_b"/&gt;
55  * &lt;callinline targets="--init_a,--init_b" haltiferror="no" tryeach="yes"/&gt;
56  * </pre>
57  *
58  * @since JWare/AntX 0.4
59  * @author ssmc, &copy;2004 <a HREF="http://www.jware.info">iDare&nbsp;Media,&nbsp;Inc.</a>
60  * @version 0.5
61  * @.safety single
62  * @.group api,helper
63  **/

64
65 public final class LocalTargetTask extends CallerTask
66 {
67     /**
68      * Initializes a new inlined target caller task.
69      **/

70     public LocalTargetTask()
71     {
72         super(AntX.flow+"callinline");
73     }
74
75
76
77     /**
78      * Initializes a new enclosed target caller task.
79      * @param iam CV-label (non-null)
80      **/

81     public LocalTargetTask(String JavaDoc iam)
82     {
83         super(iam);
84     }
85
86 // ---------------------------------------------------------------------------------------
87
// Unique Script-facing Parameters:
88
// ---------------------------------------------------------------------------------------
89

90
91     /**
92      * Initializes the names of targets to be executed inlined.
93      * @param setOfTargetNames comma-delimited list of names (non-null)
94      * @since JWare/AntX 0.4
95      **/

96     public void setTargets(String JavaDoc setOfTargetNames)
97     {
98         require_(setOfTargetNames!=null,"setTargets- nonzro names");
99         if (m_targetNames!=null) {
100             String JavaDoc error = uistrs().get("task.one.or.other.attr","targets","steps");
101             log(error,Project.MSG_ERR);
102             throw new BuildException(error,getLocation());
103         }
104         m_targetNames = setOfTargetNames;
105         m_topLevel = true;
106     }
107
108
109
110     /**
111      * Shorthand way to initialize the target name of a overridden,
112      * imported target of the same name as this task's owning target.
113      * @param importedProjectName name of imported project whose target
114      * we'd like to call (non-null)
115      * @since JWare/AntX 0.5
116      **/

117     public final void setSuper(String JavaDoc importedProjectName)
118     {
119         require_(importedProjectName!=null,"setSuper- nonzro projectname");
120         verifyInTarget_("setsuper");
121         String JavaDoc mytarget = getOwningTarget().getName();
122         setTargets(importedProjectName+"."+mytarget);
123     }
124
125
126
127     /**
128      * Returns the comma-delimited names of targets to be
129      * executed inlined. Will return <i>null</i> if never
130      * set explicitly.
131      **/

132     public final String JavaDoc getTargetNamesList()
133     {
134         return m_topLevel ? m_targetNames : null;
135     }
136
137
138
139     /**
140      * Initializes the list of steps to be executed inlined.
141      * @param setOfStepNames comma-delimited list of names (non-null)
142      * @since JWare/AntX 0.4
143      **/

144     public void setSteps(String JavaDoc setOfStepNames)
145     {
146         require_(setOfStepNames!=null,"setSteps- nonzro names");
147         if (m_targetNames!=null) {
148             String JavaDoc error = uistrs().get("task.one.or.other.attr","targets","steps");
149             log(error,Project.MSG_ERR);
150             throw new BuildException(error,getLocation());
151         }
152         m_targetNames = setOfStepNames;
153         m_topLevel = false;
154     }
155
156
157
158     /**
159      * Returns the comma-delimited names of steps to be
160      * executed inlined. Will return <i>null</i> if never
161      * set explicitly.
162      **/

163     public final String JavaDoc getStepNamesList()
164     {
165         return m_topLevel ? null : m_targetNames;
166     }
167
168
169
170     /**
171      * Adds a new fixture overlay property to this task.
172      * This property is automatically passed to each target's
173      * environment as it is executed.
174      * @param param initialized property (non-null)
175      * @since JWare/AntX 0.4
176      **/

177     public void addProperty(CopyPropertyTask param)
178     {
179         require_(param!=null,"addProperty- nonzro item");
180         getParametersKeeper().addParameter(param);
181     }
182
183
184
185     /**
186      * Adds a new fixture overlay property set to this task. The
187      * properties named by the property set are automatically
188      * copied to each target's environment before it is executed.
189      * @param param property set information (non-null)
190      * @since JWare/AntX 0.4
191      **/

192     public void addPropertySet(PropertySet param)
193     {
194         require_(param!=null,"addPropertySet- nonzro item");
195         getParametersKeeper().addParameter(param);
196     }
197
198
199
200     /**
201      * Ensures this task's list of targets is set and each target
202      * exists in enclosing project.
203      * @throws BuildException if target list is missing or at least
204      * one target does not exist.
205      **/

206     protected void verifyCanExecute_(String JavaDoc calr)
207     {
208         super.verifyCanExecute_(calr);
209
210         if (m_targetNames==null) {
211             String JavaDoc error = uistrs().get("task.needs.this.attr",
212                                         getTaskName(),"targets|steps");
213             log(error,Project.MSG_ERR);
214             throw new BuildException(error,getLocation());
215         }
216
217         List JavaDoc l= Tk.splitList(m_targetNames);
218         m_targets = l;
219
220         if (m_topLevel) {
221             String JavaDoc tn;
222             for (int i=0,N=l.size();i<N;i++) {
223                 tn = l.get(i).toString();
224                 if (!targetExists(tn)) {
225                     String JavaDoc error = uistrs().get
226                         ("flow.steplaunch.missing.target",tn,getProject().getName());
227                     log(error,Project.MSG_ERR);
228                     throw new BuildException(error,getLocation());
229                 }
230             }
231         }
232     }
233
234
235     /**
236      * Returns a filled in list of target callers for this
237      * task's list.
238      * @throws BuildException if name list invalid or a called
239      * target fails.
240      */

241     protected List JavaDoc copyOfOrderedTargetCallers()
242     {
243         verify_(m_targets!=null,"copyOf- been verified");
244
245         List JavaDoc l= m_targets;
246         List JavaDoc callers= AntXFixture.newList(l.size());
247         String JavaDoc tn;
248         LocalTargetCaller caller;
249
250         for (int i=0,N=l.size();i<N;i++) {
251             tn = l.get(i).toString();
252             caller = new LocalTargetCaller(this);
253             if (m_topLevel) {
254                 caller.setTarget(tn);
255             } else {
256                 caller.setStepName(tn);
257             }
258             transferOverlayParameters(caller);
259             callers.add(caller);
260         }
261
262         return callers;
263     }
264
265
266
267     private String JavaDoc m_targetNames;
268     private List JavaDoc m_targets;
269     private boolean m_topLevel=true;//NB:false if steps
270
}
271
272 /* end-of-LocalTargetTask.java */
273
Popular Tags