Prechádzať zdrojové kódy

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

* Resolve conflicts and update unit test
msiebeneicher 10 rokov pred
rodič
commit
dad6b05ca7

+ 5 - 22
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.+(?<!(?<!/)Test\.php)$}',
-                            preg_quote($dir),
-                            ($psrType === 'psr-0' && strpos($namespace, '_') === false) ? preg_quote(strtr($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])) {
                                 $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 {

+ 3 - 4
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;
             }
 

+ 16 - 3
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', '<?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');
         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');
         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');
     }