Procházet zdrojové kódy

Merge pull request #886 from palex-fpt/pear-binaries

Pear binaries
Jordi Boggiano před 13 roky
rodič
revize
d87b8d3493

+ 13 - 6
src/Composer/Downloader/PearPackageExtractor.php

@@ -25,6 +25,7 @@ use Composer\Util\Filesystem;
  */
 class PearPackageExtractor
 {
+    private static $rolesWithoutPackageNamePrefix = array('php', 'script', 'www');
     /** @var Filesystem */
     private $filesystem;
     private $file;
@@ -141,13 +142,13 @@ class PearPackageExtractor
             $packageName = (string) $package->name;
             $packageVersion = (string) $package->release->version;
             $sourceDir = $packageName . '-' . $packageVersion;
-            $result = $this->buildSourceList10($children, $roles, $sourceDir);
+            $result = $this->buildSourceList10($children, $roles, $sourceDir, '', null, $packageName);
         } elseif ('2.0' == $packageSchemaVersion || '2.1' == $packageSchemaVersion) {
             $children = $package->contents->children();
             $packageName = (string) $package->name;
             $packageVersion = (string) $package->version->release;
             $sourceDir = $packageName . '-' . $packageVersion;
-            $result = $this->buildSourceList20($children, $roles, $sourceDir);
+            $result = $this->buildSourceList20($children, $roles, $sourceDir, '', null, $packageName);
 
             $namespaces = $package->getNamespaces();
             $package->registerXPathNamespace('ns', $namespaces['']);
@@ -188,7 +189,7 @@ class PearPackageExtractor
         }
     }
 
-    private function buildSourceList10($children, $targetRoles, $source = '', $target = '', $role = null)
+    private function buildSourceList10($children, $targetRoles, $source = '', $target = '', $role = null, $packageName)
     {
         $result = array();
 
@@ -199,7 +200,7 @@ class PearPackageExtractor
                 $dirSource = $this->combine($source, (string) $child['name']);
                 $dirTarget = $child['baseinstalldir'] ? : $target;
                 $dirRole = $child['role'] ? : $role;
-                $dirFiles = $this->buildSourceList10($child->children(), $targetRoles, $dirSource, $dirTarget, $dirRole);
+                $dirFiles = $this->buildSourceList10($child->children(), $targetRoles, $dirSource, $dirTarget, $dirRole, $packageName);
                 $result = array_merge($result, $dirFiles);
             } elseif ($child->getName() == 'file') {
                 $fileRole = (string) $child['role'] ? : $role;
@@ -207,6 +208,9 @@ class PearPackageExtractor
                     $fileName = (string) ($child['name'] ? : $child[0]); // $child[0] means text content
                     $fileSource = $this->combine($source, $fileName);
                     $fileTarget = $this->combine((string) $child['baseinstalldir'] ? : $target, $fileName);
+                    if (!in_array($fileRole, self::$rolesWithoutPackageNamePrefix)) {
+                        $fileTarget = $packageName . '/' . $fileTarget;
+                    }
                     $result[(string) $child['name']] = array('from' => $fileSource, 'to' => $fileTarget, 'role' => $fileRole, 'tasks' => array());
                 }
             }
@@ -215,7 +219,7 @@ class PearPackageExtractor
         return $result;
     }
 
-    private function buildSourceList20($children, $targetRoles, $source = '', $target = '', $role = null)
+    private function buildSourceList20($children, $targetRoles, $source = '', $target = '', $role = null, $packageName)
     {
         $result = array();
 
@@ -226,7 +230,7 @@ class PearPackageExtractor
                 $dirSource = $this->combine($source, $child['name']);
                 $dirTarget = $child['baseinstalldir'] ? : $target;
                 $dirRole = $child['role'] ? : $role;
-                $dirFiles = $this->buildSourceList20($child->children(), $targetRoles, $dirSource, $dirTarget, $dirRole);
+                $dirFiles = $this->buildSourceList20($child->children(), $targetRoles, $dirSource, $dirTarget, $dirRole, $packageName);
                 $result = array_merge($result, $dirFiles);
             } elseif ('file' == $child->getName()) {
                 $fileRole = (string) $child['role'] ? : $role;
@@ -239,6 +243,9 @@ class PearPackageExtractor
                             $fileTasks[] = array('from' => (string) $taskNode->attributes()->from, 'to' => (string) $taskNode->attributes()->to);
                         }
                     }
+                    if (!in_array($fileRole, self::$rolesWithoutPackageNamePrefix)) {
+                        $fileTarget = $packageName . '/' . $fileTarget;
+                    }
                     $result[(string) $child['name']] = array('from' => $fileSource, 'to' => $fileTarget, 'role' => $fileRole, 'tasks' => $fileTasks);
                 }
             }

+ 0 - 1
src/Composer/Installer/InstallationManager.php

@@ -23,7 +23,6 @@ use Composer\DependencyResolver\Operation\UpdateOperation;
 use Composer\DependencyResolver\Operation\UninstallOperation;
 use Composer\DependencyResolver\Operation\MarkAliasInstalledOperation;
 use Composer\DependencyResolver\Operation\MarkAliasUninstalledOperation;
-use Composer\Util\Filesystem;
 
 /**
  * Package operation manager.

+ 16 - 13
src/Composer/Installer/PearInstaller.php

@@ -15,10 +15,8 @@ namespace Composer\Installer;
 use Composer\IO\IOInterface;
 use Composer\Composer;
 use Composer\Downloader\PearPackageExtractor;
-use Composer\Downloader\DownloadManager;
 use Composer\Repository\InstalledRepositoryInterface;
 use Composer\Package\PackageInterface;
-use Composer\Util\Filesystem;
 
 /**
  * Package installation manager.
@@ -31,9 +29,9 @@ class PearInstaller extends LibraryInstaller
     /**
      * Initializes library installer.
      *
-     * @param IOInterface     $io        io instance
-     * @param Composer        $composer
-     * @param string          $type      package type that this installer handles
+     * @param IOInterface $io       io instance
+     * @param Composer    $composer
+     * @param string      $type     package type that this installer handles
      */
     public function __construct(IOInterface $io, Composer $composer, $type = 'pear-library')
     {
@@ -52,22 +50,25 @@ class PearInstaller extends LibraryInstaller
     protected function installCode(PackageInterface $package)
     {
         parent::installCode($package);
+        parent::initializeBinDir();
 
         $isWindows = defined('PHP_WINDOWS_VERSION_BUILD') ? true : false;
+        $php_bin = $this->binDir . ($isWindows ? '/composer-php.bat' : '/composer-php');
 
+        $installPath = $this->getInstallPath($package);
         $vars = array(
             'os' => $isWindows ? 'windows' : 'linux',
-            'php_bin' => ($isWindows ? getenv('PHPRC') .'php.exe' : trim(`which php`)),
-            'pear_php' => $this->getInstallPath($package),
-            'bin_dir' => $this->getInstallPath($package) . '/bin',
-            'php_dir' => $this->getInstallPath($package),
-            'data_dir' => '@DATA_DIR@',
+            'php_bin' => $php_bin,
+            'pear_php' => $installPath,
+            'php_dir' => $installPath,
+            'bin_dir' => $installPath . '/bin',
+            'data_dir' => $installPath . '/data',
             'version' => $package->getPrettyVersion(),
         );
 
         $packageArchive = $this->getInstallPath($package).'/'.pathinfo($package->getDistUrl(), PATHINFO_BASENAME);
         $pearExtractor = new PearPackageExtractor($packageArchive);
-        $pearExtractor->extractTo($this->getInstallPath($package), array('php' => '/', 'script' => '/bin'), $vars);
+        $pearExtractor->extractTo($this->getInstallPath($package), array('php' => '/', 'script' => '/bin', 'data' => '/data'), $vars);
 
         if ($this->io->isVerbose()) {
             $this->io->write('    Cleaning up');
@@ -80,8 +81,10 @@ class PearInstaller extends LibraryInstaller
         $binariesPath = $this->getInstallPath($package) . '/bin/';
         $binaries = array();
         if (file_exists($binariesPath)) {
-            foreach (new \FilesystemIterator($binariesPath, \FilesystemIterator::KEY_AS_FILENAME) as $fileName => $value) {
-                $binaries[] = 'bin/'.$fileName;
+            foreach (new \FilesystemIterator($binariesPath, \FilesystemIterator::KEY_AS_FILENAME | \FilesystemIterator::CURRENT_AS_FILEINFO) as $fileName => $value) {
+                if (!$value->isDir()) {
+                    $binaries[] = 'bin/'.$fileName;
+                }
             }
         }
 

+ 11 - 3
src/Composer/Package/Version/VersionParser.php

@@ -24,7 +24,7 @@ use Composer\Package\LinkConstraint\VersionConstraint;
  */
 class VersionParser
 {
-    private static $modifierRegex = '[.-]?(?:(beta|RC|alpha|patch|pl|p)(?:[.-]?(\d+))?)?([.-]?dev)?';
+    private static $modifierRegex = '[._-]?(?:(beta|b|RC|alpha|a|patch|pl|p)(?:[.-]?(\d+))?)?([.-]?dev)?';
 
     /**
      * Returns the stability of a version
@@ -45,8 +45,16 @@ class VersionParser
             return 'dev';
         }
 
-        if (!empty($match[1]) && ($match[1] === 'beta' || $match[1] === 'alpha' || $match[1] === 'RC')) {
-            return $match[1];
+        if (!empty($match[1])) {
+            if ('beta' === $match[1] || 'b' === $match[1]) {
+                return 'beta';
+            }
+            if ('alpha' === $match[1] || 'a' === $match[1]) {
+                return 'alpha';
+            }
+            if ('RC' === $match[1]) {
+                return 'RC';
+            }
         }
 
         return 'stable';

+ 3 - 0
tests/Composer/Test/Package/Version/VersionParserTest.php

@@ -238,6 +238,9 @@ class VersionParserTest extends \PHPUnit_Framework_TestCase
             array('stable', '3.1.2-patch'),
             array('alpha',  '3.1.2-alpha5'),
             array('beta',   '3.1.2-beta'),
+            array('beta',   '2.0b1'),
+            array('alpha',  '1.2.0a1'),
+            array('alpha',  '1.2_a1'),
         );
     }
 }