From 0e6f3834ec0c833a602554063fcf4943df30ea6e Mon Sep 17 00:00:00 2001 From: Ben Bieker Date: Thu, 17 Nov 2011 16:47:58 +0100 Subject: [PATCH] Added an SvnDownloader The Svn Downloader can be used like the already implemented GitDownloader, for example { "name": "my-project", "version": "1.0.0", "repositories": { "MyRepo": { "package": { "name": "mypackage", "version": "2.0", "source": { "url": "https://repo.com/svnrepo", "type": "svn", "reference": "tags/v2.0" } } } }, "require": { "mypackage": "2.0" } } --- bin/composer | 1 + src/Composer/Downloader/SvnDownloader.php | 56 +++++++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 src/Composer/Downloader/SvnDownloader.php diff --git a/bin/composer b/bin/composer index 15b9a907c..8fa017ab8 100755 --- a/bin/composer +++ b/bin/composer @@ -29,6 +29,7 @@ $rm->setRepositoryClass('package', 'Composer\Repository\PackageRepository'); // initialize download manager $dm = new Downloader\DownloadManager(); $dm->setDownloader('git', new Downloader\GitDownloader()); +$dm->setDownloader('svn', new Downloader\SvnDownloader()); $dm->setDownloader('hg', new Downloader\HgDownloader()); $dm->setDownloader('pear', new Downloader\PearDownloader()); $dm->setDownloader('zip', new Downloader\ZipDownloader()); diff --git a/src/Composer/Downloader/SvnDownloader.php b/src/Composer/Downloader/SvnDownloader.php new file mode 100644 index 000000000..b162bb072 --- /dev/null +++ b/src/Composer/Downloader/SvnDownloader.php @@ -0,0 +1,56 @@ + + */ +class SvnDownloader implements DownloaderInterface +{ + /** + * {@inheritDoc} + */ + public function getInstallationSource() + { + return 'source'; + } + + /** + * {@inheritDoc} + */ + public function download(PackageInterface $package, $path) + { + if(!$package->getSourceReference()) { + throw new \InvalidArgumentException('The given package is missing reference information'); + } + + $url = escapeshellarg($package->getSourceUrl()); + $ref = escapeshellarg($package->getSourceReference()); + system(sprintf('svn co %s/%s %s', $url, $ref, $path)); + } + + /** + * {@inheritDoc} + */ + public function update(PackageInterface $initial, PackageInterface $target, $path) + { + if(!$target->getSourceReference()) { + throw new \InvalidArgumentException('The given package is missing reference information'); + } + + $url = escapeshellarg($target->getSourceUrl()); + $ref = escapeshellarg($target->getSourceReference()); + system(sprintf('cd %s && svn switch %s/%s', $path, $url, $ref)); + } + + /** + * {@inheritDoc} + */ + public function remove(PackageInterface $package, $path) + { + $fs = new Util\Filesystem(); + $fs->remove($path); + } +} \ No newline at end of file