From 159badb06bf4ed25cadbaeabd56b7b2b7b30b33e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Thieriot?= Date: Thu, 13 Dec 2012 09:08:04 +0000 Subject: [PATCH 1/2] Add ability to use a Regexp when updating packages --- doc/03-cli.md | 4 ++ src/Composer/Installer.php | 8 +++- .../installer/update-whitelist-patterns.test | 45 +++++++++++++++++++ 3 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 tests/Composer/Test/Fixtures/installer/update-whitelist-patterns.test diff --git a/doc/03-cli.md b/doc/03-cli.md index 39634e06c..2a69d7540 100644 --- a/doc/03-cli.md +++ b/doc/03-cli.md @@ -96,6 +96,10 @@ If you just want to update a few packages and not all, you can list them as such $ php composer.phar update vendor/package vendor/package2 +You can also use a Regular expression pattern to update a bunch of packages at once: + + $ php composer.phar update vendor.* + ### Options * **--prefer-source:** Install packages from `source` when available. diff --git a/src/Composer/Installer.php b/src/Composer/Installer.php index 88d4ff65f..dea566eca 100644 --- a/src/Composer/Installer.php +++ b/src/Composer/Installer.php @@ -624,7 +624,13 @@ class Installer throw new \LogicException('isUpdateable should only be called when a whitelist is present'); } - return isset($this->updateWhitelist[$package->getName()]); + foreach($this->updateWhitelist as $whiteListedPattern => $void) { + if(preg_match("#^".$whiteListedPattern."$#i", $package->getName())) { + return true; + } + } + + return false; } /** diff --git a/tests/Composer/Test/Fixtures/installer/update-whitelist-patterns.test b/tests/Composer/Test/Fixtures/installer/update-whitelist-patterns.test new file mode 100644 index 000000000..ff959dd3e --- /dev/null +++ b/tests/Composer/Test/Fixtures/installer/update-whitelist-patterns.test @@ -0,0 +1,45 @@ +--TEST-- +Update with a package whitelist only updates those corresponding to the pattern +--COMPOSER-- +{ + "repositories": [ + { + "type": "package", + "package": [ + { "name": "vendor/Test-Package", "version": "2.0" }, + { "name": "vendor/NotMe", "version": "2.0" }, + { "name": "exact/Test-Package", "version": "2.0" }, + { "name": "notexact/TestPackage", "version": "2.0" }, + { "name": "all/Package1", "version": "2.0" }, + { "name": "all/Package2", "version": "2.0" }, + { "name": "another/another", "version": "2.0" } + ] + } + ], + "require": { + "vendor/Test-Package": "*.*", + "vendor/NotMe": "*.*", + "exact/Test-Package": "*.*", + "notexact/TestPackage": "*.*", + "all/Package1": "*.*", + "all/Package2": "*.*", + "another/another": "*.*" + } +} +--INSTALLED-- +[ + { "name": "vendor/Test-Package", "version": "1.0" }, + { "name": "vendor/NotMe", "version": "1.0" }, + { "name": "exact/Test-Package", "version": "1.0" }, + { "name": "notexact/TestPackage", "version": "1.0" }, + { "name": "all/Package1", "version": "1.0" }, + { "name": "all/Package2", "version": "1.0" }, + { "name": "another/another", "version": "1.0" } +] +--RUN-- +update vendor/Test.* exact/Test-Package notexact/Test all.* +--EXPECT-- +Updating vendor/Test-Package (1.0) to vendor/Test-Package (2.0) +Updating exact/Test-Package (1.0) to exact/Test-Package (2.0) +Updating all/Package1 (1.0) to all/Package1 (2.0) +Updating all/Package2 (1.0) to all/Package2 (2.0) \ No newline at end of file From e264282ac7260b3fa54e4bf659fb69792fafd188 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Thieriot?= Date: Thu, 13 Dec 2012 14:06:06 +0000 Subject: [PATCH 2/2] Allowed only * wildcard --- doc/03-cli.md | 4 ++-- src/Composer/Installer.php | 4 +++- .../Fixtures/installer/update-whitelist-patterns.test | 11 +++++++---- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/doc/03-cli.md b/doc/03-cli.md index 2a69d7540..a87247482 100644 --- a/doc/03-cli.md +++ b/doc/03-cli.md @@ -96,9 +96,9 @@ If you just want to update a few packages and not all, you can list them as such $ php composer.phar update vendor/package vendor/package2 -You can also use a Regular expression pattern to update a bunch of packages at once: +You can also use wildcards to update a bunch of packages at once: - $ php composer.phar update vendor.* + $ php composer.phar update vendor/* ### Options diff --git a/src/Composer/Installer.php b/src/Composer/Installer.php index dea566eca..ef44d2109 100644 --- a/src/Composer/Installer.php +++ b/src/Composer/Installer.php @@ -625,7 +625,9 @@ class Installer } foreach($this->updateWhitelist as $whiteListedPattern => $void) { - if(preg_match("#^".$whiteListedPattern."$#i", $package->getName())) { + $cleanedWhiteListedPattern = str_replace('\*', '.*', preg_quote($whiteListedPattern)); + + if(preg_match("#^".$cleanedWhiteListedPattern."$#i", $package->getName())) { return true; } } diff --git a/tests/Composer/Test/Fixtures/installer/update-whitelist-patterns.test b/tests/Composer/Test/Fixtures/installer/update-whitelist-patterns.test index ff959dd3e..e8aa593c0 100644 --- a/tests/Composer/Test/Fixtures/installer/update-whitelist-patterns.test +++ b/tests/Composer/Test/Fixtures/installer/update-whitelist-patterns.test @@ -12,7 +12,8 @@ Update with a package whitelist only updates those corresponding to the pattern { "name": "notexact/TestPackage", "version": "2.0" }, { "name": "all/Package1", "version": "2.0" }, { "name": "all/Package2", "version": "2.0" }, - { "name": "another/another", "version": "2.0" } + { "name": "another/another", "version": "2.0" }, + { "name": "no/regexp", "version": "2.0" } ] } ], @@ -23,7 +24,8 @@ Update with a package whitelist only updates those corresponding to the pattern "notexact/TestPackage": "*.*", "all/Package1": "*.*", "all/Package2": "*.*", - "another/another": "*.*" + "another/another": "*.*", + "no/regexp": "*.*" } } --INSTALLED-- @@ -34,10 +36,11 @@ Update with a package whitelist only updates those corresponding to the pattern { "name": "notexact/TestPackage", "version": "1.0" }, { "name": "all/Package1", "version": "1.0" }, { "name": "all/Package2", "version": "1.0" }, - { "name": "another/another", "version": "1.0" } + { "name": "another/another", "version": "1.0" }, + { "name": "no/regexp", "version": "1.0" } ] --RUN-- -update vendor/Test.* exact/Test-Package notexact/Test all.* +update vendor/Test* exact/Test-Package notexact/Test all/* no/reg?xp --EXPECT-- Updating vendor/Test-Package (1.0) to vendor/Test-Package (2.0) Updating exact/Test-Package (1.0) to exact/Test-Package (2.0)