| 1 |
lars |
1 |
<?php
|
|
|
2 |
/*
|
|
|
3 |
* $Id: ConditionTask.php 43 2006-03-10 14:31:51Z mrook $
|
|
|
4 |
*
|
|
|
5 |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
6 |
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
7 |
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
8 |
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
9 |
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
10 |
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
11 |
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
12 |
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
13 |
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
14 |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
15 |
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
16 |
*
|
|
|
17 |
* This software consists of voluntary contributions made by many individuals
|
|
|
18 |
* and is licensed under the LGPL. For more information please see
|
|
|
19 |
* <http://phing.info>.
|
|
|
20 |
*/
|
|
|
21 |
|
|
|
22 |
require_once 'phing/tasks/system/condition/ConditionBase.php';
|
|
|
23 |
|
|
|
24 |
/**
|
|
|
25 |
* <condition> task as a generalization of <available>
|
|
|
26 |
*
|
|
|
27 |
* <p>This task supports boolean logic as well as pluggable conditions
|
|
|
28 |
* to decide, whether a property should be set.</p>
|
|
|
29 |
*
|
|
|
30 |
* <p>This task does not extend Task to take advantage of
|
|
|
31 |
* ConditionBase.</p>
|
|
|
32 |
*
|
|
|
33 |
* @author Andreas Aderhold <andi@binarycloud.com>
|
|
|
34 |
* @copyright © 2001,2002 THYRELL. All rights reserved
|
|
|
35 |
* @version $Revision: 1.7 $ $Date: 2006-03-10 15:31:51 +0100 (Fri, 10 Mar 2006) $
|
|
|
36 |
* @access public
|
|
|
37 |
* @package phing.tasks.system
|
|
|
38 |
*/
|
|
|
39 |
class ConditionTask extends ConditionBase {
|
|
|
40 |
|
|
|
41 |
private $property;
|
|
|
42 |
private $value = "true";
|
|
|
43 |
|
|
|
44 |
/**
|
|
|
45 |
* The name of the property to set. Required.
|
|
|
46 |
*/
|
|
|
47 |
function setProperty($p) {
|
|
|
48 |
$this->property = $p;
|
|
|
49 |
}
|
|
|
50 |
|
|
|
51 |
/**
|
|
|
52 |
* The value for the property to set. Defaults to "true".
|
|
|
53 |
*/
|
|
|
54 |
function setValue($v) {
|
|
|
55 |
$this->value = $v;
|
|
|
56 |
}
|
|
|
57 |
|
|
|
58 |
/**
|
|
|
59 |
* See whether our nested condition holds and set the property.
|
|
|
60 |
*/
|
|
|
61 |
function main() {
|
|
|
62 |
|
|
|
63 |
if ($this->countConditions() > 1) {
|
|
|
64 |
throw new BuildException("You must not nest more than one condition into <condition>");
|
|
|
65 |
}
|
|
|
66 |
if ($this->countConditions() < 1) {
|
|
|
67 |
throw new BuildException("You must nest a condition into <condition>");
|
|
|
68 |
}
|
|
|
69 |
$cs = $this->getIterator();
|
|
|
70 |
if ($cs->current()->evaluate()) {
|
|
|
71 |
$this->project->setProperty($this->property, $this->value);
|
|
|
72 |
}
|
|
|
73 |
}
|
|
|
74 |
}
|