]> source.dussan.org Git - nextcloud-server.git/commitdiff
adding dependency to owncloud version - with fallback to requiremin and requiremax
authorThomas Müller <thomas.mueller@tmit.eu>
Fri, 5 Dec 2014 14:28:33 +0000 (15:28 +0100)
committerThomas Müller <thomas.mueller@tmit.eu>
Thu, 11 Dec 2014 11:02:12 +0000 (12:02 +0100)
lib/private/app/dependencyanalyzer.php
lib/private/app/platform.php
tests/data/app/expected-info.json
tests/data/app/valid-info.xml
tests/lib/app/dependencyanalyzer.php

index 2e8388723850b93f7e83f6ad82b726ee929a4fe3..795017e2b37b7a04527f4dd9338266d7c90bd373 100644 (file)
@@ -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
index 6279bb5f20c4fb37c6e44b9d950e02dc9568d937..ba96fba00dbdf905cb8ed96845a86a81de38f9ec 100644 (file)
@@ -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
         */
index b899df7a8d6923339bd1fc094064ca001df96a36..ab4f103939ab79ef7ab73faed192801e87fda5c8 100644 (file)
                        },
                        "curl"
                ],
-               "os": "Linux"
+               "os": "Linux",
+               "owncloud": {
+                       "@attributes" : {
+                               "min-version": "7.01",
+                               "max-version": "8"
+                       }
+               }
        }
 }
index 42f4e3edb7fea5770d9d000b0e03f3801d55fe22..4b22d55d7bca5e58b81a4404892a15aeb223c8fc 100644 (file)
@@ -29,5 +29,6 @@
                <lib max-version="2.0">intl</lib>
                <lib>curl</lib>
                <os>Linux</os>
+               <owncloud min-version="7.0.1" max-version="8" />
        </dependencies>
 </info>
index 1cd24193ea678d57b332c122f9d00234d8471352..9c5db96e04560726a7a7df60a2d85b88a778a096 100644 (file)
@@ -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),