diff options
author | Pierre Schmitz <pierre@archlinux.de> | 2015-06-04 07:31:04 +0200 |
---|---|---|
committer | Pierre Schmitz <pierre@archlinux.de> | 2015-06-04 07:58:39 +0200 |
commit | f6d65e533c62f6deb21342d4901ece24497b433e (patch) | |
tree | f28adf0362d14bcd448f7b65a7aaf38650f923aa /vendor/wikimedia/composer-merge-plugin | |
parent | c27b2e832fe25651ef2410fae85b41072aae7519 (diff) |
Update to MediaWiki 1.25.1
Diffstat (limited to 'vendor/wikimedia/composer-merge-plugin')
-rw-r--r-- | vendor/wikimedia/composer-merge-plugin/LICENSE | 19 | ||||
-rw-r--r-- | vendor/wikimedia/composer-merge-plugin/README.md | 80 | ||||
-rw-r--r-- | vendor/wikimedia/composer-merge-plugin/composer.json | 38 | ||||
-rw-r--r-- | vendor/wikimedia/composer-merge-plugin/src/MergePlugin.php | 411 |
4 files changed, 548 insertions, 0 deletions
diff --git a/vendor/wikimedia/composer-merge-plugin/LICENSE b/vendor/wikimedia/composer-merge-plugin/LICENSE new file mode 100644 index 00000000..55e376b4 --- /dev/null +++ b/vendor/wikimedia/composer-merge-plugin/LICENSE @@ -0,0 +1,19 @@ +Copyright (c) 2014 Bryan Davis, Wikimedia Foundation, and contributors + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is furnished +to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/vendor/wikimedia/composer-merge-plugin/README.md b/vendor/wikimedia/composer-merge-plugin/README.md new file mode 100644 index 00000000..53d64579 --- /dev/null +++ b/vendor/wikimedia/composer-merge-plugin/README.md @@ -0,0 +1,80 @@ +[![Latest Stable Version](https://img.shields.io/packagist/v/wikimedia/composer-merge-plugin.svg?style=flat)](https://packagist.org/packages/wikimedia/composer-merge-plugin) [![License](https://img.shields.io/packagist/l/wikimedia/composer-merge-plugin.svg?style=flat)](https://github.com/wikimedia/composer-merge-plugin/blob/master/LICENSE) +[![Build Status](https://img.shields.io/travis/wikimedia/composer-merge-plugin.svg?style=flat)](https://travis-ci.org/wikimedia/composer-merge-plugin) +[![Code Coverage](https://img.shields.io/scrutinizer/coverage/g/wikimedia/composer-merge-plugin/master.svg?style=flat)](https://scrutinizer-ci.com/g/wikimedia/composer-merge-plugin/?branch=master) + +Composer Merge Plugin +===================== + +Merge one or more additional composer.json files at runtime. + +Installation +------------ +``` +$ composer require wikimedia/composer-merge-plugin +``` + +Usage +----- + +``` +{ + "require": { + "wikimedia/composer-merge-plugin": "dev-master" + }, + "extra": { + "merge-plugin": { + "include": [ + "composer.local.json", + "extensions/*/composer.json" + ] + } + } +} +``` + +The `include` key can specify either a single value or an array of values. +Each value is treated as a glob() pattern identifying additional composer.json +style configuration files to merge into the configuration for the current +Composer execution. By default the merge plugin is recursive, if an included +file also has a "merge-plugin" section it will also be processed. This +functionality can be disabled by setting `"recurse": false` inside the +"merge-plugin" section. + +The "require", "require-dev", "repositories" and "suggest" sections of the +found configuration files will be merged into the root package configuration +as though they were directly included in the top-level composer.json file. + +Running tests +------------- +``` +$ composer install +$ composer test +``` + +Contributing +------------ +Bug, feature requests and other issues should be reported to the [GitHub +project]. We accept code and documentation contributions via Pull Requests on +GitHub as well. + +- [PSR-2 Coding Standard][] is used by the project. The included test + configuration uses [PHP Code Sniffer][] to validate the conventions. +- Tests are encouraged. Our test coverage isn't perfect but we'd like it to + get better rather than worse, so please try to include tests with your + changes. +- Keep the documentation up to date. Make sure `README.md` and other + relevant documentation is kept up to date with your changes. +- One pull request per feature. Try to keep your changes focused on solving + a single problem. This will make it easier for us to review the change and + easier for you to make sure you have updated the necessary tests and + documentation. + +License +------- +Composer Merge plugin is licensed under the MIT license. See the `LICENSE` +file for more details. + +--- +[GitHub project]: https://github.com/wikimedia/composer-merge-plugin +[PSR-2 Coding Standard]: https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md +[PHP Code Sniffer]: http://pear.php.net/package/PHP_CodeSniffer diff --git a/vendor/wikimedia/composer-merge-plugin/composer.json b/vendor/wikimedia/composer-merge-plugin/composer.json new file mode 100644 index 00000000..5ef429ad --- /dev/null +++ b/vendor/wikimedia/composer-merge-plugin/composer.json @@ -0,0 +1,38 @@ +{ + "name": "wikimedia/composer-merge-plugin", + "description": "Composer plugin to merge multiple composer.json files", + "type": "composer-plugin", + "license": "MIT", + "minimum-stability": "dev", + "prefer-stable": true, + "require": { + "php": ">=5.3.2", + "composer-plugin-api": "1.0.0" + }, + "require-dev": { + "composer/composer": "1.0.*@dev", + "phpunit/phpunit": "~4.0", + "jakub-onderka/php-parallel-lint": "~0.8", + "squizlabs/php_codesniffer": "~2.1.0", + "phpspec/prophecy-phpunit": "~1.0" + }, + "autoload": { + "psr-4": { + "Wikimedia\\Composer\\": "src/" + } + }, + "extra": { + "class": "Wikimedia\\Composer\\MergePlugin" + }, + "config": { + "optimize-autoloader": true + }, + "scripts": { + "test": [ + "composer validate --no-interaction", + "parallel-lint src tests", + "phpunit --log-junit=reports/unitreport.xml --coverage-text --coverage-html=reports/coverage --coverage-clover=reports/coverage.xml", + "phpcs --encoding=utf-8 --standard=PSR2 --report-checkstyle=reports/checkstyle-phpcs.xml --report-full --extensions=php src/* tests/phpunit/*" + ] + } +} diff --git a/vendor/wikimedia/composer-merge-plugin/src/MergePlugin.php b/vendor/wikimedia/composer-merge-plugin/src/MergePlugin.php new file mode 100644 index 00000000..04c55886 --- /dev/null +++ b/vendor/wikimedia/composer-merge-plugin/src/MergePlugin.php @@ -0,0 +1,411 @@ +<?php +/** + * This file is part of the Composer Merge plugin. + * + * Copyright (C) 2014 Bryan Davis, Wikimedia Foundation, and contributors + * + * This software may be modified and distributed under the terms of the MIT + * license. See the LICENSE file for details. + */ + +namespace Wikimedia\Composer; + +use Composer\Composer; +use Composer\Config; +use Composer\EventDispatcher\EventSubscriberInterface; +use Composer\Installer\InstallerEvent; +use Composer\Installer\InstallerEvents; +use Composer\IO\IOInterface; +use Composer\Json\JsonFile; +use Composer\Package\BasePackage; +use Composer\Package\CompletePackage; +use Composer\Package\Loader\ArrayLoader; +use Composer\Package\RootPackageInterface; +use Composer\Package\Version\VersionParser; +use Composer\Plugin\PluginInterface; +use Composer\Script\CommandEvent; +use Composer\Script\ScriptEvents; + +/** + * Composer plugin that allows merging multiple composer.json files. + * + * When installed, this plugin will look for a "merge-patterns" key in the + * composer configuration's "extra" section. The value of this setting can be + * either a single value or an array of values. Each value is treated as + * a glob() pattern identifying additional composer.json style configuration + * files to merge into the configuration for the current compser execution. + * + * The "require", "require-dev", "repositories" and "suggest" sections of the + * found configuration files will be merged into the root package + * configuration as though they were directly included in the top-level + * composer.json file. + * + * If included files specify conflicting package versions for "require" or + * "require-dev", the normal Composer dependency solver process will be used + * to attempt to resolve the conflict. + * + * @code + * { + * "require": { + * "wikimedia/composer-merge-plugin": "dev-master" + * }, + * "extra": { + * "merge-plugin": { + * "include": [ + * "composer.local.json" + * ] + * } + * } + * } + * @endcode + * + * @author Bryan Davis <bd808@bd808.com> + */ +class MergePlugin implements PluginInterface, EventSubscriberInterface +{ + + /** + * @var Composer $composer + */ + protected $composer; + + /** + * @var IOInterface $inputOutput + */ + protected $inputOutput; + + /** + * @var ArrayLoader $loader + */ + protected $loader; + + /** + * @var array $duplicateLinks + */ + protected $duplicateLinks; + + /** + * @var bool $devMode + */ + protected $devMode; + + /** + * Whether to recursively include dependencies + * + * @var bool $recurse + */ + protected $recurse = true; + + /** + * Files that have already been processed + * + * @var string[] $loadedFiles + */ + protected $loadedFiles = array(); + + /** + * {@inheritdoc} + */ + public function activate(Composer $composer, IOInterface $io) + { + $this->composer = $composer; + $this->inputOutput = $io; + } + + /** + * {@inheritdoc} + */ + public static function getSubscribedEvents() + { + return array( + InstallerEvents::PRE_DEPENDENCIES_SOLVING => 'onDependencySolve', + ScriptEvents::PRE_INSTALL_CMD => 'onInstallOrUpdate', + ScriptEvents::PRE_UPDATE_CMD => 'onInstallOrUpdate', + ); + } + + /** + * Handle an event callback for an install or update command by checking + * for "merge-patterns" in the "extra" data and merging package contents + * if found. + * + * @param CommandEvent $event + */ + public function onInstallOrUpdate(CommandEvent $event) + { + $config = $this->readConfig($this->composer->getPackage()); + if (isset($config['recurse'])) { + $this->recurse = (bool)$config['recurse']; + } + if ($config['include']) { + $this->loader = new ArrayLoader(); + $this->duplicateLinks = array( + 'require' => array(), + 'require-dev' => array(), + ); + $this->devMode = $event->isDevMode(); + $this->mergePackages($config); + } + } + + /** + * @param RootPackageInterface $package + * @return array + */ + protected function readConfig(RootPackageInterface $package) + { + $config = array( + 'include' => array(), + ); + $extra = $package->getExtra(); + if (isset($extra['merge-plugin'])) { + $config = array_merge($config, $extra['merge-plugin']); + if (!is_array($config['include'])) { + $config['include'] = array($config['include']); + } + } + return $config; + } + + /** + * Find configuration files matching the configured glob patterns and + * merge their contents with the master package. + * + * @param array $config + */ + protected function mergePackages(array $config) + { + $root = $this->composer->getPackage(); + foreach (array_reduce( + array_map('glob', $config['include']), + 'array_merge', + array() + ) as $path) { + $this->loadFile($root, $path); + } + } + + /** + * Read a JSON file and merge its contents + * + * @param RootPackageInterface $root + * @param string $path + */ + protected function loadFile($root, $path) + { + if (in_array($path, $this->loadedFiles)) { + $this->debug("Skipping duplicate <comment>$path</comment>..."); + return; + } else { + $this->loadedFiles[] = $path; + } + $this->debug("Loading <comment>{$path}</comment>..."); + $json = $this->readPackageJson($path); + $package = $this->loader->load($json); + + $this->mergeRequires($root, $package); + $this->mergeDevRequires($root, $package); + + if (isset($json['repositories'])) { + $this->addRepositories($json['repositories'], $root); + } + + if ($package->getSuggests()) { + $root->setSuggests(array_merge( + $root->getSuggests(), + $package->getSuggests() + )); + } + + if ($this->recurse && isset($json['extra']['merge-plugin'])) { + $this->mergePackages($json['extra']['merge-plugin']); + } + } + + /** + * Read the contents of a composer.json style file into an array. + * + * The package contents are fixed up to be usable to create a Package + * object by providing dummy "name" and "version" values if they have not + * been provided in the file. This is consistent with the default root + * package loading behavior of Composer. + * + * @param string $path + * @return array + */ + protected function readPackageJson($path) + { + $file = new JsonFile($path); + $json = $file->read(); + if (!isset($json['name'])) { + $json['name'] = 'merge-plugin/' . + strtr($path, DIRECTORY_SEPARATOR, '-'); + } + if (!isset($json['version'])) { + $json['version'] = '1.0.0'; + } + return $json; + } + + /** + * @param RootPackageInterface $root + * @param CompletePackage $package + */ + protected function mergeRequires( + RootPackageInterface $root, + CompletePackage $package + ) { + $requires = $package->getRequires(); + if (!$requires) { + return; + } + + $this->mergeStabilityFlags($root, $requires); + + $root->setRequires($this->mergeLinks( + $root->getRequires(), + $requires, + $this->duplicateLinks['require'] + )); + } + + /** + * @param RootPackageInterface $root + * @param CompletePackage $package + */ + protected function mergeDevRequires( + RootPackageInterface $root, + CompletePackage $package + ) { + $requires = $package->getDevRequires(); + if (!$requires) { + return; + } + + $this->mergeStabilityFlags($root, $requires); + + $root->setDevRequires($this->mergeLinks( + $root->getDevRequires(), + $requires, + $this->duplicateLinks['require-dev'] + )); + } + + /** + * Extract and merge stability flags from the given collection of + * requires. + * + * @param RootPackageInterface $root + * @param array $requires + */ + protected function mergeStabilityFlags( + RootPackageInterface $root, + array $requires + ) { + $flags = $root->getStabilityFlags(); + foreach ($requires as $name => $link) { + $name = strtolower($name); + $version = $link->getPrettyConstraint(); + $stability = VersionParser::parseStability($version); + $flags[$name] = BasePackage::$stabilities[$stability]; + } + $root->setStabilityFlags($flags); + } + + /** + * Add a collection of repositories described by the given configuration + * to the given package and the global repository manager. + * + * @param array $repositories + * @param RootPackageInterface $root + */ + protected function addRepositories( + array $repositories, + RootPackageInterface $root + ) { + $repoManager = $this->composer->getRepositoryManager(); + $newRepos = array(); + + foreach ($repositories as $repoJson) { + $this->debug("Adding {$repoJson['type']} repository"); + $repo = $repoManager->createRepository( + $repoJson['type'], + $repoJson + ); + $repoManager->addRepository($repo); + $newRepos[] = $repo; + } + + $root->setRepositories(array_merge( + $newRepos, + $root->getRepositories() + )); + } + + /** + * Merge two collections of package links and collect duplicates for + * subsequent processing. + * + * @param array $origin Primary collection + * @param array $merge Additional collection + * @param array &dups Duplicate storage + * @return array Merged collection + */ + protected function mergeLinks(array $origin, array $merge, array &$dups) + { + foreach ($merge as $name => $link) { + if (!isset($origin[$name])) { + $this->debug("Merging <comment>{$name}</comment>"); + $origin[$name] = $link; + } else { + // Defer to solver. + $this->debug("Deferring duplicate <comment>{$name}</comment>"); + $dups[] = $link; + } + } + return $origin; + } + + /** + * Handle an event callback for pre-dependency solving phase of an install + * or update by adding any duplicate package dependencies found during + * initial merge processing to the request that will be processed by the + * dependency solver. + * + * @param InstallerEvent $event + */ + public function onDependencySolve(InstallerEvent $event) + { + if (!$this->duplicateLinks) { + return; + } + + $request = $event->getRequest(); + foreach ($this->duplicateLinks['require'] as $link) { + $this->debug("Adding dependency <comment>{$link}</comment>"); + $request->install($link->getTarget(), $link->getConstraint()); + } + if ($this->devMode) { + foreach ($this->duplicateLinks['require-dev'] as $link) { + $this->debug("Adding dev dependency <comment>{$link}</comment>"); + $request->install($link->getTarget(), $link->getConstraint()); + } + } + } + + /** + * 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}"); + } + } +} +// vim:sw=4:ts=4:sts=4:et: |