1
0
Fork 0

Merge pull request #4122 from nevvermind/revert-plugin-constraints

Revert the plugin versions converting from "1.0.0" to "^1.0" feature
pull/4056/merge
Jordi Boggiano 2015-06-09 01:03:48 +01:00
commit 4f80e7ff68
4 changed files with 10 additions and 51 deletions

View File

@ -32,13 +32,7 @@ requirements:
to define which Plugin API versions your plugin is compatible with. to define which Plugin API versions your plugin is compatible with.
The required version of the `composer-plugin-api` follows the same [rules][7] The required version of the `composer-plugin-api` follows the same [rules][7]
as a normal package's, except for the `1.0`, `1.0.0` and `1.0.0.0` _exact_ as a normal package's.
values. In only these three cases, Composer will assume your plugin
actually meant `^1.0` instead. This was introduced to maintain BC with
the old style of declaring the Plugin API version.
In other words, `"require": { "composer-plugin-api": "1.0.0" }` means
`"require": { "composer-plugin-api": "^1.0" }`.
The current composer plugin API version is 1.0.0. The current composer plugin API version is 1.0.0.

View File

@ -228,27 +228,12 @@ class VersionParser
$parsedConstraint = $this->parseConstraints($constraint); $parsedConstraint = $this->parseConstraints($constraint);
} }
// if the required Plugin API version is exactly "1.0.0", convert it to "^1.0", to keep BC
if ('composer-plugin-api' === strtolower($target) && $this->isOldStylePluginApiVersion($constraint)) {
$parsedConstraint = $this->parseConstraints('^1.0');
}
$res[strtolower($target)] = new Link($source, $target, $parsedConstraint, $description, $constraint); $res[strtolower($target)] = new Link($source, $target, $parsedConstraint, $description, $constraint);
} }
return $res; return $res;
} }
/**
* @param string $requiredPluginApiVersion
* @return bool
*/
private function isOldStylePluginApiVersion($requiredPluginApiVersion)
{
// catch "1.0", "1.0.0", "1.0.0.0" etc.
return (bool) preg_match('#^1(\.0)++$#', trim($requiredPluginApiVersion));
}
/** /**
* Parses as constraint string into LinkConstraint objects * Parses as constraint string into LinkConstraint objects
* *

View File

@ -515,18 +515,12 @@ class VersionParserTest extends \PHPUnit_Framework_TestCase
); );
} }
public function oldStylePluginApiVersions() public function pluginApiVersions()
{ {
return array( return array(
array('1.0'), array('1.0'),
array('1.0.0'), array('1.0.0'),
array('1.0.0.0'), array('1.0.0.0'),
);
}
public function newStylePluginApiVersions()
{
return array(
array('1'), array('1'),
array('=1.0.0'), array('=1.0.0'),
array('==1.0'), array('==1.0'),
@ -543,23 +537,9 @@ class VersionParserTest extends \PHPUnit_Framework_TestCase
} }
/** /**
* @dataProvider oldStylePluginApiVersions * @dataProvider pluginApiVersions
*/ */
public function testOldStylePluginApiVersionGetsConvertedIntoAnotherConstraintToKeepBc($apiVersion) public function testPluginApiVersionAreKeptAsDeclared($apiVersion)
{
$parser = new VersionParser;
/** @var Link[] $links */
$links = $parser->parseLinks('Plugin', '9.9.9', '', array('composer-plugin-api' => $apiVersion));
$this->assertArrayHasKey('composer-plugin-api', $links);
$this->assertSame('^1.0', $links['composer-plugin-api']->getConstraint()->getPrettyString());
}
/**
* @dataProvider newStylePluginApiVersions
*/
public function testNewStylePluginApiVersionAreKeptAsDeclared($apiVersion)
{ {
$parser = new VersionParser; $parser = new VersionParser;

View File

@ -249,21 +249,21 @@ class PluginInstallerTest extends TestCase
$this->pm->loadInstalledPlugins(); $this->pm->loadInstalledPlugins();
} }
public function testOldPluginVersionStyleWorksWithAPIUntil199() public function testExactPluginVersionStyleAreRegisteredCorrectly()
{ {
$pluginsWithOldStyleAPIVersions = array( $pluginsWithFixedAPIVersions = array(
$this->packages[0], $this->packages[0],
$this->packages[1], $this->packages[1],
$this->packages[2], $this->packages[2],
); );
$this->setPluginApiVersionWithPlugins('1.0.0', $pluginsWithOldStyleAPIVersions); $this->setPluginApiVersionWithPlugins('1.0.0', $pluginsWithFixedAPIVersions);
$this->assertCount(3, $this->pm->getPlugins()); $this->assertCount(3, $this->pm->getPlugins());
$this->setPluginApiVersionWithPlugins('1.9.9', $pluginsWithOldStyleAPIVersions); $this->setPluginApiVersionWithPlugins('1.0.1', $pluginsWithFixedAPIVersions);
$this->assertCount(3, $this->pm->getPlugins()); $this->assertCount(0, $this->pm->getPlugins());
$this->setPluginApiVersionWithPlugins('2.0.0-dev', $pluginsWithOldStyleAPIVersions); $this->setPluginApiVersionWithPlugins('2.0.0-dev', $pluginsWithFixedAPIVersions);
$this->assertCount(0, $this->pm->getPlugins()); $this->assertCount(0, $this->pm->getPlugins());
} }