1
0
Fork 0

Fix how download manager is constructed

This fixes tests due to upstream changes.
The createDownloadManager in the Factory now takes the config as extra
parameter.
pull/1567/head
Matthieu Moquet 2012-10-21 12:16:28 +02:00 committed by Nils Adermann
parent 60b1cc7d24
commit c248115e04
3 changed files with 21 additions and 29 deletions

View File

@ -319,22 +319,18 @@ class Factory
} }
/** /**
* @param string $workDir Directory used to download sources
* @param Downloader\DownloadManager $dm Manager use to download sources * @param Downloader\DownloadManager $dm Manager use to download sources
* @param Config $config The configuration
* *
* @return Archiver\ArchiveManager * @return Archiver\ArchiveManager
*/ */
public function createArchiveManager($workDir = null, DownloadManager $dm = null) public function createArchiveManager(DownloadManager $dm = null, Config $config)
{ {
if (null === $dm) { if (null === $dm) {
$dm = $this->createDownloadManager(new IO\NullIO()); $dm = $this->createDownloadManager(new IO\NullIO(), $config);
} }
if (null === $workDir) { $am = new Archiver\ArchiveManager($dm);
$workDir = sys_get_temp_dir();
}
$am = new Archiver\ArchiveManager($workDir, $dm);
$am->addArchiver(new Archiver\GitArchiver); $am->addArchiver(new Archiver\GitArchiver);
$am->addArchiver(new Archiver\MercurialArchiver); $am->addArchiver(new Archiver\MercurialArchiver);
$am->addArchiver(new Archiver\PharArchiver); $am->addArchiver(new Archiver\PharArchiver);

View File

@ -24,19 +24,15 @@ use Composer\Util\Filesystem;
*/ */
class ArchiveManager class ArchiveManager
{ {
protected $buildDir;
protected $downloadManager; protected $downloadManager;
protected $archivers = array(); protected $archivers = array();
/** /**
* @param string $buildDir The directory used to build the archive
* @param DownloadManager $downloadManager A manager used to download package sources * @param DownloadManager $downloadManager A manager used to download package sources
*/ */
public function __construct($buildDir, DownloadManager $downloadManager) public function __construct(DownloadManager $downloadManager)
{ {
$this->buildDir = $buildDir;
$this->downloadManager = $downloadManager; $this->downloadManager = $downloadManager;
} }
@ -53,15 +49,17 @@ class ArchiveManager
* *
* @param PackageInterface $package The package to archive * @param PackageInterface $package The package to archive
* @param string $format The format of the archive (zip, tar, ...) * @param string $format The format of the archive (zip, tar, ...)
* @param string $targetDir The diretory where to build the archive
* *
* @return string The path of the created archive * @return string The path of the created archive
*/ */
public function archive(PackageInterface $package, $format) public function archive(PackageInterface $package, $format, $targetDir)
{ {
if (empty($format)) { if (empty($format)) {
throw new \InvalidArgumentException('Format must be specified'); throw new \InvalidArgumentException('Format must be specified');
} }
// Search for the most appropriate archiver
$usableArchiver = null; $usableArchiver = null;
foreach ($this->archivers as $archiver) { foreach ($this->archivers as $archiver) {
if ($archiver->supports($format, $package->getSourceType())) { if ($archiver->supports($format, $package->getSourceType())) {
@ -78,12 +76,12 @@ class ArchiveManager
// Directory used to download the sources // Directory used to download the sources
$filesystem = new Filesystem(); $filesystem = new Filesystem();
$packageName = $package->getUniqueName(); $packageName = $package->getUniqueName();
$sources = sys_get_temp_dir().'/'.$packageName; $sources = sys_get_temp_dir().'/composer_archiver/'.$packageName;
$filesystem->ensureDirectoryExists($sources); $filesystem->ensureDirectoryExists($sources);
// Archive filename // Archive filename
$target = $this->buildDir.'/'.$packageName.'.'.$format; $target = $targetDir.'/'.$packageName.'.'.$format;
$filesystem->ensureDirectoryExists(dirname($this->buildDir.$target)); $filesystem->ensureDirectoryExists(dirname($target));
// Download sources // Download sources
$this->downloadManager->download($package, $sources, true); $this->downloadManager->download($package, $sources, true);

View File

@ -25,17 +25,15 @@ use Composer\Package\PackageInterface;
class ArchiveManagerTest extends ArchiverTest class ArchiveManagerTest extends ArchiverTest
{ {
protected $manager; protected $manager;
protected $targetDir;
protected $workDir;
public function setUp() public function setUp()
{ {
parent::setUp(); parent::setUp();
$factory = new Factory(); $factory = new Factory();
$this->manager = $factory->createArchiveManager(null, $factory->createConfig());
$this->workDir = sys_get_temp_dir(); $this->targetDir = sys_get_temp_dir().'/composer_archiver_tests';
$this->manager = $factory->createArchiveManager($this->workDir);
} }
public function testUnknownFormat() public function testUnknownFormat()
@ -44,7 +42,7 @@ class ArchiveManagerTest extends ArchiverTest
$package = $this->setupPackage(); $package = $this->setupPackage();
$this->manager->archive($package, '__unknown_format__'); $this->manager->archive($package, '__unknown_format__', $this->targetDir);
} }
public function testArchiveTarWithVcs() public function testArchiveTarWithVcs()
@ -55,7 +53,7 @@ class ArchiveManagerTest extends ArchiverTest
// The package is source from git, // The package is source from git,
// so it should `git archive --format tar` // so it should `git archive --format tar`
$this->manager->archive($package, 'tar'); $this->manager->archive($package, 'tar', $this->targetDir);
$target = $this->getTargetName($package, 'tar'); $target = $this->getTargetName($package, 'tar');
$this->assertFileExists($target); $this->assertFileExists($target);
@ -71,7 +69,7 @@ class ArchiveManagerTest extends ArchiverTest
$package = $this->setupPackage(); $package = $this->setupPackage();
// This should use the TarArchiver // This should use the TarArchiver
$this->manager->archive($package, 'tar'); $this->manager->archive($package, 'tar', $this->targetDir);
$package->setSourceType('__unknown_type__'); // disable VCS recognition $package->setSourceType('__unknown_type__'); // disable VCS recognition
$target = $this->getTargetName($package, 'tar'); $target = $this->getTargetName($package, 'tar');
@ -83,8 +81,8 @@ class ArchiveManagerTest extends ArchiverTest
protected function getTargetName(PackageInterface $package, $format) protected function getTargetName(PackageInterface $package, $format)
{ {
$packageName = str_replace('/', DIRECTORY_SEPARATOR, $package->getUniqueName()); $packageName = $package->getUniqueName();
$target = $this->workDir.DIRECTORY_SEPARATOR.$packageName.'.'.$format; $target = $this->targetDir.'/'.$packageName.'.'.$format;
return $target; return $target;
} }