adding dependencies for command line tools
This commit is contained in:
parent
b33d8a3d60
commit
08f1db4451
|
@ -10,31 +10,31 @@
|
||||||
|
|
||||||
namespace OC\App;
|
namespace OC\App;
|
||||||
|
|
||||||
|
use OCP\IL10N;
|
||||||
|
|
||||||
class DependencyAnalyzer {
|
class DependencyAnalyzer {
|
||||||
|
|
||||||
/** @var Platform */
|
/** @var Platform */
|
||||||
private $system;
|
private $platform;
|
||||||
|
|
||||||
/** @var \OCP\IL10N */
|
/** @var \OCP\IL10N */
|
||||||
private $l;
|
private $l;
|
||||||
|
|
||||||
/** @var array */
|
/** @var array */
|
||||||
private $missing;
|
private $missing = array();
|
||||||
|
|
||||||
/** @var array */
|
/** @var array */
|
||||||
private $dependencies;
|
private $dependencies = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array $app
|
* @param array $app
|
||||||
* @param Platform $platform
|
* @param Platform $platform
|
||||||
* @param \OCP\IL10N $l
|
* @param \OCP\IL10N $l
|
||||||
*/
|
*/
|
||||||
function __construct(array $app, $platform, $l) {
|
function __construct(array $app, Platform $platform, IL10N $l) {
|
||||||
$this->system = $platform;
|
$this->platform = $platform;
|
||||||
$this->l = $l;
|
$this->l = $l;
|
||||||
$this->missing = array();
|
if (isset($app['dependencies'])) {
|
||||||
$this->dependencies = array();
|
|
||||||
if (array_key_exists('dependencies', $app)) {
|
|
||||||
$this->dependencies = $app['dependencies'];
|
$this->dependencies = $app['dependencies'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -46,20 +46,21 @@ class DependencyAnalyzer {
|
||||||
public function analyze() {
|
public function analyze() {
|
||||||
$this->analysePhpVersion();
|
$this->analysePhpVersion();
|
||||||
$this->analyseSupportedDatabases();
|
$this->analyseSupportedDatabases();
|
||||||
|
$this->analyseCommands();
|
||||||
return $this->missing;
|
return $this->missing;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function analysePhpVersion() {
|
private function analysePhpVersion() {
|
||||||
if (isset($this->dependencies['php']['@attributes']['min-version'])) {
|
if (isset($this->dependencies['php']['@attributes']['min-version'])) {
|
||||||
$minVersion = $this->dependencies['php']['@attributes']['min-version'];
|
$minVersion = $this->dependencies['php']['@attributes']['min-version'];
|
||||||
if (version_compare($this->system->getPhpVersion(), $minVersion, '<')) {
|
if (version_compare($this->platform->getPhpVersion(), $minVersion, '<')) {
|
||||||
$this->missing[] = (string)$this->l->t('PHP %s or higher is required.', $minVersion);
|
$this->addMissing((string)$this->l->t('PHP %s or higher is required.', $minVersion));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (isset($this->dependencies['php']['@attributes']['max-version'])) {
|
if (isset($this->dependencies['php']['@attributes']['max-version'])) {
|
||||||
$maxVersion = $this->dependencies['php']['@attributes']['max-version'];
|
$maxVersion = $this->dependencies['php']['@attributes']['max-version'];
|
||||||
if (version_compare($this->system->getPhpVersion(), $maxVersion, '>')) {
|
if (version_compare($this->platform->getPhpVersion(), $maxVersion, '>')) {
|
||||||
$this->missing[] = (string)$this->l->t('PHP with a version less then %s is required.', $maxVersion);
|
$this->addMissing((string)$this->l->t('PHP with a version less then %s is required.', $maxVersion));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -74,14 +75,46 @@ class DependencyAnalyzer {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$supportedDatabases = array_map(function($db) {
|
$supportedDatabases = array_map(function($db) {
|
||||||
if (isset($db['@value'])) {
|
return $this->getValue($db);
|
||||||
return $db['@value'];
|
|
||||||
}
|
|
||||||
return $db;
|
|
||||||
}, $supportedDatabases);
|
}, $supportedDatabases);
|
||||||
$currentDatabase = $this->system->getDatabase();
|
$currentDatabase = $this->platform->getDatabase();
|
||||||
if (!in_array($currentDatabase, $supportedDatabases)) {
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,16 +12,32 @@ namespace OC\App;
|
||||||
|
|
||||||
use OCP\IConfig;
|
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 {
|
class Platform {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param IConfig $config
|
||||||
|
*/
|
||||||
function __construct(IConfig $config) {
|
function __construct(IConfig $config) {
|
||||||
$this->config = $config;
|
$this->config = $config;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
public function getPhpVersion() {
|
public function getPhpVersion() {
|
||||||
return phpversion();
|
return phpversion();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
public function getDatabase() {
|
public function getDatabase() {
|
||||||
$dbType = $this->config->getSystemValue('dbtype', 'sqlite');
|
$dbType = $this->config->getSystemValue('dbtype', 'sqlite');
|
||||||
if ($dbType === 'sqlite3') {
|
if ($dbType === 'sqlite3') {
|
||||||
|
@ -30,4 +46,20 @@ class Platform {
|
||||||
|
|
||||||
return $dbType;
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,6 +35,15 @@ class DependencyAnalyzer extends \PHPUnit_Framework_TestCase {
|
||||||
$this->platformMock->expects($this->any())
|
$this->platformMock->expects($this->any())
|
||||||
->method('getDatabase')
|
->method('getDatabase')
|
||||||
->will( $this->returnValue('mysql'));
|
->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')
|
$this->l10nMock = $this->getMockBuilder('\OCP\IL10N')
|
||||||
->disableOriginalConstructor()
|
->disableOriginalConstructor()
|
||||||
->getMock();
|
->getMock();
|
||||||
|
@ -64,7 +73,6 @@ class DependencyAnalyzer extends \PHPUnit_Framework_TestCase {
|
||||||
$missing = $analyser->analyze();
|
$missing = $analyser->analyze();
|
||||||
|
|
||||||
$this->assertTrue(is_array($missing));
|
$this->assertTrue(is_array($missing));
|
||||||
$this->assertEquals(count($expectedMissing), count($missing));
|
|
||||||
$this->assertEquals($expectedMissing, $missing);
|
$this->assertEquals($expectedMissing, $missing);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,10 +91,41 @@ class DependencyAnalyzer extends \PHPUnit_Framework_TestCase {
|
||||||
$missing = $analyser->analyze();
|
$missing = $analyser->analyze();
|
||||||
|
|
||||||
$this->assertTrue(is_array($missing));
|
$this->assertTrue(is_array($missing));
|
||||||
$this->assertEquals(count($expectedMissing), count($missing));
|
|
||||||
$this->assertEquals($expectedMissing, $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() {
|
function providesDatabases() {
|
||||||
return array(
|
return array(
|
||||||
// non BC - in case on databases are defined -> all are supported
|
// non BC - in case on databases are defined -> all are supported
|
||||||
|
|
Loading…
Reference in New Issue