Browse Source
Merge pull request #12625 from owncloud/app-dependencies-libs-and-commands
Merge pull request #12625 from owncloud/app-dependencies-libs-and-commands
adding dependencies for command line tools and php librariesremotes/origin/fix-10825
11 changed files with 705 additions and 68 deletions
-
27lib/private/app.php
-
210lib/private/app/dependencyanalyzer.php
-
47lib/private/app/platform.php
-
210lib/private/app/platformrepository.php
-
6settings/controller/appsettingscontroller.php
-
5settings/css/settings.css
-
8settings/templates/apps.php
-
24tests/data/app/expected-info.json
-
5tests/data/app/valid-info.xml
-
166tests/lib/app/dependencyanalyzer.php
-
65tests/lib/app/platformrepository.php
@ -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; |
|||
} |
|||
} |
|||
} |
|||
@ -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'),
|
|||
); |
|||
}} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue