1 | /*
|
---|
2 | * Copyright 2001-2005 The Apache Software Foundation
|
---|
3 | *
|
---|
4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
---|
5 | * you may not use this file except in compliance with the License.
|
---|
6 | * You may obtain a copy of the License at
|
---|
7 | *
|
---|
8 | * http://www.apache.org/licenses/LICENSE-2.0
|
---|
9 | *
|
---|
10 | * Unless required by applicable law or agreed to in writing, software
|
---|
11 | * distributed under the License is distributed on an "AS IS" BASIS,
|
---|
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
---|
13 | * See the License for the specific language governing permissions and
|
---|
14 | * limitations under the License.
|
---|
15 | *
|
---|
16 | */
|
---|
17 |
|
---|
18 | package org.apache.tools.ant.taskdefs.condition;
|
---|
19 |
|
---|
20 | import java.util.Enumeration;
|
---|
21 | import java.util.Vector;
|
---|
22 | import org.apache.tools.ant.ProjectComponent;
|
---|
23 | import org.apache.tools.ant.taskdefs.Available;
|
---|
24 | import org.apache.tools.ant.taskdefs.Checksum;
|
---|
25 | import org.apache.tools.ant.taskdefs.UpToDate;
|
---|
26 |
|
---|
27 | /**
|
---|
28 | * Baseclass for the <condition> task as well as several
|
---|
29 | * conditions - ensures that the types of conditions inside the task
|
---|
30 | * and the "container" conditions are in sync.
|
---|
31 | *
|
---|
32 | * @since Ant 1.4
|
---|
33 | */
|
---|
34 | public abstract class ConditionBase extends ProjectComponent {
|
---|
35 | private Vector conditions = new Vector();
|
---|
36 |
|
---|
37 | /**
|
---|
38 | * Count the conditions.
|
---|
39 | *
|
---|
40 | * @return the number of conditions in the container
|
---|
41 | * @since 1.1
|
---|
42 | */
|
---|
43 | protected int countConditions() {
|
---|
44 | return conditions.size();
|
---|
45 | }
|
---|
46 |
|
---|
47 | /**
|
---|
48 | * Iterate through all conditions.
|
---|
49 | *
|
---|
50 | * @return an enumeration to use for iteration
|
---|
51 | * @since 1.1
|
---|
52 | */
|
---|
53 | protected final Enumeration getConditions() {
|
---|
54 | return conditions.elements();
|
---|
55 | }
|
---|
56 |
|
---|
57 | /**
|
---|
58 | * Add an <available> condition.
|
---|
59 | * @param a an available condition
|
---|
60 | * @since 1.1
|
---|
61 | */
|
---|
62 | public void addAvailable(Available a) {
|
---|
63 | conditions.addElement(a);
|
---|
64 | }
|
---|
65 |
|
---|
66 | /**
|
---|
67 | * Add an <checksum> condition.
|
---|
68 | *
|
---|
69 | * @param c a Checksum condition
|
---|
70 | * @since 1.4, Ant 1.5
|
---|
71 | */
|
---|
72 | public void addChecksum(Checksum c) {
|
---|
73 | conditions.addElement(c);
|
---|
74 | }
|
---|
75 |
|
---|
76 | /**
|
---|
77 | * Add an <uptodate> condition.
|
---|
78 | *
|
---|
79 | * @param u an UpToDate condition
|
---|
80 | * @since 1.1
|
---|
81 | */
|
---|
82 | public void addUptodate(UpToDate u) {
|
---|
83 | conditions.addElement(u);
|
---|
84 | }
|
---|
85 |
|
---|
86 | /**
|
---|
87 | * Add an <not> condition "container".
|
---|
88 | *
|
---|
89 | * @param n a Not condition
|
---|
90 | * @since 1.1
|
---|
91 | */
|
---|
92 | public void addNot(Not n) {
|
---|
93 | conditions.addElement(n);
|
---|
94 | }
|
---|
95 |
|
---|
96 | /**
|
---|
97 | * Add an <and> condition "container".
|
---|
98 | *
|
---|
99 | * @param a an And condition
|
---|
100 | * @since 1.1
|
---|
101 | */
|
---|
102 | public void addAnd(And a) {
|
---|
103 | conditions.addElement(a);
|
---|
104 | }
|
---|
105 |
|
---|
106 | /**
|
---|
107 | * Add an <or> condition "container".
|
---|
108 | *
|
---|
109 | * @param o an Or condition
|
---|
110 | * @since 1.1
|
---|
111 | */
|
---|
112 | public void addOr(Or o) {
|
---|
113 | conditions.addElement(o);
|
---|
114 | }
|
---|
115 |
|
---|
116 | /**
|
---|
117 | * Add an <equals> condition.
|
---|
118 | *
|
---|
119 | * @param e an Equals condition
|
---|
120 | * @since 1.1
|
---|
121 | */
|
---|
122 | public void addEquals(Equals e) {
|
---|
123 | conditions.addElement(e);
|
---|
124 | }
|
---|
125 |
|
---|
126 | /**
|
---|
127 | * Add an <os> condition.
|
---|
128 | *
|
---|
129 | * @param o an Os condition
|
---|
130 | * @since 1.1
|
---|
131 | */
|
---|
132 | public void addOs(Os o) {
|
---|
133 | conditions.addElement(o);
|
---|
134 | }
|
---|
135 |
|
---|
136 | /**
|
---|
137 | * Add an <isset> condition.
|
---|
138 | *
|
---|
139 | * @param i an IsSet condition
|
---|
140 | * @since Ant 1.5
|
---|
141 | */
|
---|
142 | public void addIsSet(IsSet i) {
|
---|
143 | conditions.addElement(i);
|
---|
144 | }
|
---|
145 |
|
---|
146 | /**
|
---|
147 | * Add an <http> condition.
|
---|
148 | *
|
---|
149 | * @param h an Http condition
|
---|
150 | * @since Ant 1.5
|
---|
151 | */
|
---|
152 | public void addHttp(Http h) {
|
---|
153 | conditions.addElement(h);
|
---|
154 | }
|
---|
155 |
|
---|
156 | /**
|
---|
157 | * Add a <socket> condition.
|
---|
158 | *
|
---|
159 | * @param s a Socket condition
|
---|
160 | * @since Ant 1.5
|
---|
161 | */
|
---|
162 | public void addSocket(Socket s) {
|
---|
163 | conditions.addElement(s);
|
---|
164 | }
|
---|
165 |
|
---|
166 | /**
|
---|
167 | * Add a <filesmatch> condition.
|
---|
168 | *
|
---|
169 | * @param test a FilesMatch condition
|
---|
170 | * @since Ant 1.5
|
---|
171 | */
|
---|
172 | public void addFilesMatch(FilesMatch test) {
|
---|
173 | conditions.addElement(test);
|
---|
174 | }
|
---|
175 |
|
---|
176 | /**
|
---|
177 | * Add a <contains> condition.
|
---|
178 | *
|
---|
179 | * @param test a Contains condition
|
---|
180 | * @since Ant 1.5
|
---|
181 | */
|
---|
182 | public void addContains(Contains test) {
|
---|
183 | conditions.addElement(test);
|
---|
184 | }
|
---|
185 |
|
---|
186 | /**
|
---|
187 | * Add a <istrue> condition.
|
---|
188 | *
|
---|
189 | * @param test an IsTrue condition
|
---|
190 | * @since Ant 1.5
|
---|
191 | */
|
---|
192 | public void addIsTrue(IsTrue test) {
|
---|
193 | conditions.addElement(test);
|
---|
194 | }
|
---|
195 |
|
---|
196 | /**
|
---|
197 | * Add a <isfalse> condition.
|
---|
198 | *
|
---|
199 | * @param test an IsFalse condition
|
---|
200 | * @since Ant 1.5
|
---|
201 | */
|
---|
202 | public void addIsFalse(IsFalse test) {
|
---|
203 | conditions.addElement(test);
|
---|
204 | }
|
---|
205 |
|
---|
206 | /**
|
---|
207 | * Add an <isreference> condition.
|
---|
208 | *
|
---|
209 | * @param i an IsReference condition
|
---|
210 | * @since Ant 1.6
|
---|
211 | */
|
---|
212 | public void addIsReference(IsReference i) {
|
---|
213 | conditions.addElement(i);
|
---|
214 | }
|
---|
215 |
|
---|
216 | /**
|
---|
217 | * Add an arbitrary condition
|
---|
218 | * @param c a condition
|
---|
219 | * @since Ant 1.6
|
---|
220 | */
|
---|
221 | public void add(Condition c) {
|
---|
222 | conditions.addElement(c);
|
---|
223 | }
|
---|
224 | }
|
---|