| 1 |
lars |
1 |
<?php
|
|
|
2 |
/*
|
|
|
3 |
* $Id: OsCondition.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 that tests the OS type.
|
|
|
26 |
*
|
|
|
27 |
* @author Andreas Aderhold <andi@binarycloud.com>
|
|
|
28 |
* @copyright © 2001,2002 THYRELL. All rights reserved
|
|
|
29 |
* @version $Revision: 1.8 $ $Date: 2006-03-10 15:31:51 +0100 (Fri, 10 Mar 2006) $
|
|
|
30 |
* @access public
|
|
|
31 |
* @package phing.tasks.system.condition
|
|
|
32 |
*/
|
|
|
33 |
class OsCondition implements Condition {
|
|
|
34 |
|
|
|
35 |
private $family;
|
|
|
36 |
|
|
|
37 |
function setFamily($f) {
|
|
|
38 |
$this->family = strtolower($f);
|
|
|
39 |
}
|
|
|
40 |
|
|
|
41 |
function evaluate() {
|
|
|
42 |
$osName = strtolower(Phing::getProperty("os.name"));
|
|
|
43 |
|
|
|
44 |
if ($this->family !== null) {
|
|
|
45 |
if ($this->family === "windows") {
|
|
|
46 |
return StringHelper::startsWith("win", $osName);
|
|
|
47 |
} elseif ($this->family === "mac") {
|
|
|
48 |
return (strpos($osName, "mac") !== false || strpos($osName, "darwin") !== false);
|
|
|
49 |
} elseif ($this->family === ("unix")) {
|
|
|
50 |
return (
|
|
|
51 |
StringHelper::endsWith("ix", $osName) ||
|
|
|
52 |
StringHelper::endsWith("ux", $osName) ||
|
|
|
53 |
StringHelper::endsWith("bsd", $osName) ||
|
|
|
54 |
StringHelper::startsWith("sunos", $osName) ||
|
|
|
55 |
StringHelper::startsWith("darwin", $osName)
|
|
|
56 |
);
|
|
|
57 |
}
|
|
|
58 |
throw new BuildException("Don't know how to detect os family '" . $this->family . "'");
|
|
|
59 |
}
|
|
|
60 |
return false;
|
|
|
61 |
}
|
|
|
62 |
|
|
|
63 |
}
|