diff --git a/src/Composer/Downloader/DownloadManager.php b/src/Composer/Downloader/DownloadManager.php index 96c18c4a5..8f40fdff0 100644 --- a/src/Composer/Downloader/DownloadManager.php +++ b/src/Composer/Downloader/DownloadManager.php @@ -94,12 +94,14 @@ class DownloadManager if (!($preferSource && $sourceType) && $distType) { $downloader = $this->getDownloader($distType); $downloader->download( - $package, $targetDir, $package->getDistUrl(), $package->getDistSha1Checksum() + $package, $targetDir, + $package->getDistUrl(), $package->getDistSha1Checksum(), + $preferSource ); $package->setInstallationSource('dist'); } elseif ($sourceType) { $downloader = $this->getDownloader($sourceType); - $downloader->download($package, $targetDir, $package->getSourceUrl()); + $downloader->download($package, $targetDir, $package->getSourceUrl(), $preferSource); $package->setInstallationSource('source'); } else { throw new \InvalidArgumentException('Package should have dist or source specified'); @@ -135,9 +137,9 @@ class DownloadManager $downloader = $this->getDownloader($initialType); if ($initialType === $targetType) { - $downloader->update($initial, $target, $targetDir); + $downloader->update($initial, $target, $targetDir, $useSource); } else { - $downloader->remove($initial, $targetDir); + $downloader->remove($initial, $targetDir, $useSource); $this->download($target, $targetDir, $useSource); } } @@ -164,6 +166,6 @@ class DownloadManager $downloader = $this->getDownloader($package->getSourceType()); } - $downloader->remove($package, $targetDir); + $downloader->remove($package, $targetDir, $useSource); } } diff --git a/src/Composer/Downloader/DownloaderInterface.php b/src/Composer/Downloader/DownloaderInterface.php index 7a114ea2b..863d6bd30 100644 --- a/src/Composer/Downloader/DownloaderInterface.php +++ b/src/Composer/Downloader/DownloaderInterface.php @@ -28,8 +28,9 @@ interface DownloaderInterface * @param string $path download path * @param string $url download url * @param string $checksum package checksum (for dists) + * @param Boolean $useSource download as source */ - function download(PackageInterface $package, $path, $url, $checksum = null); + function download(PackageInterface $package, $path, $url, $checksum = null, $useSource = false); /** * Updates specific package in specific folder from initial to target version. @@ -37,14 +38,16 @@ interface DownloaderInterface * @param PackageInterface $initial initial package * @param PackageInterface $target updated package * @param string $path download path + * @param Boolean $useSource download as source */ - function update(PackageInterface $initial, PackageInterface $target, $path); + function update(PackageInterface $initial, PackageInterface $target, $path, $useSource = false); /** * Removes specific package from specific folder. * * @param PackageInterface $package package instance * @param string $path download path + * @param Boolean $useSource download as source */ - function remove(PackageInterface $package, $path); + function remove(PackageInterface $package, $path, $useSource = false); } diff --git a/tests/Composer/Test/Downloader/DownloadManagerTest.php b/tests/Composer/Test/Downloader/DownloadManagerTest.php index bf39a377a..cc48bf4d1 100644 --- a/tests/Composer/Test/Downloader/DownloadManagerTest.php +++ b/tests/Composer/Test/Downloader/DownloadManagerTest.php @@ -58,7 +58,7 @@ class DownloadManagerTest extends \PHPUnit_Framework_TestCase $pearDownloader ->expects($this->once()) ->method('download') - ->with($package, 'target_dir', 'dist_url', 'sha1'); + ->with($package, 'target_dir', 'dist_url', 'sha1', false); $manager = new DownloadManager(); $manager->setDownloader('pear', $pearDownloader); @@ -114,7 +114,7 @@ class DownloadManagerTest extends \PHPUnit_Framework_TestCase $pearDownloader ->expects($this->once()) ->method('download') - ->with($package, 'target_dir', 'dist_url', 'sha1'); + ->with($package, 'target_dir', 'dist_url', 'sha1', false); $manager = new DownloadManager(); $manager->setDownloader('pear', $pearDownloader); @@ -148,7 +148,7 @@ class DownloadManagerTest extends \PHPUnit_Framework_TestCase $gitDownloader ->expects($this->once()) ->method('download') - ->with($package, 'vendor/pkg', 'source_url'); + ->with($package, 'vendor/pkg', 'source_url', false); $manager = new DownloadManager(); $manager->setDownloader('git', $gitDownloader); @@ -182,7 +182,7 @@ class DownloadManagerTest extends \PHPUnit_Framework_TestCase $gitDownloader ->expects($this->once()) ->method('download') - ->with($package, 'vendor/pkg', 'source_url'); + ->with($package, 'vendor/pkg', 'source_url', true); $manager = new DownloadManager(); $manager->setDownloader('git', $gitDownloader); @@ -221,7 +221,7 @@ class DownloadManagerTest extends \PHPUnit_Framework_TestCase $pearDownloader ->expects($this->once()) ->method('download') - ->with($package, 'target_dir', 'dist_url', 'sha1'); + ->with($package, 'target_dir', 'dist_url', 'sha1', true); $manager = new DownloadManager(); $manager->setDownloader('pear', $pearDownloader); @@ -256,7 +256,7 @@ class DownloadManagerTest extends \PHPUnit_Framework_TestCase $gitDownloader ->expects($this->once()) ->method('download') - ->with($package, 'vendor/pkg', 'source_url'); + ->with($package, 'vendor/pkg', 'source_url', true); $manager = new DownloadManager(); $manager->setDownloader('git', $gitDownloader); @@ -306,7 +306,7 @@ class DownloadManagerTest extends \PHPUnit_Framework_TestCase $pearDownloader ->expects($this->once()) ->method('update') - ->with($initial, $target, 'vendor/bundles/FOS/UserBundle'); + ->with($initial, $target, 'vendor/bundles/FOS/UserBundle', false); $manager = new DownloadManager(); $manager->setDownloader('pear', $pearDownloader); @@ -336,7 +336,7 @@ class DownloadManagerTest extends \PHPUnit_Framework_TestCase $pearDownloader ->expects($this->once()) ->method('remove') - ->with($initial, 'vendor/bundles/FOS/UserBundle'); + ->with($initial, 'vendor/bundles/FOS/UserBundle', false); $manager = $this->getMockBuilder('Composer\Downloader\DownloadManager') ->setMethods(array('download')) @@ -372,7 +372,7 @@ class DownloadManagerTest extends \PHPUnit_Framework_TestCase $svnDownloader ->expects($this->once()) ->method('update') - ->with($initial, $target, 'vendor/pkg'); + ->with($initial, $target, 'vendor/pkg', true); $manager = new DownloadManager(); $manager->setDownloader('svn', $svnDownloader); @@ -402,7 +402,7 @@ class DownloadManagerTest extends \PHPUnit_Framework_TestCase $svnDownloader ->expects($this->once()) ->method('remove') - ->with($initial, 'vendor/pkg'); + ->with($initial, 'vendor/pkg', true); $manager = $this->getMockBuilder('Composer\Downloader\DownloadManager') ->setMethods(array('download'))