diff --git a/src/Composer/Autoload/AutoloadGenerator.php b/src/Composer/Autoload/AutoloadGenerator.php index cc71405a4c32..a64dfd5110cf 100644 --- a/src/Composer/Autoload/AutoloadGenerator.php +++ b/src/Composer/Autoload/AutoloadGenerator.php @@ -288,7 +288,7 @@ public static function autoload(\$class) } file_put_contents($targetDir.'/autoload_static.php', $this->getStaticFile($suffix, $targetDir, $vendorPath, $basePath, $staticPhpVersion)); file_put_contents($vendorPath.'/autoload.php', $this->getAutoloadFile($vendorPathToTargetDirCode, $suffix)); - file_put_contents($targetDir.'/autoload_real.php', $this->getAutoloadRealFile(true, (bool) $includePathFileContents, $targetDirLoader, (bool) $includeFilesFileContents, $vendorPathCode, $appBaseDirCode, $suffix, $useGlobalIncludePath, $prependAutoloader, $staticPhpVersion)); + file_put_contents($targetDir.'/autoload_real.php', $this->getAutoloadRealFile(true, (bool) $includePathFileContents, $targetDirLoader, (bool) $includeFilesFileContents, $vendorPathCode, $appBaseDirCode, $suffix, $useGlobalIncludePath, $prependAutoloader, $staticPhpVersion, $autoloads['extensions'])); $this->safeCopy(__DIR__.'/ClassLoader.php', $targetDir.'/ClassLoader.php'); $this->safeCopy(__DIR__.'/../../../LICENSE', $targetDir.'/LICENSE'); @@ -383,6 +383,7 @@ public function parseAutoloads(array $packageMap, PackageInterface $mainPackage) $classmap = $this->parseAutoloadsType(array_reverse($sortedPackageMap), 'classmap', $mainPackage); $files = $this->parseAutoloadsType($sortedPackageMap, 'files', $mainPackage); $exclude = $this->parseAutoloadsType($sortedPackageMap, 'exclude-from-classmap', $mainPackage); + $extensions = $this->parseExtensions($packageMap, $mainPackage); krsort($psr0); krsort($psr4); @@ -393,6 +394,7 @@ public function parseAutoloads(array $packageMap, PackageInterface $mainPackage) 'classmap' => $classmap, 'files' => $files, 'exclude-from-classmap' => $exclude, + 'extensions' => $extensions ); } @@ -548,7 +550,7 @@ protected function getAutoloadFile($vendorPathToTargetDirCode, $suffix) AUTOLOAD; } - protected function getAutoloadRealFile($useClassMap, $useIncludePath, $targetDirLoader, $useIncludeFiles, $vendorPathCode, $appBaseDirCode, $suffix, $useGlobalIncludePath, $prependAutoloader, $staticPhpVersion = 70000) + protected function getAutoloadRealFile($useClassMap, $useIncludePath, $targetDirLoader, $useIncludeFiles, $vendorPathCode, $appBaseDirCode, $suffix, $useGlobalIncludePath, $prependAutoloader, $staticPhpVersion = 70000, $autoloadExtensions) { $file = <<
setAutoloadExtensions($autoloadExtensions); + +AUTOLOAD_EXTENSION; + } + if ($targetDirLoader) { $file .= <<getName() . ':' . $path); } + protected function parseExtensions(array $packageMap, PackageInterface $mainPackage) { + $extensions = array(); + + foreach ($packageMap as $item) { + list($package, $installPath) = $item; + foreach ($package->getAutoloadExtensions() as $ext) { + $extensions[$ext] = $ext; + } + } + + return array_values($extensions); + } + /** * Sorts packages by dependency weight * diff --git a/src/Composer/Autoload/ClassLoader.php b/src/Composer/Autoload/ClassLoader.php index ac67d302a186..20f492a39cec 100644 --- a/src/Composer/Autoload/ClassLoader.php +++ b/src/Composer/Autoload/ClassLoader.php @@ -56,6 +56,8 @@ class ClassLoader private $classMapAuthoritative = false; private $missingClasses = array(); + private $autoloadExtensions = array(); + public function getPrefixes() { if (!empty($this->prefixesPsr0)) { @@ -271,6 +273,26 @@ public function isClassMapAuthoritative() return $this->classMapAuthoritative; } + /** + * Sets autoload extensions + * + * @param $autoloadExtensions + */ + public function setAutoloadExtensions($autoloadExtensions) + { + $this->autoloadExtensions = $autoloadExtensions; + } + + /** + * Returns autoload extensions + * + * @return array + */ + public function getAutoloadExtensions() + { + return $this->autoloadExtensions; + } + /** * Registers this instance as an autoloader. * @@ -326,13 +348,18 @@ public function findFile($class) return false; } - $file = $this->findFileWithExtension($class, '.php'); - - // Search for Hack files if we are running on HHVM - if (false === $file && defined('HHVM_VERSION')) { - $file = $this->findFileWithExtension($class, '.hh'); + // set autoload extensions with a reasonable default + $exts = $this->autoloadExtensions; + if (count($exts) == 0) { + $exts = ['.php']; + // Search for Hack files if we are running on HHVM + if (defined('HHVM_VERSION')) { + $exts[] = '.hh'; + } } + $file = $this->findFileWithExtensions($class, $exts); + if (false === $file) { // Remember that this class does not exist. $this->missingClasses[$class] = true; @@ -341,18 +368,22 @@ public function findFile($class) return $file; } - private function findFileWithExtension($class, $ext) + private function findFileWithExtensions($class, array $exts) { - // PSR-4 lookup - $logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR) . $ext; - + $psr4ClassPath = strtr($class, '\\', DIRECTORY_SEPARATOR); $first = $class[0]; - if (isset($this->prefixLengthsPsr4[$first])) { - foreach ($this->prefixLengthsPsr4[$first] as $prefix => $length) { - if (0 === strpos($class, $prefix)) { - foreach ($this->prefixDirsPsr4[$prefix] as $dir) { - if (file_exists($file = $dir . DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $length))) { - return $file; + + foreach ($exts as $ext) { + // PSR-4 lookup + $logicalPathPsr4 = $psr4ClassPath . $ext; + + if (isset($this->prefixLengthsPsr4[$first])) { + foreach ($this->prefixLengthsPsr4[$first] as $prefix => $length) { + if (0 === strpos($class, $prefix)) { + foreach ($this->prefixDirsPsr4[$prefix] as $dir) { + if (file_exists($file = $dir . DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $length))) { + return $file; + } } } } @@ -360,28 +391,35 @@ private function findFileWithExtension($class, $ext) } // PSR-4 fallback dirs - foreach ($this->fallbackDirsPsr4 as $dir) { - if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4)) { - return $file; + if (count($this->fallbackDirsPsr4) > 0) { + foreach ($exts as $ext) { + $logicalPathPsr4 = $psr4ClassPath . $ext; + foreach ($this->fallbackDirsPsr4 as $dir) { + if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4)) { + return $file; + } + } } } // PSR-0 lookup if (false !== $pos = strrpos($class, '\\')) { // namespaced class name - $logicalPathPsr0 = substr($logicalPathPsr4, 0, $pos + 1) - . strtr(substr($logicalPathPsr4, $pos + 1), '_', DIRECTORY_SEPARATOR); + $psr0ClassPath = substr($psr4ClassPath, 0, $pos + 1) + . strtr(substr($psr4ClassPath, $pos + 1), '_', DIRECTORY_SEPARATOR); } else { // PEAR-like class name - $logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR) . $ext; + $psr0ClassPath = strtr($class, '_', DIRECTORY_SEPARATOR); } if (isset($this->prefixesPsr0[$first])) { foreach ($this->prefixesPsr0[$first] as $prefix => $dirs) { if (0 === strpos($class, $prefix)) { - foreach ($dirs as $dir) { - if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) { - return $file; + foreach ($exts as $ext) { + foreach ($dirs as $dir) { + if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $psr0ClassPath . $ext)) { + return $file; + } } } } @@ -389,15 +427,23 @@ private function findFileWithExtension($class, $ext) } // PSR-0 fallback dirs - foreach ($this->fallbackDirsPsr0 as $dir) { - if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) { - return $file; + if (count($this->fallbackDirsPsr0) > 0) { + foreach ($exts as $ext) { + foreach ($this->fallbackDirsPsr0 as $dir) { + if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $psr0ClassPath . $ext)) { + return $file; + } + } } } // PSR-0 include paths. - if ($this->useIncludePath && $file = stream_resolve_include_path($logicalPathPsr0)) { - return $file; + if ($this->useIncludePath) { + foreach ($exts as $ext) { + if ($file = stream_resolve_include_path($psr0ClassPath . $ext)) { + return $file; + } + } } return false; diff --git a/src/Composer/Command/SelfUpdateCommand.php b/src/Composer/Command/SelfUpdateCommand.php index c0834e2c88f9..8c58c7de6a4a 100644 --- a/src/Composer/Command/SelfUpdateCommand.php +++ b/src/Composer/Command/SelfUpdateCommand.php @@ -41,7 +41,7 @@ protected function configure() $this ->setName('self-update') ->setAliases(array('selfupdate')) - ->setDescription('Updates composer.phar to the latest version.') + ->setDescription('Updates composer.phar to the latest version. Do not use in erasys environment!') ->setDefinition(array( new InputOption('rollback', 'r', InputOption::VALUE_NONE, 'Revert to an older installation of composer'), new InputOption('clean-backups', null, InputOption::VALUE_NONE, 'Delete old backups during an update. This makes the current version of composer the only backup available after the update'), @@ -65,6 +65,9 @@ protected function configure() protected function execute(InputInterface $input, OutputInterface $output) { + $this->getIO()->writeError('Composer should not be updated with this command in erasys environment.'); + return; + $config = Factory::createConfig(); if ($config->get('disable-tls') === true) { diff --git a/src/Composer/Composer.php b/src/Composer/Composer.php index c874a0796e31..d06d75ca67e7 100644 --- a/src/Composer/Composer.php +++ b/src/Composer/Composer.php @@ -28,9 +28,9 @@ */ class Composer { - const VERSION = '@package_version@'; - const BRANCH_ALIAS_VERSION = '@package_branch_alias_version@'; - const RELEASE_DATE = '@release_date@'; + const VERSION = '1.2.4-erasys-1'; + const BRANCH_ALIAS_VERSION = 'erasys'; + const RELEASE_DATE = '2016-12-06 22:00:51'; /** * @var Package\RootPackageInterface diff --git a/src/Composer/Downloader/Bzip2Downloader.php b/src/Composer/Downloader/Bzip2Downloader.php new file mode 100644 index 000000000000..c9b98304e0aa --- /dev/null +++ b/src/Composer/Downloader/Bzip2Downloader.php @@ -0,0 +1,39 @@ + + * Jordi Boggiano + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Composer\Downloader; + +/** + * Downloader for tar.bz2 files + * + * @author Konrad Gibaszewski + */ +class Bzip2Downloader extends ArchiveDownloader { + + /** + * {@inheritDoc} + */ + protected function extract($file, $path) { + try { + exec('tar xfj ' . ' ' . $file . ' -C ' . $path); + } catch (\UnexpectedValueException $e) { + $message = sprintf("Could not extract archive '%s': %s", + $file, + $e->getMessage() + ); + + throw new \RuntimeException($message, $e->getCode(), $e); + } + + } + +} diff --git a/src/Composer/Downloader/DownloadManager.php b/src/Composer/Downloader/DownloadManager.php index d18bb1cedcf2..a5edf3170f54 100644 --- a/src/Composer/Downloader/DownloadManager.php +++ b/src/Composer/Downloader/DownloadManager.php @@ -256,6 +256,7 @@ public function update(PackageInterface $initial, PackageInterface $target, $tar // upgrading from a dist stable package to a dev package, force source reinstall if ($target->isDev() && 'dist' === $installationSource) { + $this->io->writeError(" Installation source changed from stable to dev, wiping $targetDir"); $downloader->remove($initial, $targetDir); $this->download($target, $targetDir); diff --git a/src/Composer/Downloader/TarDownloader.php b/src/Composer/Downloader/TarDownloader.php index 34c43da5fdc6..c3f46e44ab63 100644 --- a/src/Composer/Downloader/TarDownloader.php +++ b/src/Composer/Downloader/TarDownloader.php @@ -13,19 +13,35 @@ namespace Composer\Downloader; /** - * Downloader for tar files: tar, tar.gz or tar.bz2 + * Class TarDownloader + * + * Downloader for uncompressed tar files * * @author Kirill chEbba Chebunin + * @author Konrad Gibaszewski + * + * @package Composer\Downloader */ -class TarDownloader extends ArchiveDownloader -{ - /** - * {@inheritDoc} - */ - protected function extract($file, $path) - { - // Can throw an UnexpectedValueException - $archive = new \PharData($file); - $archive->extractTo($path, null, true); +class TarDownloader extends ArchiveDownloader { + + /** + * {@inheritDoc} + */ + protected function extract($file, $path) { + + try { + // Unpack from tar + $archive = new \PharData($file); + $archive->extractTo($path, null, true); + + } catch (\UnexpectedValueException $e) { + $message = sprintf("Could not unpack from tar archive '%s': %s", + $file, + $e->getMessage() + ); + + throw new \RuntimeException($message, $e->getCode(), $e); } + } + } diff --git a/src/Composer/Factory.php b/src/Composer/Factory.php index 4bfae989ab17..778cc89dfc83 100644 --- a/src/Composer/Factory.php +++ b/src/Composer/Factory.php @@ -465,6 +465,7 @@ public function createDownloadManager(IOInterface $io, Config $config, EventDisp $dm->setDownloader('zip', new Downloader\ZipDownloader($io, $config, $eventDispatcher, $cache, $executor, $rfs)); $dm->setDownloader('rar', new Downloader\RarDownloader($io, $config, $eventDispatcher, $cache, $executor, $rfs)); $dm->setDownloader('tar', new Downloader\TarDownloader($io, $config, $eventDispatcher, $cache, $rfs)); + $dm->setDownloader('tar.bz2', new Downloader\Bzip2Downloader($io, $config, $eventDispatcher, $cache)); $dm->setDownloader('gzip', new Downloader\GzipDownloader($io, $config, $eventDispatcher, $cache, $executor, $rfs)); $dm->setDownloader('xz', new Downloader\XzDownloader($io, $config, $eventDispatcher, $cache, $executor, $rfs)); $dm->setDownloader('phar', new Downloader\PharDownloader($io, $config, $eventDispatcher, $cache, $rfs)); @@ -490,6 +491,7 @@ public function createArchiveManager(Config $config, Downloader\DownloadManager $am = new Archiver\ArchiveManager($dm); $am->addArchiver(new Archiver\ZipArchiver); $am->addArchiver(new Archiver\PharArchiver); + $am->addArchiver(new Archiver\GitArchiver); return $am; } diff --git a/src/Composer/Installer/LibraryInstaller.php b/src/Composer/Installer/LibraryInstaller.php index 4b1a955468ec..573fecc927b8 100644 --- a/src/Composer/Installer/LibraryInstaller.php +++ b/src/Composer/Installer/LibraryInstaller.php @@ -196,6 +196,7 @@ protected function updateCode(PackageInterface $initial, PackageInterface $targe if (substr($initialDownloadPath, 0, strlen($targetDownloadPath)) === $targetDownloadPath || substr($targetDownloadPath, 0, strlen($initialDownloadPath)) === $initialDownloadPath ) { + $this->io->writeError(" Installation download path changed, wiping library directory"); $this->removeCode($initial); $this->installCode($target); diff --git a/src/Composer/Package/AliasPackage.php b/src/Composer/Package/AliasPackage.php index 09ed4fb9b5f8..c87bb58f8a7c 100644 --- a/src/Composer/Package/AliasPackage.php +++ b/src/Composer/Package/AliasPackage.php @@ -327,6 +327,11 @@ public function getDevAutoload() return $this->aliasOf->getDevAutoload(); } + public function getAutoloadExtensions() + { + return $this->aliasOf->getAutoloadExtensions(); + } + public function getIncludePaths() { return $this->aliasOf->getIncludePaths(); diff --git a/src/Composer/Package/Archiver/ArchiveManager.php b/src/Composer/Package/Archiver/ArchiveManager.php index 52fe7bed3a87..a1b400479bfc 100644 --- a/src/Composer/Package/Archiver/ArchiveManager.php +++ b/src/Composer/Package/Archiver/ArchiveManager.php @@ -26,7 +26,7 @@ class ArchiveManager { protected $downloadManager; - protected $archivers = array(); + protected $archivers = []; /** * @var bool diff --git a/src/Composer/Package/Archiver/GitArchiver.php b/src/Composer/Package/Archiver/GitArchiver.php new file mode 100644 index 000000000000..4de3a965b8e3 --- /dev/null +++ b/src/Composer/Package/Archiver/GitArchiver.php @@ -0,0 +1,62 @@ + + * Jordi Boggiano + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Composer\Package\Archiver; + +use Composer\Util\Git as GitUtil; + +/** + * @author Till Klampaeckel + * @author Nils Adermann + * @author Matthieu Moquet + * @author Konrad Gibaszewski + */ +class GitArchiver implements ArchiverInterface { + + protected static $formats = [ + 'tar' => \Phar::TAR, + 'tar.gz' => \Phar::GZ, + 'tar.bz2' => \Phar::BZ2, + ]; + + /** + * {@inheritdoc} + */ + public function archive($sources, $target, $format, array $excludes = []) { + + $sources = realpath($sources); + + GitUtil::cleanEnv(); + + try { + $tag = shell_exec("cd $sources && git describe --tags"); + shell_exec("cd $sources && git archive -o $target $tag"); + return $target; + } catch (\UnexpectedValueException $e) { + $message = sprintf("Could not create archive '%s' from '%s': %s", + $target, + $sources, + $e->getMessage() + ); + + throw new \RuntimeException($message, $e->getCode(), $e); + } + } + + /** + * {@inheritdoc} + */ + public function supports($format, $sourceType) { + return isset(static::$formats[$format]); + } + +} diff --git a/src/Composer/Package/Dumper/ArrayDumper.php b/src/Composer/Package/Dumper/ArrayDumper.php index 714c5183b9b1..cce77869eb2f 100644 --- a/src/Composer/Package/Dumper/ArrayDumper.php +++ b/src/Composer/Package/Dumper/ArrayDumper.php @@ -32,6 +32,7 @@ public function dump(PackageInterface $package) 'installationSource' => 'installation-source', 'autoload', 'devAutoload' => 'autoload-dev', + 'autoloadExtensions' => 'autoload-extensions', 'notificationUrl' => 'notification-url', 'includePaths' => 'include-path', ); diff --git a/src/Composer/Package/Loader/ArrayLoader.php b/src/Composer/Package/Loader/ArrayLoader.php index f7e60708520a..e50585938de5 100644 --- a/src/Composer/Package/Loader/ArrayLoader.php +++ b/src/Composer/Package/Loader/ArrayLoader.php @@ -144,6 +144,10 @@ public function load(array $config, $class = 'Composer\Package\CompletePackage') $package->setDevAutoload($config['autoload-dev']); } + if (isset($config['autoload-extensions'])) { + $package->setAutoloadExtensions($config['autoload-extensions']); + } + if (isset($config['include-path'])) { $package->setIncludePaths($config['include-path']); } diff --git a/src/Composer/Package/Package.php b/src/Composer/Package/Package.php index 6c7b426e75b5..889597ee49b4 100644 --- a/src/Composer/Package/Package.php +++ b/src/Composer/Package/Package.php @@ -56,6 +56,7 @@ class Package extends BasePackage protected $suggests = array(); protected $autoload = array(); protected $devAutoload = array(); + protected $autoloadExtensions = array(); protected $includePaths = array(); protected $archiveExcludes = array(); @@ -515,6 +516,24 @@ public function getDevAutoload() return $this->devAutoload; } + /** + * Set the autoload extensions + * + * @param array $extensions + */ + public function setAutoloadExtensions(array $extensions) + { + $this->autoloadExtensions = $extensions; + } + + /** + * {@inheritDoc} + */ + public function getAutoloadExtensions() + { + return $this->autoloadExtensions; + } + /** * Sets the list of paths added to PHP's include path. * diff --git a/src/Composer/Package/PackageInterface.php b/src/Composer/Package/PackageInterface.php index 73d2ade41543..518a24e52eed 100644 --- a/src/Composer/Package/PackageInterface.php +++ b/src/Composer/Package/PackageInterface.php @@ -288,6 +288,13 @@ public function getAutoload(); */ public function getDevAutoload(); + /** + * Returns an array of autoloading extensions + * + * @return array + */ + public function getAutoloadExtensions(); + /** * Returns a list of directories which should get added to PHP's * include path.