Tweaked exclude-from-classmap: windows support, normalize paths and make sure they are all package-relative and do not leak to other packages, refs #1607
parent
084f6de24e
commit
f1b0c073ad
|
@ -28,8 +28,6 @@ use Composer\Script\ScriptEvents;
|
|||
*/
|
||||
class AutoloadGenerator
|
||||
{
|
||||
const EXCLUDE_PATTERN = '.*%s';
|
||||
|
||||
/**
|
||||
* @var EventDispatcher
|
||||
*/
|
||||
|
@ -677,7 +675,7 @@ FOOTER;
|
|||
|
||||
foreach ($autoload[$type] as $namespace => $paths) {
|
||||
foreach ((array) $paths as $path) {
|
||||
if (($type === 'files' || $type === 'classmap') && $package->getTargetDir() && !is_readable($installPath.'/'.$path)) {
|
||||
if (($type === 'files' || $type === 'classmap' || $type === 'exclude-from-classmap') && $package->getTargetDir() && !is_readable($installPath.'/'.$path)) {
|
||||
// remove target-dir from file paths of the root package
|
||||
if ($package === $mainPackage) {
|
||||
$targetDir = str_replace('\\<dirsep\\>', '[\\\\/]', preg_quote(str_replace(array('/', '\\'), '<dirsep>', $package->getTargetDir())));
|
||||
|
@ -690,17 +688,9 @@ FOOTER;
|
|||
|
||||
if ($type === 'exclude-from-classmap') {
|
||||
// first escape user input
|
||||
$path = sprintf(self::EXCLUDE_PATTERN, preg_quote($path));
|
||||
$path = preg_quote(trim(strtr($path, '\\', '/'), '/'));
|
||||
|
||||
if ($package === $mainPackage && $package->getTargetDir() && !is_readable($installPath.'/'.$path)) {
|
||||
// remove target-dir from classmap entries of the root package
|
||||
$targetDir = str_replace('\\<dirsep\\>', '[\\\\/]', preg_quote(str_replace(array('/', '\\'), '<dirsep>', $package->getTargetDir())));
|
||||
$path = ltrim(preg_replace('{^'.$targetDir.'}', '', ltrim($path, '\\/')), '\\/');
|
||||
} elseif ($package !== $mainPackage && $package->getTargetDir() && !is_readable($installPath.'/'.$path)) {
|
||||
// add target-dir to exclude entries that don't have it
|
||||
$path = preg_quote($package->getTargetDir()) . '/' . $path;
|
||||
}
|
||||
$autoloads[] = empty($installPath) ? $path : preg_quote($installPath) . '/' . $path;
|
||||
$autoloads[] = empty($installPath) ? preg_quote(strtr(getcwd(), '\\', '/')) . '/' . $path : preg_quote($installPath) . '/' . $path;
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
|
@ -1274,7 +1274,7 @@ EOF;
|
|||
'Acme\Cake\\' => array('src-cake/', 'lib-cake/'),
|
||||
),
|
||||
'classmap' => array('composersrc/'),
|
||||
'exclude-from-classmap' => array('/tests/', 'Exclude.php'),
|
||||
'exclude-from-classmap' => array('/composersrc/excludedTests/', '/composersrc/ClassToExclude.php'),
|
||||
));
|
||||
|
||||
$this->repository->expects($this->once())
|
||||
|
@ -1282,9 +1282,10 @@ EOF;
|
|||
->will($this->returnValue(array()));
|
||||
|
||||
$this->fs->ensureDirectoryExists($this->workingDir.'/composer');
|
||||
$this->fs->ensureDirectoryExists($this->workingDir.'/src/Lala');
|
||||
$this->fs->ensureDirectoryExists($this->workingDir.'/src/Lala/Test');
|
||||
$this->fs->ensureDirectoryExists($this->workingDir.'/lib');
|
||||
file_put_contents($this->workingDir.'/src/Lala/ClassMapMain.php', '<?php namespace Lala; class ClassMapMain {}');
|
||||
file_put_contents($this->workingDir.'/src/Lala/Test/ClassMapMainTest.php', '<?php namespace Lala\Test; class ClassMapMainTest {}');
|
||||
|
||||
$this->fs->ensureDirectoryExists($this->workingDir.'/src-fruit');
|
||||
$this->fs->ensureDirectoryExists($this->workingDir.'/src-cake');
|
||||
|
@ -1296,7 +1297,8 @@ EOF;
|
|||
file_put_contents($this->workingDir.'/composersrc/foo.php', '<?php class ClassMapFoo {}');
|
||||
|
||||
// this classes should not be found in the classmap
|
||||
file_put_contents($this->workingDir.'/composersrc/tests/bar.php', '<?php class ClassExcludeMapFoo {}');
|
||||
$this->fs->ensureDirectoryExists($this->workingDir.'/composersrc/excludedTests');
|
||||
file_put_contents($this->workingDir.'/composersrc/excludedTests/bar.php', '<?php class ClassExcludeMapFoo {}');
|
||||
file_put_contents($this->workingDir.'/composersrc/ClassToExclude.php', '<?php class ClassClassToExclude {}');
|
||||
|
||||
$this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', true, '_1');
|
||||
|
|
Loading…
Reference in New Issue