1
0
Fork 0

Merge branches 'add_exclude' and 'master' of https://github.com/trivago/composer into add_exclude

* Resolve conflicts and update unit test
pull/1607/head
msiebeneicher 2015-02-11 18:04:57 +01:00
parent f28785a49d
commit dad6b05ca7
3 changed files with 24 additions and 29 deletions

View File

@ -174,7 +174,7 @@ EOF;
} }
$blacklist = ''; $blacklist = '';
if(!empty($autoloads['exclude-from-classmap'])) { if (!empty($autoloads['exclude-from-classmap'])) {
$blacklist = '{(' . implode('|', $autoloads['exclude-from-classmap']) . ')}'; $blacklist = '{(' . implode('|', $autoloads['exclude-from-classmap']) . ')}';
} }
@ -189,38 +189,21 @@ EOF;
if (!is_dir($dir)) { if (!is_dir($dir)) {
continue; continue;
} }
$whitelist = sprintf(
'{%s/%s.+(?<!(?<!/)Test\.php)$}',
preg_quote($dir),
($psrType === 'psr-0' && strpos($namespace, '_') === false) ? preg_quote(strtr($namespace, '\\', '/')) : ''
);
$namespaceFilter = $namespace === '' ? null : $namespace; $namespaceFilter = $namespace === '' ? null : $namespace;
foreach (ClassMapGenerator::createMap($dir, $whitelist, $this->io, $namespaceFilter) as $class => $path) { foreach (ClassMapGenerator::createMap($dir, $blacklist, $this->io, $namespaceFilter) as $class => $path) {
if (!isset($classMap[$class])) { if (!isset($classMap[$class])) {
$path = $this->getPathCode($filesystem, $basePath, $vendorPath, $path); $path = $this->getPathCode($filesystem, $basePath, $vendorPath, $path);
$classMap[$class] = $path.",\n"; $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 ($autoloads['classmap'] as $dir) {
foreach (ClassMapGenerator::createMap($dir, null, $this->io) as $class => $path) { foreach (ClassMapGenerator::createMap($dir, $blacklist, $this->io) as $class => $path) {
//REKERNER foreach (ClassMapGenerator::createMap($dir, $blacklist) as $class => $path) {
$path = $this->getPathCode($filesystem, $basePath, $vendorPath, $path); $path = $this->getPathCode($filesystem, $basePath, $vendorPath, $path);
$classMap[$class] = $path.",\n"; $classMap[$class] = $path.",\n";
} }
@ -644,7 +627,7 @@ FOOTER;
if ($type === 'classmap' && $package !== $mainPackage && $package->getTargetDir() && !is_readable($installPath.'/'.$path)) { if ($type === 'classmap' && $package !== $mainPackage && $package->getTargetDir() && !is_readable($installPath.'/'.$path)) {
$path = $package->getTargetDir() . '/' . $path; $path = $package->getTargetDir() . '/' . $path;
} }
*/
if ($type === 'exclude-from-classmap') { if ($type === 'exclude-from-classmap') {
// first escape user input // first escape user input
$path = sprintf(self::EXCLUDE_PATTERN, preg_quote($path)); $path = sprintf(self::EXCLUDE_PATTERN, preg_quote($path));
@ -661,7 +644,7 @@ FOOTER;
$autoloads[] = empty($installPath) ? $path : preg_quote($installPath) . '/' . $path; $autoloads[] = empty($installPath) ? $path : preg_quote($installPath) . '/' . $path;
continue; continue;
} }
/*
if (empty($installPath)) { if (empty($installPath)) {
$autoloads[$namespace][] = empty($path) ? '.' : $path; $autoloads[$namespace][] = empty($path) ? '.' : $path;
} else { } else {

View File

@ -45,7 +45,7 @@ class ClassMapGenerator
* Iterate over all files in the given directory searching for classes * Iterate over all files in the given directory searching for classes
* *
* @param \Iterator|string $path The path to search in or an iterator * @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 IOInterface $io IO object
* @param string $namespace Optional namespace prefix to filter by * @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 * @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 = '') // RKERNER: public static function createMap($path, $blacklist = '')
{ {
if (is_string($path)) { if (is_string($path)) {
@ -78,8 +78,7 @@ class ClassMapGenerator
continue; continue;
} }
if ($whitelist && !preg_match($whitelist, strtr($filePath, '\\', '/'))) { if ($blacklist && preg_match($blacklist, strtr($filePath, '\\', '/'))) {
// RKERNER: if ($blacklist && preg_match($blacklist, strtr($filePath, '\\', '/'))) {
continue; continue;
} }

View File

@ -1200,6 +1200,11 @@ EOF;
$package->setAutoload(array( $package->setAutoload(array(
'psr-0' => array( 'psr-0' => array(
'Main' => 'src/', 'Main' => 'src/',
'Lala' => array('src/', 'lib/'),
),
'psr-4' => array(
'Acme\Fruit\\' => 'src-fruit/',
'Acme\Cake\\' => array('src-cake/', 'lib-cake/'),
), ),
'classmap' => array('composersrc/'), 'classmap' => array('composersrc/'),
'exclude-from-classmap' => array('/tests/'), 'exclude-from-classmap' => array('/tests/'),
@ -1210,17 +1215,25 @@ EOF;
->will($this->returnValue(array())); ->will($this->returnValue(array()));
$this->fs->ensureDirectoryExists($this->workingDir.'/composer'); $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', '<?php namespace Lala; class ClassMapMain {}');
$this->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', '<?php namespace Acme\Cake; class ClassMapBar {}');
$this->fs->ensureDirectoryExists($this->workingDir.'/composersrc'); $this->fs->ensureDirectoryExists($this->workingDir.'/composersrc');
file_put_contents($this->workingDir.'/composersrc/foo.php', '<?php class ClassMapFoo {}'); file_put_contents($this->workingDir.'/composersrc/foo.php', '<?php class ClassMapFoo {}');
// this class should not be found in the classmap
$this->fs->ensureDirectoryExists($this->workingDir.'/composersrc/tests'); $this->fs->ensureDirectoryExists($this->workingDir.'/composersrc/tests');
file_put_contents($this->workingDir.'/composersrc/tests/bar.php', '<?php class ClassExcludeMapFoo {}'); file_put_contents($this->workingDir.'/composersrc/tests/bar.php', '<?php class ClassExcludeMapFoo {}');
$this->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'); $this->assertAutoloadFiles('classmap', $this->vendorDir.'/composer', 'classmap');
} }