public function compile($pharFile = 'composer.phar')
    {
        if (file_exists($pharFile)) {
            unlink($pharFile);
        }

        $process = new Process('git log --pretty="%H" -n1 HEAD', __DIR__);
        if ($process->run() != 0) {
            throw new \RuntimeException('Can\'t run git log. You must ensure to run compile from composer git repository clone and that git binary is available.');
        }
        $this->version = trim($process->getOutput());

        $process = new Process('git log -n1 --pretty=%ci HEAD', __DIR__);
        if ($process->run() != 0) {
            throw new \RuntimeException('Can\'t run git log. You must ensure to run compile from composer git repository clone and that git binary is available.');
        }

        $this->versionDate = new \DateTime(trim($process->getOutput()));
        $this->versionDate->setTimezone(new \DateTimeZone('UTC'));

        $process = new Process('git describe --tags --exact-match HEAD');
        if ($process->run() == 0) {
            $this->version = trim($process->getOutput());
        } else {
            // get branch-alias defined in composer.json for dev-master (if any)
            $localConfig = __DIR__.'/../../composer.json';
            $file = new JsonFile($localConfig);
            $localConfig = $file->read();
            if (isset($localConfig['extra']['branch-alias']['dev-master'])) {
                $this->branchAliasVersion = $localConfig['extra']['branch-alias']['dev-master'];
            }
        }

        $phar = new \Phar($pharFile, 0, 'composer.phar');
        $phar->setSignatureAlgorithm(\Phar::SHA1);

        $phar->startBuffering();

        $finderSort = function ($a, $b) {
            return strcmp(strtr($a->getRealPath(), '\\', '/'), strtr($b->getRealPath(), '\\', '/'));
        };

        $finder = new Finder();
        $finder->files()
            ->ignoreVCS(true)
            ->name('*.php')
            ->notName('Compiler.php')
            ->notName('ClassLoader.php')
            ->in(__DIR__.'/..')
            ->sort($finderSort)
        ;

        foreach ($finder as $file) {
            $this->addFile($phar, $file);
        }
        $this->addFile($phar, new \SplFileInfo(__DIR__ . '/Autoload/ClassLoader.php'), false);

        $finder = new Finder();
        $finder->files()
            ->name('*.json')
            ->in(__DIR__.'/../../res')
            ->in(SpdxLicenses::getResourcesDir())
            ->sort($finderSort)
        ;

        foreach ($finder as $file) {
            $this->addFile($phar, $file, false);
        }
        $this->addFile($phar, new \SplFileInfo(__DIR__ . '/../../vendor/symfony/console/Resources/bin/hiddeninput.exe'), false);

        $finder = new Finder();
        $finder->files()
            ->ignoreVCS(true)
            ->name('*.php')
            ->name('LICENSE')
            ->exclude('Tests')
            ->exclude('tests')
            ->exclude('docs')
            ->in(__DIR__.'/../../vendor/symfony/')
            ->in(__DIR__.'/../../vendor/seld/jsonlint/')
            ->in(__DIR__.'/../../vendor/justinrainbow/json-schema/')
            ->in(__DIR__.'/../../vendor/composer/spdx-licenses/')
            ->in(__DIR__.'/../../vendor/composer/semver/')
            ->in(__DIR__.'/../../vendor/composer/ca-bundle/')
            ->in(__DIR__.'/../../vendor/composer/xdebug-handler/')
            ->in(__DIR__.'/../../vendor/psr/')
            ->sort($finderSort)
        ;

        foreach ($finder as $file) {
            $this->addFile($phar, $file);
        }

        $this->addFile($phar, new \SplFileInfo(__DIR__.'/../../vendor/autoload.php'));
        $this->addFile($phar, new \SplFileInfo(__DIR__.'/../../vendor/composer/autoload_namespaces.php'));
        $this->addFile($phar, new \SplFileInfo(__DIR__.'/../../vendor/composer/autoload_psr4.php'));
        $this->addFile($phar, new \SplFileInfo(__DIR__.'/../../vendor/composer/autoload_classmap.php'));
        $this->addFile($phar, new \SplFileInfo(__DIR__.'/../../vendor/composer/autoload_files.php'));
        $this->addFile($phar, new \SplFileInfo(__DIR__.'/../../vendor/composer/autoload_real.php'));
        $this->addFile($phar, new \SplFileInfo(__DIR__.'/../../vendor/composer/autoload_static.php'));
        if (file_exists(__DIR__.'/../../vendor/composer/include_paths.php')) {
            $this->addFile($phar, new \SplFileInfo(__DIR__.'/../../vendor/composer/include_paths.php'));
        }
        $this->addFile($phar, new \SplFileInfo(__DIR__.'/../../vendor/composer/ClassLoader.php'));

        $this->addFile($phar, new \SplFileInfo(CaBundle::getBundledCaBundlePath()), false);

        $this->addComposerBin($phar);

        // Stubs
        $phar->setStub($this->getStub());

        $phar->stopBuffering();

        // disabled for interoperability with systems without gzip ext
        // $phar->compressFiles(\Phar::GZ);

        $this->addFile($phar, new \SplFileInfo(__DIR__.'/../../LICENSE'), false);

        unset($phar);

        // re-sign the phar with reproducible timestamp / signature
        $util = new Timestamps($pharFile);
        $util->updateTimestamps($this->versionDate);
        $util->save($pharFile, \Phar::SHA1);
    }
public function compile($pharFile = 'composer.phar')
    {
        if (file_exists($pharFile)) {
            unlink($pharFile);
        }

        $process = new Process('git log --pretty="%H" -n1 HEAD', __DIR__);
        if ($process->run() != 0) {
            throw new \RuntimeException('Can\'t run git log. You must ensure to run compile from composer git repository clone and that git binary is available.');
        }
        $this->version = trim($process->getOutput());

        $process = new Process('git log -n1 --pretty=%ci HEAD', __DIR__);
        if ($process->run() != 0) {
            throw new \RuntimeException('Can\'t run git log. You must ensure to run compile from composer git repository clone and that git binary is available.');
        }

        $this->versionDate = new \DateTime(trim($process->getOutput()));
        $this->versionDate->setTimezone(new \DateTimeZone('UTC'));

        $process = new Process('git describe --tags --exact-match HEAD');
        if ($process->run() == 0) {
            $this->version = trim($process->getOutput());
        } else {
            
            $localConfig = __DIR__.'/../../composer.json';
            $file = new JsonFile($localConfig);
            $localConfig = $file->read();
            if (isset($localConfig['extra']['branch-alias']['dev-master'])) {
                $this->branchAliasVersion = $localConfig['extra']['branch-alias']['dev-master'];
            }
        }

        $phar = new \Phar($pharFile, 0, 'composer.phar');
        $phar->setSignatureAlgorithm(\Phar::SHA1);

        $phar->startBuffering();

        $finderSort = function ($a, $b) {
            return strcmp(strtr($a->getRealPath(), '\\', '/'), strtr($b->getRealPath(), '\\', '/'));
        };

        $finder = new Finder();
        $finder->files()
            ->ignoreVCS(true)
            ->name('*.php')
            ->notName('Compiler.php')
            ->notName('ClassLoader.php')
            ->in(__DIR__.'/..')
            ->sort($finderSort)
        ;

        foreach ($finder as $file) {
            $this->addFile($phar, $file);
        }
        $this->addFile($phar, new \SplFileInfo(__DIR__ . '/Autoload/ClassLoader.php'), false);

        $finder = new Finder();
        $finder->files()
            ->name('*.json')
            ->in(__DIR__.'/../../res')
            ->in(SpdxLicenses::getResourcesDir())
            ->sort($finderSort)
        ;

        foreach ($finder as $file) {
            $this->addFile($phar, $file, false);
        }
        $this->addFile($phar, new \SplFileInfo(__DIR__ . '/../../vendor/symfony/console/Resources/bin/hiddeninput.exe'), false);

        $finder = new Finder();
        $finder->files()
            ->ignoreVCS(true)
            ->name('*.php')
            ->name('LICENSE')
            ->exclude('Tests')
            ->exclude('tests')
            ->exclude('docs')
            ->in(__DIR__.'/../../vendor/symfony/')
            ->in(__DIR__.'/../../vendor/seld/jsonlint/')
            ->in(__DIR__.'/../../vendor/justinrainbow/json-schema/')
            ->in(__DIR__.'/../../vendor/composer/spdx-licenses/')
            ->in(__DIR__.'/../../vendor/composer/semver/')
            ->in(__DIR__.'/../../vendor/composer/ca-bundle/')
            ->in(__DIR__.'/../../vendor/composer/xdebug-handler/')
            ->in(__DIR__.'/../../vendor/psr/')
            ->sort($finderSort)
        ;

        foreach ($finder as $file) {
            $this->addFile($phar, $file);
        }

        $this->addFile($phar, new \SplFileInfo(__DIR__.'/../../vendor/autoload.php'));
        $this->addFile($phar, new \SplFileInfo(__DIR__.'/../../vendor/composer/autoload_namespaces.php'));
        $this->addFile($phar, new \SplFileInfo(__DIR__.'/../../vendor/composer/autoload_psr4.php'));
        $this->addFile($phar, new \SplFileInfo(__DIR__.'/../../vendor/composer/autoload_classmap.php'));
        $this->addFile($phar, new \SplFileInfo(__DIR__.'/../../vendor/composer/autoload_files.php'));
        $this->addFile($phar, new \SplFileInfo(__DIR__.'/../../vendor/composer/autoload_real.php'));
        $this->addFile($phar, new \SplFileInfo(__DIR__.'/../../vendor/composer/autoload_static.php'));
        if (file_exists(__DIR__.'/../../vendor/composer/include_paths.php')) {
            $this->addFile($phar, new \SplFileInfo(__DIR__.'/../../vendor/composer/include_paths.php'));
        }
        $this->addFile($phar, new \SplFileInfo(__DIR__.'/../../vendor/composer/ClassLoader.php'));

        $this->addFile($phar, new \SplFileInfo(CaBundle::getBundledCaBundlePath()), false);

        $this->addComposerBin($phar);

        
        $phar->setStub($this->getStub());

        $phar->stopBuffering();

        
        

        $this->addFile($phar, new \SplFileInfo(__DIR__.'/../../LICENSE'), false);

        unset($phar);

        
        $util = new Timestamps($pharFile);
        $util->updateTimestamps($this->versionDate);
        $util->save($pharFile, \Phar::SHA1);
    }
public function compile ( $ pharFile = 'composer.phar' ) { if ( file_exists ( $ pharFile ) ) { unlink ( $ pharFile ) ; } $ process = new Process ( 'git log --pretty="%H" -n1 HEAD' , __DIR__ ) ; if ( $ process -> run ( ) != 0 ) { throw new \ RuntimeException ( 'Can\'t run git log. You must ensure to run compile from composer git repository clone and that git binary is available.' ) ; } $ this -> version = trim ( $ process -> getOutput ( ) ) ; $ process = new Process ( 'git log -n1 --pretty=%ci HEAD' , __DIR__ ) ; if ( $ process -> run ( ) != 0 ) { throw new \ RuntimeException ( 'Can\'t run git log. You must ensure to run compile from composer git repository clone and that git binary is available.' ) ; } $ this -> versionDate = new \ DateTime ( trim ( $ process -> getOutput ( ) ) ) ; $ this -> versionDate -> setTimezone ( new \ DateTimeZone ( 'UTC' ) ) ; $ process = new Process ( 'git describe --tags --exact-match HEAD' ) ; if ( $ process -> run ( ) == 0 ) { $ this -> version = trim ( $ process -> getOutput ( ) ) ; } else { // get branch-alias defined in composer.json for dev-master (if any) $ localConfig = __DIR__ . '/../../composer.json' ; $ file = new JsonFile ( $ localConfig ) ; $ localConfig = $ file -> read ( ) ; if ( isset ( $ localConfig [ 'extra' ] [ 'branch-alias' ] [ 'dev-master' ] ) ) { $ this -> branchAliasVersion = $ localConfig [ 'extra' ] [ 'branch-alias' ] [ 'dev-master' ] ; } } $ phar = new \ Phar ( $ pharFile , 0 , 'composer.phar' ) ; $ phar -> setSignatureAlgorithm ( \ Phar :: SHA1 ) ; $ phar -> startBuffering ( ) ; $ finderSort = function ( $ a , $ b ) { return strcmp ( strtr ( $ a -> getRealPath ( ) , '\\' , '/' ) , strtr ( $ b -> getRealPath ( ) , '\\' , '/' ) ) ; } ; $ finder = new Finder ( ) ; $ finder -> files ( ) -> ignoreVCS ( true ) -> name ( '*.php' ) -> notName ( 'Compiler.php' ) -> notName ( 'ClassLoader.php' ) -> in ( __DIR__ . '/..' ) -> sort ( $ finderSort ) ; foreach ( $ finder as $ file ) { $ this -> addFile ( $ phar , $ file ) ; } $ this -> addFile ( $ phar , new \ SplFileInfo ( __DIR__ . '/Autoload/ClassLoader.php' ) , false ) ; $ finder = new Finder ( ) ; $ finder -> files ( ) -> name ( '*.json' ) -> in ( __DIR__ . '/../../res' ) -> in ( SpdxLicenses :: getResourcesDir ( ) ) -> sort ( $ finderSort ) ; foreach ( $ finder as $ file ) { $ this -> addFile ( $ phar , $ file , false ) ; } $ this -> addFile ( $ phar , new \ SplFileInfo ( __DIR__ . '/../../vendor/symfony/console/Resources/bin/hiddeninput.exe' ) , false ) ; $ finder = new Finder ( ) ; $ finder -> files ( ) -> ignoreVCS ( true ) -> name ( '*.php' ) -> name ( 'LICENSE' ) -> exclude ( 'Tests' ) -> exclude ( 'tests' ) -> exclude ( 'docs' ) -> in ( __DIR__ . '/../../vendor/symfony/' ) -> in ( __DIR__ . '/../../vendor/seld/jsonlint/' ) -> in ( __DIR__ . '/../../vendor/justinrainbow/json-schema/' ) -> in ( __DIR__ . '/../../vendor/composer/spdx-licenses/' ) -> in ( __DIR__ . '/../../vendor/composer/semver/' ) -> in ( __DIR__ . '/../../vendor/composer/ca-bundle/' ) -> in ( __DIR__ . '/../../vendor/composer/xdebug-handler/' ) -> in ( __DIR__ . '/../../vendor/psr/' ) -> sort ( $ finderSort ) ; foreach ( $ finder as $ file ) { $ this -> addFile ( $ phar , $ file ) ; } $ this -> addFile ( $ phar , new \ SplFileInfo ( __DIR__ . '/../../vendor/autoload.php' ) ) ; $ this -> addFile ( $ phar , new \ SplFileInfo ( __DIR__ . '/../../vendor/composer/autoload_namespaces.php' ) ) ; $ this -> addFile ( $ phar , new \ SplFileInfo ( __DIR__ . '/../../vendor/composer/autoload_psr4.php' ) ) ; $ this -> addFile ( $ phar , new \ SplFileInfo ( __DIR__ . '/../../vendor/composer/autoload_classmap.php' ) ) ; $ this -> addFile ( $ phar , new \ SplFileInfo ( __DIR__ . '/../../vendor/composer/autoload_files.php' ) ) ; $ this -> addFile ( $ phar , new \ SplFileInfo ( __DIR__ . '/../../vendor/composer/autoload_real.php' ) ) ; $ this -> addFile ( $ phar , new \ SplFileInfo ( __DIR__ . '/../../vendor/composer/autoload_static.php' ) ) ; if ( file_exists ( __DIR__ . '/../../vendor/composer/include_paths.php' ) ) { $ this -> addFile ( $ phar , new \ SplFileInfo ( __DIR__ . '/../../vendor/composer/include_paths.php' ) ) ; } $ this -> addFile ( $ phar , new \ SplFileInfo ( __DIR__ . '/../../vendor/composer/ClassLoader.php' ) ) ; $ this -> addFile ( $ phar , new \ SplFileInfo ( CaBundle :: getBundledCaBundlePath ( ) ) , false ) ; $ this -> addComposerBin ( $ phar ) ; // Stubs $ phar -> setStub ( $ this -> getStub ( ) ) ; $ phar -> stopBuffering ( ) ; // disabled for interoperability with systems without gzip ext // $phar->compressFiles(\Phar::GZ); $ this -> addFile ( $ phar , new \ SplFileInfo ( __DIR__ . '/../../LICENSE' ) , false ) ; unset ( $ phar ) ; // re-sign the phar with reproducible timestamp / signature $ util = new Timestamps ( $ pharFile ) ; $ util -> updateTimestamps ( $ this -> versionDate ) ; $ util -> save ( $ pharFile , \ Phar :: SHA1 ) ; }
Compiles composer into a single phar file

@param  string            $pharFile The full path to the file to create
@throws \RuntimeException
Compiles composer into a single phar file