Example #1
0
 /**
  * Log a debug message
  *
  * Messages will be output at the "very verbose" logging level (eg `-vv`
  * needed on the Composer command).
  *
  * @param string $message
  */
 public function debug($message)
 {
     if ($this->inputOutput->isVeryVerbose()) {
         $message = "  <info>[{$this->name}]</info> {$message}";
         $this->log($message);
     }
 }
 /**
  * Write a notice to IO
  *
  * @param string $action
  * @param \Netresearch\Composer\Patches\Patch $patch
  * @param \Composer\Package\PackageInterface $package
  * @param \Netresearch\Composer\Patches\Exception $exception
  */
 protected function writePatchNotice($action, Patch $patch, PackageInterface $package, $exception = null)
 {
     $adverbMap = array('test' => 'on', 'apply' => 'to', 'revert' => 'from');
     if ($action == 'test' && !$this->io->isVeryVerbose()) {
         return;
     }
     $msg = '  ' . ucfirst($action) . 'ing patch';
     if ($this->io->isVerbose() || !isset($patch->title)) {
         $msg .= ' <info>' . $patch->getChecksum() . '</info>';
     }
     $msg .= ' ' . $adverbMap[$action];
     $msg .= ' <info>' . $package->getName() . '</info>';
     if ($this->io->isVerbose()) {
         ' (<comment>' . $package->getPrettyVersion() . '</comment>)';
     }
     if (isset($patch->title)) {
         $msg .= ': <comment>' . $patch->title . '</comment>';
     }
     $this->io->write($msg);
     if ($exception) {
         $this->io->write('  <warning>Could not ' . $action . ' patch</warning>' . ($action == 'revert' ? ' (was probably not applied)' : ''));
         if ($this->io->isVerbose()) {
             $this->io->write('<warning>' . $exception->getMessage() . '</warning>');
         }
     }
 }
Example #3
0
 /**
  * Run the GrumPHP console to (de)init the git hooks
  *
  * @param $command
  */
 protected function runGrumPhpCommand($command)
 {
     $config = $this->composer->getConfig();
     $baseDir = $this->getObjectProtectedProperty($config, 'baseDir');
     $configFilename = !empty($config->get('extra')['grumphp']['config-default-path']) ? $config->get('extra')['grumphp']['config-default-path'] : $baseDir . DIRECTORY_SEPARATOR . 'grumphp.yml';
     if (!file_exists($configFilename)) {
         // Check executable which is running:
         if ($this->io->isVeryVerbose()) {
             $this->io->write(sprintf('<fg=red>File "%s" not found</fg=red>', $configFilename));
         }
         return;
     }
     $application = new \Octava\GeggsApplication();
     /** @var Config $config */
     $config = $application->getContainer()->get('octava_geggs.config');
     $grumPhpConfigData = Yaml::parse(file_get_contents($configFilename));
     $fileSystem = new Filesystem();
     foreach ($config->getVendorDirs() as $item) {
         $grumPhpConfigData['bin_dir'] = '../../../bin';
         $grumPhpConfigYml = Yaml::dump($grumPhpConfigData);
         $vendorConfigFilename = implode(DIRECTORY_SEPARATOR, [$item, 'vendor', 'grumphp.yml']);
         $fileSystem->dumpFile($vendorConfigFilename, $grumPhpConfigYml);
         $gitPreCommitFilename = implode(DIRECTORY_SEPARATOR, [$item, '.git', 'hooks', 'pre-commit']);
         $fileSystem->dumpFile($gitPreCommitFilename, $this->generatePreCommit($vendorConfigFilename));
         $gitCommitMsgFilename = implode(DIRECTORY_SEPARATOR, [$item, '.git', 'hooks', 'commit-msg']);
         $fileSystem->dumpFile($gitCommitMsgFilename, $this->generateCommitMsg($vendorConfigFilename));
         if ($this->io->isVeryVerbose()) {
             $this->io->write(sprintf('Config created %s', $vendorConfigFilename));
             $this->io->write(sprintf('Pre commit hook created %s', $gitPreCommitFilename));
             $this->io->write(sprintf('Commit msg hook created %s', $gitCommitMsgFilename));
         }
     }
     $this->io->write('<fg=yellow>GrumPHP is sniffing your vendors code!</fg=yellow>');
 }
Example #4
0
 public function __construct(array $repoConfig, IOInterface $io, Config $config, EventDispatcher $dispatcher = null, array $drivers = null)
 {
     $this->drivers = $drivers ?: array('github' => 'Composer\\Repository\\Vcs\\GitHubDriver', 'gitlab' => 'Composer\\Repository\\Vcs\\GitLabDriver', 'git-bitbucket' => 'Composer\\Repository\\Vcs\\GitBitbucketDriver', 'git' => 'Composer\\Repository\\Vcs\\GitDriver', 'hg-bitbucket' => 'Composer\\Repository\\Vcs\\HgBitbucketDriver', 'hg' => 'Composer\\Repository\\Vcs\\HgDriver', 'perforce' => 'Composer\\Repository\\Vcs\\PerforceDriver', 'svn' => 'Composer\\Repository\\Vcs\\SvnDriver');
     $this->url = $repoConfig['url'];
     $this->io = $io;
     $this->type = isset($repoConfig['type']) ? $repoConfig['type'] : 'vcs';
     $this->verbose = $io->isVeryVerbose();
     $this->config = $config;
     $this->repoConfig = $repoConfig;
 }
Example #5
0
 /**
  * Symlink the bootstrapping code into the .git folder.
  *
  * @since 0.1.0
  *
  * @param Filesystem $filesystem Reference to the Filesystem instance.
  */
 protected function linkBootstrapFiles(Filesystem $filesystem)
 {
     $rootTemplate = Paths::getPath('root_template');
     $composterTemplate = Paths::getPath('git_template');
     $files = array('bootstrap.php');
     foreach ($files as $file) {
         if (static::$io->isVeryVerbose()) {
             static::$io->write(sprintf(_('Symlinking %1$s to %2$s'), $rootTemplate . $file, $composterTemplate . $file));
         }
         $filesystem->relativeSymlink($composterTemplate . $file, $rootTemplate . $file);
     }
 }
 /**
  * @param IOInterface $io
  * @param array       $vulnerabilities
  */
 protected static function dumpVulnerabilities(IOInterface $io, array $vulnerabilities)
 {
     foreach ($vulnerabilities as $package => $infos) {
         $io->write("\n" . '  <info>' . $package . '</info> ' . $infos['version']);
         foreach ($infos['advisories'] as $key => $advisory) {
             $io->write('    <comment>' . $advisory['title'] . '</comment>');
             $io->write('    <info>' . $advisory['link'] . '</info>');
             if ($advisory['cve'] && $io->isVeryVerbose()) {
                 $io->write('    ' . $advisory['cve']);
             }
         }
     }
     $io->write("\n");
 }
 /**
  * Return TRUE if the current git branch has any uncommitted changes.
  *
  * @return bool
  */
 protected function isGitDiff($branchName = '')
 {
     $output = '';
     $command = "git diff";
     if ($branchName) {
         $command .= ' ' . $this->git['base-branch'] . ' ' . $branchName;
     }
     if ($this->executor->execute($command, $output) == 0) {
         $output = trim($output);
         if ($this->io->isVeryVerbose() && $output) {
             $this->io->write("<comment>" . substr($output, 0, 10) . "...</comment>");
         }
         return $output ? TRUE : FALSE;
     }
     return FALSE;
 }
Example #8
0
 /**
  * Run the GrumPHP console to (de)init the git hooks
  *
  * @param $command
  */
 protected function runGrumPhpCommand($command)
 {
     $config = $this->composer->getConfig();
     $commandLocator = new ExternalCommand($config->get('bin-dir'), new ExecutableFinder());
     $executable = $commandLocator->locate('grumphp');
     $builder = new ProcessBuilder(array($executable, $command, '--no-interaction'));
     $process = $builder->getProcess();
     // Check executable which is running:
     if ($this->io->isVeryVerbose()) {
         $this->io->write('Running process : ' . $process->getCommandLine());
     }
     $process->run();
     if (!$process->isSuccessful()) {
         $this->io->write('<fg=red>GrumPHP can not sniff your commits. Did you specify the correct git-dir?</fg=red>');
         $this->io->write('<fg=red>' . $process->getErrorOutput() . '</fg=red>');
         return;
     }
     $this->io->write('<fg=yellow>' . $process->getOutput() . '</fg=yellow>');
 }
 /**
  * Write a notice to IO
  *
  * @param string $action
  * @param \Netresearch\Composer\Patches\Patch $patch
  * @param \Composer\Package\PackageInterface $package
  */
 protected function writePatchNotice($action, Patch $patch, PackageInterface $package)
 {
     $adverbMap = array('test' => 'on', 'apply' => 'to', 'revert' => 'from');
     if ($action == 'test' && !$this->io->isVeryVerbose()) {
         return;
     }
     $msg = '  - ' . ucfirst($action) . 'ing patch';
     if ($this->io->isVerbose() || !isset($patch->title)) {
         $msg .= ' <info>' . $patch->getChecksum() . '</info>';
     }
     $msg .= ' ' . $adverbMap[$action];
     $msg .= ' <info>' . $package->getName() . '</info>';
     if ($this->io->isVerbose()) {
         ' (<comment>' . $package->getPrettyVersion() . '</comment>)';
     }
     if (isset($patch->title)) {
         $msg .= ': <comment>' . $patch->title . '</comment>';
     }
     $this->io->write($msg);
 }
Example #10
0
 protected function doInstall($localRepo, $installedRepo, $platformRepo, $aliases, $withDevReqs)
 {
     // init vars
     $lockedRepository = null;
     $repositories = null;
     // initialize locker to create aliased packages
     $installFromLock = false;
     if (!$this->update && $this->locker->isLocked()) {
         $installFromLock = true;
         try {
             $lockedRepository = $this->locker->getLockedRepository($withDevReqs);
         } catch (\RuntimeException $e) {
             // if there are dev requires, then we really can not install
             if ($this->package->getDevRequires()) {
                 throw $e;
             }
             // no require-dev in composer.json and the lock file was created with no dev info, so skip them
             $lockedRepository = $this->locker->getLockedRepository();
         }
     }
     $this->whitelistUpdateDependencies($localRepo, $withDevReqs, $this->package->getRequires(), $this->package->getDevRequires());
     $this->io->writeError('<info>Loading composer repositories with package information</info>');
     // creating repository pool
     $policy = $this->createPolicy();
     $pool = $this->createPool($withDevReqs, $lockedRepository);
     $pool->addRepository($installedRepo, $aliases);
     if ($installFromLock) {
         $pool->addRepository($lockedRepository, $aliases);
     }
     if (!$installFromLock) {
         $repositories = $this->repositoryManager->getRepositories();
         foreach ($repositories as $repository) {
             $pool->addRepository($repository, $aliases);
         }
     }
     // creating requirements request
     $request = $this->createRequest($pool, $this->package, $platformRepo);
     if (!$installFromLock) {
         // remove unstable packages from the localRepo if they don't match the current stability settings
         $removedUnstablePackages = array();
         foreach ($localRepo->getPackages() as $package) {
             if (!$pool->isPackageAcceptable($package->getNames(), $package->getStability()) && $this->installationManager->isPackageInstalled($localRepo, $package)) {
                 $removedUnstablePackages[$package->getName()] = true;
                 $request->remove($package->getName(), new VersionConstraint('=', $package->getVersion()));
             }
         }
     }
     if ($this->update) {
         $this->io->writeError('<info>Updating dependencies' . ($withDevReqs ? ' (including require-dev)' : '') . '</info>');
         $request->updateAll();
         if ($withDevReqs) {
             $links = array_merge($this->package->getRequires(), $this->package->getDevRequires());
         } else {
             $links = $this->package->getRequires();
         }
         foreach ($links as $link) {
             $request->install($link->getTarget(), $link->getConstraint());
         }
         // if the updateWhitelist is enabled, packages not in it are also fixed
         // to the version specified in the lock, or their currently installed version
         if ($this->updateWhitelist) {
             if ($this->locker->isLocked()) {
                 try {
                     $currentPackages = $this->locker->getLockedRepository($withDevReqs)->getPackages();
                 } catch (\RuntimeException $e) {
                     // fetch only non-dev packages from lock if doing a dev update fails due to a previously incomplete lock file
                     $currentPackages = $this->locker->getLockedRepository()->getPackages();
                 }
             } else {
                 $currentPackages = $installedRepo->getPackages();
             }
             // collect packages to fixate from root requirements as well as installed packages
             $candidates = array();
             foreach ($links as $link) {
                 $candidates[$link->getTarget()] = true;
             }
             foreach ($localRepo->getPackages() as $package) {
                 $candidates[$package->getName()] = true;
             }
             // fix them to the version in lock (or currently installed) if they are not updateable
             foreach ($candidates as $candidate => $dummy) {
                 foreach ($currentPackages as $curPackage) {
                     if ($curPackage->getName() === $candidate) {
                         if (!$this->isUpdateable($curPackage) && !isset($removedUnstablePackages[$curPackage->getName()])) {
                             $constraint = new VersionConstraint('=', $curPackage->getVersion());
                             $request->install($curPackage->getName(), $constraint);
                         }
                         break;
                     }
                 }
             }
         }
     } elseif ($installFromLock) {
         $this->io->writeError('<info>Installing dependencies' . ($withDevReqs ? ' (including require-dev)' : '') . ' from lock file</info>');
         if (!$this->locker->isFresh()) {
             $this->io->writeError('<warning>Warning: The lock file is not up to date with the latest changes in composer.json. You may be getting outdated dependencies. Run update to update them.</warning>');
         }
         foreach ($lockedRepository->getPackages() as $package) {
             $version = $package->getVersion();
             if (isset($aliases[$package->getName()][$version])) {
                 $version = $aliases[$package->getName()][$version]['alias_normalized'];
             }
             $constraint = new VersionConstraint('=', $version);
             $constraint->setPrettyString($package->getPrettyVersion());
             $request->install($package->getName(), $constraint);
         }
         foreach ($this->locker->getPlatformRequirements($withDevReqs) as $link) {
             $request->install($link->getTarget(), $link->getConstraint());
         }
     } else {
         $this->io->writeError('<info>Installing dependencies' . ($withDevReqs ? ' (including require-dev)' : '') . '</info>');
         if ($withDevReqs) {
             $links = array_merge($this->package->getRequires(), $this->package->getDevRequires());
         } else {
             $links = $this->package->getRequires();
         }
         foreach ($links as $link) {
             $request->install($link->getTarget(), $link->getConstraint());
         }
     }
     // force dev packages to have the latest links if we update or install from a (potentially new) lock
     $this->processDevPackages($localRepo, $pool, $policy, $repositories, $lockedRepository, $installFromLock, 'force-links');
     // solve dependencies
     $this->eventDispatcher->dispatchInstallerEvent(InstallerEvents::PRE_DEPENDENCIES_SOLVING, $this->devMode, $policy, $pool, $installedRepo, $request);
     $solver = new Solver($policy, $pool, $installedRepo);
     try {
         $operations = $solver->solve($request, $this->ignorePlatformReqs);
         $this->eventDispatcher->dispatchInstallerEvent(InstallerEvents::POST_DEPENDENCIES_SOLVING, $this->devMode, $policy, $pool, $installedRepo, $request, $operations);
     } catch (SolverProblemsException $e) {
         $this->io->writeError('<error>Your requirements could not be resolved to an installable set of packages.</error>');
         $this->io->writeError($e->getMessage());
         return max(1, $e->getCode());
     }
     // force dev packages to be updated if we update or install from a (potentially new) lock
     $operations = $this->processDevPackages($localRepo, $pool, $policy, $repositories, $lockedRepository, $installFromLock, 'force-updates', $operations);
     // execute operations
     if (!$operations) {
         $this->io->writeError('Nothing to install or update');
     }
     $operations = $this->movePluginsToFront($operations);
     $operations = $this->moveUninstallsToFront($operations);
     foreach ($operations as $operation) {
         // collect suggestions
         if ('install' === $operation->getJobType()) {
             foreach ($operation->getPackage()->getSuggests() as $target => $reason) {
                 $this->suggestedPackages[] = array('source' => $operation->getPackage()->getPrettyName(), 'target' => $target, 'reason' => $reason);
             }
         }
         // not installing from lock, force dev packages' references if they're in root package refs
         if (!$installFromLock) {
             $package = null;
             if ('update' === $operation->getJobType()) {
                 $package = $operation->getTargetPackage();
             } elseif ('install' === $operation->getJobType()) {
                 $package = $operation->getPackage();
             }
             if ($package && $package->isDev()) {
                 $references = $this->package->getReferences();
                 if (isset($references[$package->getName()])) {
                     $package->setSourceReference($references[$package->getName()]);
                     $package->setDistReference($references[$package->getName()]);
                 }
             }
             if ('update' === $operation->getJobType() && $operation->getTargetPackage()->isDev() && $operation->getTargetPackage()->getVersion() === $operation->getInitialPackage()->getVersion() && $operation->getTargetPackage()->getSourceReference() === $operation->getInitialPackage()->getSourceReference()) {
                 if ($this->io->isDebug()) {
                     $this->io->writeError('  - Skipping update of ' . $operation->getTargetPackage()->getPrettyName() . ' to the same reference-locked version');
                     $this->io->writeError('');
                 }
                 continue;
             }
         }
         $event = 'Composer\\Installer\\PackageEvents::PRE_PACKAGE_' . strtoupper($operation->getJobType());
         if (defined($event) && $this->runScripts) {
             $this->eventDispatcher->dispatchPackageEvent(constant($event), $this->devMode, $policy, $pool, $installedRepo, $request, $operations, $operation);
         }
         // output non-alias ops in dry run, output alias ops in debug verbosity
         if ($this->dryRun && false === strpos($operation->getJobType(), 'Alias')) {
             $this->io->writeError('  - ' . $operation);
             $this->io->writeError('');
         } elseif ($this->io->isDebug() && false !== strpos($operation->getJobType(), 'Alias')) {
             $this->io->writeError('  - ' . $operation);
             $this->io->writeError('');
         }
         $this->installationManager->execute($localRepo, $operation);
         // output reasons why the operation was ran, only for install/update operations
         if ($this->verbose && $this->io->isVeryVerbose() && in_array($operation->getJobType(), array('install', 'update'))) {
             $reason = $operation->getReason();
             if ($reason instanceof Rule) {
                 switch ($reason->getReason()) {
                     case Rule::RULE_JOB_INSTALL:
                         $this->io->writeError('    REASON: Required by root: ' . $reason->getPrettyString($pool));
                         $this->io->writeError('');
                         break;
                     case Rule::RULE_PACKAGE_REQUIRES:
                         $this->io->writeError('    REASON: ' . $reason->getPrettyString($pool));
                         $this->io->writeError('');
                         break;
                 }
             }
         }
         $event = 'Composer\\Installer\\PackageEvents::POST_PACKAGE_' . strtoupper($operation->getJobType());
         if (defined($event) && $this->runScripts) {
             $this->eventDispatcher->dispatchPackageEvent(constant($event), $this->devMode, $policy, $pool, $installedRepo, $request, $operations, $operation);
         }
         if (!$this->dryRun) {
             $localRepo->write();
         }
     }
     return 0;
 }
Example #11
0
 /**
  * @param  RepositoryInterface $localRepo
  * @param  RepositoryInterface $installedRepo
  * @param  PlatformRepository  $platformRepo
  * @param  array               $aliases
  * @return array [int, PackageInterfaces[]|null] with the exit code and an array of dev packages on update, or null on install
  */
 protected function doInstall($localRepo, $installedRepo, $platformRepo, $aliases)
 {
     // init vars
     $lockedRepository = null;
     $repositories = null;
     // initialize locked repo if we are installing from lock or in a partial update
     // and a lock file is present as we need to force install non-whitelisted lock file
     // packages in that case
     if (!$this->update || !empty($this->updateWhitelist) && $this->locker->isLocked()) {
         try {
             $lockedRepository = $this->locker->getLockedRepository($this->devMode);
         } catch (\RuntimeException $e) {
             // if there are dev requires, then we really can not install
             if ($this->package->getDevRequires()) {
                 throw $e;
             }
             // no require-dev in composer.json and the lock file was created with no dev info, so skip them
             $lockedRepository = $this->locker->getLockedRepository();
         }
     }
     $this->whitelistUpdateDependencies($localRepo, $this->package->getRequires(), $this->package->getDevRequires());
     $this->io->writeError('<info>Loading composer repositories with package information</info>');
     // creating repository pool
     $policy = $this->createPolicy();
     $pool = $this->createPool($this->update ? null : $lockedRepository);
     $pool->addRepository($installedRepo, $aliases);
     if ($this->update) {
         $repositories = $this->repositoryManager->getRepositories();
         foreach ($repositories as $repository) {
             $pool->addRepository($repository, $aliases);
         }
     }
     // Add the locked repository after the others in case we are doing a
     // partial update so missing packages can be found there still.
     // For installs from lock it's the only one added so it is first
     if ($lockedRepository) {
         $pool->addRepository($lockedRepository, $aliases);
     }
     // creating requirements request
     $request = $this->createRequest($this->package, $platformRepo);
     if ($this->update) {
         // remove unstable packages from the localRepo if they don't match the current stability settings
         $removedUnstablePackages = array();
         foreach ($localRepo->getPackages() as $package) {
             if (!$pool->isPackageAcceptable($package->getNames(), $package->getStability()) && $this->installationManager->isPackageInstalled($localRepo, $package)) {
                 $removedUnstablePackages[$package->getName()] = true;
                 $request->remove($package->getName(), new Constraint('=', $package->getVersion()));
             }
         }
         $this->io->writeError('<info>Updating dependencies' . ($this->devMode ? ' (including require-dev)' : '') . '</info>');
         $request->updateAll();
         $links = array_merge($this->package->getRequires(), $this->package->getDevRequires());
         foreach ($links as $link) {
             $request->install($link->getTarget(), $link->getConstraint());
         }
         // if the updateWhitelist is enabled, packages not in it are also fixed
         // to the version specified in the lock, or their currently installed version
         if ($this->updateWhitelist) {
             $currentPackages = $this->getCurrentPackages($installedRepo);
             // collect packages to fixate from root requirements as well as installed packages
             $candidates = array();
             foreach ($links as $link) {
                 $candidates[$link->getTarget()] = true;
                 $rootRequires[$link->getTarget()] = $link;
             }
             foreach ($currentPackages as $package) {
                 $candidates[$package->getName()] = true;
             }
             // fix them to the version in lock (or currently installed) if they are not updateable
             foreach ($candidates as $candidate => $dummy) {
                 foreach ($currentPackages as $curPackage) {
                     if ($curPackage->getName() === $candidate) {
                         if (!$this->isUpdateable($curPackage) && !isset($removedUnstablePackages[$curPackage->getName()])) {
                             $constraint = new Constraint('=', $curPackage->getVersion());
                             $description = $this->locker->isLocked() ? '(locked at' : '(installed at';
                             $requiredAt = isset($rootRequires[$candidate]) ? ', required as ' . $rootRequires[$candidate]->getPrettyConstraint() : '';
                             $constraint->setPrettyString($description . ' ' . $curPackage->getPrettyVersion() . $requiredAt . ')');
                             $request->install($curPackage->getName(), $constraint);
                         }
                         break;
                     }
                 }
             }
         }
     } else {
         $this->io->writeError('<info>Installing dependencies' . ($this->devMode ? ' (including require-dev)' : '') . ' from lock file</info>');
         if (!$this->locker->isFresh()) {
             $this->io->writeError('<warning>Warning: The lock file is not up to date with the latest changes in composer.json. You may be getting outdated dependencies. Run update to update them.</warning>', true, IOInterface::QUIET);
         }
         foreach ($lockedRepository->getPackages() as $package) {
             $version = $package->getVersion();
             if (isset($aliases[$package->getName()][$version])) {
                 $version = $aliases[$package->getName()][$version]['alias_normalized'];
             }
             $constraint = new Constraint('=', $version);
             $constraint->setPrettyString($package->getPrettyVersion());
             $request->install($package->getName(), $constraint);
         }
         foreach ($this->locker->getPlatformRequirements($this->devMode) as $link) {
             $request->install($link->getTarget(), $link->getConstraint());
         }
     }
     // force dev packages to have the latest links if we update or install from a (potentially new) lock
     $this->processDevPackages($localRepo, $pool, $policy, $repositories, $installedRepo, $lockedRepository, 'force-links');
     // solve dependencies
     $this->eventDispatcher->dispatchInstallerEvent(InstallerEvents::PRE_DEPENDENCIES_SOLVING, $this->devMode, $policy, $pool, $installedRepo, $request);
     $solver = new Solver($policy, $pool, $installedRepo, $this->io);
     try {
         $operations = $solver->solve($request, $this->ignorePlatformReqs);
     } catch (SolverProblemsException $e) {
         $this->io->writeError('<error>Your requirements could not be resolved to an installable set of packages.</error>', true, IOInterface::QUIET);
         $this->io->writeError($e->getMessage());
         return array(max(1, $e->getCode()), array());
     }
     // force dev packages to be updated if we update or install from a (potentially new) lock
     $operations = $this->processDevPackages($localRepo, $pool, $policy, $repositories, $installedRepo, $lockedRepository, 'force-updates', $operations);
     $this->eventDispatcher->dispatchInstallerEvent(InstallerEvents::POST_DEPENDENCIES_SOLVING, $this->devMode, $policy, $pool, $installedRepo, $request, $operations);
     $this->io->writeError("Analyzed " . count($pool) . " packages to resolve dependencies", true, IOInterface::VERBOSE);
     $this->io->writeError("Analyzed " . $solver->getRuleSetSize() . " rules to resolve dependencies", true, IOInterface::VERBOSE);
     // execute operations
     if (!$operations) {
         $this->io->writeError('Nothing to install or update');
     }
     $operations = $this->movePluginsToFront($operations);
     $operations = $this->moveUninstallsToFront($operations);
     // extract dev packages and mark them to be skipped if it's a --no-dev install or update
     // we also force them to be uninstalled if they are present in the local repo
     if ($this->update) {
         $devPackages = $this->extractDevPackages($operations, $localRepo, $platformRepo, $aliases);
         if (!$this->devMode) {
             $operations = $this->filterDevPackageOperations($devPackages, $operations, $localRepo);
         }
     } else {
         $devPackages = null;
     }
     if ($operations) {
         $installs = $updates = $uninstalls = array();
         foreach ($operations as $operation) {
             if ($operation instanceof InstallOperation) {
                 $installs[] = $operation->getPackage()->getPrettyName() . ':' . $operation->getPackage()->getFullPrettyVersion();
             } elseif ($operation instanceof UpdateOperation) {
                 $updates[] = $operation->getTargetPackage()->getPrettyName() . ':' . $operation->getTargetPackage()->getFullPrettyVersion();
             } elseif ($operation instanceof UninstallOperation) {
                 $uninstalls[] = $operation->getPackage()->getPrettyName();
             }
         }
         $this->io->writeError(sprintf("<info>Package operations: %d install%s, %d update%s, %d removal%s</info>", count($installs), 1 === count($installs) ? '' : 's', count($updates), 1 === count($updates) ? '' : 's', count($uninstalls), 1 === count($uninstalls) ? '' : 's'));
         if ($installs) {
             $this->io->writeError("Installs: " . implode(', ', $installs), true, IOInterface::VERBOSE);
         }
         if ($updates) {
             $this->io->writeError("Updates: " . implode(', ', $updates), true, IOInterface::VERBOSE);
         }
         if ($uninstalls) {
             $this->io->writeError("Removals: " . implode(', ', $uninstalls), true, IOInterface::VERBOSE);
         }
     }
     foreach ($operations as $operation) {
         // collect suggestions
         if ('install' === $operation->getJobType()) {
             $this->suggestedPackagesReporter->addSuggestionsFromPackage($operation->getPackage());
         }
         // updating, force dev packages' references if they're in root package refs
         if ($this->update) {
             $package = null;
             if ('update' === $operation->getJobType()) {
                 $package = $operation->getTargetPackage();
             } elseif ('install' === $operation->getJobType()) {
                 $package = $operation->getPackage();
             }
             if ($package && $package->isDev()) {
                 $references = $this->package->getReferences();
                 if (isset($references[$package->getName()])) {
                     $this->updateInstallReferences($package, $references[$package->getName()]);
                 }
             }
             if ('update' === $operation->getJobType() && $operation->getTargetPackage()->isDev() && $operation->getTargetPackage()->getVersion() === $operation->getInitialPackage()->getVersion() && (!$operation->getTargetPackage()->getSourceReference() || $operation->getTargetPackage()->getSourceReference() === $operation->getInitialPackage()->getSourceReference()) && (!$operation->getTargetPackage()->getDistReference() || $operation->getTargetPackage()->getDistReference() === $operation->getInitialPackage()->getDistReference())) {
                 $this->io->writeError('  - Skipping update of ' . $operation->getTargetPackage()->getPrettyName() . ' to the same reference-locked version', true, IOInterface::DEBUG);
                 $this->io->writeError('', true, IOInterface::DEBUG);
                 continue;
             }
         }
         $event = 'Composer\\Installer\\PackageEvents::PRE_PACKAGE_' . strtoupper($operation->getJobType());
         if (defined($event) && $this->runScripts) {
             $this->eventDispatcher->dispatchPackageEvent(constant($event), $this->devMode, $policy, $pool, $installedRepo, $request, $operations, $operation);
         }
         // output non-alias ops in dry run, output alias ops in debug verbosity
         if ($this->dryRun && false === strpos($operation->getJobType(), 'Alias')) {
             $this->io->writeError('  - ' . $operation);
             $this->io->writeError('');
         } elseif ($this->io->isDebug() && false !== strpos($operation->getJobType(), 'Alias')) {
             $this->io->writeError('  - ' . $operation);
             $this->io->writeError('');
         }
         $this->installationManager->execute($localRepo, $operation);
         // output reasons why the operation was ran, only for install/update operations
         if ($this->verbose && $this->io->isVeryVerbose() && in_array($operation->getJobType(), array('install', 'update'))) {
             $reason = $operation->getReason();
             if ($reason instanceof Rule) {
                 switch ($reason->getReason()) {
                     case Rule::RULE_JOB_INSTALL:
                         $this->io->writeError('    REASON: Required by the root package: ' . $reason->getPrettyString($pool));
                         $this->io->writeError('');
                         break;
                     case Rule::RULE_PACKAGE_REQUIRES:
                         $this->io->writeError('    REASON: ' . $reason->getPrettyString($pool));
                         $this->io->writeError('');
                         break;
                 }
             }
         }
         $event = 'Composer\\Installer\\PackageEvents::POST_PACKAGE_' . strtoupper($operation->getJobType());
         if (defined($event) && $this->runScripts) {
             $this->eventDispatcher->dispatchPackageEvent(constant($event), $this->devMode, $policy, $pool, $installedRepo, $request, $operations, $operation);
         }
         if (!$this->dryRun) {
             $localRepo->write();
         }
     }
     if (!$this->dryRun) {
         // force source/dist urls to be updated for all packages
         $this->processPackageUrls($pool, $policy, $localRepo, $repositories);
         $localRepo->write();
     }
     return array(0, $devPackages);
 }
Example #12
0
 /**
  * Print a message in the user console
  *
  * @param string $level   The message level ("normal", "verbose", "very-verbose", "debug")
  * @param string $message The message (sprintf format)
  * @param array  $vars    The message variables
  *
  * @return void
  */
 protected function output($level, $message, array $vars = array())
 {
     if ('normal' === $level || 'verbose' === $level && $this->io->isVerbose() || 'very-verbose' === $level && $this->io->isVeryVerbose() || 'debug' === $level && $this->io->isDebug()) {
         $this->io->write(vsprintf($message, $vars));
     }
 }