From 08f1db445134e98188f3e1e5b6b84a6eac1f6346 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Thu, 4 Dec 2014 17:04:35 +0100 Subject: [PATCH 01/11] adding dependencies for command line tools --- lib/private/app/dependencyanalyzer.php | 69 +++++++++++++++++++------- lib/private/app/platform.php | 32 ++++++++++++ tests/lib/app/dependencyanalyzer.php | 43 +++++++++++++++- 3 files changed, 124 insertions(+), 20 deletions(-) diff --git a/lib/private/app/dependencyanalyzer.php b/lib/private/app/dependencyanalyzer.php index fb4b376165..172b8e88c0 100644 --- a/lib/private/app/dependencyanalyzer.php +++ b/lib/private/app/dependencyanalyzer.php @@ -10,31 +10,31 @@ namespace OC\App; +use OCP\IL10N; + class DependencyAnalyzer { /** @var Platform */ - private $system; + private $platform; /** @var \OCP\IL10N */ private $l; /** @var array */ - private $missing; + private $missing = array(); /** @var array */ - private $dependencies; + private $dependencies = array(); /** * @param array $app * @param Platform $platform * @param \OCP\IL10N $l */ - function __construct(array $app, $platform, $l) { - $this->system = $platform; + function __construct(array $app, Platform $platform, IL10N $l) { + $this->platform = $platform; $this->l = $l; - $this->missing = array(); - $this->dependencies = array(); - if (array_key_exists('dependencies', $app)) { + if (isset($app['dependencies'])) { $this->dependencies = $app['dependencies']; } } @@ -46,20 +46,21 @@ class DependencyAnalyzer { public function analyze() { $this->analysePhpVersion(); $this->analyseSupportedDatabases(); + $this->analyseCommands(); return $this->missing; } 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); + if (version_compare($this->platform->getPhpVersion(), $minVersion, '<')) { + $this->addMissing((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 (version_compare($this->platform->getPhpVersion(), $maxVersion, '>')) { + $this->addMissing((string)$this->l->t('PHP with a version less then %s is required.', $maxVersion)); } } } @@ -74,14 +75,46 @@ class DependencyAnalyzer { return; } $supportedDatabases = array_map(function($db) { - if (isset($db['@value'])) { - return $db['@value']; - } - return $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)); + $this->addMissing((string)$this->l->t('Following databases are supported: %s', join(', ', $supportedDatabases))); } } + + private function analyseCommands() { + if (!isset($this->dependencies['command'])) { + return; + } + + $commands = $this->dependencies['command']; + $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)) { + $this->addMissing((string)$this->l->t('The command line tool %s could not be found', $commandName)); + } + } + } + + /** + * @param $element + * @return mixed + */ + private function getValue($element) { + if (isset($element['@value'])) + return $element['@value']; + return strval($element); + } + + /** + * @param $minVersion + */ + private function addMissing($message) { + $this->missing[] = $message; + } } diff --git a/lib/private/app/platform.php b/lib/private/app/platform.php index 39f8a2979f..da515a235a 100644 --- a/lib/private/app/platform.php +++ b/lib/private/app/platform.php @@ -12,16 +12,32 @@ namespace OC\App; 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 getDatabase() { $dbType = $this->config->getSystemValue('dbtype', 'sqlite'); if ($dbType === 'sqlite3') { @@ -30,4 +46,20 @@ 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); + } } diff --git a/tests/lib/app/dependencyanalyzer.php b/tests/lib/app/dependencyanalyzer.php index 7d06842e8a..a21b53264b 100644 --- a/tests/lib/app/dependencyanalyzer.php +++ b/tests/lib/app/dependencyanalyzer.php @@ -35,6 +35,15 @@ 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->l10nMock = $this->getMockBuilder('\OCP\IL10N') ->disableOriginalConstructor() ->getMock(); @@ -64,7 +73,6 @@ class DependencyAnalyzer extends \PHPUnit_Framework_TestCase { $missing = $analyser->analyze(); $this->assertTrue(is_array($missing)); - $this->assertEquals(count($expectedMissing), count($missing)); $this->assertEquals($expectedMissing, $missing); } @@ -83,10 +91,41 @@ class DependencyAnalyzer extends \PHPUnit_Framework_TestCase { $missing = $analyser->analyze(); $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; + } + $analyser = new \OC\App\DependencyAnalyzer($app, $this->platformMock, $this->l10nMock); + $missing = $analyser->analyze(); + + $this->assertTrue(is_array($missing)); + $this->assertEquals($expectedMissing, $missing); + } + + 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(), array('grep')), + ); + } + function providesDatabases() { return array( // non BC - in case on databases are defined -> all are supported From 770f9876595a3cebd4b911a237ec1e681bc506be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Fri, 5 Dec 2014 13:52:51 +0100 Subject: [PATCH 02/11] adding supported libraries - including min and max version --- lib/private/app/dependencyanalyzer.php | 48 +++++- lib/private/app/platform.php | 6 + lib/private/app/platformrepository.php | 210 +++++++++++++++++++++++++ tests/data/app/expected-info.json | 15 ++ tests/data/app/valid-info.xml | 3 + tests/lib/app/dependencyanalyzer.php | 46 +++++- 6 files changed, 320 insertions(+), 8 deletions(-) create mode 100644 lib/private/app/platformrepository.php diff --git a/lib/private/app/dependencyanalyzer.php b/lib/private/app/dependencyanalyzer.php index 172b8e88c0..af36637b67 100644 --- a/lib/private/app/dependencyanalyzer.php +++ b/lib/private/app/dependencyanalyzer.php @@ -44,13 +44,14 @@ class DependencyAnalyzer { * @returns array of missing dependencies */ public function analyze() { - $this->analysePhpVersion(); - $this->analyseSupportedDatabases(); - $this->analyseCommands(); + $this->analyzePhpVersion(); + $this->analyzeDatabases(); + $this->analyzeCommands(); + $this->analyzeLibraries(); return $this->missing; } - private function analysePhpVersion() { + private function analyzePhpVersion() { if (isset($this->dependencies['php']['@attributes']['min-version'])) { $minVersion = $this->dependencies['php']['@attributes']['min-version']; if (version_compare($this->platform->getPhpVersion(), $minVersion, '<')) { @@ -60,12 +61,12 @@ class DependencyAnalyzer { if (isset($this->dependencies['php']['@attributes']['max-version'])) { $maxVersion = $this->dependencies['php']['@attributes']['max-version']; if (version_compare($this->platform->getPhpVersion(), $maxVersion, '>')) { - $this->addMissing((string)$this->l->t('PHP with a version less then %s is required.', $maxVersion)); + $this->addMissing((string)$this->l->t('PHP with a version lower than %s is required.', $maxVersion)); } } } - private function analyseSupportedDatabases() { + private function analyzeDatabases() { if (!isset($this->dependencies['database'])) { return; } @@ -83,7 +84,7 @@ class DependencyAnalyzer { } } - private function analyseCommands() { + private function analyzeCommands() { if (!isset($this->dependencies['command'])) { return; } @@ -101,6 +102,39 @@ class DependencyAnalyzer { } } + private function analyzeLibraries() { + if (!isset($this->dependencies['lib'])) { + return; + } + + $libs = $this->dependencies['lib']; + foreach($libs as $lib) { + $libName = $this->getValue($lib); + $libVersion = $this->platform->getLibraryVersion($libName); + if (is_null($libVersion)) { + $this->addMissing((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, '<')) { + $this->addMissing((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, '>')) { + $this->addMissing((string)$this->l->t('Library %s with a version lower than %s is required - available version %s.', + array($libName, $maxVersion, $libVersion))); + } + } + } + } + } + /** * @param $element * @return mixed diff --git a/lib/private/app/platform.php b/lib/private/app/platform.php index da515a235a..6279bb5f20 100644 --- a/lib/private/app/platform.php +++ b/lib/private/app/platform.php @@ -62,4 +62,10 @@ class Platform { $path = \OC_Helper::findBinaryPath($command); return ($path !== null); } + + public function getLibraryVersion($name) { + $repo = new PlatformRepository(); + $lib = $repo->findLibrary($name); + return $lib; + } } diff --git a/lib/private/app/platformrepository.php b/lib/private/app/platformrepository.php new file mode 100644 index 0000000000..96d04ec2e4 --- /dev/null +++ b/lib/private/app/platformrepository.php @@ -0,0 +1,210 @@ +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; + } + } +} diff --git a/tests/data/app/expected-info.json b/tests/data/app/expected-info.json index fc0ab22497..a425622998 100644 --- a/tests/data/app/expected-info.json +++ b/tests/data/app/expected-info.json @@ -44,6 +44,21 @@ }, "@value": "notepad.exe" } + ], + "lib": [ + { + "@attributes" : { + "min-version": "1.2" + }, + "@value": "xml" + }, + { + "@attributes" : { + "max-version": "2.0" + }, + "@value": "intl" + }, + "curl" ] } } diff --git a/tests/data/app/valid-info.xml b/tests/data/app/valid-info.xml index f01f5fd55e..0ea15b63a4 100644 --- a/tests/data/app/valid-info.xml +++ b/tests/data/app/valid-info.xml @@ -25,5 +25,8 @@ mysql grep notepad.exe + xml + intl + curl diff --git a/tests/lib/app/dependencyanalyzer.php b/tests/lib/app/dependencyanalyzer.php index a21b53264b..872d5cfb2c 100644 --- a/tests/lib/app/dependencyanalyzer.php +++ b/tests/lib/app/dependencyanalyzer.php @@ -43,6 +43,14 @@ class DependencyAnalyzer extends \PHPUnit_Framework_TestCase { ->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->l10nMock = $this->getMockBuilder('\OCP\IL10N') ->disableOriginalConstructor() @@ -112,6 +120,42 @@ class DependencyAnalyzer extends \PHPUnit_Framework_TestCase { $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; + } + + $analyser = new \OC\App\DependencyAnalyzer($app, $this->platformMock, $this->l10nMock); + $missing = $analyser->analyze(); + + $this->assertTrue(is_array($missing)); + $this->assertEquals($expectedMissing, $missing); + } + + function providesLibs() { + return array( + // we expect curl to exist + array(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), @@ -142,7 +186,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'), ); } } From ee46548f57310b45ce723fd03ec29bfb686f8bc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Fri, 5 Dec 2014 14:51:41 +0100 Subject: [PATCH 03/11] adding dependencies for supported platforms --- lib/private/app/dependencyanalyzer.php | 21 +++++++++++++++++++ tests/data/app/expected-info.json | 3 ++- tests/data/app/valid-info.xml | 1 + tests/lib/app/dependencyanalyzer.php | 28 ++++++++++++++++++++++++++ 4 files changed, 52 insertions(+), 1 deletion(-) diff --git a/lib/private/app/dependencyanalyzer.php b/lib/private/app/dependencyanalyzer.php index af36637b67..2e83887238 100644 --- a/lib/private/app/dependencyanalyzer.php +++ b/lib/private/app/dependencyanalyzer.php @@ -48,6 +48,7 @@ class DependencyAnalyzer { $this->analyzeDatabases(); $this->analyzeCommands(); $this->analyzeLibraries(); + $this->analyzeOS(); return $this->missing; } @@ -135,6 +136,26 @@ class DependencyAnalyzer { } } + private function analyzeOS() { + if (!isset($this->dependencies['os'])) { + return; + } + + $oss = $this->dependencies['os']; + if (empty($oss)) { + return; + } + $oss = array_map(function($os) { + return $this->getValue($os); + }, $oss); + $currentOS = $this->platform->getOS(); + if (!in_array($currentOS, $oss)) { + $this->addMissing((string)$this->l->t('Following platforms are supported: %s', join(', ', $oss))); + } + } + + + /** * @param $element * @return mixed diff --git a/tests/data/app/expected-info.json b/tests/data/app/expected-info.json index a425622998..b899df7a8d 100644 --- a/tests/data/app/expected-info.json +++ b/tests/data/app/expected-info.json @@ -59,6 +59,7 @@ "@value": "intl" }, "curl" - ] + ], + "os": "Linux" } } diff --git a/tests/data/app/valid-info.xml b/tests/data/app/valid-info.xml index 0ea15b63a4..42f4e3edb7 100644 --- a/tests/data/app/valid-info.xml +++ b/tests/data/app/valid-info.xml @@ -28,5 +28,6 @@ xml intl curl + Linux diff --git a/tests/lib/app/dependencyanalyzer.php b/tests/lib/app/dependencyanalyzer.php index 872d5cfb2c..1cd24193ea 100644 --- a/tests/lib/app/dependencyanalyzer.php +++ b/tests/lib/app/dependencyanalyzer.php @@ -141,6 +141,34 @@ class DependencyAnalyzer extends \PHPUnit_Framework_TestCase { $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; + } + + $analyser = new \OC\App\DependencyAnalyzer($app, $this->platformMock, $this->l10nMock); + $missing = $analyser->analyze(); + + $this->assertTrue(is_array($missing)); + $this->assertEquals($expectedMissing, $missing); + } + + function providesOS() { + return array( + array(array(), null), + array(array(), array()), + array(array('Following platforms are supported: WINNT'), array('WINNT')) + ); + } + function providesLibs() { return array( // we expect curl to exist From 5a03e0a5cf30f4ad5cecd7a90ad3bc2a004770aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Fri, 5 Dec 2014 15:28:33 +0100 Subject: [PATCH 04/11] adding dependency to owncloud version - with fallback to requiremin and requiremax --- lib/private/app/dependencyanalyzer.php | 27 ++++++++++++++++++++++ lib/private/app/platform.php | 8 +++++++ tests/data/app/expected-info.json | 8 ++++++- tests/data/app/valid-info.xml | 1 + tests/lib/app/dependencyanalyzer.php | 32 ++++++++++++++++++++++++++ 5 files changed, 75 insertions(+), 1 deletion(-) diff --git a/lib/private/app/dependencyanalyzer.php b/lib/private/app/dependencyanalyzer.php index 2e83887238..795017e2b3 100644 --- a/lib/private/app/dependencyanalyzer.php +++ b/lib/private/app/dependencyanalyzer.php @@ -26,6 +26,8 @@ class DependencyAnalyzer { /** @var array */ private $dependencies = array(); + private $appInfo = array(); + /** * @param array $app * @param Platform $platform @@ -49,6 +51,7 @@ class DependencyAnalyzer { $this->analyzeCommands(); $this->analyzeLibraries(); $this->analyzeOS(); + $this->analyzeOC(); return $this->missing; } @@ -154,7 +157,31 @@ class DependencyAnalyzer { } } + private function analyzeOC() { + $minVersion = null; + if (isset($this->dependencies['owncloud']['@attributes']['min-version'])) { + $minVersion = $this->dependencies['owncloud']['@attributes']['min-version']; + } elseif (isset($this->appInfo['requiremin'])) { + $minVersion = $this->appInfo['requiremin']; + } + $maxVersion = null; + if (isset($this->dependencies['oc']['@attributes']['max-version'])) { + $maxVersion = $this->dependencies['oc']['@attributes']['max-version']; + } elseif (isset($this->appInfo['requiremax'])) { + $maxVersion = $this->appInfo['requiremax']; + } + if (!is_null($minVersion)) { + if (version_compare($this->platform->getOcVersion(), $minVersion, '<')) { + $this->addMissing((string)$this->l->t('ownCloud %s or higher is required.', $minVersion)); + } + } + if (!is_null($maxVersion)) { + if (version_compare($this->platform->getOcVersion(), $maxVersion, '>')) { + $this->addMissing((string)$this->l->t('ownCloud with a version lower than %s is required.', $maxVersion)); + } + } + } /** * @param $element diff --git a/lib/private/app/platform.php b/lib/private/app/platform.php index 6279bb5f20..ba96fba00d 100644 --- a/lib/private/app/platform.php +++ b/lib/private/app/platform.php @@ -10,6 +10,7 @@ namespace OC\App; +use OC_Util; use OCP\IConfig; /** @@ -35,6 +36,13 @@ class Platform { return phpversion(); } + /** + * @return string + */ + public function getOcVersion() { + return OC_Util::getVersion(); + } + /** * @return string */ diff --git a/tests/data/app/expected-info.json b/tests/data/app/expected-info.json index b899df7a8d..ab4f103939 100644 --- a/tests/data/app/expected-info.json +++ b/tests/data/app/expected-info.json @@ -60,6 +60,12 @@ }, "curl" ], - "os": "Linux" + "os": "Linux", + "owncloud": { + "@attributes" : { + "min-version": "7.01", + "max-version": "8" + } + } } } diff --git a/tests/data/app/valid-info.xml b/tests/data/app/valid-info.xml index 42f4e3edb7..4b22d55d7b 100644 --- a/tests/data/app/valid-info.xml +++ b/tests/data/app/valid-info.xml @@ -29,5 +29,6 @@ intl curl Linux + diff --git a/tests/lib/app/dependencyanalyzer.php b/tests/lib/app/dependencyanalyzer.php index 1cd24193ea..9c5db96e04 100644 --- a/tests/lib/app/dependencyanalyzer.php +++ b/tests/lib/app/dependencyanalyzer.php @@ -51,6 +51,9 @@ class DependencyAnalyzer extends \PHPUnit_Framework_TestCase { } return null; })); + $this->platformMock->expects($this->any()) + ->method('getOcVersion') + ->will( $this->returnValue('8.0.1')); $this->l10nMock = $this->getMockBuilder('\OCP\IL10N') ->disableOriginalConstructor() @@ -161,6 +164,35 @@ class DependencyAnalyzer extends \PHPUnit_Framework_TestCase { $this->assertEquals($expectedMissing, $missing); } + /** + * @dataProvider providesOC + * @param $expectedMissing + * @param $oc + */ + function testOC($expectedMissing, $oc) { + $app = array( + 'dependencies' => array() + ); + if (!is_null($oc)) { + $app['dependencies']['oc'] = $oc; + } + + $analyser = new \OC\App\DependencyAnalyzer($app, $this->platformMock, $this->l10nMock); + $missing = $analyser->analyze(); + + $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), From 95fc5addec189d21f4d714e3863c81d85d95ce09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Thu, 11 Dec 2014 15:24:36 +0100 Subject: [PATCH 05/11] adjust styling of missing dependencies in apps management --- settings/css/settings.css | 5 +++++ settings/templates/apps.php | 8 ++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/settings/css/settings.css b/settings/css/settings.css index 4594a22c6d..5cd9207fd6 100644 --- a/settings/css/settings.css +++ b/settings/css/settings.css @@ -200,6 +200,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; diff --git a/settings/templates/apps.php b/settings/templates/apps.php index 3bb0d45f58..48fe0f5a9c 100644 --- a/settings/templates/apps.php +++ b/settings/templates/apps.php @@ -52,12 +52,14 @@

{{/if}} {{#unless canInstall}} -
t('This app cannot be installed because the following dependencies are not fulfilled:')); ?>
+
+

t('This app cannot be installed because the following dependencies are not fulfilled:')); ?>

    {{#each missingDependencies}}
  • {{this}}
  • {{/each}}
+
{{/unless}} {{#if update}} @@ -70,9 +72,7 @@
{{else}} - {{#if canInstall}} - "/> - {{/if}} + "/> {{/if}} {{#if canUnInstall}} From 6566dc83e798b0956c1646b0a4e91873cc08bb9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Thu, 11 Dec 2014 15:37:45 +0100 Subject: [PATCH 06/11] single dependencies will not be represented as an array + fix unit tests --- lib/private/app/dependencyanalyzer.php | 25 +++++++++++++++++++------ tests/lib/app/dependencyanalyzer.php | 8 +++++--- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/lib/private/app/dependencyanalyzer.php b/lib/private/app/dependencyanalyzer.php index 795017e2b3..92f65be1cd 100644 --- a/lib/private/app/dependencyanalyzer.php +++ b/lib/private/app/dependencyanalyzer.php @@ -79,6 +79,9 @@ class DependencyAnalyzer { if (empty($supportedDatabases)) { return; } + if (!is_array($supportedDatabases)) { + $supportedDatabases = array($supportedDatabases); + } $supportedDatabases = array_map(function($db) { return $this->getValue($db); }, $supportedDatabases); @@ -94,6 +97,9 @@ class DependencyAnalyzer { } $commands = $this->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) { @@ -112,6 +118,9 @@ class DependencyAnalyzer { } $libs = $this->dependencies['lib']; + if (!is_array($libs)) { + $libs = array($libs); + } foreach($libs as $lib) { $libName = $this->getValue($lib); $libVersion = $this->platform->getLibraryVersion($libName); @@ -148,9 +157,13 @@ class DependencyAnalyzer { if (empty($oss)) { return; } - $oss = array_map(function($os) { - return $this->getValue($os); - }, $oss); + 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)) { $this->addMissing((string)$this->l->t('Following platforms are supported: %s', join(', ', $oss))); @@ -165,8 +178,8 @@ class DependencyAnalyzer { $minVersion = $this->appInfo['requiremin']; } $maxVersion = null; - if (isset($this->dependencies['oc']['@attributes']['max-version'])) { - $maxVersion = $this->dependencies['oc']['@attributes']['max-version']; + if (isset($this->dependencies['owncloud']['@attributes']['max-version'])) { + $maxVersion = $this->dependencies['owncloud']['@attributes']['max-version']; } elseif (isset($this->appInfo['requiremax'])) { $maxVersion = $this->appInfo['requiremax']; } @@ -190,7 +203,7 @@ class DependencyAnalyzer { private function getValue($element) { if (isset($element['@value'])) return $element['@value']; - return strval($element); + return (string)$element; } /** diff --git a/tests/lib/app/dependencyanalyzer.php b/tests/lib/app/dependencyanalyzer.php index 9c5db96e04..8443dc5d31 100644 --- a/tests/lib/app/dependencyanalyzer.php +++ b/tests/lib/app/dependencyanalyzer.php @@ -174,7 +174,7 @@ class DependencyAnalyzer extends \PHPUnit_Framework_TestCase { 'dependencies' => array() ); if (!is_null($oc)) { - $app['dependencies']['oc'] = $oc; + $app['dependencies']['owncloud'] = $oc; } $analyser = new \OC\App\DependencyAnalyzer($app, $this->platformMock, $this->l10nMock); @@ -197,6 +197,7 @@ class DependencyAnalyzer extends \PHPUnit_Framework_TestCase { 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')) ); } @@ -204,7 +205,7 @@ class DependencyAnalyzer extends \PHPUnit_Framework_TestCase { function providesLibs() { return array( // we expect curl to exist - array(array(), array('curl')), + 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 @@ -226,7 +227,7 @@ class DependencyAnalyzer extends \PHPUnit_Framework_TestCase { // 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(), array('grep')), + array(array(), 'grep'), ); } @@ -235,6 +236,7 @@ class DependencyAnalyzer extends \PHPUnit_Framework_TestCase { // 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'))), ); } From f1d17141133efa267ed5b30f01a4117162b76ce6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Thu, 11 Dec 2014 16:22:30 +0100 Subject: [PATCH 07/11] fix unit tests --- tests/data/app/expected-info.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/data/app/expected-info.json b/tests/data/app/expected-info.json index ab4f103939..d86ffed482 100644 --- a/tests/data/app/expected-info.json +++ b/tests/data/app/expected-info.json @@ -63,7 +63,7 @@ "os": "Linux", "owncloud": { "@attributes" : { - "min-version": "7.01", + "min-version": "7.0.1", "max-version": "8" } } From d94c1731d7887fa15156cec94916d71ee763d9d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Thu, 11 Dec 2014 17:02:07 +0100 Subject: [PATCH 08/11] check app dependencies on installation as well --- lib/private/app.php | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/lib/private/app.php b/lib/private/app.php index 86db8fd9f5..c84e9c5e98 100644 --- a/lib/private/app.php +++ b/lib/private/app.php @@ -25,6 +25,8 @@ * License along with this library. If not, see . * */ +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($app, new Platform($config), $l); + $missing = $dependencyAnalyzer->analyze(); + 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")); } From dcb88e395b63ac0747b1eb1af5cf3d3e65173efb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Fri, 12 Dec 2014 12:34:53 +0100 Subject: [PATCH 09/11] rework api of DependencyAnalyzer --- lib/private/app.php | 4 +- lib/private/app/dependencyanalyzer.php | 152 +++++++++--------- settings/controller/appsettingscontroller.php | 6 +- tests/lib/app/dependencyanalyzer.php | 31 ++-- 4 files changed, 94 insertions(+), 99 deletions(-) diff --git a/lib/private/app.php b/lib/private/app.php index c84e9c5e98..ecdc8ca832 100644 --- a/lib/private/app.php +++ b/lib/private/app.php @@ -1112,8 +1112,8 @@ class OC_App { } // check for required dependencies - $dependencyAnalyzer = new DependencyAnalyzer($app, new Platform($config), $l); - $missing = $dependencyAnalyzer->analyze(); + $dependencyAnalyzer = new DependencyAnalyzer(new Platform($config), $l); + $missing = $dependencyAnalyzer->analyze($app); if(!empty($missing)) { $missingMsg = join(PHP_EOL, $missing); throw new \Exception( diff --git a/lib/private/app/dependencyanalyzer.php b/lib/private/app/dependencyanalyzer.php index 92f65be1cd..ae40e8523f 100644 --- a/lib/private/app/dependencyanalyzer.php +++ b/lib/private/app/dependencyanalyzer.php @@ -1,5 +1,5 @@ platform = $platform; $this->l = $l; - if (isset($app['dependencies'])) { - $this->dependencies = $app['dependencies']; - } } /** * @param array $app * @returns array of missing dependencies */ - public function analyze() { - $this->analyzePhpVersion(); - $this->analyzeDatabases(); - $this->analyzeCommands(); - $this->analyzeLibraries(); - $this->analyzeOS(); - $this->analyzeOC(); - 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 analyzePhpVersion() { - if (isset($this->dependencies['php']['@attributes']['min-version'])) { - $minVersion = $this->dependencies['php']['@attributes']['min-version']; + 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, '<')) { - $this->addMissing((string)$this->l->t('PHP %s or higher is required.', $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 (isset($dependencies['php']['@attributes']['max-version'])) { + $maxVersion = $dependencies['php']['@attributes']['max-version']; if (version_compare($this->platform->getPhpVersion(), $maxVersion, '>')) { - $this->addMissing((string)$this->l->t('PHP with a version lower than %s is required.', $maxVersion)); + $missing[] = (string)$this->l->t('PHP with a version lower than %s is required.', $maxVersion); } } + return $missing; } - private function analyzeDatabases() { - 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; } if (!is_array($supportedDatabases)) { $supportedDatabases = array($supportedDatabases); } - $supportedDatabases = array_map(function($db) { + $supportedDatabases = array_map(function ($db) { return $this->getValue($db); }, $supportedDatabases); $currentDatabase = $this->platform->getDatabase(); if (!in_array($currentDatabase, $supportedDatabases)) { - $this->addMissing((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() { - if (!isset($this->dependencies['command'])) { - return; + private function analyzeCommands($dependencies) { + $missing = []; + if (!isset($dependencies['command'])) { + return $missing; } - $commands = $this->dependencies['command']; + $commands = $dependencies['command']; if (!is_array($commands)) { $commands = array($commands); } $os = $this->platform->getOS(); - foreach($commands as $command) { + foreach ($commands as $command) { if (isset($command['@attributes']['os']) && $command['@attributes']['os'] !== $os) { continue; } $commandName = $this->getValue($command); if (!$this->platform->isCommandKnown($commandName)) { - $this->addMissing((string)$this->l->t('The command line tool %s could not be found', $commandName)); + $missing[] = (string)$this->l->t('The command line tool %s could not be found', $commandName); } } + return $missing; } - private function analyzeLibraries() { - if (!isset($this->dependencies['lib'])) { - return; + private function analyzeLibraries($dependencies) { + $missing = []; + if (!isset($dependencies['lib'])) { + return $missing; } - $libs = $this->dependencies['lib']; + $libs = $dependencies['lib']; if (!is_array($libs)) { $libs = array($libs); } - foreach($libs as $lib) { + foreach ($libs as $lib) { $libName = $this->getValue($lib); $libVersion = $this->platform->getLibraryVersion($libName); if (is_null($libVersion)) { - $this->addMissing((string)$this->l->t('The library %s is not available.', $libName)); + $missing[] = (string)$this->l->t('The library %s is not available.', $libName); continue; } @@ -133,29 +135,31 @@ class DependencyAnalyzer { if (isset($lib['@attributes']['min-version'])) { $minVersion = $lib['@attributes']['min-version']; if (version_compare($libVersion, $minVersion, '<')) { - $this->addMissing((string)$this->l->t('Library %s with a version higher than %s is required - available version %s.', - array($libName, $minVersion, $libVersion))); + $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, '>')) { - $this->addMissing((string)$this->l->t('Library %s with a version lower than %s is required - available version %s.', - array($libName, $maxVersion, $libVersion))); + $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() { - if (!isset($this->dependencies['os'])) { - return; + private function analyzeOS($dependencies) { + $missing = []; + if (!isset($dependencies['os'])) { + return $missing; } - $oss = $this->dependencies['os']; + $oss = $dependencies['os']; if (empty($oss)) { - return; + return $missing; } if (is_array($oss)) { $oss = array_map(function ($os) { @@ -166,34 +170,37 @@ class DependencyAnalyzer { } $currentOS = $this->platform->getOS(); if (!in_array($currentOS, $oss)) { - $this->addMissing((string)$this->l->t('Following platforms are supported: %s', join(', ', $oss))); + $missing[] = (string)$this->l->t('Following platforms are supported: %s', join(', ', $oss)); } + return $missing; } - private function analyzeOC() { + private function analyzeOC($dependencies, $appInfo) { + $missing = []; $minVersion = null; - if (isset($this->dependencies['owncloud']['@attributes']['min-version'])) { - $minVersion = $this->dependencies['owncloud']['@attributes']['min-version']; - } elseif (isset($this->appInfo['requiremin'])) { - $minVersion = $this->appInfo['requiremin']; + if (isset($dependencies['owncloud']['@attributes']['min-version'])) { + $minVersion = $dependencies['owncloud']['@attributes']['min-version']; + } elseif (isset($appInfo['requiremin'])) { + $minVersion = $appInfo['requiremin']; } $maxVersion = null; - if (isset($this->dependencies['owncloud']['@attributes']['max-version'])) { - $maxVersion = $this->dependencies['owncloud']['@attributes']['max-version']; - } elseif (isset($this->appInfo['requiremax'])) { - $maxVersion = $this->appInfo['requiremax']; + 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, '<')) { - $this->addMissing((string)$this->l->t('ownCloud %s or higher is required.', $minVersion)); + $missing[] = (string)$this->l->t('ownCloud %s or higher is required.', $minVersion); } } if (!is_null($maxVersion)) { if (version_compare($this->platform->getOcVersion(), $maxVersion, '>')) { - $this->addMissing((string)$this->l->t('ownCloud with a version lower than %s is required.', $maxVersion)); + $missing[] = (string)$this->l->t('ownCloud with a version lower than %s is required.', $maxVersion); } } + return $missing; } /** @@ -205,11 +212,4 @@ class DependencyAnalyzer { return $element['@value']; return (string)$element; } - - /** - * @param $minVersion - */ - private function addMissing($message) { - $this->missing[] = $message; - } } diff --git a/settings/controller/appsettingscontroller.php b/settings/controller/appsettingscontroller.php index 3ad52bd218..b9e60c376d 100644 --- a/settings/controller/appsettingscontroller.php +++ b/settings/controller/appsettingscontroller.php @@ -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; diff --git a/tests/lib/app/dependencyanalyzer.php b/tests/lib/app/dependencyanalyzer.php index 8443dc5d31..a79995b78b 100644 --- a/tests/lib/app/dependencyanalyzer.php +++ b/tests/lib/app/dependencyanalyzer.php @@ -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() @@ -63,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); } /** @@ -80,8 +81,7 @@ 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($expectedMissing, $missing); @@ -98,8 +98,7 @@ 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($expectedMissing, $missing); @@ -116,8 +115,7 @@ class DependencyAnalyzer extends \PHPUnit_Framework_TestCase { if (!is_null($commands)) { $app['dependencies']['command'] = $commands; } - $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($expectedMissing, $missing); @@ -137,8 +135,7 @@ class DependencyAnalyzer extends \PHPUnit_Framework_TestCase { $app['dependencies']['lib'] = $libs; } - $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($expectedMissing, $missing); @@ -157,8 +154,7 @@ class DependencyAnalyzer extends \PHPUnit_Framework_TestCase { $app['dependencies']['os'] = $oss; } - $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($expectedMissing, $missing); @@ -177,8 +173,7 @@ class DependencyAnalyzer extends \PHPUnit_Framework_TestCase { $app['dependencies']['owncloud'] = $oc; } - $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($expectedMissing, $missing); From 79dfff2b4a0c67f86bb2d9c85dc2753a687025f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Fri, 12 Dec 2014 13:33:22 +0100 Subject: [PATCH 10/11] adding unit tests for PlatformRepository::normalizeVersion() --- tests/lib/app/platformrepository.php | 65 ++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 tests/lib/app/platformrepository.php diff --git a/tests/lib/app/platformrepository.php b/tests/lib/app/platformrepository.php new file mode 100644 index 0000000000..3d8849ce8a --- /dev/null +++ b/tests/lib/app/platformrepository.php @@ -0,0 +1,65 @@ +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'), + ); + }} From e58b9d3eb70996a6ccccabf979125fc0797fbd85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Mon, 15 Dec 2014 12:23:56 +0100 Subject: [PATCH 11/11] fixing owncloud version --- lib/private/app/platform.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/private/app/platform.php b/lib/private/app/platform.php index ba96fba00d..578f541e5d 100644 --- a/lib/private/app/platform.php +++ b/lib/private/app/platform.php @@ -40,7 +40,8 @@ class Platform { * @return string */ public function getOcVersion() { - return OC_Util::getVersion(); + $v = OC_Util::getVersion(); + return join('.', $v); } /**