Merge branch '1.10'

main
Jordi Boggiano 3 years ago
commit 07b8c23f02
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC

@ -150,6 +150,11 @@
* Fixed suggest output being very spammy, it now is only one line long and shows more rarely
* Fixed conflict rules like e.g. >=5 from matching dev-master, as it is not normalized to 9999999-dev internally anymore
### [1.10.20] 2021-01-27
* Fixed exclude-from-classmap causing regex issues when having too many paths
* Fixed compatibility issue with Symfony 4/5
### [1.10.19] 2020-12-04
* Fixed regression on PHP 8.0
@ -1090,6 +1095,7 @@
[2.0.0-alpha3]: https://github.com/composer/composer/compare/2.0.0-alpha2...2.0.0-alpha3
[2.0.0-alpha2]: https://github.com/composer/composer/compare/2.0.0-alpha1...2.0.0-alpha2
[2.0.0-alpha1]: https://github.com/composer/composer/compare/1.10.7...2.0.0-alpha1
[1.10.20]: https://github.com/composer/composer/compare/1.10.19...1.10.20
[1.10.19]: https://github.com/composer/composer/compare/1.10.18...1.10.19
[1.10.18]: https://github.com/composer/composer/compare/1.10.17...1.10.18
[1.10.17]: https://github.com/composer/composer/compare/1.10.16...1.10.17

@ -576,14 +576,23 @@ the branch or tag that is currently checked out. Otherwise, the version should
be explicitly defined in the package's `composer.json` file. If the version
cannot be resolved by these means, it is assumed to be `dev-master`.
When the version cannot be inferred from the local VCS repository, you should use
the special `branch-version` entry under `extra` instead of `version`:
When the version cannot be inferred from the local VCS repository, or when you
want to override the version, you can use the `versions` option when declaring
the repository:
```json
{
"extra": {
"branch-version": "4.2-dev"
}
"repositories": [
{
"type": "path",
"url": "../../packages/my-package",
"options": {
"versions": {
"my/package": "4.2-dev"
}
}
}
]
}
```

@ -275,7 +275,7 @@ EOF;
$excluded = null;
if (!empty($autoloads['exclude-from-classmap'])) {
$excluded = '{(' . implode('|', $autoloads['exclude-from-classmap']) . ')}';
$excluded = $autoloads['exclude-from-classmap'];
}
$classMap = array();
@ -398,8 +398,31 @@ EOF;
return $classMap;
}
/**
* @param ?array $excluded
*/
private function generateClassMap($dir, $excluded, $namespaceFilter, $autoloadType, $showAmbiguousWarning, array &$scannedFiles)
{
if ($excluded) {
// filter excluded patterns here to only use those matching $dir
// exclude-from-classmap patterns are all realpath'd so we can only filter them if $dir exists so that realpath($dir) will work
// if $dir does not exist, it should anyway not find anything there so no trouble
if (file_exists($dir)) {
// transform $dir in the same way that exclude-from-classmap patterns are transformed so we can match them against each other
$dirMatch = preg_quote(strtr(realpath($dir), '\\', '/'));
foreach ($excluded as $index => $pattern) {
// extract the constant string prefix of the pattern here, until we reach a non-escaped regex special character
$pattern = preg_replace('{^(([^.+*?\[^\]$(){}=!<>|:\\\\#-]+|\\\\[.+*?\[^\]$(){}=!<>|:#-])*).*}', '$1', $pattern);
// if the pattern is not a subset or superset of $dir, it is unrelated and we skip it
if (0 !== strpos($pattern, $dirMatch) && 0 !== strpos($dirMatch, $pattern)) {
unset($excluded[$index]);
}
}
}
$excluded = $excluded ? '{(' . implode('|', $excluded) . ')}' : null;
}
return ClassMapGenerator::createMap($dir, $excluded, $showAmbiguousWarning ? $this->io : null, $namespaceFilter, $autoloadType, $scannedFiles);
}
@ -513,7 +536,7 @@ EOF;
if (isset($autoloads['classmap'])) {
$excluded = null;
if (!empty($autoloads['exclude-from-classmap'])) {
$excluded = '{(' . implode('|', $autoloads['exclude-from-classmap']) . ')}';
$excluded = $autoloads['exclude-from-classmap'];
}
$scannedFiles = array();

@ -51,7 +51,7 @@ class ClassMapGenerator
* Iterate over all files in the given directory searching for classes
*
* @param \Iterator|string $path The path to search in or an iterator
* @param string $excluded Regex that matches against the file path that exclude from the classmap.
* @param string $excluded Regex that matches file paths to be excluded from the classmap
* @param IOInterface $io IO object
* @param string $namespace Optional namespace prefix to filter by
* @param string $autoloadType psr-0|psr-4 Optional autoload standard to use mapping rules

@ -74,10 +74,8 @@ class RootPackageLoader extends ArrayLoader
if (!isset($config['version'])) {
$commit = null;
if (isset($config['extra']['branch-version'])) {
$config['version'] = preg_replace('{(\.x)?(-dev)?$}', '', $config['extra']['branch-version']).'.x-dev';
} elseif (getenv('COMPOSER_ROOT_VERSION')) {
// override with env var if available
// override with env var if available
if (getenv('COMPOSER_ROOT_VERSION')) {
$config['version'] = getenv('COMPOSER_ROOT_VERSION');
} else {
$versionData = $this->versionGuesser->guessVersion($config, $cwd ?: getcwd());

@ -170,10 +170,11 @@ class PathRepository extends ArrayRepository implements ConfigurableRepositoryIn
'reference' => sha1($json . serialize($this->options)),
);
$package['transport-options'] = $this->options;
unset($package['transport-options']['versions']);
// use the branch-version as the package version if available
if (!isset($package['version']) && isset($package['extra']['branch-version'])) {
$package['version'] = preg_replace('{(\.x)?(-dev)?$}', '', $package['extra']['branch-version']).'.x-dev';
// use the version provided as option if available
if (isset($package['name'], $this->options['versions'][$package['name']])) {
$package['version'] = $this->options['versions'][$package['name']];
}
// carry over the root package version if this path repo is in the same git repository as root package

@ -1447,9 +1447,9 @@ EOF;
$package->setAutoload(array(
'psr-0' => array('Foo' => '../path/../src'),
'psr-4' => array('Acme\Foo\\' => '../path/../src-psr4'),
'classmap' => array('../classmap'),
'classmap' => array('../classmap', '../classmap2/subdir', 'classmap3', 'classmap4'),
'files' => array('../test.php'),
'exclude-from-classmap' => array('./../classmap/excluded'),
'exclude-from-classmap' => array('./../classmap/excluded', '../classmap2', 'classmap3/classes.php', 'classmap4/*/classes.php'),
));
$this->repository->expects($this->once())
@ -1458,9 +1458,15 @@ EOF;
$this->fs->ensureDirectoryExists($this->workingDir.'/src/Foo');
$this->fs->ensureDirectoryExists($this->workingDir.'/classmap/excluded');
$this->fs->ensureDirectoryExists($this->workingDir.'/classmap2/subdir');
$this->fs->ensureDirectoryExists($this->workingDir.'/working-dir/classmap3');
$this->fs->ensureDirectoryExists($this->workingDir.'/working-dir/classmap4/foo/');
file_put_contents($this->workingDir.'/src/Foo/Bar.php', '<?php namespace Foo; class Bar {}');
file_put_contents($this->workingDir.'/classmap/classes.php', '<?php namespace Foo; class Foo {}');
file_put_contents($this->workingDir.'/classmap/excluded/classes.php', '<?php namespace Foo; class Boo {}');
file_put_contents($this->workingDir.'/classmap2/subdir/classes.php', '<?php namespace Foo; class Boo2 {}');
file_put_contents($this->workingDir.'/working-dir/classmap3/classes.php', '<?php namespace Foo; class Boo3 {}');
file_put_contents($this->workingDir.'/working-dir/classmap4/foo/classes.php', '<?php namespace Foo; class Boo4 {}');
file_put_contents($this->workingDir.'/test.php', '<?php class Foo {}');
$this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', true, '_14');

@ -202,28 +202,4 @@ class RootPackageLoaderTest extends TestCase
$this->assertEquals("dev-latest-production", $package->getPrettyVersion());
}
/**
* @dataProvider provideExtraBranchVersion
*/
public function testLoadExtraBranchVersion($branchVersion)
{
$package = $this->loadPackage(array(
'extra' => array(
'branch-version' => $branchVersion,
),
));
$this->assertEquals('1.2.x-dev', $package->getPrettyVersion());
}
public function provideExtraBranchVersion()
{
return array(
array('1.2'),
array('1.2.x'),
array('1.2-dev'),
array('1.2.x-dev'),
);
}
}

@ -1,6 +0,0 @@
{
"name": "test/path-branch-versioned",
"extra": {
"branch-version": "1.2"
}
}

@ -67,7 +67,7 @@ class PathRepositoryTest extends TestCase
$this->assertNotEmpty($packageVersion);
}
public function testLoadPackageFromFileSystemWithExtraBranchVersion()
public function testLoadPackageFromFileSystemWithWildcard()
{
$ioInterface = $this->getMockBuilder('Composer\IO\IOInterface')
->getMock();
@ -75,16 +75,24 @@ class PathRepositoryTest extends TestCase
$config = new \Composer\Config();
$versionGuesser = null;
$repositoryUrl = implode(DIRECTORY_SEPARATOR, array(__DIR__, 'Fixtures', 'path', 'with-branch-version'));
$repositoryUrl = implode(DIRECTORY_SEPARATOR, array(__DIR__, 'Fixtures', 'path', '*'));
$repository = new PathRepository(array('url' => $repositoryUrl), $ioInterface, $config);
$packages = $repository->getPackages();
$names = array();
$this->assertEquals(2, $repository->count());
$package = $packages[0];
$names[] = $package->getName();
$this->assertEquals(1, $repository->count());
$package = $packages[1];
$names[] = $package->getName();
$this->assertTrue($repository->hasPackage($this->getPackage('test/path-branch-versioned', '1.2.x-dev')));
sort($names);
$this->assertEquals(array('test/path-unversioned', 'test/path-versioned'), $names);
}
public function testLoadPackageFromFileSystemWithWildcard()
public function testLoadPackageWithExplicitVersions()
{
$ioInterface = $this->getMockBuilder('Composer\IO\IOInterface')
->getMock();
@ -92,19 +100,28 @@ class PathRepositoryTest extends TestCase
$config = new \Composer\Config();
$versionGuesser = null;
$options = array(
'versions' => array(
'test/path-unversioned' => '4.3.2.1',
'test/path-versioned' => '3.2.1.0',
),
);
$repositoryUrl = implode(DIRECTORY_SEPARATOR, array(__DIR__, 'Fixtures', 'path', '*'));
$repository = new PathRepository(array('url' => $repositoryUrl), $ioInterface, $config);
$repository = new PathRepository(array('url' => $repositoryUrl, 'options' => $options), $ioInterface, $config);
$packages = $repository->getPackages();
$result = array();
$this->assertGreaterThanOrEqual(3, $repository->count());
$versions = array();
$this->assertEquals(2, $repository->count());
$package = $packages[0];
$versions[$package->getName()] = $package->getVersion();
foreach ($packages as $package) {
$result[$package->getName()] = $package->getPrettyVersion();
}
$package = $packages[1];
$versions[$package->getName()] = $package->getVersion();
ksort($result);
$this->assertSame(array('test/path-branch-versioned' => '1.2.x-dev', 'test/path-unversioned' => $result['test/path-unversioned'], 'test/path-versioned' => '0.0.2'), $result);
ksort($versions);
$this->assertSame(array('test/path-unversioned' => '4.3.2.1', 'test/path-versioned' => '3.2.1.0'), $versions);
}
/**

Loading…
Cancel
Save