2012-01-22 20:14:56 +00:00
|
|
|
<?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\Downloader;
|
|
|
|
|
|
|
|
use Composer\Package\PackageInterface;
|
|
|
|
use Composer\Util\ProcessExecutor;
|
|
|
|
use Composer\IO\IOInterface;
|
2012-02-09 17:45:28 +00:00
|
|
|
use Composer\Util\Filesystem;
|
2012-01-22 20:14:56 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @author Jordi Boggiano <j.boggiano@seld.be>
|
|
|
|
*/
|
|
|
|
abstract class VcsDownloader implements DownloaderInterface
|
|
|
|
{
|
|
|
|
protected $io;
|
|
|
|
protected $process;
|
2012-02-18 15:59:39 +00:00
|
|
|
protected $filesystem;
|
2012-01-22 20:14:56 +00:00
|
|
|
|
2012-02-18 15:59:39 +00:00
|
|
|
public function __construct(IOInterface $io, ProcessExecutor $process = null, Filesystem $fs = null)
|
2012-01-22 20:14:56 +00:00
|
|
|
{
|
|
|
|
$this->io = $io;
|
|
|
|
$this->process = $process ?: new ProcessExecutor;
|
2012-02-18 15:59:39 +00:00
|
|
|
$this->filesystem = $fs ?: new Filesystem;
|
2012-01-22 20:14:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritDoc}
|
|
|
|
*/
|
|
|
|
public function getInstallationSource()
|
|
|
|
{
|
|
|
|
return 'source';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritDoc}
|
|
|
|
*/
|
|
|
|
public function download(PackageInterface $package, $path)
|
|
|
|
{
|
|
|
|
if (!$package->getSourceReference()) {
|
2012-03-07 23:11:52 +00:00
|
|
|
throw new \InvalidArgumentException('Package '.$package->getPrettyName().' is missing reference information');
|
2012-01-22 20:14:56 +00:00
|
|
|
}
|
|
|
|
|
2012-04-27 19:40:46 +00:00
|
|
|
$this->io->write(" - Installing <info>" . $package->getName() . "</info> (<comment>" . $package->getPrettyVersion() . "</comment>)");
|
2012-03-06 10:09:50 +00:00
|
|
|
$this->filesystem->removeDirectory($path);
|
2012-01-22 20:14:56 +00:00
|
|
|
$this->doDownload($package, $path);
|
|
|
|
$this->io->write('');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritDoc}
|
|
|
|
*/
|
|
|
|
public function update(PackageInterface $initial, PackageInterface $target, $path)
|
|
|
|
{
|
|
|
|
if (!$target->getSourceReference()) {
|
2012-03-07 23:11:52 +00:00
|
|
|
throw new \InvalidArgumentException('Package '.$target->getPrettyName().' is missing reference information');
|
2012-01-22 20:14:56 +00:00
|
|
|
}
|
|
|
|
|
2012-05-09 15:41:43 +00:00
|
|
|
$this->io->write(" - Updating <info>" . $target->getName() . "</info> (<comment>" . $target->getPrettyVersion() . "</comment>)");
|
2012-01-22 20:14:56 +00:00
|
|
|
$this->enforceCleanDirectory($path);
|
|
|
|
$this->doUpdate($initial, $target, $path);
|
|
|
|
$this->io->write('');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritDoc}
|
|
|
|
*/
|
|
|
|
public function remove(PackageInterface $package, $path)
|
|
|
|
{
|
|
|
|
$this->enforceCleanDirectory($path);
|
2012-04-27 19:40:46 +00:00
|
|
|
$this->io->write(" - Removing <info>" . $package->getName() . "</info> (<comment>" . $package->getPrettyVersion() . "</comment>)");
|
2012-04-05 20:58:15 +00:00
|
|
|
if (!$this->filesystem->removeDirectory($path)) {
|
|
|
|
throw new \RuntimeException('Could not completely delete '.$path.', aborting.');
|
|
|
|
}
|
2012-01-22 20:14:56 +00:00
|
|
|
}
|
|
|
|
|
2012-06-25 23:18:10 +00:00
|
|
|
/**
|
|
|
|
* Guarantee that no changes have been made to the local copy
|
|
|
|
*
|
|
|
|
* @throws \RuntimeException if the directory is not clean
|
|
|
|
*/
|
|
|
|
protected function enforceCleanDirectory($path)
|
|
|
|
{
|
2012-08-18 12:34:24 +00:00
|
|
|
if (null !== $this->getLocalChanges($path)) {
|
2012-06-25 23:18:10 +00:00
|
|
|
throw new \RuntimeException('Source directory ' . $path . ' has uncommitted changes.');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-22 20:14:56 +00:00
|
|
|
/**
|
|
|
|
* Downloads specific package into specific folder.
|
|
|
|
*
|
2012-05-22 10:07:08 +00:00
|
|
|
* @param PackageInterface $package package instance
|
|
|
|
* @param string $path download path
|
2012-01-22 20:14:56 +00:00
|
|
|
*/
|
|
|
|
abstract protected function doDownload(PackageInterface $package, $path);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Updates specific package in specific folder from initial to target version.
|
|
|
|
*
|
2012-05-22 10:07:08 +00:00
|
|
|
* @param PackageInterface $initial initial package
|
|
|
|
* @param PackageInterface $target updated package
|
|
|
|
* @param string $path download path
|
2012-01-22 20:14:56 +00:00
|
|
|
*/
|
|
|
|
abstract protected function doUpdate(PackageInterface $initial, PackageInterface $target, $path);
|
|
|
|
|
|
|
|
/**
|
2012-06-25 23:18:10 +00:00
|
|
|
* Checks for changes to the local copy
|
2012-01-22 20:14:56 +00:00
|
|
|
*
|
2012-08-18 12:34:24 +00:00
|
|
|
* @param string $path package directory
|
|
|
|
* @return string|null changes or null
|
2012-01-22 20:14:56 +00:00
|
|
|
*/
|
2012-08-18 12:34:24 +00:00
|
|
|
abstract public function getLocalChanges($path);
|
2012-01-23 07:41:59 +00:00
|
|
|
}
|