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.

184 lines
3.8 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\Repository\Vcs;
use Composer\Config;
use Composer\Cache;
use Composer\IO\IOInterface;
11 years ago
use Composer\Util\ProcessExecutor;
use Composer\Util\Perforce;
/**
* @author Matt Whittom <Matt.Whittom@veteransunited.com>
*/
class PerforceDriver extends VcsDriver
{
protected $depot;
protected $branch;
/** @var ?Perforce */
protected $perforce = null;
7 years ago
/**
* {@inheritDoc}
*/
11 years ago
public function initialize()
{
11 years ago
$this->depot = $this->repoConfig['depot'];
$this->branch = '';
if (!empty($this->repoConfig['branch'])) {
$this->branch = $this->repoConfig['branch'];
}
$this->initPerforce($this->repoConfig);
$this->perforce->p4Login();
$this->perforce->checkStream();
$this->perforce->writeP4ClientSpec();
11 years ago
$this->perforce->connectClient();
return true;
}
private function initPerforce($repoConfig)
11 years ago
{
if (!empty($this->perforce)) {
11 years ago
return;
}
if (!Cache::isUsable($this->config->get('cache-vcs-dir'))) {
throw new \RuntimeException('PerforceDriver requires a usable cache directory, and it looks like you set it to be disabled');
}
$repoDir = $this->config->get('cache-vcs-dir') . '/' . $this->depot;
$this->perforce = Perforce::create($repoConfig, $this->getUrl(), $repoDir, $this->process, $this->io);
11 years ago
}
/**
* {@inheritdoc}
*/
public function getFileContent($file, $identifier)
{
return $this->perforce->getFileContent($file, $identifier);
}
/**
* {@inheritdoc}
*/
public function getChangeDate($identifier)
{
return null;
}
/**
* {@inheritDoc}
*/
11 years ago
public function getRootIdentifier()
{
return $this->branch;
}
/**
* {@inheritDoc}
*/
11 years ago
public function getBranches()
{
return $this->perforce->getBranches();
}
/**
* {@inheritDoc}
*/
11 years ago
public function getTags()
{
return $this->perforce->getTags();
}
/**
* {@inheritDoc}
*/
11 years ago
public function getDist($identifier)
{
return null;
}
/**
* {@inheritDoc}
*/
11 years ago
public function getSource($identifier)
{
return array(
7 years ago
'type' => 'perforce',
'url' => $this->repoConfig['url'],
'reference' => $identifier,
7 years ago
'p4user' => $this->perforce->getUser(),
);
}
/**
* {@inheritDoc}
*/
11 years ago
public function getUrl()
{
return $this->url;
}
/**
* {@inheritDoc}
*/
11 years ago
public function hasComposerFile($identifier)
{
$composerInfo = $this->perforce->getComposerInformation('//' . $this->depot . '/' . $identifier);
10 years ago
return !empty($composerInfo);
}
/**
* {@inheritDoc}
*/
11 years ago
public function getContents($url)
{
throw new \BadMethodCallException('Not implemented/used in PerforceDriver');
}
/**
* {@inheritDoc}
*/
public static function supports(IOInterface $io, Config $config, $url, $deep = false)
11 years ago
{
if ($deep || preg_match('#\b(perforce|p4)\b#i', $url)) {
return Perforce::checkServerExists($url, new ProcessExecutor($io));
}
return false;
}
/**
* {@inheritDoc}
*/
11 years ago
public function cleanup()
{
$this->perforce->cleanupClientSpec();
$this->perforce = null;
}
11 years ago
public function getDepot()
{
return $this->depot;
}
11 years ago
public function getBranch()
{
return $this->branch;
}
}