source: release-kits/wirk3/ant-scripts/tasks/antelope/src/ise/antelope/tasks/BooleanConditionTask.java@ 15023

Last change on this file since 15023 was 15023, checked in by oranfry, 16 years ago

did the bulk of the work on wirk3

File size: 5.8 KB
Line 
1/*
2* The Apache Software License, Version 1.1
3*
4* Copyright (c) 2001-2002 The Apache Software Foundation. All rights
5* reserved.
6*
7* Redistribution and use in source and binary forms, with or without
8* modification, are permitted provided that the following conditions
9* are met:
10*
11* 1. Redistributions of source code must retain the above copyright
12* notice, this list of conditions and the following disclaimer.
13*
14* 2. Redistributions in binary form must reproduce the above copyright
15* notice, this list of conditions and the following disclaimer in
16* the documentation and/or other materials provided with the
17* distribution.
18*
19* 3. The end-user documentation included with the redistribution, if
20* any, must include the following acknowlegement:
21* "This product includes software developed by the
22* Apache Software Foundation (http://www.apache.org/)."
23* Alternately, this acknowlegement may appear in the software itself,
24* if and wherever such third-party acknowlegements normally appear.
25*
26* 4. The names "The Jakarta Project", "Ant", and "Apache Software
27* Foundation" must not be used to endorse or promote products derived
28* from this software without prior written permission. For written
29* permission, please contact [email protected].
30*
31* 5. Products derived from this software may not be called "Apache"
32* nor may "Apache" appear in their names without prior written
33* permission of the Apache Group.
34*
35* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
36* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
37* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
38* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
39* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
41* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
42* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
43* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
44* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
45* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
46* SUCH DAMAGE.
47* ====================================================================
48*
49* This software consists of voluntary contributions made by many
50* individuals on behalf of the Apache Software Foundation. For more
51* information on the Apache Software Foundation, please see
52* <http://www.apache.org/>.
53*/
54package ise.antelope.tasks;
55import java.util.Enumeration;
56
57import java.util.Vector;
58
59import org.apache.tools.ant.BuildException;
60import org.apache.tools.ant.Project;
61import org.apache.tools.ant.ProjectComponent;
62import org.apache.tools.ant.Task;
63import org.apache.tools.ant.TaskAdapter;
64import org.apache.tools.ant.taskdefs.ConditionTask;
65import org.apache.tools.ant.taskdefs.condition.*;
66import org.apache.tools.ant.taskdefs.condition.Condition;
67
68import ise.antelope.tasks.condition.*;
69
70/**
71 * Wraps a ConditionBase so that the If task can use standard Ant Conditions as
72 * its evaluated boolean expression. Wrapping like this means that future
73 * additions to ConditionBase will automatically be picked up without modifying
74 * this class.
75 *
76 * @author Dale Anson
77 * @version $Revision: 1.4 $
78 * @ant.task category="control"
79 */
80public class BooleanConditionTask extends TaskAdapter {
81
82 private BooleanConditionBase cb;
83
84 private String property = null;
85 private String value = "true";
86
87 /** Constructor for BooleanConditionTask */
88 public BooleanConditionTask() {
89 cb = new BooleanConditionBase();
90 super.setProxy(cb);
91 cb.setProject(getProject());
92 }
93
94 /**
95 * Gets the proxy attribute of the BooleanConditionTask object
96 *
97 * @return The proxy value
98 */
99 public Object getProxy() {
100 return cb;
101 }
102
103 /**
104 * Sets the proxy attribute of the BooleanConditionTask object
105 *
106 * @param proxy The new proxy value
107 */
108 public void setProxy(Object proxy) {
109 super.setProxy(cb);
110 }
111
112 /**
113 * The name of the property to set. Optional.
114 *
115 * @param p The new property value
116 */
117 public void setProperty(String p) {
118 property = p;
119 }
120
121 /**
122 * The value for the property to set, if condition evaluates to true.
123 * Defaults to "true".
124 *
125 * @param v The new value value
126 */
127 public void setValue(String v) {
128 value = v;
129 }
130
131 /**
132 * Override {@link org.apache.tools.ant.Task#maybeConfigure maybeConfigure}
133 * in a way that leaves the nested tasks unconfigured until they get
134 * executed.
135 *
136 * @exception BuildException Description of Exception
137 * @since Ant 1.5
138 */
139 public void maybeConfigure() throws BuildException {
140 if (isInvalid()) {
141 super.maybeConfigure();
142 }
143 else {
144 getRuntimeConfigurableWrapper().maybeConfigure(getProject(), true);
145 }
146 }
147
148 /**
149 * Forwards to eval().
150 *
151 * @exception BuildException Description of Exception
152 */
153 public void execute() throws BuildException {
154 eval();
155 }
156
157 /**
158 * Evaluates the condition object.
159 *
160 * @return true or false, depending on the evaluation of the condition.
161 */
162 public boolean eval() {
163 maybeConfigure();
164 cb.setProject(getProject());
165 if (cb.getConditionCount() > 1) {
166 throw new BuildException("You must not nest more than one condition.");
167 }
168 if (cb.getConditionCount() < 1) {
169 throw new BuildException("You must nest one condition.");
170 }
171
172 boolean b = cb.getFirstCondition().eval();
173 if (b && property != null)
174 getProject().setNewProperty(property, value);
175 return b;
176 }
177
178}
179
Note: See TracBrowser for help on using the repository browser.