Update to Drupal 8.0-dev-2015-11-17. Commits through da81cd220, Tue Nov 17 15:53:49 2015 +0000, Issue #2617224 by Wim Leers: Move around/fix some documentation.
This commit is contained in:
parent
4afb23bbd3
commit
7784f4c23d
929 changed files with 19798 additions and 5304 deletions
|
@ -42,24 +42,60 @@ class Logger
|
|||
/**
|
||||
* Log a debug message
|
||||
*
|
||||
* Messages will be output at the "verbose" logging level (eg `-v` needed
|
||||
* on the Composer command).
|
||||
* 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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
}
|
||||
|
||||
if (method_exists($this->inputOutput, 'writeError')) {
|
||||
$this->inputOutput->writeError($message);
|
||||
} else {
|
||||
// @codeCoverageIgnoreStart
|
||||
// Backwards compatiblity for Composer before cb336a5
|
||||
$this->inputOutput->write($message);
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
/**
|
||||
* Log a warning message
|
||||
*
|
||||
* @param string $message
|
||||
*/
|
||||
public function warning($message)
|
||||
{
|
||||
$message = " <error>[{$this->name}]</error> {$message}";
|
||||
$this->log($message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a message
|
||||
*
|
||||
* @param string $message
|
||||
*/
|
||||
protected function log($message)
|
||||
{
|
||||
if (method_exists($this->inputOutput, 'writeError')) {
|
||||
$this->inputOutput->writeError($message);
|
||||
} else {
|
||||
// @codeCoverageIgnoreStart
|
||||
// Backwards compatiblity for Composer before cb336a5
|
||||
$this->inputOutput->write($message);
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,13 +16,17 @@ use Composer\Composer;
|
|||
use Composer\Json\JsonFile;
|
||||
use Composer\Package\BasePackage;
|
||||
use Composer\Package\CompletePackage;
|
||||
use Composer\Package\Link;
|
||||
use Composer\Package\Loader\ArrayLoader;
|
||||
use Composer\Package\RootAliasPackage;
|
||||
use Composer\Package\RootPackage;
|
||||
use Composer\Package\RootPackageInterface;
|
||||
use Composer\Package\Version\VersionParser;
|
||||
use UnexpectedValueException;
|
||||
|
||||
/**
|
||||
* Processing for a composer.json file that will be merged into a RootPackage
|
||||
* Processing for a composer.json file that will be merged into
|
||||
* a RootPackageInterface
|
||||
*
|
||||
* @author Bryan Davis <bd808@bd808.com>
|
||||
*/
|
||||
|
@ -79,6 +83,17 @@ class ExtraPackage
|
|||
$this->json['extra']['merge-plugin']['include'] : array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get list of additional packages to require if precessing recursively.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getRequires()
|
||||
{
|
||||
return isset($this->json['extra']['merge-plugin']['require']) ?
|
||||
$this->json['extra']['merge-plugin']['require'] : array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the contents of a composer.json style file into an array.
|
||||
*
|
||||
|
@ -123,25 +138,30 @@ class ExtraPackage
|
|||
}
|
||||
|
||||
/**
|
||||
* Merge this package into a RootPackage
|
||||
* Merge this package into a RootPackageInterface
|
||||
*
|
||||
* @param RootPackage $root
|
||||
* @param RootPackageInterface $root
|
||||
* @param PluginState $state
|
||||
*/
|
||||
public function mergeInto(RootPackage $root, PluginState $state)
|
||||
public function mergeInto(RootPackageInterface $root, PluginState $state)
|
||||
{
|
||||
$this->addRepositories($root);
|
||||
|
||||
$this->mergeRequires($root, $state);
|
||||
$this->mergeDevRequires($root, $state);
|
||||
$this->mergeRequires('require', $root, $state);
|
||||
if ($state->isDevMode()) {
|
||||
$this->mergeRequires('require-dev', $root, $state);
|
||||
}
|
||||
|
||||
$this->mergePackageLinks('conflict', $root);
|
||||
$this->mergePackageLinks('replace', $root);
|
||||
$this->mergePackageLinks('provide', $root);
|
||||
|
||||
$this->mergeConflicts($root);
|
||||
$this->mergeReplaces($root);
|
||||
$this->mergeProvides($root);
|
||||
$this->mergeSuggests($root);
|
||||
|
||||
$this->mergeAutoload($root);
|
||||
$this->mergeDevAutoload($root);
|
||||
$this->mergeAutoload('autoload', $root);
|
||||
if ($state->isDevMode()) {
|
||||
$this->mergeAutoload('devAutoload', $root);
|
||||
}
|
||||
|
||||
$this->mergeExtra($root, $state);
|
||||
}
|
||||
|
@ -150,9 +170,9 @@ class ExtraPackage
|
|||
* Add a collection of repositories described by the given configuration
|
||||
* to the given package and the global repository manager.
|
||||
*
|
||||
* @param RootPackage $root
|
||||
* @param RootPackageInterface $root
|
||||
*/
|
||||
protected function addRepositories(RootPackage $root)
|
||||
protected function addRepositories(RootPackageInterface $root)
|
||||
{
|
||||
if (!isset($this->json['repositories'])) {
|
||||
return;
|
||||
|
@ -164,7 +184,7 @@ class ExtraPackage
|
|||
if (!isset($repoJson['type'])) {
|
||||
continue;
|
||||
}
|
||||
$this->logger->debug("Adding {$repoJson['type']} repository");
|
||||
$this->logger->info("Adding {$repoJson['type']} repository");
|
||||
$repo = $repoManager->createRepository(
|
||||
$repoJson['type'],
|
||||
$repoJson
|
||||
|
@ -173,125 +193,102 @@ class ExtraPackage
|
|||
$newRepos[] = $repo;
|
||||
}
|
||||
|
||||
$root->setRepositories(array_merge(
|
||||
$unwrapped = self::unwrapIfNeeded($root, 'setRepositories');
|
||||
$unwrapped->setRepositories(array_merge(
|
||||
$newRepos,
|
||||
$root->getRepositories()
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge require into a RootPackage
|
||||
* Merge require or require-dev into a RootPackageInterface
|
||||
*
|
||||
* @param RootPackage $root
|
||||
* @param string $type 'require' or 'require-dev'
|
||||
* @param RootPackageInterface $root
|
||||
* @param PluginState $state
|
||||
*/
|
||||
protected function mergeRequires(RootPackage $root, PluginState $state)
|
||||
{
|
||||
$requires = $this->package->getRequires();
|
||||
protected function mergeRequires(
|
||||
$type,
|
||||
RootPackageInterface $root,
|
||||
PluginState $state
|
||||
) {
|
||||
$linkType = BasePackage::$supportedLinkTypes[$type];
|
||||
$getter = 'get' . ucfirst($linkType['method']);
|
||||
$setter = 'set' . ucfirst($linkType['method']);
|
||||
|
||||
$requires = $this->package->{$getter}();
|
||||
if (empty($requires)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->mergeStabilityFlags($root, $requires);
|
||||
|
||||
$dups = array();
|
||||
$root->setRequires($this->mergeLinks(
|
||||
$root->getRequires(),
|
||||
$requires = $this->replaceSelfVersionDependencies(
|
||||
$type,
|
||||
$requires,
|
||||
$state->replaceDuplicateLinks(),
|
||||
$dups
|
||||
));
|
||||
$state->addDuplicateLinks('require', $dups);
|
||||
}
|
||||
$root
|
||||
);
|
||||
|
||||
/**
|
||||
* Merge require-dev into RootPackage
|
||||
*
|
||||
* @param RootPackage $root
|
||||
* @param PluginState $state
|
||||
*/
|
||||
protected function mergeDevRequires(RootPackage $root, PluginState $state)
|
||||
{
|
||||
$requires = $this->package->getDevRequires();
|
||||
if (empty($requires)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->mergeStabilityFlags($root, $requires);
|
||||
|
||||
$dups = array();
|
||||
$root->setDevRequires($this->mergeLinks(
|
||||
$root->getDevRequires(),
|
||||
$root->{$setter}($this->mergeOrDefer(
|
||||
$type,
|
||||
$root->{$getter}(),
|
||||
$requires,
|
||||
$state->replaceDuplicateLinks(),
|
||||
$dups
|
||||
$state
|
||||
));
|
||||
$state->addDuplicateLinks('require-dev', $dups);
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge two collections of package links and collect duplicates for
|
||||
* subsequent processing.
|
||||
*
|
||||
* @param string $type 'require' or 'require-dev'
|
||||
* @param array $origin Primary collection
|
||||
* @param array $merge Additional collection
|
||||
* @param bool $replace Replace exising links?
|
||||
* @param array &dups Duplicate storage
|
||||
* @param PluginState $state
|
||||
* @return array Merged collection
|
||||
*/
|
||||
protected function mergeLinks(
|
||||
protected function mergeOrDefer(
|
||||
$type,
|
||||
array $origin,
|
||||
array $merge,
|
||||
$replace,
|
||||
array &$dups
|
||||
$state
|
||||
) {
|
||||
$dups = array();
|
||||
foreach ($merge as $name => $link) {
|
||||
if (!isset($origin[$name]) || $replace) {
|
||||
$this->logger->debug("Merging <comment>{$name}</comment>");
|
||||
if (!isset($origin[$name]) || $state->replaceDuplicateLinks()) {
|
||||
$this->logger->info("Merging <comment>{$name}</comment>");
|
||||
$origin[$name] = $link;
|
||||
} else {
|
||||
// Defer to solver.
|
||||
$this->logger->debug(
|
||||
$this->logger->info(
|
||||
"Deferring duplicate <comment>{$name}</comment>"
|
||||
);
|
||||
$dups[] = $link;
|
||||
}
|
||||
}
|
||||
$state->addDuplicateLinks($type, $dups);
|
||||
return $origin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge autoload into a RootPackage
|
||||
* Merge autoload or autoload-dev into a RootPackageInterface
|
||||
*
|
||||
* @param RootPackage $root
|
||||
* @param string $type 'autoload' or 'devAutoload'
|
||||
* @param RootPackageInterface $root
|
||||
*/
|
||||
protected function mergeAutoload(RootPackage $root)
|
||||
protected function mergeAutoload($type, RootPackageInterface $root)
|
||||
{
|
||||
$autoload = $this->package->getAutoload();
|
||||
$getter = 'get' . ucfirst($type);
|
||||
$setter = 'set' . ucfirst($type);
|
||||
|
||||
$autoload = $this->package->{$getter}();
|
||||
if (empty($autoload)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$root->setAutoload(array_merge_recursive(
|
||||
$root->getAutoload(),
|
||||
$this->fixRelativePaths($autoload)
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge autoload-dev into a RootPackage
|
||||
*
|
||||
* @param RootPackage $root
|
||||
*/
|
||||
protected function mergeDevAutoload(RootPackage $root)
|
||||
{
|
||||
$autoload = $this->package->getDevAutoload();
|
||||
if (empty($autoload)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$root->setDevAutoload(array_merge_recursive(
|
||||
$root->getDevAutoload(),
|
||||
$unwrapped = self::unwrapIfNeeded($root, $setter);
|
||||
$unwrapped->{$setter}(array_merge_recursive(
|
||||
$root->{$getter}(),
|
||||
$this->fixRelativePaths($autoload)
|
||||
));
|
||||
}
|
||||
|
@ -319,83 +316,64 @@ class ExtraPackage
|
|||
|
||||
/**
|
||||
* Extract and merge stability flags from the given collection of
|
||||
* requires and merge them into a RootPackage
|
||||
* requires and merge them into a RootPackageInterface
|
||||
*
|
||||
* @param RootPackage $root
|
||||
* @param RootPackageInterface $root
|
||||
* @param array $requires
|
||||
*/
|
||||
protected function mergeStabilityFlags(
|
||||
RootPackage $root,
|
||||
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);
|
||||
$sf = new StabilityFlags($flags, $root->getMinimumStability());
|
||||
|
||||
$unwrapped = self::unwrapIfNeeded($root, 'setStabilityFlags');
|
||||
$unwrapped->setStabilityFlags(array_merge(
|
||||
$flags,
|
||||
$sf->extractAll($requires)
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge conflicting packages into a RootPackage
|
||||
* Merge package links of the given type into a RootPackageInterface
|
||||
*
|
||||
* @param RootPackage $root
|
||||
* @param string $type 'conflict', 'replace' or 'provide'
|
||||
* @param RootPackageInterface $root
|
||||
*/
|
||||
protected function mergeConflicts(RootPackage $root)
|
||||
protected function mergePackageLinks($type, RootPackageInterface $root)
|
||||
{
|
||||
$conflicts = $this->package->getConflicts();
|
||||
if (!empty($conflicts)) {
|
||||
$root->setconflicts(array_merge(
|
||||
$root->getConflicts(),
|
||||
$conflicts
|
||||
$linkType = BasePackage::$supportedLinkTypes[$type];
|
||||
$getter = 'get' . ucfirst($linkType['method']);
|
||||
$setter = 'set' . ucfirst($linkType['method']);
|
||||
|
||||
$links = $this->package->{$getter}();
|
||||
if (!empty($links)) {
|
||||
$unwrapped = self::unwrapIfNeeded($root, $setter);
|
||||
if ($root !== $unwrapped) {
|
||||
$this->logger->warning(
|
||||
'This Composer version does not support ' .
|
||||
"'{$type}' merging for aliased packages."
|
||||
);
|
||||
}
|
||||
$unwrapped->{$setter}(array_merge(
|
||||
$root->{$getter}(),
|
||||
$this->replaceSelfVersionDependencies($type, $links, $root)
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge replaced packages into a RootPackage
|
||||
* Merge suggested packages into a RootPackageInterface
|
||||
*
|
||||
* @param RootPackage $root
|
||||
* @param RootPackageInterface $root
|
||||
*/
|
||||
protected function mergeReplaces(RootPackage $root)
|
||||
{
|
||||
$replaces = $this->package->getReplaces();
|
||||
if (!empty($replaces)) {
|
||||
$root->setReplaces(array_merge(
|
||||
$root->getReplaces(),
|
||||
$replaces
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge provided virtual packages into a RootPackage
|
||||
*
|
||||
* @param RootPackage $root
|
||||
*/
|
||||
protected function mergeProvides(RootPackage $root)
|
||||
{
|
||||
$provides = $this->package->getProvides();
|
||||
if (!empty($provides)) {
|
||||
$root->setProvides(array_merge(
|
||||
$root->getProvides(),
|
||||
$provides
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge suggested packages into a RootPackage
|
||||
*
|
||||
* @param RootPackage $root
|
||||
*/
|
||||
protected function mergeSuggests(RootPackage $root)
|
||||
protected function mergeSuggests(RootPackageInterface $root)
|
||||
{
|
||||
$suggests = $this->package->getSuggests();
|
||||
if (!empty($suggests)) {
|
||||
$root->setSuggests(array_merge(
|
||||
$unwrapped = self::unwrapIfNeeded($root, 'setSuggests');
|
||||
$unwrapped->setSuggests(array_merge(
|
||||
$root->getSuggests(),
|
||||
$suggests
|
||||
));
|
||||
|
@ -403,12 +381,12 @@ class ExtraPackage
|
|||
}
|
||||
|
||||
/**
|
||||
* Merge extra config into a RootPackage
|
||||
* Merge extra config into a RootPackageInterface
|
||||
*
|
||||
* @param RootPackage $root
|
||||
* @param RootPackageInterface $root
|
||||
* @param PluginState $state
|
||||
*/
|
||||
public function mergeExtra(RootPackage $root, PluginState $state)
|
||||
public function mergeExtra(RootPackageInterface $root, PluginState $state)
|
||||
{
|
||||
$extra = $this->package->getExtra();
|
||||
unset($extra['merge-plugin']);
|
||||
|
@ -417,21 +395,93 @@ class ExtraPackage
|
|||
}
|
||||
|
||||
$rootExtra = $root->getExtra();
|
||||
$unwrapped = self::unwrapIfNeeded($root, 'setExtra');
|
||||
|
||||
if ($state->replaceDuplicateLinks()) {
|
||||
$root->setExtra(array_merge($rootExtra, $extra));
|
||||
$unwrapped->setExtra(
|
||||
array_merge($rootExtra, $extra)
|
||||
);
|
||||
|
||||
} else {
|
||||
foreach ($extra as $key => $value) {
|
||||
if (isset($rootExtra[$key])) {
|
||||
$this->logger->debug(
|
||||
"Ignoring duplicate <comment>{$key}</comment> in ".
|
||||
"<comment>{$this->path}</comment> extra config."
|
||||
foreach (array_intersect(
|
||||
array_keys($extra),
|
||||
array_keys($rootExtra)
|
||||
) as $key) {
|
||||
$this->logger->info(
|
||||
"Ignoring duplicate <comment>{$key}</comment> in ".
|
||||
"<comment>{$this->path}</comment> extra config."
|
||||
);
|
||||
}
|
||||
$unwrapped->setExtra(
|
||||
array_merge($extra, $rootExtra)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update Links with a 'self.version' constraint with the root package's
|
||||
* version.
|
||||
*
|
||||
* @param string $type Link type
|
||||
* @param array $links
|
||||
* @param RootPackageInterface $root
|
||||
* @return array
|
||||
*/
|
||||
protected function replaceSelfVersionDependencies(
|
||||
$type,
|
||||
array $links,
|
||||
RootPackageInterface $root
|
||||
) {
|
||||
$linkType = BasePackage::$supportedLinkTypes[$type];
|
||||
$version = $root->getVersion();
|
||||
$prettyVersion = $root->getPrettyVersion();
|
||||
$vp = new VersionParser();
|
||||
|
||||
return array_map(
|
||||
function ($link) use ($linkType, $version, $prettyVersion, $vp) {
|
||||
if ('self.version' === $link->getPrettyConstraint()) {
|
||||
return new Link(
|
||||
$link->getSource(),
|
||||
$link->getTarget(),
|
||||
$vp->parseConstraints($version),
|
||||
$linkType['description'],
|
||||
$prettyVersion
|
||||
);
|
||||
}
|
||||
}
|
||||
$root->setExtra(array_merge($extra, $rootExtra));
|
||||
return $link;
|
||||
},
|
||||
$links
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a full featured Package from a RootPackageInterface.
|
||||
*
|
||||
* In Composer versions before 599ad77 the RootPackageInterface only
|
||||
* defines a sub-set of operations needed by composer-merge-plugin and
|
||||
* RootAliasPackage only implemented those methods defined by the
|
||||
* interface. Most of the unimplemented methods in RootAliasPackage can be
|
||||
* worked around because the getter methods that are implemented proxy to
|
||||
* the aliased package which we can modify by unwrapping. The exception
|
||||
* being modifying the 'conflicts', 'provides' and 'replaces' collections.
|
||||
* We have no way to actually modify those collections unfortunately in
|
||||
* older versions of Composer.
|
||||
*
|
||||
* @param RootPackageInterface $root
|
||||
* @param string $method Method needed
|
||||
* @return RootPackageInterface|RootPackage
|
||||
*/
|
||||
public static function unwrapIfNeeded(
|
||||
RootPackageInterface $root,
|
||||
$method = 'setExtra'
|
||||
) {
|
||||
if ($root instanceof RootAliasPackage &&
|
||||
!method_exists($root, $method)
|
||||
) {
|
||||
// Unwrap and return the aliased RootPackage.
|
||||
$root = $root->getAliasOf();
|
||||
}
|
||||
return $root;
|
||||
}
|
||||
}
|
||||
// vim:sw=4:ts=4:sts=4:et:
|
||||
|
|
18
vendor/wikimedia/composer-merge-plugin/src/Merge/MissingFileException.php
vendored
Normal file
18
vendor/wikimedia/composer-merge-plugin/src/Merge/MissingFileException.php
vendored
Normal file
|
@ -0,0 +1,18 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of the Composer Merge plugin.
|
||||
*
|
||||
* Copyright (C) 2015 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\Merge;
|
||||
|
||||
/**
|
||||
* @author Bryan Davis <bd808@bd808.com>
|
||||
*/
|
||||
class MissingFileException extends \RuntimeException
|
||||
{
|
||||
}
|
|
@ -11,9 +11,6 @@
|
|||
namespace Wikimedia\Composer\Merge;
|
||||
|
||||
use Composer\Composer;
|
||||
use Composer\Package\AliasPackage;
|
||||
use Composer\Package\RootPackage;
|
||||
use UnexpectedValueException;
|
||||
|
||||
/**
|
||||
* Mutable plugin state
|
||||
|
@ -32,6 +29,11 @@ class PluginState
|
|||
*/
|
||||
protected $includes = array();
|
||||
|
||||
/**
|
||||
* @var array $requires
|
||||
*/
|
||||
protected $requires = array();
|
||||
|
||||
/**
|
||||
* @var array $duplicateLinks
|
||||
*/
|
||||
|
@ -52,6 +54,12 @@ class PluginState
|
|||
*/
|
||||
protected $replace = false;
|
||||
|
||||
/**
|
||||
* Whether to merge the -dev sections.
|
||||
* @var bool $mergeDev
|
||||
*/
|
||||
protected $mergeDev = true;
|
||||
|
||||
/**
|
||||
* Whether to merge the extra section.
|
||||
*
|
||||
|
@ -99,12 +107,14 @@ class PluginState
|
|||
*/
|
||||
public function loadSettings()
|
||||
{
|
||||
$extra = $this->getRootPackage()->getExtra();
|
||||
$extra = $this->composer->getPackage()->getExtra();
|
||||
$config = array_merge(
|
||||
array(
|
||||
'include' => array(),
|
||||
'require' => array(),
|
||||
'recurse' => true,
|
||||
'replace' => false,
|
||||
'merge-dev' => true,
|
||||
'merge-extra' => false,
|
||||
),
|
||||
isset($extra['merge-plugin']) ? $extra['merge-plugin'] : array()
|
||||
|
@ -112,33 +122,14 @@ class PluginState
|
|||
|
||||
$this->includes = (is_array($config['include'])) ?
|
||||
$config['include'] : array($config['include']);
|
||||
$this->requires = (is_array($config['require'])) ?
|
||||
$config['require'] : array($config['require']);
|
||||
$this->recurse = (bool)$config['recurse'];
|
||||
$this->replace = (bool)$config['replace'];
|
||||
$this->mergeDev = (bool)$config['merge-dev'];
|
||||
$this->mergeExtra = (bool)$config['merge-extra'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the root package
|
||||
*
|
||||
* @return RootPackage
|
||||
*/
|
||||
public function getRootPackage()
|
||||
{
|
||||
$root = $this->composer->getPackage();
|
||||
if ($root instanceof AliasPackage) {
|
||||
$root = $root->getAliasOf();
|
||||
}
|
||||
// @codeCoverageIgnoreStart
|
||||
if (!$root instanceof RootPackage) {
|
||||
throw new UnexpectedValueException(
|
||||
'Expected instance of RootPackage, got ' .
|
||||
get_class($root)
|
||||
);
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
return $root;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get list of filenames and/or glob patterns to include
|
||||
*
|
||||
|
@ -149,6 +140,16 @@ class PluginState
|
|||
return $this->includes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get list of filenames and/or glob patterns to require
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getRequires()
|
||||
{
|
||||
return $this->requires;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the first install flag
|
||||
*
|
||||
|
@ -216,7 +217,7 @@ class PluginState
|
|||
*/
|
||||
public function isDevMode()
|
||||
{
|
||||
return $this->devMode;
|
||||
return $this->mergeDev && $this->devMode;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
181
vendor/wikimedia/composer-merge-plugin/src/Merge/StabilityFlags.php
vendored
Normal file
181
vendor/wikimedia/composer-merge-plugin/src/Merge/StabilityFlags.php
vendored
Normal file
|
@ -0,0 +1,181 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of the Composer Merge plugin.
|
||||
*
|
||||
* Copyright (C) 2015 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\Merge;
|
||||
|
||||
use Composer\Package\BasePackage;
|
||||
use Composer\Package\Version\VersionParser;
|
||||
|
||||
/**
|
||||
* Adapted from Composer's RootPackageLoader::extractStabilityFlags
|
||||
* @author Bryan Davis <bd808@bd808.com>
|
||||
*/
|
||||
class StabilityFlags
|
||||
{
|
||||
|
||||
/**
|
||||
* @var array Current package name => stability mappings
|
||||
*/
|
||||
protected $stabilityFlags;
|
||||
|
||||
/**
|
||||
* @var int Current default minimum stability
|
||||
*/
|
||||
protected $minimumStability;
|
||||
|
||||
/**
|
||||
* @var string Regex to extract an explict stability flag (eg '@dev')
|
||||
*/
|
||||
protected $explicitStabilityRe;
|
||||
|
||||
|
||||
/**
|
||||
* @param array $stabilityFlags Current package name => stability mappings
|
||||
* @param int $minimumStability Current default minimum stability
|
||||
*/
|
||||
public function __construct(
|
||||
array $stabilityFlags = array(),
|
||||
$minimumStability = BasePackage::STABILITY_STABLE
|
||||
) {
|
||||
$this->stabilityFlags = $stabilityFlags;
|
||||
$this->minimumStability = $this->getStabilityInt($minimumStability);
|
||||
$this->explicitStabilityRe = '/^[^@]*?@(' .
|
||||
implode('|', array_keys(BasePackage::$stabilities)) .
|
||||
')$/i';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the stability value for a given string.
|
||||
*
|
||||
* @param string $name Stability name
|
||||
* @return int Stability value
|
||||
*/
|
||||
protected function getStabilityInt($name)
|
||||
{
|
||||
$name = VersionParser::normalizeStability($name);
|
||||
return isset(BasePackage::$stabilities[$name]) ?
|
||||
BasePackage::$stabilities[$name] :
|
||||
BasePackage::STABILITY_STABLE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract and merge stability flags from the given collection of
|
||||
* requires with another collection of stability flags.
|
||||
*
|
||||
* @param array $requires New package name => link mappings
|
||||
* @return array Unified package name => stability mappings
|
||||
*/
|
||||
public function extractAll(array $requires)
|
||||
{
|
||||
$flags = array();
|
||||
|
||||
foreach ($requires as $name => $link) {
|
||||
$name = strtolower($name);
|
||||
$version = $link->getPrettyConstraint();
|
||||
|
||||
$stability = $this->getExplicitStability($version);
|
||||
|
||||
if ($stability === null) {
|
||||
$stability = $this->getParsedStability($version);
|
||||
}
|
||||
|
||||
$flags[$name] = max($stability, $this->getCurrentStability($name));
|
||||
}
|
||||
|
||||
// Filter out null stability values
|
||||
return array_filter($flags, function ($v) {
|
||||
return $v !== null;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Extract the most unstable explicit stability (eg '@dev') from a version
|
||||
* specification.
|
||||
*
|
||||
* @param string $version
|
||||
* @return int|null Stability or null if no explict stability found
|
||||
*/
|
||||
protected function getExplicitStability($version)
|
||||
{
|
||||
$found = null;
|
||||
$constraints = $this->splitConstraints($version);
|
||||
foreach ($constraints as $constraint) {
|
||||
if (preg_match($this->explicitStabilityRe, $constraint, $match)) {
|
||||
$stability = $this->getStabilityInt($match[1]);
|
||||
$found = max($stability, $found);
|
||||
}
|
||||
}
|
||||
return $found;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Split a version specification into a list of version constraints.
|
||||
*
|
||||
* @param string $version
|
||||
* @return array
|
||||
*/
|
||||
protected function splitConstraints($version)
|
||||
{
|
||||
$found = array();
|
||||
$orConstraints = preg_split('/\s*\|\|?\s*/', trim($version));
|
||||
foreach ($orConstraints as $constraints) {
|
||||
$andConstraints = preg_split(
|
||||
'/(?<!^|as|[=>< ,]) *(?<!-)[, ](?!-) *(?!,|as|$)/',
|
||||
$constraints
|
||||
);
|
||||
foreach ($andConstraints as $constraint) {
|
||||
$found[] = $constraint;
|
||||
}
|
||||
}
|
||||
return $found;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the stability of a version
|
||||
*
|
||||
* @param string $version
|
||||
* @return int|null Stability or null if STABLE or less than minimum
|
||||
*/
|
||||
protected function getParsedStability($version)
|
||||
{
|
||||
// Drop aliasing if used
|
||||
$version = preg_replace('/^([^,\s@]+) as .+$/', '$1', $version);
|
||||
$stability = $this->getStabilityInt(
|
||||
VersionParser::parseStability($version)
|
||||
);
|
||||
|
||||
if ($stability === BasePackage::STABILITY_STABLE ||
|
||||
$this->minimumStability > $stability
|
||||
) {
|
||||
// Ignore if 'stable' or more stable than the global
|
||||
// minimum
|
||||
$stability = null;
|
||||
}
|
||||
|
||||
return $stability;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the current stability of a given package.
|
||||
*
|
||||
* @param string $name
|
||||
* @return int|null Stability of null if not set
|
||||
*/
|
||||
protected function getCurrentStability($name)
|
||||
{
|
||||
return isset($this->stabilityFlags[$name]) ?
|
||||
$this->stabilityFlags[$name] : null;
|
||||
}
|
||||
}
|
||||
// vim:sw=4:ts=4:sts=4:et:
|
|
@ -11,6 +11,7 @@
|
|||
namespace Wikimedia\Composer;
|
||||
|
||||
use Wikimedia\Composer\Merge\ExtraPackage;
|
||||
use Wikimedia\Composer\Merge\MissingFileException;
|
||||
use Wikimedia\Composer\Merge\PluginState;
|
||||
|
||||
use Composer\Composer;
|
||||
|
@ -23,7 +24,7 @@ use Composer\Installer\InstallerEvents;
|
|||
use Composer\Installer\PackageEvent;
|
||||
use Composer\Installer\PackageEvents;
|
||||
use Composer\IO\IOInterface;
|
||||
use Composer\Package\RootPackage;
|
||||
use Composer\Package\RootPackageInterface;
|
||||
use Composer\Plugin\PluginInterface;
|
||||
use Composer\Script\Event;
|
||||
use Composer\Script\ScriptEvents;
|
||||
|
@ -32,13 +33,17 @@ use Composer\Script\ScriptEvents;
|
|||
* Composer plugin that allows merging multiple composer.json files.
|
||||
*
|
||||
* When installed, this plugin will look for a "merge-plugin" 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.
|
||||
* composer configuration's "extra" section. The value for this key is
|
||||
* a set of options configuring the plugin.
|
||||
*
|
||||
* The "require", "require-dev", "repositories", "extra" and "suggest" sections
|
||||
* of the found configuration files will be merged into the root package
|
||||
* An "include" setting is required. 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 "autoload", "autoload-dev", "conflict", "provide", "replace",
|
||||
* "repositories", "require", "require-dev", 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.
|
||||
*
|
||||
|
@ -48,10 +53,10 @@ use Composer\Script\ScriptEvents;
|
|||
* change this default behaviour so that the last-defined version of a package
|
||||
* will win, allowing for force-overrides of package defines.
|
||||
*
|
||||
* By default the "extra" section is not merged. This can be enabled with the
|
||||
* 'merge-extra' key by setting it to true. In normal mode, when the same key
|
||||
* is found in both the original and the imported extra section, the version
|
||||
* in the original config is used and the imported version is skipped. If
|
||||
* By default the "extra" section is not merged. This can be enabled by
|
||||
* setitng the 'merge-extra' key to true. In normal mode, when the same key is
|
||||
* found in both the original and the imported extra section, the version in
|
||||
* the original config is used and the imported version is skipped. If
|
||||
* 'replace' mode is active, this behaviour changes so the imported version of
|
||||
* the key is used, replacing the version in the original config.
|
||||
*
|
||||
|
@ -140,7 +145,8 @@ class MergePlugin implements PluginInterface, EventSubscriberInterface
|
|||
{
|
||||
$this->state->loadSettings();
|
||||
$this->state->setDevMode($event->isDevMode());
|
||||
$this->mergeIncludes($this->state->getIncludes());
|
||||
$this->mergeFiles($this->state->getIncludes(), false);
|
||||
$this->mergeFiles($this->state->getRequires(), true);
|
||||
|
||||
if ($event->getName() === ScriptEvents::PRE_AUTOLOAD_DUMP) {
|
||||
$this->state->setDumpAutoloader(true);
|
||||
|
@ -155,16 +161,29 @@ class MergePlugin implements PluginInterface, EventSubscriberInterface
|
|||
* Find configuration files matching the configured glob patterns and
|
||||
* merge their contents with the master package.
|
||||
*
|
||||
* @param array $includes List of files/glob patterns
|
||||
* @param array $patterns List of files/glob patterns
|
||||
* @param bool $required Are the patterns required to match files?
|
||||
* @throws MissingFileException when required and a pattern returns no
|
||||
* results
|
||||
*/
|
||||
protected function mergeIncludes(array $includes)
|
||||
protected function mergeFiles(array $patterns, $required = false)
|
||||
{
|
||||
$root = $this->state->getRootPackage();
|
||||
foreach (array_reduce(
|
||||
array_map('glob', $includes),
|
||||
'array_merge',
|
||||
array()
|
||||
) as $path) {
|
||||
$root = $this->composer->getPackage();
|
||||
|
||||
$files = array_map(
|
||||
function ($files, $pattern) use ($required) {
|
||||
if ($required && !$files) {
|
||||
throw new MissingFileException(
|
||||
"merge-plugin: No files matched required '{$pattern}'"
|
||||
);
|
||||
}
|
||||
return $files;
|
||||
},
|
||||
array_map('glob', $patterns),
|
||||
$patterns
|
||||
);
|
||||
|
||||
foreach (array_reduce($files, 'array_merge', array()) as $path) {
|
||||
$this->mergeFile($root, $path);
|
||||
}
|
||||
}
|
||||
|
@ -172,26 +191,25 @@ class MergePlugin implements PluginInterface, EventSubscriberInterface
|
|||
/**
|
||||
* Read a JSON file and merge its contents
|
||||
*
|
||||
* @param RootPackage $root
|
||||
* @param RootPackageInterface $root
|
||||
* @param string $path
|
||||
*/
|
||||
protected function mergeFile(RootPackage $root, $path)
|
||||
protected function mergeFile(RootPackageInterface $root, $path)
|
||||
{
|
||||
if (isset($this->loadedFiles[$path])) {
|
||||
$this->logger->debug(
|
||||
"Skipping duplicate <comment>$path</comment>..."
|
||||
);
|
||||
$this->logger->debug("Already merged <comment>$path</comment>");
|
||||
return;
|
||||
} else {
|
||||
$this->loadedFiles[$path] = true;
|
||||
}
|
||||
$this->logger->debug("Loading <comment>{$path}</comment>...");
|
||||
$this->logger->info("Loading <comment>{$path}</comment>...");
|
||||
|
||||
$package = new ExtraPackage($path, $this->composer, $this->logger);
|
||||
$package->mergeInto($root, $this->state);
|
||||
|
||||
if ($this->state->recurseIncludes()) {
|
||||
$this->mergeIncludes($package->getIncludes());
|
||||
$this->mergeFiles($package->getIncludes(), false);
|
||||
$this->mergeFiles($package->getRequires(), true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -207,14 +225,14 @@ class MergePlugin implements PluginInterface, EventSubscriberInterface
|
|||
{
|
||||
$request = $event->getRequest();
|
||||
foreach ($this->state->getDuplicateLinks('require') as $link) {
|
||||
$this->logger->debug(
|
||||
$this->logger->info(
|
||||
"Adding dependency <comment>{$link}</comment>"
|
||||
);
|
||||
$request->install($link->getTarget(), $link->getConstraint());
|
||||
}
|
||||
if ($this->state->isDevMode()) {
|
||||
foreach ($this->state->getDuplicateLinks('require-dev') as $link) {
|
||||
$this->logger->debug(
|
||||
$this->logger->info(
|
||||
"Adding dev dependency <comment>{$link}</comment>"
|
||||
);
|
||||
$request->install($link->getTarget(), $link->getConstraint());
|
||||
|
@ -234,7 +252,7 @@ class MergePlugin implements PluginInterface, EventSubscriberInterface
|
|||
if ($op instanceof InstallOperation) {
|
||||
$package = $op->getPackage()->getName();
|
||||
if ($package === self::PACKAGE_NAME) {
|
||||
$this->logger->debug('composer-merge-plugin installed');
|
||||
$this->logger->info('composer-merge-plugin installed');
|
||||
$this->state->setFirstInstall(true);
|
||||
$this->state->setLocked(
|
||||
$event->getComposer()->getLocker()->isLocked()
|
||||
|
@ -255,7 +273,7 @@ class MergePlugin implements PluginInterface, EventSubscriberInterface
|
|||
// @codeCoverageIgnoreStart
|
||||
if ($this->state->isFirstInstall()) {
|
||||
$this->state->setFirstInstall(false);
|
||||
$this->logger->debug(
|
||||
$this->logger->info(
|
||||
'<comment>' .
|
||||
'Running additional update to apply merge settings' .
|
||||
'</comment>'
|
||||
|
|
Reference in a new issue