From dad6b05ca76231e3840d0516a88fd38f859ead64 Mon Sep 17 00:00:00 2001 From: msiebeneicher Date: Wed, 11 Feb 2015 18:04:57 +0100 Subject: [PATCH] Merge branches 'add_exclude' and 'master' of https://github.com/trivago/composer into add_exclude * Resolve conflicts and update unit test --- src/Composer/Autoload/AutoloadGenerator.php | 27 ++++--------------- src/Composer/Autoload/ClassMapGenerator.php | 7 +++-- .../Test/Autoload/AutoloadGeneratorTest.php | 19 ++++++++++--- 3 files changed, 24 insertions(+), 29 deletions(-) diff --git a/src/Composer/Autoload/AutoloadGenerator.php b/src/Composer/Autoload/AutoloadGenerator.php index b0ce14481..2cebad4bd 100644 --- a/src/Composer/Autoload/AutoloadGenerator.php +++ b/src/Composer/Autoload/AutoloadGenerator.php @@ -174,7 +174,7 @@ EOF; } $blacklist = ''; - if(!empty($autoloads['exclude-from-classmap'])) { + if (!empty($autoloads['exclude-from-classmap'])) { $blacklist = '{(' . implode('|', $autoloads['exclude-from-classmap']) . ')}'; } @@ -189,38 +189,21 @@ EOF; if (!is_dir($dir)) { continue; } - $whitelist = sprintf( - '{%s/%s.+(?io, $namespaceFilter) as $class => $path) { + foreach (ClassMapGenerator::createMap($dir, $blacklist, $this->io, $namespaceFilter) as $class => $path) { if (!isset($classMap[$class])) { $path = $this->getPathCode($filesystem, $basePath, $vendorPath, $path); $classMap[$class] = $path.",\n"; } } - /* - * RKERNER - * foreach (ClassMapGenerator::createMap($dir, $blacklist) as $class => $path) { - if ('' === $namespace || 0 === strpos($class, $namespace)) { - if (!isset($classMap[$class])) { - $path = $this->getPathCode($filesystem, $basePath, $vendorPath, $path); - $classMap[$class] = $path.",\n"; - } - } - } - */ } } } } foreach ($autoloads['classmap'] as $dir) { - foreach (ClassMapGenerator::createMap($dir, null, $this->io) as $class => $path) { - //REKERNER foreach (ClassMapGenerator::createMap($dir, $blacklist) as $class => $path) { + foreach (ClassMapGenerator::createMap($dir, $blacklist, $this->io) as $class => $path) { $path = $this->getPathCode($filesystem, $basePath, $vendorPath, $path); $classMap[$class] = $path.",\n"; } @@ -644,7 +627,7 @@ FOOTER; if ($type === 'classmap' && $package !== $mainPackage && $package->getTargetDir() && !is_readable($installPath.'/'.$path)) { $path = $package->getTargetDir() . '/' . $path; } - +*/ if ($type === 'exclude-from-classmap') { // first escape user input $path = sprintf(self::EXCLUDE_PATTERN, preg_quote($path)); @@ -661,7 +644,7 @@ FOOTER; $autoloads[] = empty($installPath) ? $path : preg_quote($installPath) . '/' . $path; continue; } - +/* if (empty($installPath)) { $autoloads[$namespace][] = empty($path) ? '.' : $path; } else { diff --git a/src/Composer/Autoload/ClassMapGenerator.php b/src/Composer/Autoload/ClassMapGenerator.php index 80e1fe8b4..1f0e1ceed 100644 --- a/src/Composer/Autoload/ClassMapGenerator.php +++ b/src/Composer/Autoload/ClassMapGenerator.php @@ -45,7 +45,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 $whitelist Regex that matches against the file path + * @param string $blacklist Regex that matches against the file path that exclude from the classmap. * @param IOInterface $io IO object * @param string $namespace Optional namespace prefix to filter by * @@ -53,7 +53,7 @@ class ClassMapGenerator * * @throws \RuntimeException When the path is neither an existing file nor directory */ - public static function createMap($path, $whitelist = null, IOInterface $io = null, $namespace = null) + public static function createMap($path, $blacklist = '', IOInterface $io = null, $namespace = null) // RKERNER: public static function createMap($path, $blacklist = '') { if (is_string($path)) { @@ -78,8 +78,7 @@ class ClassMapGenerator continue; } - if ($whitelist && !preg_match($whitelist, strtr($filePath, '\\', '/'))) { - // RKERNER: if ($blacklist && preg_match($blacklist, strtr($filePath, '\\', '/'))) { + if ($blacklist && preg_match($blacklist, strtr($filePath, '\\', '/'))) { continue; } diff --git a/tests/Composer/Test/Autoload/AutoloadGeneratorTest.php b/tests/Composer/Test/Autoload/AutoloadGeneratorTest.php index 11639fddc..efb9a012c 100644 --- a/tests/Composer/Test/Autoload/AutoloadGeneratorTest.php +++ b/tests/Composer/Test/Autoload/AutoloadGeneratorTest.php @@ -1200,6 +1200,11 @@ EOF; $package->setAutoload(array( 'psr-0' => array( 'Main' => 'src/', + 'Lala' => array('src/', 'lib/'), + ), + 'psr-4' => array( + 'Acme\Fruit\\' => 'src-fruit/', + 'Acme\Cake\\' => array('src-cake/', 'lib-cake/'), ), 'classmap' => array('composersrc/'), 'exclude-from-classmap' => array('/tests/'), @@ -1210,17 +1215,25 @@ EOF; ->will($this->returnValue(array())); $this->fs->ensureDirectoryExists($this->workingDir.'/composer'); - $this->fs->ensureDirectoryExists($this->workingDir.'/src'); + $this->fs->ensureDirectoryExists($this->workingDir.'/src/Lala'); + $this->fs->ensureDirectoryExists($this->workingDir.'/lib'); + file_put_contents($this->workingDir.'/src/Lala/ClassMapMain.php', 'fs->ensureDirectoryExists($this->workingDir.'/src-fruit'); + $this->fs->ensureDirectoryExists($this->workingDir.'/src-cake'); + $this->fs->ensureDirectoryExists($this->workingDir.'/lib-cake'); + file_put_contents($this->workingDir.'/src-cake/ClassMapBar.php', 'fs->ensureDirectoryExists($this->workingDir.'/composersrc'); file_put_contents($this->workingDir.'/composersrc/foo.php', 'fs->ensureDirectoryExists($this->workingDir.'/composersrc/tests'); file_put_contents($this->workingDir.'/composersrc/tests/bar.php', 'generator->dump($this->config, $this->repository, $package, $this->im, 'composer', false, '_1'); + $this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', true, '_1'); - // Assert that autoload_classmap.php was correctly generated. + // Assert that autoload_classmap.php was correctly generated. $this->assertAutoloadFiles('classmap', $this->vendorDir.'/composer', 'classmap'); }