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
parent
60b1cc7d24
commit
c248115e04
|
@ -319,22 +319,18 @@ class Factory
|
|||
}
|
||||
|
||||
/**
|
||||
* @param string $workDir Directory used to download sources
|
||||
* @param Downloader\DownloadManager $dm Manager use to download sources
|
||||
* @param Config $config The configuration
|
||||
*
|
||||
* @return Archiver\ArchiveManager
|
||||
*/
|
||||
public function createArchiveManager($workDir = null, DownloadManager $dm = null)
|
||||
public function createArchiveManager(DownloadManager $dm = null, Config $config)
|
||||
{
|
||||
if (null === $dm) {
|
||||
$dm = $this->createDownloadManager(new IO\NullIO());
|
||||
$dm = $this->createDownloadManager(new IO\NullIO(), $config);
|
||||
}
|
||||
|
||||
if (null === $workDir) {
|
||||
$workDir = sys_get_temp_dir();
|
||||
}
|
||||
|
||||
$am = new Archiver\ArchiveManager($workDir, $dm);
|
||||
$am = new Archiver\ArchiveManager($dm);
|
||||
$am->addArchiver(new Archiver\GitArchiver);
|
||||
$am->addArchiver(new Archiver\MercurialArchiver);
|
||||
$am->addArchiver(new Archiver\PharArchiver);
|
||||
|
|
|
@ -24,19 +24,15 @@ use Composer\Util\Filesystem;
|
|||
*/
|
||||
class ArchiveManager
|
||||
{
|
||||
protected $buildDir;
|
||||
|
||||
protected $downloadManager;
|
||||
|
||||
protected $archivers = array();
|
||||
|
||||
/**
|
||||
* @param string $buildDir The directory used to build the archive
|
||||
* @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;
|
||||
}
|
||||
|
||||
|
@ -53,15 +49,17 @@ class ArchiveManager
|
|||
*
|
||||
* @param PackageInterface $package The package to archive
|
||||
* @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
|
||||
*/
|
||||
public function archive(PackageInterface $package, $format)
|
||||
public function archive(PackageInterface $package, $format, $targetDir)
|
||||
{
|
||||
if (empty($format)) {
|
||||
throw new \InvalidArgumentException('Format must be specified');
|
||||
}
|
||||
|
||||
// Search for the most appropriate archiver
|
||||
$usableArchiver = null;
|
||||
foreach ($this->archivers as $archiver) {
|
||||
if ($archiver->supports($format, $package->getSourceType())) {
|
||||
|
@ -78,12 +76,12 @@ class ArchiveManager
|
|||
// Directory used to download the sources
|
||||
$filesystem = new Filesystem();
|
||||
$packageName = $package->getUniqueName();
|
||||
$sources = sys_get_temp_dir().'/'.$packageName;
|
||||
$sources = sys_get_temp_dir().'/composer_archiver/'.$packageName;
|
||||
$filesystem->ensureDirectoryExists($sources);
|
||||
|
||||
// Archive filename
|
||||
$target = $this->buildDir.'/'.$packageName.'.'.$format;
|
||||
$filesystem->ensureDirectoryExists(dirname($this->buildDir.$target));
|
||||
$target = $targetDir.'/'.$packageName.'.'.$format;
|
||||
$filesystem->ensureDirectoryExists(dirname($target));
|
||||
|
||||
// Download sources
|
||||
$this->downloadManager->download($package, $sources, true);
|
||||
|
|
|
@ -25,17 +25,15 @@ use Composer\Package\PackageInterface;
|
|||
class ArchiveManagerTest extends ArchiverTest
|
||||
{
|
||||
protected $manager;
|
||||
|
||||
protected $workDir;
|
||||
protected $targetDir;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$factory = new Factory();
|
||||
|
||||
$this->workDir = sys_get_temp_dir();
|
||||
$this->manager = $factory->createArchiveManager($this->workDir);
|
||||
$this->manager = $factory->createArchiveManager(null, $factory->createConfig());
|
||||
$this->targetDir = sys_get_temp_dir().'/composer_archiver_tests';
|
||||
}
|
||||
|
||||
public function testUnknownFormat()
|
||||
|
@ -44,7 +42,7 @@ class ArchiveManagerTest extends ArchiverTest
|
|||
|
||||
$package = $this->setupPackage();
|
||||
|
||||
$this->manager->archive($package, '__unknown_format__');
|
||||
$this->manager->archive($package, '__unknown_format__', $this->targetDir);
|
||||
}
|
||||
|
||||
public function testArchiveTarWithVcs()
|
||||
|
@ -55,7 +53,7 @@ class ArchiveManagerTest extends ArchiverTest
|
|||
|
||||
// The package is source from git,
|
||||
// so it should `git archive --format tar`
|
||||
$this->manager->archive($package, 'tar');
|
||||
$this->manager->archive($package, 'tar', $this->targetDir);
|
||||
|
||||
$target = $this->getTargetName($package, 'tar');
|
||||
$this->assertFileExists($target);
|
||||
|
@ -71,7 +69,7 @@ class ArchiveManagerTest extends ArchiverTest
|
|||
$package = $this->setupPackage();
|
||||
|
||||
// This should use the TarArchiver
|
||||
$this->manager->archive($package, 'tar');
|
||||
$this->manager->archive($package, 'tar', $this->targetDir);
|
||||
|
||||
$package->setSourceType('__unknown_type__'); // disable VCS recognition
|
||||
$target = $this->getTargetName($package, 'tar');
|
||||
|
@ -83,8 +81,8 @@ class ArchiveManagerTest extends ArchiverTest
|
|||
|
||||
protected function getTargetName(PackageInterface $package, $format)
|
||||
{
|
||||
$packageName = str_replace('/', DIRECTORY_SEPARATOR, $package->getUniqueName());
|
||||
$target = $this->workDir.DIRECTORY_SEPARATOR.$packageName.'.'.$format;
|
||||
$packageName = $package->getUniqueName();
|
||||
$target = $this->targetDir.'/'.$packageName.'.'.$format;
|
||||
|
||||
return $target;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue