From 07a7284ffc07de38758dc4d9c2e20cf864ba6633 Mon Sep 17 00:00:00 2001 From: Phillip Look Date: Mon, 14 Oct 2013 10:49:34 +0200 Subject: [PATCH] Change dependency processing for update with whitelisted packages By default dependencies of white listed packages are no longer installed automaticaly. To Install dependencies of whitelisted packages use --with-dependencies. - rework after review comments - precise documentation of option - add missing punctuation marks --- doc/03-cli.md | 4 +- src/Composer/Command/UpdateCommand.php | 4 +- src/Composer/Installer.php | 18 +++++++++ .../update-whitelist-locked-require.test | 4 +- .../update-whitelist-with-dependencies.test | 40 +++++++++++++++++++ ...te-whitelist-with-dependency-conflict.test | 38 ++++++++++++++++++ .../Fixtures/installer/update-whitelist.test | 9 ++--- tests/Composer/Test/InstallerTest.php | 3 +- 8 files changed, 110 insertions(+), 10 deletions(-) create mode 100644 tests/Composer/Test/Fixtures/installer/update-whitelist-with-dependencies.test create mode 100644 tests/Composer/Test/Fixtures/installer/update-whitelist-with-dependency-conflict.test diff --git a/doc/03-cli.md b/doc/03-cli.md index 267d19893..9c07776ff 100644 --- a/doc/03-cli.md +++ b/doc/03-cli.md @@ -122,7 +122,9 @@ You can also use wildcards to update a bunch of packages at once: autoloader. This is recommended especially for production, but can take a bit of time to run so it is currently not done by default. * **--lock:** Only updates the lock file hash to suppress warning about the - lock file being out of date + lock file being out of date. +* **--with-dependencies** Add also all dependencies of whitelisted packages to the whitelist. + So all packages with their dependencies are updated recursively. ## require diff --git a/src/Composer/Command/UpdateCommand.php b/src/Composer/Command/UpdateCommand.php index ceabf7ff4..b2f8298e1 100644 --- a/src/Composer/Command/UpdateCommand.php +++ b/src/Composer/Command/UpdateCommand.php @@ -43,8 +43,9 @@ class UpdateCommand extends Command new InputOption('no-custom-installers', null, InputOption::VALUE_NONE, 'DEPRECATED: Use no-plugins instead.'), new InputOption('no-scripts', null, InputOption::VALUE_NONE, 'Skips the execution of all scripts defined in composer.json file.'), new InputOption('no-progress', null, InputOption::VALUE_NONE, 'Do not output download progress.'), + new InputOption('with-dependencies', null, InputOption::VALUE_NONE, 'Add also all dependencies of whitelisted packages to the whitelist.'), new InputOption('verbose', 'v|vv|vvv', InputOption::VALUE_NONE, 'Shows more details including new commits pulled in when updating packages.'), - new InputOption('optimize-autoloader', 'o', InputOption::VALUE_NONE, 'Optimize autoloader during autoloader dump') + new InputOption('optimize-autoloader', 'o', InputOption::VALUE_NONE, 'Optimize autoloader during autoloader dump.') )) ->setHelp(<<update command reads the composer.json file from the @@ -107,6 +108,7 @@ EOT ->setOptimizeAutoloader($input->getOption('optimize-autoloader')) ->setUpdate(true) ->setUpdateWhitelist($input->getOption('lock') ? array('lock') : $input->getArgument('packages')) + ->setWhitelistDependencies($input->getOption('with-dependencies')) ; if ($input->getOption('no-plugins')) { diff --git a/src/Composer/Installer.php b/src/Composer/Installer.php index f7169c271..4c04a7eec 100644 --- a/src/Composer/Installer.php +++ b/src/Composer/Installer.php @@ -106,6 +106,7 @@ class Installer protected $update = false; protected $runScripts = true; protected $updateWhitelist = null; + protected $whitelistDependencies = false; /** * @var array @@ -851,6 +852,10 @@ class Installer $seen[$package->getId()] = true; $this->updateWhitelist[$package->getName()] = true; + if (!$this->whitelistDependencies) { + continue; + } + $requires = $package->getRequires(); foreach ($requires as $require) { @@ -1051,6 +1056,19 @@ class Installer return $this; } + /** + * Should dependencies of whitelisted packages be updated recursively? + * + * @param boolean $updateDependencies + * @return Installer + */ + public function setWhitelistDependencies($updateDependencies = true) + { + $this->whitelistDependencies = (boolean) $updateDependencies; + + return $this; + } + /** * Disables plugins. * diff --git a/tests/Composer/Test/Fixtures/installer/update-whitelist-locked-require.test b/tests/Composer/Test/Fixtures/installer/update-whitelist-locked-require.test index 6586e461f..381416af1 100644 --- a/tests/Composer/Test/Fixtures/installer/update-whitelist-locked-require.test +++ b/tests/Composer/Test/Fixtures/installer/update-whitelist-locked-require.test @@ -1,5 +1,5 @@ --TEST-- -Update with a package whitelist only updates those packages and their dependencies if they are not present in composer.json +Update with a package whitelist only updates those packages if they are not present in composer.json --COMPOSER-- { "repositories": [ @@ -30,7 +30,7 @@ Update with a package whitelist only updates those packages and their dependenci { "name": "fixed-sub-dependency", "version": "1.0.0" } ] --RUN-- -update whitelisted +update whitelisted dependency --EXPECT-- Updating dependency (1.0.0) to dependency (1.1.0) Updating whitelisted (1.0.0) to whitelisted (1.1.0) diff --git a/tests/Composer/Test/Fixtures/installer/update-whitelist-with-dependencies.test b/tests/Composer/Test/Fixtures/installer/update-whitelist-with-dependencies.test new file mode 100644 index 000000000..bb2e04193 --- /dev/null +++ b/tests/Composer/Test/Fixtures/installer/update-whitelist-with-dependencies.test @@ -0,0 +1,40 @@ +--TEST-- +Update with a package whitelist only updates those packages and their dependencies listed as command arguments +--COMPOSER-- +{ + "repositories": [ + { + "type": "package", + "package": [ + { "name": "fixed", "version": "1.1.0" }, + { "name": "fixed", "version": "1.0.0" }, + { "name": "whitelisted", "version": "1.1.0", "require": { "dependency": "1.1.0" } }, + { "name": "whitelisted", "version": "1.0.0", "require": { "dependency": "1.0.0" } }, + { "name": "dependency", "version": "1.1.0" }, + { "name": "dependency", "version": "1.0.0" }, + { "name": "unrelated", "version": "1.1.0", "require": { "unrelated-dependency": "1.*" } }, + { "name": "unrelated", "version": "1.0.0", "require": { "unrelated-dependency": "1.*" } }, + { "name": "unrelated-dependency", "version": "1.1.0" }, + { "name": "unrelated-dependency", "version": "1.0.0" } + ] + } + ], + "require": { + "fixed": "1.*", + "whitelisted": "1.*", + "unrelated": "1.*" + } +} +--INSTALLED-- +[ + { "name": "fixed", "version": "1.0.0" }, + { "name": "whitelisted", "version": "1.0.0", "require": { "dependency": "1.0.0" } }, + { "name": "dependency", "version": "1.0.0" }, + { "name": "unrelated", "version": "1.0.0", "require": { "unrelated-dependency": "1.*" } }, + { "name": "unrelated-dependency", "version": "1.0.0" } +] +--RUN-- +update whitelisted --with-dependencies +--EXPECT-- +Updating dependency (1.0.0) to dependency (1.1.0) +Updating whitelisted (1.0.0) to whitelisted (1.1.0) diff --git a/tests/Composer/Test/Fixtures/installer/update-whitelist-with-dependency-conflict.test b/tests/Composer/Test/Fixtures/installer/update-whitelist-with-dependency-conflict.test new file mode 100644 index 000000000..f63229fbc --- /dev/null +++ b/tests/Composer/Test/Fixtures/installer/update-whitelist-with-dependency-conflict.test @@ -0,0 +1,38 @@ +--TEST-- +Update with a package whitelist only updates whitelisted packages if no dependency conflicts +--COMPOSER-- +{ + "repositories": [ + { + "type": "package", + "package": [ + { "name": "fixed", "version": "1.1.0" }, + { "name": "fixed", "version": "1.0.0" }, + { "name": "whitelisted", "version": "1.1.0", "require": { "dependency": "1.1.0" } }, + { "name": "whitelisted", "version": "1.0.0", "require": { "dependency": "1.0.0" } }, + { "name": "dependency", "version": "1.1.0" }, + { "name": "dependency", "version": "1.0.0" }, + { "name": "unrelated", "version": "1.1.0", "require": { "unrelated-dependency": "1.*" } }, + { "name": "unrelated", "version": "1.0.0", "require": { "unrelated-dependency": "1.*" } }, + { "name": "unrelated-dependency", "version": "1.1.0" }, + { "name": "unrelated-dependency", "version": "1.0.0" } + ] + } + ], + "require": { + "fixed": "1.*", + "whitelisted": "1.*", + "unrelated": "1.*" + } +} +--INSTALLED-- +[ + { "name": "fixed", "version": "1.0.0" }, + { "name": "whitelisted", "version": "1.0.0", "require": { "dependency": "1.0.0" } }, + { "name": "dependency", "version": "1.0.0" }, + { "name": "unrelated", "version": "1.0.0", "require": { "unrelated-dependency": "1.*" } }, + { "name": "unrelated-dependency", "version": "1.0.0" } +] +--RUN-- +update whitelisted +--EXPECT-- diff --git a/tests/Composer/Test/Fixtures/installer/update-whitelist.test b/tests/Composer/Test/Fixtures/installer/update-whitelist.test index 3d7ca30af..751d79e70 100644 --- a/tests/Composer/Test/Fixtures/installer/update-whitelist.test +++ b/tests/Composer/Test/Fixtures/installer/update-whitelist.test @@ -1,5 +1,5 @@ --TEST-- -Update with a package whitelist only updates those packages and their dependencies listed as command arguments +Update with a package whitelist only updates those packages listed as command arguments --COMPOSER-- { "repositories": [ @@ -8,8 +8,8 @@ Update with a package whitelist only updates those packages and their dependenci "package": [ { "name": "fixed", "version": "1.1.0" }, { "name": "fixed", "version": "1.0.0" }, - { "name": "whitelisted", "version": "1.1.0", "require": { "dependency": "1.1.0" } }, - { "name": "whitelisted", "version": "1.0.0", "require": { "dependency": "1.0.0" } }, + { "name": "whitelisted", "version": "1.1.0", "require": { "dependency": "1.*" } }, + { "name": "whitelisted", "version": "1.0.0", "require": { "dependency": "1.*" } }, { "name": "dependency", "version": "1.1.0" }, { "name": "dependency", "version": "1.0.0" }, { "name": "unrelated", "version": "1.1.0", "require": { "unrelated-dependency": "1.*" } }, @@ -28,7 +28,7 @@ Update with a package whitelist only updates those packages and their dependenci --INSTALLED-- [ { "name": "fixed", "version": "1.0.0" }, - { "name": "whitelisted", "version": "1.0.0", "require": { "dependency": "1.0.0" } }, + { "name": "whitelisted", "version": "1.0.0", "require": { "dependency": "1.*" } }, { "name": "dependency", "version": "1.0.0" }, { "name": "unrelated", "version": "1.0.0", "require": { "unrelated-dependency": "1.*" } }, { "name": "unrelated-dependency", "version": "1.0.0" } @@ -36,5 +36,4 @@ Update with a package whitelist only updates those packages and their dependenci --RUN-- update whitelisted --EXPECT-- -Updating dependency (1.0.0) to dependency (1.1.0) Updating whitelisted (1.0.0) to whitelisted (1.1.0) diff --git a/tests/Composer/Test/InstallerTest.php b/tests/Composer/Test/InstallerTest.php index bd9e7d3b6..29c153e88 100644 --- a/tests/Composer/Test/InstallerTest.php +++ b/tests/Composer/Test/InstallerTest.php @@ -214,7 +214,8 @@ class InstallerTest extends TestCase ->setDevMode($input->getOption('dev')) ->setUpdate(true) ->setDryRun($input->getOption('dry-run')) - ->setUpdateWhitelist($input->getArgument('packages')); + ->setUpdateWhitelist($input->getArgument('packages')) + ->setWhitelistDependencies($input->getOption('with-dependencies')); return $installer->run() ? 0 : 1; });