Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Erasys changes #2

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions src/Composer/Autoload/AutoloadGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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);
Expand All @@ -393,6 +394,7 @@ public function parseAutoloads(array $packageMap, PackageInterface $mainPackage)
'classmap' => $classmap,
'files' => $files,
'exclude-from-classmap' => $exclude,
'extensions' => $extensions
);
}

Expand Down Expand Up @@ -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 = <<<HEADER
<?php
Expand Down Expand Up @@ -641,6 +643,14 @@ public static function getLoader()
INCLUDEPATH;
}

if ($autoloadExtensions) {
$autoloadExtensions = var_export($autoloadExtensions, true);
$file .= <<<AUTOLOAD_EXTENSION
\$loader->setAutoloadExtensions($autoloadExtensions);

AUTOLOAD_EXTENSION;
}

if ($targetDirLoader) {
$file .= <<<REGISTER_TARGET_DIR_AUTOLOAD
spl_autoload_register(array('ComposerAutoloaderInit$suffix', 'autoload'), true, true);
Expand Down Expand Up @@ -872,6 +882,19 @@ protected function getFileIdentifier(PackageInterface $package, $path)
return md5($package->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
*
Expand Down
104 changes: 75 additions & 29 deletions src/Composer/Autoload/ClassLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ class ClassLoader
private $classMapAuthoritative = false;
private $missingClasses = array();

private $autoloadExtensions = array();

public function getPrefixes()
{
if (!empty($this->prefixesPsr0)) {
Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -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;
Expand All @@ -341,63 +368,82 @@ 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;
}
}
}
}
}
}

// 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;
}
}
}
}
}
}

// 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;
Expand Down
5 changes: 4 additions & 1 deletion src/Composer/Command/SelfUpdateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand All @@ -65,6 +65,9 @@ protected function configure()

protected function execute(InputInterface $input, OutputInterface $output)
{
$this->getIO()->writeError('<error>Composer should not be updated with this command in erasys environment.</error>');
return;

$config = Factory::createConfig();

if ($config->get('disable-tls') === true) {
Expand Down
6 changes: 3 additions & 3 deletions src/Composer/Composer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
39 changes: 39 additions & 0 deletions src/Composer/Downloader/Bzip2Downloader.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

/*
* This file is part of Composer.
*
* (c) Nils Adermann <[email protected]>
* Jordi Boggiano <[email protected]>
*
* 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 <[email protected]>
*/
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);
}

}

}
1 change: 1 addition & 0 deletions src/Composer/Downloader/DownloadManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(" <info>Installation source changed from stable to dev, wiping $targetDir</info>");
$downloader->remove($initial, $targetDir);
$this->download($target, $targetDir);

Expand Down
38 changes: 27 additions & 11 deletions src/Composer/Downloader/TarDownloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>
* @author Konrad Gibaszewski <[email protected]>
*
* @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);
}
}

}
2 changes: 2 additions & 0 deletions src/Composer/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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;
}
Expand Down
1 change: 1 addition & 0 deletions src/Composer/Installer/LibraryInstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(" <info>Installation download path changed, wiping library directory</info>");
$this->removeCode($initial);
$this->installCode($target);

Expand Down
5 changes: 5 additions & 0 deletions src/Composer/Package/AliasPackage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Loading