diff --git a/src/Composer/Command/DebugPackagesCommand.php b/src/Composer/Command/DebugPackagesCommand.php index b92d06373..a953baed6 100644 --- a/src/Composer/Command/DebugPackagesCommand.php +++ b/src/Composer/Command/DebugPackagesCommand.php @@ -33,7 +33,7 @@ class DebugPackagesCommand extends Command ->setName('debug:packages') ->setDescription('Lists all existing packages and their version') ->setHelp(<<php composer debug:packages +php composer.phar debug:packages EOT ) diff --git a/src/Composer/Command/InstallCommand.php b/src/Composer/Command/InstallCommand.php index f5c8e9cca..55cb2d8e1 100644 --- a/src/Composer/Command/InstallCommand.php +++ b/src/Composer/Command/InstallCommand.php @@ -43,7 +43,7 @@ The install command reads the composer.json file from the current directory, processes it, and downloads and installs all the libraries and dependencies outlined in that file. -php composer install +php composer.phar install EOT ) @@ -51,10 +51,15 @@ EOT } protected function execute(InputInterface $input, OutputInterface $output) + { + return $this->install($output, $input->getOption('dev')); + } + + public function install(OutputInterface $output, $preferSource, $update = false) { $composer = $this->getComposer(); - if ($input->getOption('dev')) { + if ($preferSource) { $composer->getDownloadManager()->setPreferSource(true); } @@ -72,7 +77,30 @@ EOT // creating requirements request $request = new Request($pool); - if ($composer->getLocker()->isLocked()) { + if ($update) { + $output->writeln('> Updating dependencies.'); + $listedPackages = array(); + $installedPackages = $installedRepo->getPackages(); + + foreach ($composer->getPackage()->getRequires() as $link) { + $listedPackages[] = $link->getTarget(); + + foreach ($installedPackages as $package) { + if ($package->getName() === $link->getTarget()) { + $request->update($link->getTarget(), $link->getConstraint()); + continue 2; + } + } + + $request->install($link->getTarget(), $link->getConstraint()); + } + + foreach ($localRepo->getPackages() as $package) { + if (!in_array($package->getName(), $listedPackages)) { + $request->remove($package->getName()); + } + } + } elseif ($composer->getLocker()->isLocked()) { $output->writeln('> Found lockfile. Reading.'); foreach ($composer->getLocker()->getLockedPackages() as $package) { @@ -80,6 +108,7 @@ EOT $request->install($package->getName(), $constraint); } } else { + $output->writeln('> Installing dependencies.'); foreach ($composer->getPackage()->getRequires() as $link) { $request->install($link->getTarget(), $link->getConstraint()); } @@ -116,7 +145,7 @@ EOT $installationManager->execute($operation); } - if (!$composer->getLocker()->isLocked()) { + if ($update || !$composer->getLocker()->isLocked()) { $composer->getLocker()->lockPackages($localRepo->getPackages()); $output->writeln('> Locked'); } diff --git a/src/Composer/Command/UpdateCommand.php b/src/Composer/Command/UpdateCommand.php new file mode 100644 index 000000000..90573a872 --- /dev/null +++ b/src/Composer/Command/UpdateCommand.php @@ -0,0 +1,58 @@ + + * Jordi Boggiano + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Composer\Command; + +use Composer\Autoload\AutoloadGenerator; +use Composer\DependencyResolver; +use Composer\DependencyResolver\Pool; +use Composer\DependencyResolver\Request; +use Composer\DependencyResolver\Operation; +use Composer\Package\LinkConstraint\VersionConstraint; +use Composer\Repository\PlatformRepository; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\InputOption; +use Symfony\Component\Console\Output\OutputInterface; + +/** + * @author Jordi Boggiano + */ +class UpdateCommand extends Command +{ + protected function configure() + { + $this + ->setName('update') + ->setDescription('Updates your dependencies to the latest version, and updates the composer.lock file.') + ->setDefinition(array( + new InputOption('dev', null, InputOption::VALUE_NONE, 'Forces installation from package sources when possible, including VCS information.'), + )) + ->setHelp(<<update command reads the composer.json file from the +current directory, processes it, and updates, removes or installs all the +dependencies. + +php composer.phar update + +EOT + ) + ; + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + $composer = $this->getComposer(); + + $installCommand = $this->getApplication()->find('install'); + return $installCommand->install($output, $input->getOption('dev'), true); + } +} diff --git a/src/Composer/Console/Application.php b/src/Composer/Console/Application.php index 1f0f12e8a..b34607eee 100644 --- a/src/Composer/Console/Application.php +++ b/src/Composer/Console/Application.php @@ -64,6 +64,7 @@ class Application extends BaseApplication protected function registerCommands() { $this->add(new Command\InstallCommand()); + $this->add(new Command\UpdateCommand()); $this->add(new Command\DebugPackagesCommand()); } }