Permalink
Browse files

new functionality for dumping as .tar.gz

  • Loading branch information...
1 parent 7355cfd commit 064d570ecf31ffedd23269b635b6ce9a6e8d1570 Ulf Harnhammar committed Jun 18, 2012
Showing with 102 additions and 0 deletions.
  1. +52 −0 src/Composer/Package/Dumper/TarGzDumper.php
  2. +50 −0 tests/Composer/Test/Package/Dumper/TarGzDumperTest.php
@@ -0,0 +1,52 @@
+<?php
+/*
+ * This file is part of Composer.
+ *
+ * (c) Nils Adermann <naderman@naderman.de>
+ * Jordi Boggiano <j.boggiano@seld.be>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Composer\Package\Dumper;
+
+use Composer\Package\Dumper\BaseDumper;
+use Composer\Package\Dumper\DumperInterface;
+use Composer\Package\PackageInterface;
+use Composer\Util\ProcessExecutor;
+
+/**
+ * @author Ulf Härnhammar <ulfharn@gmail.com>
+ */
+class TarGzDumper extends BaseDumper
+{
+ protected $format = 'tar.gz';
+
+ public function dump(PackageInterface $package)
+ {
+ $workDir = $this->getAndEnsureWorkDirectory($package);
+
+ $fileName = $this->getFilename($package, 'tar.gz');
+ $sourceType = $package->getSourceType();
+ $sourceRef = $package->getSourceReference();
+
+ switch ($sourceType) {
+ case 'git':
+ $this->downloadGit($package, $workDir);
+ $this->packageGit($fileName, $sourceRef, $workDir);
+ break;
+ case 'hg':
+ $this->downloadHg($package, $workDir);
+ $this->packageHg($fileName, $sourceRef, $workDir);
+ break;
+ case 'svn':
+ $dir = $workDir . (substr($sourceRef, 0, 1) !== '/')?'/':'' . $sourceRef;
+ $this->downloadSvn($package, $workDir);
+ $this->package($fileName, $dir, \Phar::GZ);
+ break;
+ default:
+ throw new \InvalidArgumentException("Unable to handle repositories of type '{$sourceType}'.");
+ }
+ }
+}
@@ -0,0 +1,50 @@
+<?php
+/*
+ * This file is part of Composer.
+ *
+ * (c) Nils Adermann <naderman@naderman.de>
+ * Jordi Boggiano <j.boggiano@seld.be>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Composer\Test\Package\Dumper;
+
+use Composer\Package\Dumper\TarGzDumper;
+use Composer\Package\MemoryPackage;
+
+class TarGzDumperTest extends \PHPUnit_Framework_TestCase
+{
+ /**
+ * @todo Replace with local git repo to run offline.
+ */
+ public function testThis()
+ {
+ $package = new MemoryPackage('lagged/Lagged_Session_SaveHandler_Memcache', '0.5.0', '0.5.0');
+ $package->setSourceUrl('git://github.com/lagged/Lagged_Session_SaveHandler_Memcache.git');
+ $package->setSourceReference('0.5.0');
+ $package->setSourceType('git');
+
+ $temp = sys_get_temp_dir();
+
+ $targz = new TarGzDumper($temp);
+ $targz->dump($package);
+
+ $name = preg_replace('#[^a-z0-9_-]#', '-', $package->getUniqueName());
+
+ $dist = sprintf('%s/%s.tar.gz',
+ $temp, $name
+ );
+ $this->assertFileExists($dist);
+ unlink($dist);
+ }
+
+ /**
+ * @expectedException \InvalidArgumentException
+ */
+ public function testException()
+ {
+ new TarGzDumper("/totally-random-" . time());
+ }
+}

0 comments on commit 064d570

Please sign in to comment.