You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

107 lines
2.7 KiB
PHTML

<?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;
11 years ago
use Composer\Repository\VcsRepository;
use Composer\Util\Perforce;
/**
* @author Matt Whittom <Matt.Whittom@veteransunited.com>
*/
class PerforceDownloader extends VcsDownloader
{
11 years ago
protected $perforce;
/**
* {@inheritDoc}
*/
public function doDownload(PackageInterface $package, $path)
{
$ref = $package->getSourceReference();
$label = $this->getLabelFromSourceReference($ref);
$this->io->write(' Cloning ' . $ref);
$this->initPerforce($package, $path);
11 years ago
$this->perforce->setStream($ref);
$this->perforce->p4Login($this->io);
11 years ago
$this->perforce->writeP4ClientSpec();
$this->perforce->connectClient();
$this->perforce->syncCodeBase($label);
$this->perforce->cleanupClientSpec();
11 years ago
}
private function getLabelFromSourceReference($ref)
{
$pos = strpos($ref,'@');
if (false !== $pos)
{
return substr($ref, $pos + 1);
}
return null;
}
public function initPerforce($package, $path)
{
if (!empty($this->perforce)) {
$this->perforce->initializePath($path);
11 years ago
return;
}
11 years ago
$repository = $package->getRepository();
$repoConfig = null;
if ($repository instanceof VcsRepository) {
$repoConfig = $this->getRepoConfig($repository);
}
$this->perforce = Perforce::create($repoConfig, $package->getSourceUrl(), $path, $this->process, $this->io);
11 years ago
}
private function getRepoConfig(VcsRepository $repository)
{
return $repository->getRepoConfig();
}
/**
* {@inheritDoc}
*/
public function doUpdate(PackageInterface $initial, PackageInterface $target, $path)
{
$this->doDownload($target, $path);
}
/**
* {@inheritDoc}
*/
public function getLocalChanges(PackageInterface $package, $path)
{
$this->io->write('Perforce driver does not check for local changes before overriding', true);
11 years ago
return;
}
/**
* {@inheritDoc}
*/
protected function getCommitLogs($fromReference, $toReference, $path)
{
$commitLogs = $this->perforce->getCommitLogs($fromReference, $toReference);
11 years ago
return $commitLogs;
}
public function setPerforce($perforce)
{
11 years ago
$this->perforce = $perforce;
}
}