diff --git a/src/Composer/Autoload/AutoloadGenerator.php b/src/Composer/Autoload/AutoloadGenerator.php index ec604bcd2..c70c20f36 100644 --- a/src/Composer/Autoload/AutoloadGenerator.php +++ b/src/Composer/Autoload/AutoloadGenerator.php @@ -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('\\', '[\\\\/]', preg_quote(str_replace(array('/', '\\'), '', $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('\\', '[\\\\/]', preg_quote(str_replace(array('/', '\\'), '', $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; } diff --git a/tests/Composer/Test/Autoload/AutoloadGeneratorTest.php b/tests/Composer/Test/Autoload/AutoloadGeneratorTest.php index efc3a6a93..0e373702b 100644 --- a/tests/Composer/Test/Autoload/AutoloadGeneratorTest.php +++ b/tests/Composer/Test/Autoload/AutoloadGeneratorTest.php @@ -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', 'workingDir.'/src/Lala/Test/ClassMapMainTest.php', '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', 'workingDir.'/composersrc/tests/bar.php', 'fs->ensureDirectoryExists($this->workingDir.'/composersrc/excludedTests'); + file_put_contents($this->workingDir.'/composersrc/excludedTests/bar.php', 'workingDir.'/composersrc/ClassToExclude.php', 'generator->dump($this->config, $this->repository, $package, $this->im, 'composer', true, '_1');