diff --git a/src/Composer/Downloader/XzDownloader.php b/src/Composer/Downloader/XzDownloader.php new file mode 100644 index 000000000..edebf2f67 --- /dev/null +++ b/src/Composer/Downloader/XzDownloader.php @@ -0,0 +1,59 @@ + + * Jordi Boggiano + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Composer\Downloader; + +use Composer\Config; +use Composer\Cache; +use Composer\EventDispatcher\EventDispatcher; +use Composer\Package\PackageInterface; +use Composer\Util\ProcessExecutor; +use Composer\IO\IOInterface; + +/** + * Xz archive downloader. + * + * @author Pavel Puchkin + * @author Pierre Rudloff + */ +class XzDownloader extends ArchiveDownloader +{ + protected $process; + + public function __construct(IOInterface $io, Config $config, EventDispatcher $eventDispatcher = null, Cache $cache = null, ProcessExecutor $process = null) + { + $this->process = $process ?: new ProcessExecutor($io); + parent::__construct($io, $config, $eventDispatcher, $cache); + } + + protected function extract($file, $path) + { + + $command = 'tar -xJf ' . ProcessExecutor::escape($file) . ' -C ' . ProcessExecutor::escape($path); + + if (0 === $this->process->execute($command, $ignoredOutput)) { + return; + } + + $processError = 'Failed to execute ' . $command . "\n\n" . $this->process->getErrorOutput(); + throw new \RuntimeException($processError); + + } + + /** + * {@inheritdoc} + */ + protected function getFileName(PackageInterface $package, $path) + { + return $path.'/'.pathinfo(parse_url($package->getDistUrl(), PHP_URL_PATH), PATHINFO_BASENAME); + } +} diff --git a/src/Composer/Factory.php b/src/Composer/Factory.php index 65cd8e3ed..49c31601d 100644 --- a/src/Composer/Factory.php +++ b/src/Composer/Factory.php @@ -403,6 +403,7 @@ class Factory $dm->setDownloader('rar', new Downloader\RarDownloader($io, $config, $eventDispatcher, $cache)); $dm->setDownloader('tar', new Downloader\TarDownloader($io, $config, $eventDispatcher, $cache)); $dm->setDownloader('gzip', new Downloader\GzipDownloader($io, $config, $eventDispatcher, $cache)); + $dm->setDownloader('xz', new Downloader\XzDownloader($io, $config, $eventDispatcher, $cache)); $dm->setDownloader('phar', new Downloader\PharDownloader($io, $config, $eventDispatcher, $cache)); $dm->setDownloader('file', new Downloader\FileDownloader($io, $config, $eventDispatcher, $cache)); $dm->setDownloader('path', new Downloader\PathDownloader($io, $config, $eventDispatcher, $cache));