From 154092ba1a9b05caa0c450dd947be286c4897191 Mon Sep 17 00:00:00 2001 From: voroks Date: Wed, 19 Aug 2015 15:08:27 +0800 Subject: [PATCH] Added removing file 'include_path.php' (if it is empty). --- src/Composer/Autoload/AutoloadGenerator.php | 13 ++-- .../Test/Autoload/AutoloadGeneratorTest.php | 13 +++- ...load_real_functions_with_include_paths.php | 59 +++++++++++++++++++ ...moved_include_paths_and_autolad_files.php} | 0 .../Fixtures/include_paths_functions.php | 15 +++++ ...ude_paths_functions_with_removed_extra.php | 11 ++++ 6 files changed, 103 insertions(+), 8 deletions(-) create mode 100644 tests/Composer/Test/Autoload/Fixtures/autoload_real_functions_with_include_paths.php rename tests/Composer/Test/Autoload/Fixtures/{autoload_real_functions_with_removed_extra.php => autoload_real_functions_with_removed_include_paths_and_autolad_files.php} (100%) create mode 100644 tests/Composer/Test/Autoload/Fixtures/include_paths_functions.php create mode 100644 tests/Composer/Test/Autoload/Fixtures/include_paths_functions_with_removed_extra.php diff --git a/src/Composer/Autoload/AutoloadGenerator.php b/src/Composer/Autoload/AutoloadGenerator.php index 90d17bcf3..7227166a8 100644 --- a/src/Composer/Autoload/AutoloadGenerator.php +++ b/src/Composer/Autoload/AutoloadGenerator.php @@ -252,17 +252,20 @@ EOF; file_put_contents($targetDir.'/autoload_namespaces.php', $namespacesFile); file_put_contents($targetDir.'/autoload_psr4.php', $psr4File); file_put_contents($targetDir.'/autoload_classmap.php', $classmapFile); - if ($includePathFile = $this->getIncludePathsFile($packageMap, $filesystem, $basePath, $vendorPath, $vendorPathCode52, $appBaseDirCode)) { - file_put_contents($targetDir.'/include_paths.php', $includePathFile); + $includePathFilePath = $targetDir.'/include_paths.php'; + if ($includePathFileContents = $this->getIncludePathsFile($packageMap, $filesystem, $basePath, $vendorPath, $vendorPathCode52, $appBaseDirCode)) { + file_put_contents($includePathFilePath, $includePathFileContents); + } else if (file_exists($includePathFilePath)){ + unlink($includePathFilePath); } $includeFilesFilePath = $targetDir.'/autoload_files.php'; - if ($includeFilesFile = $this->getIncludeFilesFile($autoloads['files'], $filesystem, $basePath, $vendorPath, $vendorPathCode52, $appBaseDirCode)) { - file_put_contents($includeFilesFilePath, $includeFilesFile); + if ($includeFilesFileContents = $this->getIncludeFilesFile($autoloads['files'], $filesystem, $basePath, $vendorPath, $vendorPathCode52, $appBaseDirCode)) { + file_put_contents($includeFilesFilePath, $includeFilesFileContents); } else if (file_exists($includeFilesFilePath)) { unlink($includeFilesFilePath); } file_put_contents($vendorPath.'/autoload.php', $this->getAutoloadFile($vendorPathToTargetDirCode, $suffix)); - file_put_contents($targetDir.'/autoload_real.php', $this->getAutoloadRealFile(true, (bool) $includePathFile, $targetDirLoader, (bool) $includeFilesFile, $vendorPathCode, $appBaseDirCode, $suffix, $useGlobalIncludePath, $prependAutoloader, $classMapAuthoritative)); + file_put_contents($targetDir.'/autoload_real.php', $this->getAutoloadRealFile(true, (bool) $includePathFileContents, $targetDirLoader, (bool) $includeFilesFileContents, $vendorPathCode, $appBaseDirCode, $suffix, $useGlobalIncludePath, $prependAutoloader, $classMapAuthoritative)); $this->safeCopy(__DIR__.'/ClassLoader.php', $targetDir.'/ClassLoader.php'); $this->safeCopy(__DIR__.'/../../../LICENSE', $targetDir.'/LICENSE'); diff --git a/tests/Composer/Test/Autoload/AutoloadGeneratorTest.php b/tests/Composer/Test/Autoload/AutoloadGeneratorTest.php index 08f9cc09d..007f16363 100644 --- a/tests/Composer/Test/Autoload/AutoloadGeneratorTest.php +++ b/tests/Composer/Test/Autoload/AutoloadGeneratorTest.php @@ -589,6 +589,7 @@ class AutoloadGeneratorTest extends TestCase { $autoloadPackage = new Package('a', '1.0', '1.0'); $autoloadPackage->setAutoload(array('files' => array('root.php'))); + $autoloadPackage->setIncludePaths(array('/lib', '/src')); $notAutoloadPackage = new Package('a', '1.0', '1.0'); @@ -597,8 +598,11 @@ class AutoloadGeneratorTest extends TestCase $autoloadPackages[] = $b = new Package('b/b', '1.0', '1.0'); $autoloadPackages[] = $c = new Package('c/c', '1.0', '1.0'); $a->setAutoload(array('files' => array('test.php'))); + $a->setIncludePaths(array('lib1', 'src1')); $b->setAutoload(array('files' => array('test2.php'))); + $b->setIncludePaths(array('lib2')); $c->setAutoload(array('files' => array('test3.php', 'foo/bar/test4.php'))); + $c->setIncludePaths(array('lib3')); $c->setTargetDir('foo/bar'); $notAutoloadPackages = array(); @@ -629,18 +633,21 @@ class AutoloadGeneratorTest extends TestCase $this->generator->dump($this->config, $this->repository, $autoloadPackage, $this->im, 'composer', false, 'FilesAutoload'); $this->assertFileEquals(__DIR__.'/Fixtures/autoload_functions.php', $this->vendorDir.'/autoload.php'); - $this->assertFileEquals(__DIR__.'/Fixtures/autoload_real_functions.php', $this->vendorDir.'/composer/autoload_real.php'); + $this->assertFileEquals(__DIR__.'/Fixtures/autoload_real_functions_with_include_paths.php', $this->vendorDir.'/composer/autoload_real.php'); $this->assertFileEquals(__DIR__.'/Fixtures/autoload_files_functions.php', $this->vendorDir.'/composer/autoload_files.php'); + $this->assertFileEquals(__DIR__.'/Fixtures/include_paths_functions.php', $this->vendorDir.'/composer/include_paths.php'); $this->generator->dump($this->config, $this->repository, $autoloadPackage, $this->im, 'composer', false, 'FilesAutoload'); $this->assertFileEquals(__DIR__.'/Fixtures/autoload_functions.php', $this->vendorDir.'/autoload.php'); - $this->assertFileEquals(__DIR__.'/Fixtures/autoload_real_functions.php', $this->vendorDir.'/composer/autoload_real.php'); + $this->assertFileEquals(__DIR__.'/Fixtures/autoload_real_functions_with_include_paths.php', $this->vendorDir.'/composer/autoload_real.php'); $this->assertFileEquals(__DIR__.'/Fixtures/autoload_files_functions_with_removed_extra.php', $this->vendorDir.'/composer/autoload_files.php'); + $this->assertFileEquals(__DIR__.'/Fixtures/include_paths_functions_with_removed_extra.php', $this->vendorDir.'/composer/include_paths.php'); $this->generator->dump($this->config, $this->repository, $notAutoloadPackage, $this->im, 'composer', false, 'FilesAutoload'); $this->assertFileEquals(__DIR__.'/Fixtures/autoload_functions.php', $this->vendorDir.'/autoload.php'); - $this->assertFileEquals(__DIR__.'/Fixtures/autoload_real_functions_with_removed_extra.php', $this->vendorDir.'/composer/autoload_real.php'); + $this->assertFileEquals(__DIR__.'/Fixtures/autoload_real_functions_with_removed_include_paths_and_autolad_files.php', $this->vendorDir.'/composer/autoload_real.php'); $this->assertFileNotExists($this->vendorDir.'/composer/autoload_files.php'); + $this->assertFileNotExists($this->vendorDir.'/composer/include_paths.php'); } public function testFilesAutoloadOrderByDependencies() diff --git a/tests/Composer/Test/Autoload/Fixtures/autoload_real_functions_with_include_paths.php b/tests/Composer/Test/Autoload/Fixtures/autoload_real_functions_with_include_paths.php new file mode 100644 index 000000000..68fb6ecbf --- /dev/null +++ b/tests/Composer/Test/Autoload/Fixtures/autoload_real_functions_with_include_paths.php @@ -0,0 +1,59 @@ + $path) { + $loader->set($namespace, $path); + } + + $map = require __DIR__ . '/autoload_psr4.php'; + foreach ($map as $namespace => $path) { + $loader->setPsr4($namespace, $path); + } + + $classMap = require __DIR__ . '/autoload_classmap.php'; + if ($classMap) { + $loader->addClassMap($classMap); + } + + $loader->register(true); + + $includeFiles = require __DIR__ . '/autoload_files.php'; + foreach ($includeFiles as $file) { + composerRequireFilesAutoload($file); + } + + return $loader; + } +} + +function composerRequireFilesAutoload($file) +{ + require $file; +} diff --git a/tests/Composer/Test/Autoload/Fixtures/autoload_real_functions_with_removed_extra.php b/tests/Composer/Test/Autoload/Fixtures/autoload_real_functions_with_removed_include_paths_and_autolad_files.php similarity index 100% rename from tests/Composer/Test/Autoload/Fixtures/autoload_real_functions_with_removed_extra.php rename to tests/Composer/Test/Autoload/Fixtures/autoload_real_functions_with_removed_include_paths_and_autolad_files.php diff --git a/tests/Composer/Test/Autoload/Fixtures/include_paths_functions.php b/tests/Composer/Test/Autoload/Fixtures/include_paths_functions.php new file mode 100644 index 000000000..f1095cf67 --- /dev/null +++ b/tests/Composer/Test/Autoload/Fixtures/include_paths_functions.php @@ -0,0 +1,15 @@ +