Example #1
0
 /**
  * Log an informative message
  *
  * Messages will be output at the "verbose" logging level (eg `-v` needed
  * on the Composer command).
  *
  * @param string $message
  */
 public function info($message)
 {
     if ($this->inputOutput->isVerbose()) {
         $message = "  <info>[{$this->name}]</info> {$message}";
         $this->log($message);
     }
 }
Example #2
0
 /**
  * The 'logical'-operation of this Installer.
  * PHPCS does not define constants for the config options,
  * doing so ourself would only lead to outdated intel.
  *
  * @see https://github.com/squizlabs/PHP_CodeSniffer/wiki/Configuration-Options
  */
 public function execute()
 {
     if ($this->io->isVerbose()) {
         $this->io->write('Configured phpcs to use Hostnet standard');
     }
     self::configure();
 }
Example #3
0
 /**
  * {@inheritdoc}
  */
 public function activate(Composer $composer, IOInterface $io)
 {
     $this->composer = $composer;
     $this->io = $io;
     $this->curlClient = new CurlClient(self::generateUserAgent());
     if ($this->io->isVerbose()) {
         $this->io->write("<info>[Curl]</info> plugin activate");
     }
     $pluginConfig = $this->composer->getConfig()->get('curl-plugin');
     if (isset($pluginConfig['hosts']) && is_array($pluginConfig['hosts'])) {
         $this->hosts = array_merge($this->hosts, $pluginConfig['hosts']);
     }
 }
Example #4
0
 /**
  * Log a debug message
  *
  * Messages will be output at the "verbose" logging level (eg `-v` needed
  * on the Composer command).
  *
  * @param string $message
  */
 public function debug($message)
 {
     if ($this->inputOutput->isVerbose()) {
         $message = "  <info>[{$this->name}]</info> {$message}";
         if (method_exists($this->inputOutput, 'writeError')) {
             $this->inputOutput->writeError($message);
         } else {
             // @codeCoverageIgnoreStart
             // Backwards compatiblity for Composer before cb336a5
             $this->inputOutput->write($message);
             // @codeCoverageIgnoreEnd
         }
     }
 }
Example #5
0
 /**
  * Executes a shell command with escaping.
  *
  * @param string $cmd
  * @return bool
  */
 protected function executeCommand($cmd)
 {
     // Shell-escape all arguments except the command.
     $args = func_get_args();
     foreach ($args as $index => $arg) {
         if ($index !== 0) {
             $args[$index] = escapeshellarg($arg);
         }
     }
     // And replace the arguments.
     $command = call_user_func_array('sprintf', $args);
     $output = '';
     if ($this->io->isVerbose()) {
         $this->io->write('<comment>' . $command . '</comment>');
         $io = $this->io;
         $output = function ($type, $data) use($io) {
             if ($type == Process::ERR) {
                 $io->write('<error>' . $data . '</error>');
             } else {
                 $io->write('<comment>' . $data . '</comment>');
             }
         };
     }
     return $this->executor->execute($command, $output) == 0;
 }
 /**
  * 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 #7
0
 public function __construct(array $repoConfig, IOInterface $io, Config $config = null, array $drivers = null)
 {
     $this->drivers = $drivers ?: array('github' => 'Composer\\Repository\\Vcs\\GitHubDriver', 'git-bitbucket' => 'Composer\\Repository\\Vcs\\GitBitbucketDriver', 'git' => 'Composer\\Repository\\Vcs\\GitDriver', 'svn' => 'Composer\\Repository\\Vcs\\SvnDriver', 'hg-bitbucket' => 'Composer\\Repository\\Vcs\\HgBitbucketDriver', 'hg' => 'Composer\\Repository\\Vcs\\HgDriver');
     $this->url = $repoConfig['url'];
     $this->io = $io;
     $this->type = isset($repoConfig['type']) ? $repoConfig['type'] : 'vcs';
     $this->verbose = $io->isVerbose();
 }
Example #8
0
 /**
  * @param                $message
  * @param Exception|null $exception
  */
 private function printWarning($message, Exception $exception = null)
 {
     if (!$exception) {
         $reasonPhrase = '';
     } elseif ($this->io->isVerbose()) {
         $reasonPhrase = $exception instanceof PuliRunnerException ? $exception->getFullError() : $exception->getMessage() . "\n\n" . $exception->getTraceAsString();
     } else {
         $reasonPhrase = $exception instanceof PuliRunnerException ? $exception->getShortError() : $exception->getMessage();
     }
     $this->io->writeError(sprintf('<warning>Warning: %s%s</warning>', $message, $reasonPhrase ? ': ' . $reasonPhrase : '.'));
 }
Example #9
0
 /**
  * Activate the Composer plugin.
  *
  * @since 0.1.0
  *
  * @param Composer    $composer Reference to the Composer instance.
  * @param IOInterface $io       Reference to the IO interface.
  */
 public function activate(Composer $composer, IOInterface $io)
 {
     static::$io = $io;
     if (static::$io->isVerbose()) {
         static::$io->write(_('Activating PHP Composter plugin'), true);
     }
     $installer = new Installer(static::$io, $composer);
     $composer->getInstallationManager()->addInstaller($installer);
     $filesystem = new Filesystem();
     $this->cleanUp($filesystem);
     $this->linkBootstrapFiles($filesystem);
     $this->createGitHooks($filesystem);
 }
Example #10
0
 /**
  * Executes a shell command
  *
  * @param  string $command the command to execute
  * @param  mixed  $output  the output will be written into this var if passed by ref
  *                         if a callable is passed it will be used as output handler
  * @param  string $cwd     the working directory
  * @return bool
  */
 protected function executeCommand($command, &$output = null, $cwd = null)
 {
     $success = $this->executor->execute($command, $output, $cwd) == 0;
     if ($this->io->isVerbose()) {
         $this->io->write('<comment>' . $command . '</comment>');
         $io = $this->io;
         $output = function ($type, $data) use($io) {
             if ($type == Process::ERR) {
                 $io->write('<error>' . $data . '</error>');
             } else {
                 $io->write('<comment>' . $data . '</comment>');
             }
         };
     }
     return $success;
 }
Example #11
0
    /**
     * Create the global runonce file TL_ROOT/system/runonce.php file if required.
     *
     * @param IOInterface $inputOutput The composer io stream.
     *
     * @param string      $root        The Contao installation root path.
     *
     * @return void
     */
    public static function createRunonce(IOInterface $inputOutput, $root)
    {
        // create runonce
        $runonces = array_unique(static::$runonces);
        if (count($runonces)) {
            $file = 'system/runonce.php';
            $buffer = '';
            $index = 0;
            while (file_exists($root . DIRECTORY_SEPARATOR . $file)) {
                $buffer .= file_get_contents($root . DIRECTORY_SEPARATOR . $file);
                $index++;
                $file = 'system/runonce_' . $index . '.php';
            }
            if ($index > 0) {
                rename($root . '/system/runonce.php', $root . DIRECTORY_SEPARATOR . $file);
                array_unshift($runonces, $file);
            }
            // Filter the runonces.
            $filtered = array();
            foreach ($runonces as $runonce) {
                if (strpos($buffer, $runonce) !== false) {
                    $inputOutput->write(sprintf('<info>Not adding runonce %s, already mentioned in existing runonce file.</info>', $runonce));
                    continue;
                }
                $filtered[] = $runonce;
            }
            $array = var_export($filtered, true);
            $runonce = <<<EOF
<?php

\$executor = new \\ContaoCommunityAlliance\\Composer\\Plugin\\RunonceExecutor();
\$executor->run({$array});

EOF;
            file_put_contents($root . '/system/runonce.php', $runonce);
            static::$runonces = array();
            $inputOutput->write(sprintf('<info>Runonce created with %d updates</info>', count($runonces)));
            if ($inputOutput->isVerbose()) {
                foreach ($runonces as $runonce) {
                    $inputOutput->write('  - ' . $runonce);
                }
            }
        }
    }
Example #12
0
 /**
  * Returns ordered list of packages:
  * - listed earlier in the composer.json will get earlier in the list
  * - childs before parents.
  * @return \Composer\Package\PackageInterface[]
  */
 public function findPackages()
 {
     $root = $this->composer->getPackage();
     $this->plainList[$root->getPrettyName()] = $root;
     foreach ($this->composer->getRepositoryManager()->getLocalRepository()->getCanonicalPackages() as $package) {
         $this->plainList[$package->getPrettyName()] = $package;
     }
     $this->orderedList = [];
     $this->iteratePackage($root, true);
     if ($this->io->isVerbose()) {
         $packages = implode("\n", $this->orderedList);
         $this->io->writeError($packages);
     }
     $res = [];
     foreach ($this->orderedList as $name) {
         $res[] = $this->plainList[$name];
     }
     return $res;
 }
 /**
  * Copy from specified file/folder
  *
  * @param string $webroot     Webroot
  * @param string $path        Path
  * @param string $destination Destination (optional)
  *
  * @return $this
  */
 private function copyFrom($webroot, $path, $destination = null)
 {
     if (null === $destination) {
         $destination = $path;
         $from = $this->projectRoot . DIRECTORY_SEPARATOR . $path;
     } else {
         // if the destination was defined then we assume the path is either absolute or relative to the webroot
         // because it has been defined by the user in the extra mapping
         $from = $path;
     }
     $to = $this->projectRoot . DIRECTORY_SEPARATOR . $webroot . DIRECTORY_SEPARATOR . $destination;
     $filesystem = $this->getFilesystem();
     if ($filesystem->exists($to)) {
         $filesystem->remove($to);
     }
     $filesystem->symlink($from, $to, true);
     if ($this->io->isVerbose()) {
         $this->io->write(sprintf('Moved %s to %s', $from, $to));
     }
 }
Example #14
0
 /**
  * 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);
 }
 /**
  * Put the environment
  */
 private function putEnvironment()
 {
     $parameters = $this->loadYaml($this->file);
     foreach ($parameters['parameters'] as $parameterName => $parameterValue) {
         $encodedEnv = $this->encodeEnvironment($parameterName, $parameterValue, false);
         if (!$this->overwrite && getenv($encodedEnv)) {
             if ($this->io->isDebug()) {
                 $this->io->write(sprintf('<info>Skipped existing environment variable "%s" with value "%s" (exiting value: "%s").</info>', $encodedEnv, $parameterValue, getenv($encodedEnv)));
             } elseif ($this->io->isVerbose()) {
                 $this->io->write(sprintf('<info>Skipped existing environment variable "%s".</info>', $encodedEnv));
             }
             continue;
         }
         putenv($this->encodeEnvironment($parameterName, $parameterValue, true));
         if ($this->io->isDebug()) {
             $this->io->write(sprintf('<info>Set environment variable "%s" to "%s".</info>', $encodedEnv, $parameterValue));
         } elseif ($this->io->isVerbose()) {
             $this->io->write(sprintf('<info>Set environment variable "%s".</info>', $encodedEnv));
         }
     }
 }
 protected function execute($command, array $args, IOInterface $io = null, $workingDirectory = null)
 {
     $processExecutor = new ProcessExecutor($io);
     array_unshift($args, $this->findBinary($command));
     $args = array_map([$processExecutor, 'escape'], $args);
     $outputHandler = function ($type, $data) use($io) {
         if (!$io->isVerbose()) {
             return;
         }
         switch ($type) {
             case Process::ERR:
                 $io->writeError($data);
                 break;
             case Process::OUT:
             default:
                 $io->write($data);
                 break;
         }
     };
     $fullCommand = implode(' ', $args);
     if ($processExecutor->execute($fullCommand, $outputHandler, $workingDirectory) > 0) {
         throw ProcessFailedException::create($command, $fullCommand, $processExecutor->getErrorOutput());
     }
 }
Example #17
0
 public static function supports(IOInterface $io, Config $config, $url, $deep = false)
 {
     if (!preg_match('#^((?:https?|git)://([^/]+)/|git@([^:]+):)([^/]+)/(.+?)(?:\\.git)?$#', $url, $matches)) {
         return false;
     }
     $originUrl = !empty($matches[2]) ? $matches[2] : $matches[3];
     if (!in_array($originUrl, $config->get('github-domains'))) {
         return false;
     }
     if (!extension_loaded('openssl')) {
         if ($io->isVerbose()) {
             $io->write('Skipping GitHub driver for ' . $url . ' because the OpenSSL PHP extension is missing.');
         }
         return false;
     }
     return true;
 }
 /**
  * Sets the IO.
  *
  * @param IOInterface $io
  */
 public function setIO(IOInterface $io)
 {
     $this->io = $io;
     $this->verbose = $io->isVerbose();
 }
Example #19
0
 private function printWarning(IOInterface $io, $message, PuliRunnerException $exception = null)
 {
     if (!$exception) {
         $reasonPhrase = '';
     } elseif ($io->isVerbose()) {
         $reasonPhrase = $exception->getFullError();
     } else {
         $reasonPhrase = $exception->getShortError();
     }
     $io->writeError(sprintf('<warning>Warning: %s%s</warning>', $message, $reasonPhrase ? ': ' . $reasonPhrase : '.'));
 }
Example #20
0
 /**
  * Uses the config `gitlab-domains` to see if the driver supports the url for the
  * repository given.
  *
  * {@inheritDoc}
  */
 public static function supports(IOInterface $io, Config $config, $url, $deep = false)
 {
     if (!preg_match(self::URL_REGEX, $url, $match)) {
         return false;
     }
     $scheme = !empty($match['scheme']) ? $match['scheme'] : 'https';
     $originUrl = !empty($match['domain']) ? $match['domain'] : $match['domain2'];
     if (!in_array($originUrl, (array) $config->get('gitlab-domains'))) {
         return false;
     }
     if ('https' === $scheme && !extension_loaded('openssl')) {
         if ($io->isVerbose()) {
             $io->write('Skipping GitLab driver for ' . $url . ' because the OpenSSL PHP extension is missing.');
         }
         return false;
     }
     return true;
 }
Example #21
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));
     }
 }
Example #22
0
 /**
  * {@inheritDoc}
  */
 public static function supports(IOInterface $io, $url, $deep = false)
 {
     if (!preg_match('#^((?:https?|git)://github\\.com/|git@github\\.com:)([^/]+)/(.+?)(?:\\.git)?$#', $url)) {
         return false;
     }
     if (!extension_loaded('openssl')) {
         if ($io->isVerbose()) {
             $io->write('Skipping GitHub driver for ' . $url . ' because the OpenSSL PHP extension is missing.');
         }
         return false;
     }
     return true;
 }
 /**
  * {@inheritDoc}
  */
 public function update(PackageInterface $initial, PackageInterface $target, $path)
 {
     if (!$target->getSourceReference()) {
         throw new \InvalidArgumentException('Package ' . $target->getPrettyName() . ' is missing reference information');
     }
     $name = $target->getName();
     if ($initial->getPrettyVersion() == $target->getPrettyVersion()) {
         if ($target->getSourceType() === 'svn') {
             $from = $initial->getSourceReference();
             $to = $target->getSourceReference();
         } else {
             $from = substr($initial->getSourceReference(), 0, 7);
             $to = substr($target->getSourceReference(), 0, 7);
         }
         $name .= ' ' . $initial->getPrettyVersion();
     } else {
         $from = $initial->getFullPrettyVersion();
         $to = $target->getFullPrettyVersion();
     }
     $this->io->writeError("  - Updating <info>" . $name . "</info> (<comment>" . $from . "</comment> => <comment>" . $to . "</comment>)");
     $this->cleanChanges($initial, $path, true);
     $urls = $target->getSourceUrls();
     $exception = null;
     while ($url = array_shift($urls)) {
         try {
             if (Filesystem::isLocalPath($url)) {
                 $url = realpath($url);
             }
             $this->doUpdate($initial, $target, $path, $url);
             $exception = null;
             break;
         } catch (\Exception $exception) {
             // rethrow phpunit exceptions to avoid hard to debug bug failures
             if ($exception instanceof \PHPUnit_Framework_Exception) {
                 throw $exception;
             }
             if ($this->io->isDebug()) {
                 $this->io->writeError('Failed: [' . get_class($exception) . '] ' . $exception->getMessage());
             } elseif (count($urls)) {
                 $this->io->writeError('    Failed, trying the next URL');
             }
         }
     }
     $this->reapplyChanges($path);
     // print the commit logs if in verbose mode and VCS metadata is present
     // because in case of missing metadata code would trigger another exception
     if (!$exception && $this->io->isVerbose() && $this->hasMetadataRepository($path)) {
         $message = 'Pulling in changes:';
         $logs = $this->getCommitLogs($initial->getSourceReference(), $target->getSourceReference(), $path);
         if (!trim($logs)) {
             $message = 'Rolling back changes:';
             $logs = $this->getCommitLogs($target->getSourceReference(), $initial->getSourceReference(), $path);
         }
         if (trim($logs)) {
             $logs = implode("\n", array_map(function ($line) {
                 return '      ' . $line;
             }, explode("\n", $logs)));
             // escape angle brackets for proper output in the console
             $logs = str_replace('<', '\\<', $logs);
             $this->io->writeError('    ' . $message);
             $this->io->writeError($logs);
         }
     }
     if (!$urls && $exception) {
         throw $exception;
     }
     $this->io->writeError('');
 }
 protected function beforeDrupalSaveCustom(PackageEvent $event, IOInterface $io)
 {
     // Change permissions for a better outcome when deleting existing sites,
     // since Drupal changes the permissions on these directories.
     $sitesDir = $this->drupalRoot . '/sites';
     if (!is_dir($sitesDir)) {
         $io->write("<error>Missing {$sitesDir->tmpdir}</error>");
         return;
     }
     $scanFiles = scandir($sitesDir);
     foreach ($scanFiles as $partialPath) {
         if ($partialPath != '.' && $partialPath != '..') {
             $filePath = "{$sitesDir}/{$partialPath}";
             if (is_dir($filePath)) {
                 @chmod($filePath, 0755);
                 @chmod("{$filePath}/settings.php", 0644);
             }
         }
     }
     $file = new FileSystem();
     foreach ($this->drupalCustom as $path) {
         if (!file_exists($path)) {
             continue;
         }
         if (!isset($this->tmpdir)) {
             $this->tmpdir = uniqid('/tmp/dci') . '.bak';
             if ($io->isVerbose()) {
                 $io->write("<info>Ensure {$this->tmpdir}</info>");
             }
             $file->ensureDirectoryExists($this->tmpdir);
         }
         $basename = basename($path);
         $tmpfile = $this->tmpdir . '/' . $basename;
         if (file_exists($tmpfile)) {
             $tmpfile = $this->tmpdir . '/' . md5($path);
             if ($io->isVerbose()) {
                 $io->write("<info>Ensure {$tmpfile}</info>");
             }
             $file->ensureDirectoryExists($tmpfile);
             $tmpfile .= '/' . $basename;
         }
         $io->write("<info>Save {$path} to {$tmpfile}</info>");
         $file->rename($path, $tmpfile);
         $this->tmp[$path] = $tmpfile;
     }
 }
Example #25
0
 /**
  * @param  RepositoryInterface $localRepo
  * @param  RepositoryInterface $installedRepo
  * @param  PlatformRepository  $platformRepo
  * @param  array               $aliases
  * @param  bool                $withDevReqs
  * @return int
  */
 protected function doInstall($localRepo, $installedRepo, $platformRepo, $aliases, $withDevReqs)
 {
     // init vars
     $lockedRepository = null;
     $repositories = null;
     // initialize locker to create aliased packages
     $installFromLock = !$this->update && $this->locker->isLocked();
     // 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 ($installFromLock || !empty($this->updateWhitelist) && $this->locker->isLocked()) {
         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, $installFromLock ? $lockedRepository : null);
     $pool->addRepository($installedRepo, $aliases);
     if (!$installFromLock) {
         $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 (!$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 Constraint('=', $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) {
             $currentPackages = $this->getCurrentPackages($withDevReqs, $installedRepo);
             // 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 Constraint('=', $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 Constraint('=', $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, $installedRepo, $lockedRepository, $installFromLock, $withDevReqs, '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());
     }
     if ($this->io->isVerbose()) {
         $this->io->writeError("Analyzed " . count($pool) . " packages to resolve dependencies");
         $this->io->writeError("Analyzed " . $solver->getRuleSetSize() . " rules to resolve dependencies");
     }
     // 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, $installFromLock, $withDevReqs, '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->getTargetPackage()->getSourceReference() === $operation->getInitialPackage()->getSourceReference()) && (!$operation->getTargetPackage()->getDistReference() || $operation->getTargetPackage()->getDistReference() === $operation->getInitialPackage()->getDistReference())) {
                 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();
         }
     }
     if (!$this->dryRun) {
         // force source/dist urls to be updated for all packages
         $this->processPackageUrls($pool, $policy, $localRepo, $repositories);
         $localRepo->write();
     }
     return 0;
 }
Example #26
0
 /**
  * Writes message only in verbose mode.
  * @param string $message
  */
 private function verboseLog($message)
 {
     if ($this->io->isVerbose()) {
         $this->io->write($message);
     }
 }
Example #27
0
 /**
  * Log a debug message
  *
  * Messages will be output at the "verbose" logging level (eg `-v` needed
  * on the Composer command).
  *
  * @param string $message
  */
 protected function debug($message)
 {
     if ($this->inputOutput->isVerbose()) {
         $this->inputOutput->write("  <info>[merge]</info> {$message}");
     }
 }
 /**
  * Print Debug msg in verbose mode
  *
  * @param $message
  */
 private function debug($message)
 {
     if ($this->io->isVerbose()) {
         $this->io->write(sprintf("<info>[CheckerPlugin]</info> %s", $message));
     }
 }
 /**
  * {@inheritDoc}
  */
 public static function supports(IOInterface $io, Config $config, $url, $deep = false)
 {
     if (!preg_match('#^https?://bitbucket\\.org/([^/]+)/(.+?)\\.git$#', $url)) {
         return false;
     }
     if (!extension_loaded('openssl')) {
         if ($io->isVerbose()) {
             $io->writeError('Skipping Bitbucket git driver for ' . $url . ' because the OpenSSL PHP extension is missing.');
         }
         return false;
     }
     return true;
 }
 public static function createRunonces(IOInterface $io, $root)
 {
     // create runonce
     $runonces = array_unique(static::$runonces);
     if (count($runonces)) {
         $file = 'system/runonce.php';
         $n = 0;
         while (file_exists($root . DIRECTORY_SEPARATOR . $file)) {
             $n++;
             $file = 'system/runonce_' . $n . '.php';
         }
         if ($n > 0) {
             rename($root . '/system/runonce.php', $root . DIRECTORY_SEPARATOR . $file);
             array_unshift($runonces, $file);
         }
         $template = file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . 'RunonceExecutorTemplate.php');
         $template = str_replace('TEMPLATE_RUNONCE_ARRAY', var_export($runonces, true), $template);
         file_put_contents($root . '/system/runonce.php', $template);
         $io->write(sprintf('<info>Runonce created with %d updates</info>', count($runonces)));
         if ($io->isVerbose()) {
             foreach ($runonces as $runonce) {
                 $io->write('  - ' . $runonce);
             }
         }
     }
 }