KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > idaremedia > antx > condition > solo > AssertTask


1 /**
2  * $Id: AssertTask.java 186 2007-03-16 13:42:35Z ssmc $
3  * Copyright 2002-2005 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 as published by the
8  * Free Software Foundation; either version 2.1 of the License, or (at your option) any
9  * 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 (GNU Lesser General Public License) 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 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.condition.solo;
30
31 import java.io.File JavaDoc;
32 import java.text.MessageFormat JavaDoc;
33
34 import org.apache.tools.ant.AntTypeDefinition;
35 import org.apache.tools.ant.BuildException;
36 import org.apache.tools.ant.ComponentHelper;
37 import org.apache.tools.ant.DynamicAttribute;
38 import org.apache.tools.ant.Project;
39 import org.apache.tools.ant.taskdefs.condition.Condition;
40 import org.apache.tools.ant.types.Path;
41 import org.apache.tools.ant.types.Reference;
42
43 import com.idaremedia.antx.AntX;
44 import com.idaremedia.antx.Iteration;
45 import com.idaremedia.antx.NoiseLevel;
46 import com.idaremedia.antx.StringEquality;
47 import com.idaremedia.antx.helpers.Tk;
48 import com.idaremedia.antx.apis.BuildAssertionException;
49 import com.idaremedia.antx.condition.FileNotEmpty;
50 import com.idaremedia.antx.condition.ShortHandConditions;
51 import com.idaremedia.antx.condition.URIable;
52 import com.idaremedia.antx.parameters.Handling;
53 import com.idaremedia.antx.parameters.IsA;
54
55 /**
56  * Base class for Eiffelisque Design-by-Contract assertion tasks. Usually mapped to the
57  * &lt;assert&gt; Ant task.
58  * <p>
59  * Using any of the attribute-based inlined shortcuts to setup the assertion's condition,
60  * forces the assertion into a single-condition mode where only that one (inlined)
61  * condition will be permitted.
62  * <p>
63  * <b>Example usage:</b><pre>
64  * &lt;assert antIs="1.5.4"/&gt;
65  * &lt;assert antLike="^.*version 1\.[5-9].*"/&gt;
66  *
67  * &lt;assert istrue="${j2se14.present}"/&gt;
68  * &lt;assert isnotset="build.number"/&gt;
69  * &lt;assert isfile="${buildnum.sql.file}" filepath="${sqlfiles.path}/&gt;
70  * &lt;assert isnotwhitespace="cvs.revision" isa="variable"/&gt;
71  * &lt;assert isnumeric="${build.number}"/&gt;
72  * &lt;assert matches="(internal)|(distribution)" value="${build.type}"/&gt;
73  * &lt;assert isref="build.copyfilters" class="org.apache.tools.ant.types.PatternSet"/&gt;
74  *
75  * &lt;<b>assert</b> logic="or" msgid="require.j2se13"&gt;
76  * &lt;isset property="j2se13.present"/&gt;
77  * &lt;isset property="j2se14.present"/&gt;
78  * &lt;/assert&gt;
79  *
80  * &lt;<b>assert</b> failproperty="dirty.build" msgid="require.dist.clean"&gt;
81  * &lt;isset property="build.type"&gt;
82  * &lt;equals match="${DISTRIBUTION}" property="dist.type"/&gt;
83  * &lt;noneset&gt;
84  * &lt;property value="build.number"&gt;
85  * &lt;property value="fetch.disable"&gt;
86  * &lt;property value="clean.disable"&gt;
87  * &lt;variable value="build.duration"&gt;
88  * &lt;reference value="buildnum"&gt;
89  * &lt;/noneset&gt;
90  * &lt;/assert&gt;
91  *
92  * <i><b>For Ant 1.6 or later:</b></i>
93  * &lt;typedef name="moonisright" classname="..."/&gt; <i>[your condition impl]</i>
94  * &lt;<b>assert</b>&gt;
95  * &lt;<b>moonisright</b> date=${DSTAMP}.../&gt;
96  * &lt;/assert&gt;
97  * -OR-
98  * &lt;<b>assert</b> moonisright="${DSTAMP}"/&gt;
99  * </pre>
100  *
101  * @since JWare/AntX 0.1 (was AssertionRule)
102  * @author ssmc, &copy;2002-2005 <a HREF="http://www.jware.info">iDare&nbsp;Media,&nbsp;Inc.</a>
103  * @version 0.5
104  * @.safety single
105  * @.group api,infra
106  * @.expects Ant 1.6 or later for automatic freeform
107  **/

108
109 public class AssertTask extends CompoundRuleTask
110     implements ShortHandConditions, FreeformRule, DynamicAttribute
111 {
112     /**
113      * Initializes a new AssertTask instance.
114      **/

115     public AssertTask()
116     {
117         super(AntX.rules+"assert");
118     }
119
120
121     /**
122      * Initializes a new CV-labeled AssertTask instance.
123      * @param iam CV-label (non-null)
124      **/

125     public AssertTask(String JavaDoc iam)
126     {
127         super(iam);
128     }
129
130
131     /**
132      * Initializes a new optionally embedded AssertTask subclass.
133      * @param iam CV-label (non-null)
134      * @param embedded <i>true</i> if act like embedded rule
135      * @param droppable <i>true</i> if can be disabled globally
136      **/

137     protected AssertTask(String JavaDoc iam, boolean embedded, boolean droppable)
138     {
139         super(iam,embedded);
140         m_droppable = droppable;
141     }
142
143
144     /**
145      * Initializes the enclosing project for this task. Also
146      * updates internal project-component helpers.
147      **/

148     public void setProject(Project project)
149     {
150         super.setProject(project);
151         m_shh.setProject(project);
152     }
153
154
155     /**
156      * Returns <i>true</i> if this assertion pays attention to
157      * the fixture's "disable assertions" option(s). Is <i>true</i>
158      * by default.
159      * @since JWare/AntX 0.4
160      **/

161     public final boolean isDroppable()
162     {
163         return m_droppable;
164     }
165
166 // ---------------------------------------------------------------------------------------
167
// Parameters:
168
// ---------------------------------------------------------------------------------------
169

170     /**
171      * Sets name of the property set if this assertion fails. Example usage:
172      * <code>&lt;ensure isfile="${build.log}" failproperty="errs.no.logfile"/&gt;</code>
173      **/

174     public final void setFailProperty(String JavaDoc property)
175     {
176         require_(!Tk.isWhitespace(property),"setfailp- nonwspc");
177         setUpdateProperty(property);
178     }
179
180
181     /**
182      * Returns the property updated if this assertion fails. Returns
183      * default property-name if this attribute never set.
184      **/

185     public final String JavaDoc getFailProperty()
186     {
187         return getUpdateProperty();
188     }
189
190
191     /**
192      * Sets value to use for failure property if this assertion fails.
193      * Default value is string "<i>true</i>."
194      **/

195     public final void setFailValue(String JavaDoc failPropertyValue)
196     {
197         setUpdatePropertyValue(failPropertyValue);
198     }
199
200
201     /**
202      * Returns this assertion's fail property value. Returns "<i>true</i>"
203      * if never explicitly set.
204      **/

205     public final String JavaDoc getFailValue()
206     {
207         return getUpdatePropertyValue();
208     }
209
210
211     /**
212      * Sets the default condition combining logic operator for
213      * this assertion. Defaults to 'anding' multiple conditions. Example
214      * usage: <pre>
215      * &lt;require logic="or"&gt;
216      * &lt;isset property="j2se14.present"/&gt;
217      * &lt;isset property="j2ee15.present"/&gt;
218      * &lt;/require&gt;
219      * </pre>
220      **/

221     public final void setLogic(BooleanRule.Operator logic)
222     {
223         setDefaultCombineOperator(logic);
224     }
225
226
227     /**
228      * Returns the combine logic of this task. Defaults to <i>AND</i>
229      * if never set.
230      * @since JWare/AntX 0.3
231      **/

232     public final BooleanRule.Operator getLogic()
233     {
234         return getDefaultCombineOperator();
235     }
236
237
238     /**
239      * Sets this assertion to use an existing build rule as its
240      * definition. The reference will be evaluated (and verified)
241      * the first time this task is evaluated.
242      * @param ruleId build rule reference id (non-null)
243      * @since JWare/AntX 0.2
244      **/

245     public final void setRuleId(Reference ruleId)
246     {
247         setReferralReference(ruleId);
248     }
249
250
251     /**
252      * Sets an inlined message to be displayed if assertion fails.
253      * Diagnostics aid.
254      **/

255     public final void setMsg(String JavaDoc msg)
256     {
257         if (!Tk.isWhitespace(msg)) {
258             m_defaultMsg = uistrs().get("brul.assert.failed.lead",msg);
259         } else {
260             m_defaultMsg = msg;
261         }
262     }
263
264
265     /**
266      * Returns this task's inlined default message. Returns
267      * <i>null</i> if never set.
268      */

269     public final String JavaDoc getDefaultMsg()
270     {
271         return m_defaultMsg;
272     }
273
274
275 // ---------------------------------------------------------------------------------------
276
// Evaluation:
277
// ---------------------------------------------------------------------------------------
278

279     /**
280      * Returns <i>true</i> if the given referral's effect is undefined or
281      * less-drastic than an error.
282      * @since JWare/AntX 0.2
283      **/

284     protected boolean isIncompatibleReferral(ShareableCondition rule)
285     {
286         NoiseLevel effect = rule.getFailureEffect();
287         if (NoiseLevel.isAsBadAs(effect,NoiseLevel.ERROR)) {
288             return false;
289         }
290         return true;
291     }
292
293
294
295     /**
296      * Determines if this task should blindly return <i>true</i> because
297      * all build script assertions have been disabled.
298      * @since JWare/AntX 0.4
299      **/

300     protected final boolean isDropped()
301     {
302         return isDroppable() &&
303             Iteration.defaultdefaults().isAssertionsDisabled();
304     }
305
306
307
308     /**
309      * Called to record this conditon's evaluation results. For
310      * assertions a <i>false</i> result is very bad. <i>true</i> results
311      * are basically ignored.
312      **/

313     protected void setEvalResult(boolean istrue, final String JavaDoc listing)
314         throws BuildException
315     {
316         String JavaDoc prop = getFailProperty();
317
318         if (!istrue) {
319             String JavaDoc what = getFailValue();
320
321             if (prop!=null) {
322                 checkIfProperty_(prop,true);
323                 getProject().setNewProperty(prop, what);
324
325                 log("Assertion false; setting failure property "+prop+
326                     " to "+what, Project.MSG_DEBUG);
327             }
328
329             String JavaDoc errmsg;
330             if (getMsgId()==null) {
331                 String JavaDoc inlined = getDefaultMsg();
332                 //Default if no inlined or inlined contains unresolved properties
333
if (inlined==null) {
334                     errmsg = uistrs().get("brul.assert.failed",listing);
335                 } else if (inlined.indexOf("${")>=0) {
336                     errmsg = inlined;
337                 } else {
338                     errmsg = MessageFormat.format(inlined,new Object JavaDoc[]{listing});
339                 }
340             } else {
341                 errmsg = getMsg(newMsgGetter(listing));
342             }
343
344             violationOccured(errmsg);
345
346             throw new BuildAssertionException(errmsg, getLocation());
347
348         } else if (prop!=null) {
349             String JavaDoc state = "true";
350             if (isDropped()) {
351                 state += " (disabled)";
352             }
353             log("Assertion "+state+"; not setting failure property "+prop,
354                 Project.MSG_DEBUG);
355         }
356     }
357
358
359     /**
360      * Evaluates this assertion condition. If assertion condition
361      * not met, this evaluation throws a build exception immediately;
362      * so never returns <i>false</i>.
363      * @throws BuildAssertionException if assertion <i>false</i>
364      **/

365     public boolean eval() throws BuildException
366     {
367         if (runReferral()) {
368             return getReferral().eval(new Referee());
369         }
370
371         if (isDropped()) {
372             return true;
373         }
374
375         verifyCanExecute_("eval");
376
377         if (m_shh.isActivated()) {
378             return defaultSingleConditionEval();
379
380         }
381         return defaultMultipleConditionEval();
382     }
383
384
385
386     /**
387      * Called whenever this assertion's condition has not been met.
388      * Subclasses can extend the default response which simply logs
389      * and error message.
390      * @param ermsg error message
391      **/

392     protected void violationOccured(String JavaDoc ermsg)
393     {
394         if (ermsg==null) {
395             ermsg= uistrs().get("brul.assert.failed.default");
396         }
397         log(ermsg, Project.MSG_ERR);
398     }
399
400
401 // ---------------------------------------------------------------------------------------
402
// Free-form (Application) Nested Elements:
403
// ---------------------------------------------------------------------------------------
404

405     /**
406      * Adds an arbitrary application-defined condition to
407      * this assertion.
408      * @param c custom condition definition (non-null)
409      * @since JWare/AntX 0.3
410      **/

411     public void addConfigured(Condition c)
412     {
413         require_(c!=null,"add- nonzro condition");
414         xaddCondition(c);
415     }
416     
417     
418     
419     /**
420      * Adds an arbitrary appication-defined condition shorthand to this
421      * assertion. The name of the parameter must be the typedef'd name of
422      * the condition (which must be all lowercased to work with Ant's dynamic
423      * attribute facility).
424      * @param name condition name (no namespace)
425      * @param value condition evaluation URI fragment (non-null)
426      * @since JWare/AntX 0.5
427      * @throws BuildException if attribute's name is not a valid URIable condition.
428      **/

429     public void setDynamicAttribute(String JavaDoc name, String JavaDoc value)
430     {
431         require_(name!=null, "setFreeform- nonzro condition name");
432         require_(value!=null,"setFreeform- nonzro uri fragment");
433
434         boolean ok = false;
435         Project P = getProject();
436         
437         AntTypeDefinition td = ComponentHelper.getComponentHelper(P).getDefinition(name);
438         if (td!=null) {
439             Class JavaDoc cls = td.getExposedClass(P);
440             if (cls!=null && URIable.class.isAssignableFrom(cls)) {
441                 URIable c = (URIable)td.create(P);
442                 c.xsetFromURI(value);
443                 m_shh.activateCondition(c,"set"+name);
444                 ok = true;
445             }
446         }
447         if (!ok) {
448             String JavaDoc err = getAntXMsg("task.unsupported.attr",getTaskName(),name);
449             log(err,Project.MSG_ERR);
450             throw new BuildException(err,getLocation());
451         }
452     }
453
454 // ---------------------------------------------------------------------------------------
455
// ShortHand-Condition Definitions:
456
// ---------------------------------------------------------------------------------------
457

458     /**
459      * Attribute-shortcut for a single 'istrue' condition; for
460      * example: <code>&lt;ensure istrue="${jdk14.present}"/&gt;</code>
461      **/

462     public void setIsTrue(String JavaDoc value)
463     {
464         m_shh.setIsTrue(value);
465     }
466
467
468     /**
469      * Attribute-shortcut for a single 'isfalse' condition; for
470      * example: <code>&lt;require isfalse="${jdk14.present}"/&gt;</code>
471      **/

472     public void setIsFalse(String JavaDoc value)
473     {
474         m_shh.setIsFalse(value);
475     }
476
477
478     /**
479      * Attribute-shortcut for a single 'isset' condition; for
480      * example: <code>&lt;require isset="stem"/&gt;</code>
481      **/

482     public void setIsSet(String JavaDoc property)
483     {
484         m_shh.setIsSet(property);
485     }
486
487
488     /**
489      * Attribute-shortcut for a single 'issettrue' condition; for
490      * example: <code>&lt;assert issettrue="test.engine.present"/&gt;</code>
491      * @since JWare/AntX 0.2
492      **/

493     public void setIsSetTrue(String JavaDoc property)
494     {
495         m_shh.setIsSetTrue(property);
496     }
497
498
499     /**
500      * Attribute-shortcut for a single 'isnotset' condition; for
501      * example: <code>&lt;require isnotset="build.number"/&gt;</code>
502      **/

503     public void setIsNotSet(String JavaDoc property)
504     {
505         m_shh.setIsNotSet(property);
506     }
507
508
509     /**
510      * Set the type-cast modifier for this task's short-hand flex
511      * condition.
512      * @param isa the value source for short-hand condition
513      * @since JWare/AntX 0.2
514      **/

515     public void setIsA(IsA isa)
516     {
517         m_shh.setIsA(isa);
518     }
519
520
521     /**
522      * Attribute-shortcut for a single 'varset' condition; for
523      * example: <code>&lt;require varset="is.distrib"/&gt;</code>
524      * @since JWare/AntX 0.2
525      **/

526     public void setVarSet(String JavaDoc variable)
527     {
528         m_shh.setVarSet(variable);
529     }
530
531
532     /**
533      * Attribute-shortcut for a single 'varnotset' condition; for
534      * example: <code>&lt;require varnotset="__loopcount"/&gt;</code>
535      **/

536     public void setVarNotSet(String JavaDoc variable)
537     {
538         m_shh.setVarNotSet(variable);
539     }
540
541
542     /**
543      * Attribute-shortcut for a single 'varsettrue' condition; for
544      * example: <code>&lt;assert varsettrue="loop.isdebug"/&gt;</code>
545      * @since JWare/AntX 0.2
546      **/

547     public void setVarSetTrue(String JavaDoc variable)
548     {
549         m_shh.setVarSetTrue(variable);
550     }
551
552
553     /**
554      * Attribute-shortcut for checking existence of a reference;
555      * for example: <code>&lt;assert isref="test.sources"/&gt;</code>
556      **/

557     public void setIsRef(String JavaDoc refId)
558     {
559         m_shh.setIsRef(refId);
560     }
561
562
563     /**
564      * Parameter short-hand for a &lt;not&gt;'isreference' condition.
565      * @since JWare/AntX 0.5
566      **/

567     public void setIsNotRef(String JavaDoc refId)
568     {
569         m_shh.setIsNotRef(refId);
570     }
571
572
573     /**
574      * Specifies a required class for an is-reference condition.
575      * @see #setIsRef
576      **/

577     public void setClass(String JavaDoc clzId)
578     {
579         m_shh.setClassName(clzId);
580     }
581
582
583     /**
584      * Specifies the leniency of the kind-of-class check in an
585      * is-reference condition.
586      * @see #setIsRef
587      **/

588     public void setIsKindOf(boolean isKindOf)
589     {
590         m_shh.setIsKindOf(isKindOf);
591     }
592
593
594     /**
595      * Attribute-shortcut for a single 'anyset' condition; for
596      * example: <code>&lt;assert anyset="ant14.present,ant15.present"/&gt;</code>
597      * @since JWare/AntX 0.2
598      **/

599     public void setAnySet(String JavaDoc properties)
600     {
601         m_shh.setAnySet(properties);
602     }
603
604
605     /**
606      * Attribute-shortcut for a single 'allset' condition; for
607      * example: <code>&lt;assert allset="junit.present,log4j.present"/&gt;</code>
608      * @since JWare/AntX 0.2
609      **/

610     public void setAllSet(String JavaDoc properties)
611     {
612         m_shh.setAllSet(properties);
613     }
614
615
616     /**
617      * Attribute-shortcut for a single 'allset' condition; for
618      * example:
619      * <span class="src">&lt;assert allsetlike="^build\..*"
620      * whitespace="reject"/&gt;</span>.
621      * @param pattern the filtering pattern for all script
622      * properties
623      * @since JWare/AntX 0.4
624      **/

625     public void setAllSetLike(String JavaDoc pattern)
626     {
627         m_shh.setAllSetLike(pattern);
628     }
629
630
631     /**
632      * Attribute-shortcut for a single 'noneset' condition; for
633      * example: <code>&lt;assert noneset="build.number,build.time"/&gt;</code>
634      * @since JWare/AntX 0.2
635      **/

636     public void setNoneSet(String JavaDoc properties)
637     {
638         m_shh.setNoneSet(properties);
639     }
640
641 // ---------------------------------------------------------------------------------------
642

643     /**
644      * Attribute-shortcut for a single 'isboolean' condition; for
645      * example: <code>&lt;assert isboolean="${jprobe.isdebug}"/&gt;</code>
646      * @since JWare/AntX 0.2
647      **/

648     public void setIsBoolean(String JavaDoc value)
649     {
650         m_shh.setIsBoolean(value);
651     }
652
653
654     /**
655      * Attribute-shortcut for a single 'isnumeric' condition; for
656      * example: <code>&lt;assert isnumeric="${build.number}"/&gt;</code>
657      **/

658     public void setIsNumeric(String JavaDoc value)
659     {
660         m_shh.setIsNumeric(value);
661     }
662
663
664     /**
665      * Set the 'greather-than-or-equal' modifier for a short-hand
666      * 'isnumeric' condition.
667      **/

668     public void setGT(String JavaDoc gt)
669     {
670         m_shh.setGT(gt);
671     }
672
673
674     /**
675      * Sets the 'greather-than' modifier for a short-hand
676      * 'isnumeric' condition.
677      **/

678     public void setGTE(String JavaDoc gte)
679     {
680         m_shh.setGTE(gte);
681     }
682
683
684     /**
685      * Sets the 'less-than' modifier for a short-hand 'isnumeric
686      * condition.
687      **/

688     public void setLT(String JavaDoc lt)
689     {
690         m_shh.setLT(lt);
691     }
692
693
694     /**
695      * Sets the 'less-than-or-equal' modifier for a short-hand
696      * 'isnumeric' condition.
697      **/

698     public void setLTE(String JavaDoc lte)
699     {
700         m_shh.setLTE(lte);
701     }
702
703
704 // ---------------------------------------------------------------------------------------
705

706     /**
707      * Attribute-shortcut for checking existence of a file;
708      * for example: <code>&lt;ensure isfile="${build.logfile}"/&gt;</code>
709      **/

710     public void setIsFile(File JavaDoc file)
711     {
712         m_shh.setIsFile(file);
713     }
714
715
716     /**
717      * Attribute-shortcut for checking existence of a directory;
718      * for example: <code>&lt;ensure isdirectory="${module.classes}"/&gt;</code>
719      **/

720     public void setIsDirectory(File JavaDoc directory)
721     {
722         m_shh.setIsDirectory(directory);
723     }
724
725
726     /**
727      * Attribute-shortcut for checking that a file exists and is not empty;
728      * for example: <code>&lt;assert filenotempty="${sql.results}"/&gt;</code>
729      * @since JWare/AntX 0.2
730      **/

731     public void setFileNotEmpty(File JavaDoc file)
732     {
733         FileNotEmpty t= new FileNotEmpty(file,getProject());
734         m_shh.activateCondition(t,"setFileNotEmpty");
735     }
736
737
738     /**
739      * Attribute-shortcut for a single 'isresource' condition; for
740      * example: <code>&lt;assert isresource="${build.uistrs}"/&gt;</code>
741      **/

742     public void setIsResource(String JavaDoc resource)
743     {
744         m_shh.setIsResource(resource);
745     }
746
747
748     /**
749      * Attribute-shortcut for a single 'isclass' condition; for
750      * example: <code>&lt;assert isclass="junit.framework.Assert"/&gt;</code>
751      * @param classname name of class to verify (can be loaded)
752      **/

753     public void setIsClass(String JavaDoc classname)
754     {
755         m_shh.setIsClass(classname);
756     }
757
758
759     /**
760      * Specifies a lookup classpath for a shorthand 'available'
761      * condition.
762      **/

763     public void setClasspath(Path clsp)
764     {
765         m_shh.setClasspath(clsp);
766     }
767
768
769     /**
770      * Specifies a lookup filepath for a shorthand 'available'
771      * condition.
772      * @since JWare/AntX 0.2
773      **/

774     public void setFilepath(Path filp)
775     {
776         m_shh.setFilepath(filp);
777     }
778
779
780     /**
781      * Specifies a lookup classpath-ref for an inlined 'available'
782      * condition.
783      **/

784     public void setClasspathRef(Reference cpr)
785     {
786         m_shh.setClasspathRef(cpr);
787     }
788
789
790     /**
791      * Specifies Ant's runtime classes should be included for
792      * an inlined 'isclass' condition; like <code>&lt;assert isclass="foo"
793      * systemclasses="false"/&gt;</code>.
794      * @param included <i>false</i> if system classes excluded
795      * @since JWare/AntX 0.2
796      **/

797     public void setSystemClasses(boolean included)
798     {
799         m_shh.setSystemClasses(included);
800     }
801
802
803 // ---------------------------------------------------------------------------------------
804
/**
805      * Shortcut for checking the OS's family name; for example:
806      * <code>&lt;require osfamily="unix"/&gt;</code>
807      **/

808     public void setOSFamily(String JavaDoc family)
809     {
810         m_shh.setOSFamily(family);
811     }
812
813
814     /**
815      * Shortcut for checking the OS's information; for example:
816      * <code>&lt;require os="unix,Linux,i686"/&gt;</code>
817      * @since JWare/AntX 0.4
818      **/

819     public void setOS(String JavaDoc selector)
820     {
821         m_shh.setOS(selector);
822     }
823
824
825     /**
826      * Shortcut for checking whether a web server is alive or
827      * not; for example: <code>&lt;assert httpalive="http://pet.mycompany.com"/&gt;</code>
828      * @since JWare/AntX 0.3
829      **/

830     public void setHttpAlive(String JavaDoc url)
831     {
832         m_shh.setHttpAlive(url);
833     }
834
835
836 // ---------------------------------------------------------------------------------------
837

838     /**
839      * Attribute-shortcut for checking whether a property's value is
840      * all whitespace; for example:
841      * <code>&lt;require isnotwhitespace="${module.title}"/&gt;</code>
842      **/

843     public void setIsNotWhitespace(String JavaDoc value)
844     {
845         m_shh.setIsNotWhitespace(value);
846     }
847
848
849     /**
850      * Attribute-shorthand for checking an '<i>equals</i>' condition. Most
851      * useful during task build-file verification; for example,
852      * <code>&lt;assert equals="com.idaremedia.antx" value="${stem}"/&gt;</code>
853      * @param arg1 value against which other arg ('value') compared
854      **/

855     public void setEquals(String JavaDoc arg1)
856     {
857         StringEquality t= m_shh.getEqualityCondition();
858         t.setKnownArg(arg1);
859         m_shh.activateCondition(t,"setEquals");
860     }
861
862
863     /**
864      * Attribute-shortcut for checking a '<i>notequals</i>' condition;
865      * for example, <code>&lt;assert notequals="debug" ignorecase="true"
866      * value="${build.type}"/&gt;</code>
867      * @param arg1 value against which other arg ('value') compared
868      **/

869     public void setNotEquals(String JavaDoc arg1)
870     {
871         StringEquality t= m_shh.getEqualityCondition();
872         t.setKnownArg(arg1);
873         t.setNegate(true);
874         m_shh.activateCondition(t,"setNotEquals");
875     }
876
877
878     /**
879      * Attribute-shortcut for checking a '<i>startswith</i>' condition; for
880      * example, <code>&lt;assert startswith="com.idaremedia." value="${stem}"/&gt;</code>
881      * @param arg1 value which other arg ('value') must start-with
882      **/

883     public void setStartsWith(String JavaDoc arg1)
884     {
885         StringEquality t= m_shh.getEqualityCondition();
886         t.setKnownArg(arg1);
887         t.setOperator(StringEquality.OP_STARTSWITH);
888         m_shh.activateCondition(t,"setStartsWith");
889     }
890
891
892     /**
893      * Attribute-shortcut for checking a '<i>endswith</i>' condition; for
894      * example, <code>&lt;assert endswith=".xml" ignorecase="true" value="${filename}"/&gt;</code>
895      * @param arg1 value which other arg ('value') must end-with
896      **/

897     public void setEndsWith(String JavaDoc arg1)
898     {
899         StringEquality t= m_shh.getEqualityCondition();
900         t.setKnownArg(arg1);
901         t.setOperator(StringEquality.OP_ENDSWITH);
902         m_shh.activateCondition(t,"setEndsWith");
903     }
904
905
906     /**
907      * Attribute-shortcut for checking a '<i>matches</i>' condition; for
908      * example, <code>&lt;assert matches="(internal)|(dist)" value="${build.type}"/&gt;</code>
909      * @param pattern pattern against which other arg ('value') matched
910      **/

911     public void setMatches(String JavaDoc pattern)
912     {
913         m_shh.setMatches(pattern);
914     }
915
916
917     /**
918      * Attribute-shortcut for checking a '<i>contains</i>' condition; for example,
919      * <code>&lt;assert contains="idaremedia.antx" value="${stem}"/&gt;</code>
920      * @param substring substring which must exist in other arg ('value')
921      **/

922     public void setContains(String JavaDoc substring)
923     {
924         StringEquality t= m_shh.getEqualityCondition();
925         t.setKnownArg(substring);
926         t.setOperator(StringEquality.OP_CONTAINS);
927         m_shh.activateCondition(t,"setContains");
928     }
929
930
931     /**
932      * Sets the unknown value being compared in a inlined equality condition.
933      * @param value the second (unknown) value to match
934      **/

935     public void setValue(String JavaDoc value)
936     {
937         m_shh.setValue(value);
938     }
939
940
941     /**
942      * Sets the unknown value in an inlined equality condition as a variable
943      * property's name. The exported property's value will be read at comparison
944      * time.
945      * @param variable the variable whose contents will be matched
946      * @since JWare/AntX 0.2
947      **/

948     public void setVariable(String JavaDoc variable)
949     {
950         m_shh.setVariable(variable);
951     }
952
953
954     /**
955      * Synonym for {@linkplain #setVariable setVariable}.
956      **/

957     public final void setVar(String JavaDoc variable)
958     {
959         setVariable(variable);
960     }
961
962
963     /**
964      * Sets the unknown value in an inlined equality condition as a property's
965      * name. The property's value will be read at comparison time.
966      * @param property the property whose contents will be matched
967      * @since JWare/AntX 0.2
968      **/

969     public void setProperty(String JavaDoc property)
970     {
971         m_shh.setProperty(property);
972     }
973
974
975     /**
976      * Sets the unknown value in an inlined equality condition as a reference's
977      * name. The reference's (stringified) value will be read at comparison time.
978      * @param refid the reference whose contents will be matched
979      * @since JWare/AntX 0.2
980      **/

981     public void setReference(String JavaDoc refid)
982     {
983         m_shh.setReference(refid);
984     }
985
986 // ---------------------------------------------------------------------------------------
987

988     /**
989      * Defines short hand &lt;antversion is="&#8230;"/&gt; condition.
990      * @since JWare/AntX 0.4
991      **/

992     public void setAntIs(String JavaDoc version)
993     {
994         m_shh.setAntIs(version);
995     }
996
997
998     /**
999      * Defines short hand &lt;antversion pattern="&#8230;"/&gt;
1000     * condition.
1001     * @since JWare/AntX 0.4
1002     **/

1003    public void setAntLike(String JavaDoc pattern)
1004    {
1005        m_shh.setAntLike(pattern);
1006    }
1007
1008// ---------------------------------------------------------------------------------------
1009

1010    /**
1011     * Set the case-sensitivity of this task's short-hand condition.
1012     * @param ignore <i>true</i> if case insensitive
1013     **/

1014    public void setIgnoreCase(boolean ignore)
1015    {
1016        m_shh.setIgnoreCase(ignore);
1017    }
1018
1019
1020    /**
1021     * Returns <i>true</i> if task's short-hand condition's ignore case
1022     * option is activated.
1023     * @since JWare/AntX 0.2
1024     **/

1025    public boolean isIgnoreCase()
1026    {
1027        return m_shh.isIgnoreCase();
1028    }
1029
1030
1031    /**
1032     * Set the will-trim option of this task's short-hand condition
1033     * @param trim <i>true</i> if condition' unknown strings will be trimmed
1034     **/

1035    public void setTrim(boolean trim)
1036    {
1037        m_shh.setTrim(trim);
1038    }
1039
1040
1041    /**
1042     * Returns <i>true</i> if task's short-hand condition's trim strings
1043     * option is activated.
1044     * @since JWare/AntX 0.2
1045     **/

1046    public boolean willTrim()
1047    {
1048        return m_shh.willTrim();
1049    }
1050
1051
1052    /**
1053     * Set the ignore-whitespace of a inlined string comparison condition.
1054     * @param response <i>ignore</i> if all-whitespace values should be ignored
1055     * @since JWare/AntX 0.2
1056     **/

1057    public void setWhitespace(Handling response)
1058    {
1059        m_shh.setWhitespace(response);
1060    }
1061
1062
1063    /**
1064     * Returns <i>true</i> if task's short-hand condition's ignore-
1065     * whitespace option is activated.
1066     * @since JWare/AntX 0.2
1067     **/

1068    public boolean ignoreWhitespace()
1069    {
1070        return m_shh.ignoreWhitespace();
1071    }
1072
1073
1074    /**
1075     * Set the allow-synonyms modifier for this task's short-hand condition.
1076     * @param allowAll <i>true</i> if boolean synonyms are allowed
1077     * @since JWare/AntX 0.2
1078     **/

1079    public void setSynonyms(boolean allowAll)
1080    {
1081        m_shh.setSynonyms(allowAll);
1082    }
1083
1084
1085    /**
1086     * Specifies how a property-dependent condition should treat
1087     * unresolved property values.
1088     * @since JWare/AntX 0.4
1089     **/

1090    public void setMalformed(Handling response)
1091    {
1092        m_shh.setMalformed(response);
1093    }
1094
1095
1096    /**
1097     * Returns how this assertion will handle unresolved
1098     * properties.
1099     * @since JWare/AntX 0.4
1100     **/

1101    public Handling getMalformedHandling()
1102    {
1103        return m_shh.getMalformedHandling();
1104    }
1105
1106
1107// ---------------------------------------------------------------------------------------
1108

1109    /**
1110     * Diagnostic assertion for checking that a copied reference's project has not
1111     * been stomped on. Generic name but currently only implemented for 'project'
1112     * field.
1113     * @since JWare/AntX 0.3
1114     * @see #setItem1
1115     **/

1116    public void setSameField(String JavaDoc fieldname)
1117    {
1118        require_("project".equals(fieldname),"setfield- only 'project'");
1119        EqualFields t = (EqualFields)m_shh.getHalfBakedObject(EqualFields.class);
1120        m_shh.activateCondition(t,"setSameField");
1121    }
1122
1123
1124    /**
1125     * Sets the first reference for a &lt;samefield&gt; shorthand assertion.
1126     * @param refid reference identifier (non-null)
1127     * @since JWare/AntX 0.3
1128     **/

1129    public void setItem1(String JavaDoc refid)
1130    {
1131        EqualFields t = (EqualFields)m_shh.getHalfBakedObject(EqualFields.class);
1132        t.setItem1(refid);
1133    }
1134
1135
1136    /**
1137     * Sets the second reference for a &lt;samefield&gt; shorthand assertion.
1138     * @param refid reference identifier or "null" string for null comparison
1139     * @since JWare/AntX 0.3
1140     **/

1141    public void setItem2(String JavaDoc refid)
1142    {
1143        EqualFields t = (EqualFields)m_shh.getHalfBakedObject(EqualFields.class);
1144        t.setItem2(refid);
1145    }
1146
1147// ---------------------------------------------------------------------------------------
1148

1149    private String JavaDoc m_defaultMsg;
1150    private final ShortHandHelper m_shh = new ShortHandHelper(this);
1151    private boolean m_droppable=true;
1152}
1153
1154/* end-of-AssertTask.java */
1155
Popular Tags