Browse Source

Merge pull request #116 from wwwdata/svn

Added an SvnDownloader
Jordi Boggiano 13 years ago
parent
commit
2e211c4649
2 changed files with 57 additions and 0 deletions
  1. 1 0
      bin/composer
  2. 56 0
      src/Composer/Downloader/SvnDownloader.php

+ 1 - 0
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());

+ 56 - 0
src/Composer/Downloader/SvnDownloader.php

@@ -0,0 +1,56 @@
+<?php
+
+namespace Composer\Downloader;
+
+use Composer\Package\PackageInterface;
+
+/**
+ * @author Ben Bieker <mail@ben-bieker.de>
+ */
+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);
+    }
+}