Merge pull request #12625 from owncloud/app-dependencies-libs-and-commands

adding dependencies for command line tools and php libraries
This commit is contained in:
Bernhard Posselt 2014-12-15 12:34:46 +01:00
commit be45366013
11 changed files with 705 additions and 68 deletions

View File

@ -25,6 +25,8 @@
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
*/
use OC\App\DependencyAnalyzer;
use OC\App\Platform;
/**
* This class manages the apps. It allows them to register and integrate in the
@ -1082,6 +1084,7 @@ class OC_App {
*/
public static function installApp($app) {
$l = \OC::$server->getL10N('core');
$config = \OC::$server->getConfig();
$appData=OC_OCSClient::getApplication($app);
// check if app is a shipped app or not. OCS apps have an integer as id, shipped apps use a string
@ -1106,13 +1109,25 @@ class OC_App {
array($info['name'])
)
);
}else{
OC_Appconfig::setValue( $app, 'enabled', 'yes' );
if(isset($appData['id'])) {
OC_Appconfig::setValue( $app, 'ocsid', $appData['id'] );
}
\OC_Hook::emit('OC_App', 'post_enable', array('app' => $app));
}
// check for required dependencies
$dependencyAnalyzer = new DependencyAnalyzer(new Platform($config), $l);
$missing = $dependencyAnalyzer->analyze($app);
if(!empty($missing)) {
$missingMsg = join(PHP_EOL, $missing);
throw new \Exception(
$l->t('App \"%s\" cannot be installed because the following dependencies are not fulfilled: %s',
array($info['name'], $missingMsg)
)
);
}
$config->setAppValue($app, 'enabled', 'yes');
if(isset($appData['id'])) {
$config->setAppValue($app, 'ocsid', $appData['id'] );
}
\OC_Hook::emit('OC_App', 'post_enable', array('app' => $app));
}else{
throw new \Exception($l->t("No app name specified"));
}

View File

@ -1,5 +1,5 @@
<?php
/**
/**
* @author Thomas Müller
* @copyright 2014 Thomas Müller deepdiver@owncloud.com
*
@ -10,78 +10,206 @@
namespace OC\App;
use OCP\IL10N;
class DependencyAnalyzer {
/** @var Platform */
private $system;
private $platform;
/** @var \OCP\IL10N */
private $l;
/** @var array */
private $missing;
/** @var array */
private $dependencies;
/**
* @param array $app
* @param Platform $platform
* @param \OCP\IL10N $l
*/
function __construct(array $app, $platform, $l) {
$this->system = $platform;
function __construct(Platform $platform, IL10N $l) {
$this->platform = $platform;
$this->l = $l;
$this->missing = array();
$this->dependencies = array();
if (array_key_exists('dependencies', $app)) {
$this->dependencies = $app['dependencies'];
}
}
/**
* @param array $app
* @returns array of missing dependencies
*/
public function analyze() {
$this->analysePhpVersion();
$this->analyseSupportedDatabases();
return $this->missing;
public function analyze($app) {
$this->appInfo = $app;
if (isset($app['dependencies'])) {
$dependencies = $app['dependencies'];
} else {
$dependencies = [];
}
return array_merge(
$this->analyzePhpVersion($dependencies),
$this->analyzeDatabases($dependencies),
$this->analyzeCommands($dependencies),
$this->analyzeLibraries($dependencies),
$this->analyzeOS($dependencies),
$this->analyzeOC($dependencies, $app));
}
private function analysePhpVersion() {
if (isset($this->dependencies['php']['@attributes']['min-version'])) {
$minVersion = $this->dependencies['php']['@attributes']['min-version'];
if (version_compare($this->system->getPhpVersion(), $minVersion, '<')) {
$this->missing[] = (string)$this->l->t('PHP %s or higher is required.', $minVersion);
private function analyzePhpVersion($dependencies) {
$missing = [];
if (isset($dependencies['php']['@attributes']['min-version'])) {
$minVersion = $dependencies['php']['@attributes']['min-version'];
if (version_compare($this->platform->getPhpVersion(), $minVersion, '<')) {
$missing[] = (string)$this->l->t('PHP %s or higher is required.', $minVersion);
}
}
if (isset($this->dependencies['php']['@attributes']['max-version'])) {
$maxVersion = $this->dependencies['php']['@attributes']['max-version'];
if (version_compare($this->system->getPhpVersion(), $maxVersion, '>')) {
$this->missing[] = (string)$this->l->t('PHP with a version less then %s is required.', $maxVersion);
if (isset($dependencies['php']['@attributes']['max-version'])) {
$maxVersion = $dependencies['php']['@attributes']['max-version'];
if (version_compare($this->platform->getPhpVersion(), $maxVersion, '>')) {
$missing[] = (string)$this->l->t('PHP with a version lower than %s is required.', $maxVersion);
}
}
return $missing;
}
private function analyseSupportedDatabases() {
if (!isset($this->dependencies['database'])) {
return;
private function analyzeDatabases($dependencies) {
$missing = [];
if (!isset($dependencies['database'])) {
return $missing;
}
$supportedDatabases = $this->dependencies['database'];
$supportedDatabases = $dependencies['database'];
if (empty($supportedDatabases)) {
return;
return $missing;
}
$supportedDatabases = array_map(function($db) {
if (isset($db['@value'])) {
return $db['@value'];
}
return $db;
if (!is_array($supportedDatabases)) {
$supportedDatabases = array($supportedDatabases);
}
$supportedDatabases = array_map(function ($db) {
return $this->getValue($db);
}, $supportedDatabases);
$currentDatabase = $this->system->getDatabase();
$currentDatabase = $this->platform->getDatabase();
if (!in_array($currentDatabase, $supportedDatabases)) {
$this->missing[] = (string)$this->l->t('Following databases are supported: %s', join(', ', $supportedDatabases));
$missing[] = (string)$this->l->t('Following databases are supported: %s', join(', ', $supportedDatabases));
}
return $missing;
}
private function analyzeCommands($dependencies) {
$missing = [];
if (!isset($dependencies['command'])) {
return $missing;
}
$commands = $dependencies['command'];
if (!is_array($commands)) {
$commands = array($commands);
}
$os = $this->platform->getOS();
foreach ($commands as $command) {
if (isset($command['@attributes']['os']) && $command['@attributes']['os'] !== $os) {
continue;
}
$commandName = $this->getValue($command);
if (!$this->platform->isCommandKnown($commandName)) {
$missing[] = (string)$this->l->t('The command line tool %s could not be found', $commandName);
}
}
return $missing;
}
private function analyzeLibraries($dependencies) {
$missing = [];
if (!isset($dependencies['lib'])) {
return $missing;
}
$libs = $dependencies['lib'];
if (!is_array($libs)) {
$libs = array($libs);
}
foreach ($libs as $lib) {
$libName = $this->getValue($lib);
$libVersion = $this->platform->getLibraryVersion($libName);
if (is_null($libVersion)) {
$missing[] = (string)$this->l->t('The library %s is not available.', $libName);
continue;
}
if (is_array($lib)) {
if (isset($lib['@attributes']['min-version'])) {
$minVersion = $lib['@attributes']['min-version'];
if (version_compare($libVersion, $minVersion, '<')) {
$missing[] = (string)$this->l->t('Library %s with a version higher than %s is required - available version %s.',
array($libName, $minVersion, $libVersion));
}
}
if (isset($lib['@attributes']['max-version'])) {
$maxVersion = $lib['@attributes']['max-version'];
if (version_compare($libVersion, $maxVersion, '>')) {
$missing[] = (string)$this->l->t('Library %s with a version lower than %s is required - available version %s.',
array($libName, $maxVersion, $libVersion));
}
}
}
}
return $missing;
}
private function analyzeOS($dependencies) {
$missing = [];
if (!isset($dependencies['os'])) {
return $missing;
}
$oss = $dependencies['os'];
if (empty($oss)) {
return $missing;
}
if (is_array($oss)) {
$oss = array_map(function ($os) {
return $this->getValue($os);
}, $oss);
} else {
$oss = array($oss);
}
$currentOS = $this->platform->getOS();
if (!in_array($currentOS, $oss)) {
$missing[] = (string)$this->l->t('Following platforms are supported: %s', join(', ', $oss));
}
return $missing;
}
private function analyzeOC($dependencies, $appInfo) {
$missing = [];
$minVersion = null;
if (isset($dependencies['owncloud']['@attributes']['min-version'])) {
$minVersion = $dependencies['owncloud']['@attributes']['min-version'];
} elseif (isset($appInfo['requiremin'])) {
$minVersion = $appInfo['requiremin'];
}
$maxVersion = null;
if (isset($dependencies['owncloud']['@attributes']['max-version'])) {
$maxVersion = $dependencies['owncloud']['@attributes']['max-version'];
} elseif (isset($appInfo['requiremax'])) {
$maxVersion = $appInfo['requiremax'];
}
if (!is_null($minVersion)) {
if (version_compare($this->platform->getOcVersion(), $minVersion, '<')) {
$missing[] = (string)$this->l->t('ownCloud %s or higher is required.', $minVersion);
}
}
if (!is_null($maxVersion)) {
if (version_compare($this->platform->getOcVersion(), $maxVersion, '>')) {
$missing[] = (string)$this->l->t('ownCloud with a version lower than %s is required.', $maxVersion);
}
}
return $missing;
}
/**
* @param $element
* @return mixed
*/
private function getValue($element) {
if (isset($element['@value']))
return $element['@value'];
return (string)$element;
}
}

View File

@ -10,18 +10,43 @@
namespace OC\App;
use OC_Util;
use OCP\IConfig;
/**
* Class Platform
*
* This class basically abstracts any kind of information which can be retrieved from the underlying system.
*
* @package OC\App
*/
class Platform {
/**
* @param IConfig $config
*/
function __construct(IConfig $config) {
$this->config = $config;
}
/**
* @return string
*/
public function getPhpVersion() {
return phpversion();
}
/**
* @return string
*/
public function getOcVersion() {
$v = OC_Util::getVersion();
return join('.', $v);
}
/**
* @return string
*/
public function getDatabase() {
$dbType = $this->config->getSystemValue('dbtype', 'sqlite');
if ($dbType === 'sqlite3') {
@ -30,4 +55,26 @@ class Platform {
return $dbType;
}
/**
* @return string
*/
public function getOS() {
return php_uname('s');
}
/**
* @param $command
* @return bool
*/
public function isCommandKnown($command) {
$path = \OC_Helper::findBinaryPath($command);
return ($path !== null);
}
public function getLibraryVersion($name) {
$repo = new PlatformRepository();
$lib = $repo->findLibrary($name);
return $lib;
}
}

View File

@ -0,0 +1,210 @@
<?php
namespace OC\App;
/**
* Class PlatformRepository
*
* Inspired by the composer project - licensed under MIT
* https://github.com/composer/composer/blob/master/src/Composer/Repository/PlatformRepository.php#L82
*
* @package OC\App
*/
class PlatformRepository {
public function __construct() {
$this->packages = $this->initialize();
}
protected function initialize() {
$loadedExtensions = get_loaded_extensions();
$packages = array();
// Extensions scanning
foreach ($loadedExtensions as $name) {
if (in_array($name, array('standard', 'Core'))) {
continue;
}
$ext = new \ReflectionExtension($name);
try {
$prettyVersion = $ext->getVersion();
} catch (\UnexpectedValueException $e) {
$prettyVersion = '0';
}
try {
$prettyVersion = $this->normalizeVersion($prettyVersion);
} catch (\UnexpectedValueException $e) {
continue;
}
$packages[$this->buildPackageName($name)] = $prettyVersion;
}
foreach ($loadedExtensions as $name) {
$prettyVersion = null;
switch ($name) {
case 'curl':
$curlVersion = curl_version();
$prettyVersion = $curlVersion['version'];
break;
case 'iconv':
$prettyVersion = ICONV_VERSION;
break;
case 'intl':
$name = 'ICU';
if (defined('INTL_ICU_VERSION')) {
$prettyVersion = INTL_ICU_VERSION;
} else {
$reflector = new \ReflectionExtension('intl');
ob_start();
$reflector->info();
$output = ob_get_clean();
preg_match('/^ICU version => (.*)$/m', $output, $matches);
$prettyVersion = $matches[1];
}
break;
case 'libxml':
$prettyVersion = LIBXML_DOTTED_VERSION;
break;
case 'openssl':
$prettyVersion = preg_replace_callback('{^(?:OpenSSL\s*)?([0-9.]+)([a-z]?).*}', function ($match) {
return $match[1] . (empty($match[2]) ? '' : '.' . (ord($match[2]) - 96));
}, OPENSSL_VERSION_TEXT);
break;
case 'pcre':
$prettyVersion = preg_replace('{^(\S+).*}', '$1', PCRE_VERSION);
break;
case 'uuid':
$prettyVersion = phpversion('uuid');
break;
case 'xsl':
$prettyVersion = LIBXSLT_DOTTED_VERSION;
break;
default:
// None handled extensions have no special cases, skip
continue 2;
}
try {
$prettyVersion = $this->normalizeVersion($prettyVersion);
} catch (\UnexpectedValueException $e) {
continue;
}
$packages[$this->buildPackageName($name)] = $prettyVersion;
}
return $packages;
}
private function buildPackageName($name) {
return str_replace(' ', '-', $name);
}
/**
* @param $name
* @return string
*/
public function findLibrary($name) {
$extName = $this->buildPackageName($name);
if (isset($this->packages[$extName])) {
return $this->packages[$extName];
}
return null;
}
private static $modifierRegex = '[._-]?(?:(stable|beta|b|RC|alpha|a|patch|pl|p)(?:[.-]?(\d+))?)?([.-]?dev)?';
/**
* Normalizes a version string to be able to perform comparisons on it
*
* https://github.com/composer/composer/blob/master/src/Composer/Package/Version/VersionParser.php#L94
*
* @param string $version
* @param string $fullVersion optional complete version string to give more context
* @throws \UnexpectedValueException
* @return string
*/
public function normalizeVersion($version, $fullVersion = null) {
$version = trim($version);
if (null === $fullVersion) {
$fullVersion = $version;
}
// ignore aliases and just assume the alias is required instead of the source
if (preg_match('{^([^,\s]+) +as +([^,\s]+)$}', $version, $match)) {
$version = $match[1];
}
// match master-like branches
if (preg_match('{^(?:dev-)?(?:master|trunk|default)$}i', $version)) {
return '9999999-dev';
}
if ('dev-' === strtolower(substr($version, 0, 4))) {
return 'dev-' . substr($version, 4);
}
// match classical versioning
if (preg_match('{^v?(\d{1,3})(\.\d+)?(\.\d+)?(\.\d+)?' . self::$modifierRegex . '$}i', $version, $matches)) {
$version = $matches[1]
. (!empty($matches[2]) ? $matches[2] : '.0')
. (!empty($matches[3]) ? $matches[3] : '.0')
. (!empty($matches[4]) ? $matches[4] : '.0');
$index = 5;
} elseif (preg_match('{^v?(\d{4}(?:[.:-]?\d{2}){1,6}(?:[.:-]?\d{1,3})?)' . self::$modifierRegex . '$}i', $version, $matches)) { // match date-based versioning
$version = preg_replace('{\D}', '-', $matches[1]);
$index = 2;
} elseif (preg_match('{^v?(\d{4,})(\.\d+)?(\.\d+)?(\.\d+)?' . self::$modifierRegex . '$}i', $version, $matches)) {
$version = $matches[1]
. (!empty($matches[2]) ? $matches[2] : '.0')
. (!empty($matches[3]) ? $matches[3] : '.0')
. (!empty($matches[4]) ? $matches[4] : '.0');
$index = 5;
}
// add version modifiers if a version was matched
if (isset($index)) {
if (!empty($matches[$index])) {
if ('stable' === $matches[$index]) {
return $version;
}
$version .= '-' . $this->expandStability($matches[$index]) . (!empty($matches[$index + 1]) ? $matches[$index + 1] : '');
}
if (!empty($matches[$index + 2])) {
$version .= '-dev';
}
return $version;
}
$extraMessage = '';
if (preg_match('{ +as +' . preg_quote($version) . '$}', $fullVersion)) {
$extraMessage = ' in "' . $fullVersion . '", the alias must be an exact version';
} elseif (preg_match('{^' . preg_quote($version) . ' +as +}', $fullVersion)) {
$extraMessage = ' in "' . $fullVersion . '", the alias source must be an exact version, if it is a branch name you should prefix it with dev-';
}
throw new \UnexpectedValueException('Invalid version string "' . $version . '"' . $extraMessage);
}
private function expandStability($stability) {
$stability = strtolower($stability);
switch ($stability) {
case 'a':
return 'alpha';
case 'b':
return 'beta';
case 'p':
case 'pl':
return 'patch';
case 'rc':
return 'RC';
default:
return $stability;
}
}
}

View File

@ -118,7 +118,8 @@ class AppSettingsController extends Controller {
}
// fix groups to be an array
$apps = array_map(function($app){
$dependencyAnalyzer = new DependencyAnalyzer(new Platform($this->config), $this->l10n);
$apps = array_map(function($app) use ($dependencyAnalyzer) {
$groups = array();
if (is_string($app['groups'])) {
$groups = json_decode($app['groups']);
@ -127,8 +128,7 @@ class AppSettingsController extends Controller {
$app['canUnInstall'] = !$app['active'] && $app['removable'];
// analyse dependencies
$dependencyAnalyzer = new DependencyAnalyzer($app, new Platform($this->config), $this->l10n);
$missing = $dependencyAnalyzer->analyze();
$missing = $dependencyAnalyzer->analyze($app);
$app['canInstall'] = empty($missing);
$app['missingDependencies'] = $missing;

View File

@ -203,6 +203,11 @@ span.version { margin-left:1em; margin-right:1em; color:#555; }
border-bottom: 1px solid #e8e8e8;
}
.app-dependencies {
margin-top: 10px;
color: #c33;
}
.missing-dependencies {
list-style: initial;
list-style-type: initial;

View File

@ -52,12 +52,14 @@
</p>
{{/if}}
{{#unless canInstall}}
<div><?php p($l->t('This app cannot be installed because the following dependencies are not fulfilled:')); ?></div>
<div class="app-dependencies">
<p><?php p($l->t('This app cannot be installed because the following dependencies are not fulfilled:')); ?></p>
<ul class="missing-dependencies">
{{#each missingDependencies}}
<li>{{this}}</li>
{{/each}}
</ul>
</div>
{{/unless}}
{{#if update}}
@ -70,9 +72,7 @@
<br />
<input type="hidden" id="group_select" title="<?php p($l->t('All')); ?>" style="width: 200px">
{{else}}
{{#if canInstall}}
<input class="enable" type="submit" data-appid="{{id}}" data-active="false" value="<?php p($l->t("Enable"));?>"/>
{{/if}}
<input class="enable" type="submit" data-appid="{{id}}" data-active="false" {{#unless canInstall}}disabled="disabled"{{/unless}} value="<?php p($l->t("Enable"));?>"/>
{{/if}}
{{#if canUnInstall}}
<input class="uninstall" type="submit" value="<?php p($l->t('Uninstall App')); ?>" data-appid="{{id}}" />

View File

@ -44,6 +44,28 @@
},
"@value": "notepad.exe"
}
]
],
"lib": [
{
"@attributes" : {
"min-version": "1.2"
},
"@value": "xml"
},
{
"@attributes" : {
"max-version": "2.0"
},
"@value": "intl"
},
"curl"
],
"os": "Linux",
"owncloud": {
"@attributes" : {
"min-version": "7.0.1",
"max-version": "8"
}
}
}
}

View File

@ -25,5 +25,10 @@
<database>mysql</database>
<command os="linux">grep</command>
<command os="windows">notepad.exe</command>
<lib min-version="1.2">xml</lib>
<lib max-version="2.0">intl</lib>
<lib>curl</lib>
<os>Linux</os>
<owncloud min-version="7.0.1" max-version="8" />
</dependencies>
</info>

View File

@ -15,16 +15,15 @@ use OCP\IL10N;
class DependencyAnalyzer extends \PHPUnit_Framework_TestCase {
/**
* @var Platform
*/
/** @var Platform */
private $platformMock;
/**
* @var IL10N
*/
/** @var IL10N */
private $l10nMock;
/** @var \OC\App\DependencyAnalyzer */
private $analyser;
public function setUp() {
$this->platformMock = $this->getMockBuilder('\OC\App\Platform')
->disableOriginalConstructor()
@ -35,6 +34,26 @@ class DependencyAnalyzer extends \PHPUnit_Framework_TestCase {
$this->platformMock->expects($this->any())
->method('getDatabase')
->will( $this->returnValue('mysql'));
$this->platformMock->expects($this->any())
->method('getOS')
->will( $this->returnValue('Linux'));
$this->platformMock->expects($this->any())
->method('isCommandKnown')
->will( $this->returnCallback(function($command) {
return ($command === 'grep');
}));
$this->platformMock->expects($this->any())
->method('getLibraryVersion')
->will( $this->returnCallback(function($lib) {
if ($lib === 'curl') {
return "2.3.4";
}
return null;
}));
$this->platformMock->expects($this->any())
->method('getOcVersion')
->will( $this->returnValue('8.0.1'));
$this->l10nMock = $this->getMockBuilder('\OCP\IL10N')
->disableOriginalConstructor()
->getMock();
@ -43,6 +62,8 @@ class DependencyAnalyzer extends \PHPUnit_Framework_TestCase {
->will($this->returnCallback(function($text, $parameters = array()) {
return vsprintf($text, $parameters);
}));
$this->analyser = new \OC\App\DependencyAnalyzer($this->platformMock, $this->l10nMock);
}
/**
@ -60,11 +81,9 @@ class DependencyAnalyzer extends \PHPUnit_Framework_TestCase {
if (!is_null($maxVersion)) {
$app['dependencies']['php']['@attributes']['max-version'] = $maxVersion;
}
$analyser = new \OC\App\DependencyAnalyzer($app, $this->platformMock, $this->l10nMock);
$missing = $analyser->analyze();
$missing = $this->analyser->analyze($app);
$this->assertTrue(is_array($missing));
$this->assertEquals(count($expectedMissing), count($missing));
$this->assertEquals($expectedMissing, $missing);
}
@ -79,19 +98,140 @@ class DependencyAnalyzer extends \PHPUnit_Framework_TestCase {
if (!is_null($databases)) {
$app['dependencies']['database'] = $databases;
}
$analyser = new \OC\App\DependencyAnalyzer($app, $this->platformMock, $this->l10nMock);
$missing = $analyser->analyze();
$missing = $this->analyser->analyze($app);
$this->assertTrue(is_array($missing));
$this->assertEquals(count($expectedMissing), count($missing));
$this->assertEquals($expectedMissing, $missing);
}
/**
* @dataProvider providesCommands
*/
public function testCommand($expectedMissing, $commands) {
$app = array(
'dependencies' => array(
)
);
if (!is_null($commands)) {
$app['dependencies']['command'] = $commands;
}
$missing = $this->analyser->analyze($app);
$this->assertTrue(is_array($missing));
$this->assertEquals($expectedMissing, $missing);
}
/**
* @dataProvider providesLibs
* @param $expectedMissing
* @param $libs
*/
function testLibs($expectedMissing, $libs) {
$app = array(
'dependencies' => array(
)
);
if (!is_null($libs)) {
$app['dependencies']['lib'] = $libs;
}
$missing = $this->analyser->analyze($app);
$this->assertTrue(is_array($missing));
$this->assertEquals($expectedMissing, $missing);
}
/**
* @dataProvider providesOS
* @param $expectedMissing
* @param $oss
*/
function testOS($expectedMissing, $oss) {
$app = array(
'dependencies' => array()
);
if (!is_null($oss)) {
$app['dependencies']['os'] = $oss;
}
$missing = $this->analyser->analyze($app);
$this->assertTrue(is_array($missing));
$this->assertEquals($expectedMissing, $missing);
}
/**
* @dataProvider providesOC
* @param $expectedMissing
* @param $oc
*/
function testOC($expectedMissing, $oc) {
$app = array(
'dependencies' => array()
);
if (!is_null($oc)) {
$app['dependencies']['owncloud'] = $oc;
}
$missing = $this->analyser->analyze($app);
$this->assertTrue(is_array($missing));
$this->assertEquals($expectedMissing, $missing);
}
function providesOC() {
return array(
// no version -> no missing dependency
array(array(), null),
array(array('ownCloud 9 or higher is required.'), array('@attributes' => array('min-version' => '9'))),
array(array('ownCloud with a version lower than 5.1.2 is required.'), array('@attributes' => array('max-version' => '5.1.2'))),
);
}
function providesOS() {
return array(
array(array(), null),
array(array(), array()),
array(array('Following platforms are supported: ANDROID'), 'ANDROID'),
array(array('Following platforms are supported: WINNT'), array('WINNT'))
);
}
function providesLibs() {
return array(
// we expect curl to exist
array(array(), 'curl'),
// we expect abcde to exist
array(array('The library abcde is not available.'), array('abcde')),
// curl in version 100.0 does not exist
array(array('Library curl with a version higher than 100.0 is required - available version 2.3.4.'),
array(array('@attributes' => array('min-version' => '100.0'), '@value' => 'curl'))),
// curl in version 100.0 does not exist
array(array('Library curl with a version lower than 1.0.0 is required - available version 2.3.4.'),
array(array('@attributes' => array('max-version' => '1.0.0'), '@value' => 'curl')))
);
}
function providesCommands() {
return array(
array(array(), null),
// grep is known on linux
array(array(), array(array('@attributes' => array('os' => 'Linux'), '@value' => 'grep'))),
// grepp is not known on linux
array(array('The command line tool grepp could not be found'), array(array('@attributes' => array('os' => 'Linux'), '@value' => 'grepp'))),
// we don't care about tools on Windows - we are on Linux
array(array(), array(array('@attributes' => array('os' => 'Windows'), '@value' => 'grepp'))),
// grep is known on all systems
array(array(), 'grep'),
);
}
function providesDatabases() {
return array(
// non BC - in case on databases are defined -> all are supported
array(array(), null),
array(array(), array()),
array(array('Following databases are supported: mongodb'), 'mongodb'),
array(array('Following databases are supported: sqlite, postgres'), array('sqlite', array('@value' => 'postgres'))),
);
}
@ -103,7 +243,7 @@ class DependencyAnalyzer extends \PHPUnit_Framework_TestCase {
array(array(), null, '5.5'),
array(array(), '5.4', '5.5'),
array(array('PHP 5.4.4 or higher is required.'), '5.4.4', null),
array(array('PHP with a version less then 5.4.2 is required.'), null, '5.4.2'),
array(array('PHP with a version lower than 5.4.2 is required.'), null, '5.4.2'),
);
}
}

View File

@ -0,0 +1,65 @@
<?php
/**
* @author Thomas Müller
* @copyright 2014 Thomas Müller deepdiver@owncloud.com
* later.
* See the COPYING-README file.
*/
namespace Test\App;
use OC;
class PlatformRepository extends \Test\TestCase {
/**
* @dataProvider providesVersions
* @param $expected
* @param $input
*/
public function testVersion($input, $expected) {
$pr = new OC\App\PlatformRepository();
$normalizedVersion = $pr->normalizeVersion($input);
$this->assertEquals($expected, $normalizedVersion);
}
public function providesVersions() {
return array(
'none' => array('1.0.0', '1.0.0.0'),
'none/2' => array('1.2.3.4', '1.2.3.4'),
'parses state' => array('1.0.0RC1dev', '1.0.0.0-RC1-dev'),
'CI parsing' => array('1.0.0-rC15-dev', '1.0.0.0-RC15-dev'),
'delimiters' => array('1.0.0.RC.15-dev', '1.0.0.0-RC15-dev'),
'RC uppercase' => array('1.0.0-rc1', '1.0.0.0-RC1'),
'patch replace' => array('1.0.0.pl3-dev', '1.0.0.0-patch3-dev'),
'forces w.x.y.z' => array('1.0-dev', '1.0.0.0-dev'),
'forces w.x.y.z/2' => array('0', '0.0.0.0'),
'parses long' => array('10.4.13-beta', '10.4.13.0-beta'),
'parses long/2' => array('10.4.13beta2', '10.4.13.0-beta2'),
'parses long/semver' => array('10.4.13beta.2', '10.4.13.0-beta2'),
'expand shorthand' => array('10.4.13-b', '10.4.13.0-beta'),
'expand shorthand2' => array('10.4.13-b5', '10.4.13.0-beta5'),
'strips leading v' => array('v1.0.0', '1.0.0.0'),
'strips v/datetime' => array('v20100102', '20100102'),
'parses dates y-m' => array('2010.01', '2010-01'),
'parses dates w/ .' => array('2010.01.02', '2010-01-02'),
'parses dates w/ -' => array('2010-01-02', '2010-01-02'),
'parses numbers' => array('2010-01-02.5', '2010-01-02-5'),
'parses dates y.m.Y' => array('2010.1.555', '2010.1.555.0'),
'parses datetime' => array('20100102-203040', '20100102-203040'),
'parses dt+number' => array('20100102203040-10', '20100102203040-10'),
'parses dt+patch' => array('20100102-203040-p1', '20100102-203040-patch1'),
'parses master' => array('dev-master', '9999999-dev'),
'parses trunk' => array('dev-trunk', '9999999-dev'),
// 'parses branches' => array('1.x-dev', '1.9999999.9999999.9999999-dev'),
'parses arbitrary' => array('dev-feature-foo', 'dev-feature-foo'),
'parses arbitrary2' => array('DEV-FOOBAR', 'dev-FOOBAR'),
'parses arbitrary3' => array('dev-feature/foo', 'dev-feature/foo'),
'ignores aliases' => array('dev-master as 1.0.0', '9999999-dev'),
// 'semver metadata' => array('dev-master+foo.bar', '9999999-dev'),
// 'semver metadata/2' => array('1.0.0-beta.5+foo', '1.0.0.0-beta5'),
// 'semver metadata/3' => array('1.0.0+foo', '1.0.0.0'),
// 'metadata w/ alias' => array('1.0.0+foo as 2.0', '1.0.0.0'),
);
}}