Update PearDownloader to use PEAR extractor
parent
01a49ea49e
commit
5c16889c48
|
@ -12,25 +12,41 @@
|
||||||
|
|
||||||
namespace Composer\Downloader;
|
namespace Composer\Downloader;
|
||||||
|
|
||||||
|
use Composer\Package\PackageInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Downloader for pear packages
|
* Downloader for pear packages
|
||||||
*
|
*
|
||||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||||
* @author Kirill chEbba Chebunin <iam@chebba.org>
|
* @author Kirill chEbba Chebunin <iam@chebba.org>
|
||||||
*/
|
*/
|
||||||
class PearDownloader extends TarDownloader
|
class PearDownloader extends FileDownloader
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
protected function extract($file, $path)
|
public function download(PackageInterface $package, $path)
|
||||||
{
|
{
|
||||||
parent::extract($file, $path);
|
parent::download($package, $path);
|
||||||
if (file_exists($path . '/package.sig')) {
|
|
||||||
unlink($path . '/package.sig');
|
$fileName = $this->getFileName($package, $path);
|
||||||
|
if ($this->io->isVerbose()) {
|
||||||
|
$this->io->write(' Installing PEAR package');
|
||||||
}
|
}
|
||||||
if (file_exists($path . '/package.xml')) {
|
try {
|
||||||
unlink($path . '/package.xml');
|
$pearExtractor = new PearPackageExtractor($fileName);
|
||||||
|
$pearExtractor->extractTo($path);
|
||||||
|
|
||||||
|
if ($this->io->isVerbose()) {
|
||||||
|
$this->io->write(' Cleaning up');
|
||||||
|
}
|
||||||
|
unlink($fileName);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
// clean up
|
||||||
|
$this->filesystem->removeDirectory($path);
|
||||||
|
throw $e;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->io->write('');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,38 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of Composer.
|
||||||
|
*
|
||||||
|
* (c) Nils Adermann <naderman@naderman.de>
|
||||||
|
* Jordi Boggiano <j.boggiano@seld.be>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Composer\Test\Downloader;
|
||||||
|
|
||||||
|
use Composer\Downloader\PearDownloader;
|
||||||
|
|
||||||
|
class PearDownloaderTest extends \PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
|
public function testErrorMessages()
|
||||||
|
{
|
||||||
|
$packageMock = $this->getMock('Composer\Package\PackageInterface');
|
||||||
|
$packageMock->expects($this->any())
|
||||||
|
->method('getDistUrl')
|
||||||
|
->will($this->returnValue('file://'.__FILE__))
|
||||||
|
;
|
||||||
|
|
||||||
|
$io = $this->getMock('Composer\IO\IOInterface');
|
||||||
|
$downloader = new PearDownloader($io);
|
||||||
|
|
||||||
|
try {
|
||||||
|
$downloader->download($packageMock, sys_get_temp_dir().'/composer-pear-test');
|
||||||
|
$this->fail('Download of invalid pear packages should throw an exception');
|
||||||
|
} catch (\UnexpectedValueException $e) {
|
||||||
|
$this->assertContains('Failed to extract PEAR package', $e->getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue