Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small additions to the os condition #922

Merged
merged 10 commits into from
Jul 1, 2018
32 changes: 19 additions & 13 deletions classes/phing/tasks/system/condition/OsCondition.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php
/*
*
/**
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
Expand All @@ -27,6 +26,12 @@
*/
class OsCondition implements Condition
{
public const FAMILY_WINDOWS = 'windows';
public const FAMILY_MAC = 'mac';
public const FAMILY_UNIX = 'unix';

private const DARWIN = 'darwin';

private $family;

/**
Expand Down Expand Up @@ -56,27 +61,28 @@ public static function isFamily($family)
/**
* @param string $family
* @return bool
* @throws \BuildException
*/
public static function isOS($family)
{
$osName = strtolower(Phing::getProperty("os.name"));
$osName = strtolower(Phing::getProperty('os.name'));

if ($family !== null) {
if ($family === "windows") {
return StringHelper::startsWith("win", $osName);
if ($family === self::FAMILY_WINDOWS) {
return StringHelper::startsWith('win', $osName);
}

if ($family === "mac") {
return (strpos($osName, "mac") !== false || strpos($osName, "darwin") !== false);
if ($family === self::FAMILY_MAC) {
return (strpos($osName, self::FAMILY_MAC) !== false || strpos($osName, self::DARWIN) !== false);
}

if ($family === ("unix")) {
if ($family === self::FAMILY_UNIX) {
return (
StringHelper::endsWith("ix", $osName) ||
StringHelper::endsWith("ux", $osName) ||
StringHelper::endsWith("bsd", $osName) ||
StringHelper::startsWith("sunos", $osName) ||
StringHelper::startsWith("darwin", $osName)
StringHelper::endsWith('ix', $osName) ||
StringHelper::endsWith('ux', $osName) ||
StringHelper::endsWith('bsd', $osName) ||
StringHelper::startsWith('sunos', $osName) ||
StringHelper::startsWith(self::DARWIN, $osName)
);
}
throw new BuildException("Don't know how to detect os family '" . $family . "'");
Expand Down