From 53191eb0febfd114a095111a7983edf2c5dc334f Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Sat, 14 Apr 2012 11:55:57 +0200 Subject: [PATCH] Remove recommend, make suggest informational, add require-dev, fixes #78, fixes #510 --- src/Composer/Command/InstallCommand.php | 6 +-- src/Composer/Command/UpdateCommand.php | 8 ++-- src/Composer/DependencyResolver/Solver.php | 12 ----- src/Composer/Installer.php | 50 ++++++--------------- src/Composer/Package/AliasPackage.php | 18 +++----- src/Composer/Package/BasePackage.php | 11 +++-- src/Composer/Package/Dumper/ArrayDumper.php | 13 ++++-- src/Composer/Package/Loader/ArrayLoader.php | 10 +++-- src/Composer/Package/MemoryPackage.php | 14 +++--- src/Composer/Package/PackageInterface.php | 16 +++---- 10 files changed, 61 insertions(+), 97 deletions(-) diff --git a/src/Composer/Command/InstallCommand.php b/src/Composer/Command/InstallCommand.php index 1f711c334..bb6c636b6 100644 --- a/src/Composer/Command/InstallCommand.php +++ b/src/Composer/Command/InstallCommand.php @@ -32,8 +32,7 @@ class InstallCommand extends Command ->setDefinition(array( new InputOption('prefer-source', null, InputOption::VALUE_NONE, 'Forces installation from package sources when possible, including VCS information.'), new InputOption('dry-run', null, InputOption::VALUE_NONE, 'Outputs the operations but will not execute anything (implicitly enables --verbose).'), - new InputOption('no-install-recommends', null, InputOption::VALUE_NONE, 'Do not install recommended packages (ignored when installing from an existing lock file).'), - new InputOption('install-suggests', null, InputOption::VALUE_NONE, 'Also install suggested packages (ignored when installing from an existing lock file).'), + new InputOption('dev', null, InputOption::VALUE_NONE, 'Enables installation of dev-require packages.'), )) ->setHelp(<<install command reads the composer.json file from the @@ -57,8 +56,7 @@ EOT ->setDryRun($input->getOption('dry-run')) ->setVerbose($input->getOption('verbose')) ->setPreferSource($input->getOption('prefer-source')) - ->setInstallRecommends(!$input->getOption('no-install-recommends')) - ->setInstallSuggests($input->getOption('install-suggests')) + ->setDevMode($input->getOption('dev')) ; return $install->run() ? 0 : 1; diff --git a/src/Composer/Command/UpdateCommand.php b/src/Composer/Command/UpdateCommand.php index 44bd17b90..ffc848d87 100644 --- a/src/Composer/Command/UpdateCommand.php +++ b/src/Composer/Command/UpdateCommand.php @@ -30,8 +30,7 @@ class UpdateCommand extends Command ->setDefinition(array( new InputOption('prefer-source', null, InputOption::VALUE_NONE, 'Forces installation from package sources when possible, including VCS information.'), new InputOption('dry-run', null, InputOption::VALUE_NONE, 'Outputs the operations but will not execute anything (implicitly enables --verbose).'), - new InputOption('no-install-recommends', null, InputOption::VALUE_NONE, 'Do not install recommended packages.'), - new InputOption('install-suggests', null, InputOption::VALUE_NONE, 'Also install suggested packages.'), + new InputOption('dev', null, InputOption::VALUE_NONE, 'Enables installation of dev-require packages.'), )) ->setHelp(<<update command reads the composer.json file from the @@ -55,11 +54,10 @@ EOT ->setDryRun($input->getOption('dry-run')) ->setVerbose($input->getOption('verbose')) ->setPreferSource($input->getOption('prefer-source')) - ->setInstallRecommends(!$input->getOption('no-install-recommends')) - ->setInstallSuggests($input->getOption('install-suggests')) + ->setDevMode($input->getOption('dev')) ->setUpdate(true) ; - return $install->run(); + return $install->run() ? 0 : 1; } } diff --git a/src/Composer/DependencyResolver/Solver.php b/src/Composer/DependencyResolver/Solver.php index c19aa212b..6d939f063 100644 --- a/src/Composer/DependencyResolver/Solver.php +++ b/src/Composer/DependencyResolver/Solver.php @@ -283,18 +283,6 @@ class Solver } } } - - foreach ($package->getRecommends() as $link) { - foreach ($this->pool->whatProvides($link->getTarget(), $link->getConstraint()) as $recommend) { - $workQueue->enqueue($recommend); - } - } - - foreach ($package->getSuggests() as $link) { - foreach ($this->pool->whatProvides($link->getTarget(), $link->getConstraint()) as $suggest) { - $workQueue->enqueue($suggest); - } - } } } diff --git a/src/Composer/Installer.php b/src/Composer/Installer.php index 794d42ead..bd8b15827 100644 --- a/src/Composer/Installer.php +++ b/src/Composer/Installer.php @@ -77,10 +77,9 @@ class Installer protected $eventDispatcher; protected $preferSource = false; + protected $devMode = false; protected $dryRun = false; protected $verbose = false; - protected $installRecommends = true; - protected $installSuggests = false; protected $update = false; /** @@ -332,14 +331,6 @@ class Installer { $links = $this->package->getRequires(); - if ($this->installRecommends) { - $links = array_merge($links, $this->package->getRecommends()); - } - - if ($this->installSuggests) { - $links = array_merge($links, $this->package->getSuggests()); - } - return $links; } @@ -379,7 +370,7 @@ class Installer * @param boolean $dryRun * @return Installer */ - public function setDryRun($dryRun=true) + public function setDryRun($dryRun = true) { $this->dryRun = (boolean) $dryRun; @@ -387,53 +378,40 @@ class Installer } /** - * install recommend packages - * - * @param boolean $noInstallRecommends - * @return Installer - */ - public function setInstallRecommends($installRecommends=true) - { - $this->installRecommends = (boolean) $installRecommends; - - return $this; - } - - /** - * also install suggested packages + * prefer source installation * - * @param boolean $installSuggests + * @param boolean $preferSource * @return Installer */ - public function setInstallSuggests($installSuggests=true) + public function setPreferSource($preferSource = true) { - $this->installSuggests = (boolean) $installSuggests; + $this->preferSource = (boolean) $preferSource; return $this; } /** - * prefer source installation + * update packages * - * @param boolean $preferSource + * @param boolean $update * @return Installer */ - public function setPreferSource($preferSource=true) + public function setUpdate($update = true) { - $this->preferSource = (boolean) $preferSource; + $this->update = (boolean) $update; return $this; } /** - * update packages + * enables dev packages * * @param boolean $update * @return Installer */ - public function setUpdate($update=true) + public function setDevMode($devMode = true) { - $this->update = (boolean) $update; + $this->devMode = (boolean) $devMode; return $this; } @@ -444,7 +422,7 @@ class Installer * @param boolean $verbose * @return Installer */ - public function setVerbose($verbose=true) + public function setVerbose($verbose = true) { $this->verbose = (boolean) $verbose; diff --git a/src/Composer/Package/AliasPackage.php b/src/Composer/Package/AliasPackage.php index e453e3068..af5887c9e 100644 --- a/src/Composer/Package/AliasPackage.php +++ b/src/Composer/Package/AliasPackage.php @@ -52,7 +52,7 @@ class AliasPackage extends BasePackage $this->dev = VersionParser::isDev($version); // replace self.version dependencies - foreach (array('requires', 'recommends', 'suggests') as $type) { + foreach (array('requires', 'devRequires') as $type) { $links = $aliasOf->{'get'.ucfirst($type)}(); foreach ($links as $index => $link) { // link is self.version, but must be replacing also the replaced version @@ -141,17 +141,9 @@ class AliasPackage extends BasePackage /** * {@inheritDoc} */ - public function getRecommends() + public function getDevRequires() { - return $this->recommends; - } - - /** - * {@inheritDoc} - */ - public function getSuggests() - { - return $this->suggests; + return $this->devRequires; } /** @@ -266,6 +258,10 @@ class AliasPackage extends BasePackage { return $this->aliasOf->getHomepage(); } + public function getSuggests() + { + return $this->aliasOf->getSuggests(); + } public function getAuthors() { return $this->aliasOf->getAuthors(); diff --git a/src/Composer/Package/BasePackage.php b/src/Composer/Package/BasePackage.php index 90fb67868..171c5ee08 100644 --- a/src/Composer/Package/BasePackage.php +++ b/src/Composer/Package/BasePackage.php @@ -25,12 +25,11 @@ use Composer\Repository\PlatformRepository; abstract class BasePackage implements PackageInterface { public static $supportedLinkTypes = array( - 'require' => 'requires', - 'conflict' => 'conflicts', - 'provide' => 'provides', - 'replace' => 'replaces', - 'recommend' => 'recommends', - 'suggest' => 'suggests', + 'require' => array('description' => 'requires', 'method' => 'requires'), + 'conflict' => array('description' => 'conflicts', 'method' => 'conflicts'), + 'provide' => array('description' => 'provides', 'method' => 'provides'), + 'replace' => array('description' => 'replaces', 'method' => 'replaces'), + 'require-dev' => array('description' => 'requires (for development)', 'method' => 'devRequires'), ); protected $name; diff --git a/src/Composer/Package/Dumper/ArrayDumper.php b/src/Composer/Package/Dumper/ArrayDumper.php index 188d55c5c..ed25e656b 100644 --- a/src/Composer/Package/Dumper/ArrayDumper.php +++ b/src/Composer/Package/Dumper/ArrayDumper.php @@ -12,6 +12,7 @@ namespace Composer\Package\Dumper; +use Composer\Package\BasePackage; use Composer\Package\PackageInterface; /** @@ -26,7 +27,6 @@ class ArrayDumper 'binaries' => 'bin', 'scripts', 'type', - 'names', 'extra', 'installationSource' => 'installation-source', 'license', @@ -36,6 +36,7 @@ class ArrayDumper 'keywords', 'autoload', 'repositories', + 'includePaths' => 'include-path', ); $data = array(); @@ -64,14 +65,18 @@ class ArrayDumper $data['dist']['shasum'] = $package->getDistSha1Checksum(); } - foreach (array('require', 'conflict', 'provide', 'replace', 'suggest', 'recommend') as $linkType) { - if ($links = $package->{'get'.ucfirst($linkType).'s'}()) { + foreach (BasePackage::$supportedLinkTypes as $type => $opts) { + if ($links = $package->{'get'.ucfirst($opts['method'])}()) { foreach ($links as $link) { - $data[$linkType][$link->getTarget()] = $link->getPrettyConstraint(); + $data[$type][$link->getTarget()] = $link->getPrettyConstraint(); } } } + if ($packages = $package->getSuggests()) { + $data['suggest'] = $packages; + } + foreach ($keys as $method => $key) { if (is_numeric($method)) { $method = $key; diff --git a/src/Composer/Package/Loader/ArrayLoader.php b/src/Composer/Package/Loader/ArrayLoader.php index b44d6b950..0e706bad9 100644 --- a/src/Composer/Package/Loader/ArrayLoader.php +++ b/src/Composer/Package/Loader/ArrayLoader.php @@ -156,15 +156,19 @@ class ArrayLoader } } - foreach (Package\BasePackage::$supportedLinkTypes as $type => $description) { + foreach (Package\BasePackage::$supportedLinkTypes as $type => $opts) { if (isset($config[$type])) { - $method = 'set'.ucfirst($description); + $method = 'set'.ucfirst($opts['method']); $package->{$method}( - $this->loadLinksFromConfig($package, $description, $config[$type]) + $this->loadLinksFromConfig($package, $opts['description'], $config[$type]) ); } } + if (isset($config['suggest']) && is_array($config['suggest'])) { + $package->setSuggests($config['suggest']); + } + if (isset($config['autoload'])) { $package->setAutoload($config['autoload']); } diff --git a/src/Composer/Package/MemoryPackage.php b/src/Composer/Package/MemoryPackage.php index 8944f9b47..4a8f55cde 100644 --- a/src/Composer/Package/MemoryPackage.php +++ b/src/Composer/Package/MemoryPackage.php @@ -53,7 +53,7 @@ class MemoryPackage extends BasePackage protected $conflicts = array(); protected $provides = array(); protected $replaces = array(); - protected $recommends = array(); + protected $devRequires = array(); protected $suggests = array(); protected $autoload = array(); protected $includePaths = array(); @@ -484,25 +484,25 @@ class MemoryPackage extends BasePackage /** * Set the recommended packages * - * @param array $recommends A set of package links + * @param array $devRequires A set of package links */ - public function setRecommends(array $recommends) + public function setDevRequires(array $devRequires) { - $this->recommends = $recommends; + $this->devRequires = $devRequires; } /** * {@inheritDoc} */ - public function getRecommends() + public function getDevRequires() { - return $this->recommends; + return $this->devRequires; } /** * Set the suggested packages * - * @param array $suggests A set of package links + * @param array $suggests A set of package names/comments */ public function setSuggests(array $suggests) { diff --git a/src/Composer/Package/PackageInterface.php b/src/Composer/Package/PackageInterface.php index 82a51e8b5..5b8d2ddb2 100644 --- a/src/Composer/Package/PackageInterface.php +++ b/src/Composer/Package/PackageInterface.php @@ -220,20 +220,18 @@ interface PackageInterface function getReplaces(); /** - * Returns a set of links to packages which are recommended in - * combination with this package. These would most likely be installed - * automatically in combination with this package. + * Returns a set of links to packages which are required to develop + * this package. These are installed if in dev mode. * - * @return array An array of package links defining recommended packages + * @return array An array of package links defining packages required for development */ - function getRecommends(); + function getDevRequires(); /** - * Returns a set of links to packages which are suggested in combination - * with this package. These can be suggested to the user, but will not be - * automatically installed with this package. + * Returns a set of package names and reasons why they are useful in + * combination with this package. * - * @return array An array of package links defining suggested packages + * @return array An array of package suggestions with descriptions */ function getSuggests();