1
0
Fork 0

Fixed issue with downloader assuming repository would be VcsRepository

pull/2184/merge^2
matt-whittom 2013-08-22 09:49:22 -05:00 committed by mwhittom
parent a543e8bc8f
commit f737e49aae
4 changed files with 50 additions and 21 deletions

View File

@ -37,7 +37,7 @@ class PerforceDownloader extends VcsDownloader
$label = $package->getPrettyVersion();
$this->io->write(" Cloning ".$ref);
$this->initPerforce($package, $path);
$this->initPerforce($package, $path, $ref);
$this->perforce->setStream($ref);
$this->perforce->queryP4User($this->io);
$this->perforce->writeP4ClientSpec();
@ -46,15 +46,22 @@ class PerforceDownloader extends VcsDownloader
$this->perforce->cleanupClientSpec();
}
private function initPerforce($package, $path){
private function initPerforce($package, $path, $ref){
if ($this->perforceInjected){
return;
}
$repository = $package->getRepository();
$repoConfig = $repository->getRepoConfig();
$repoConfig = null;
if ($repository instanceof VcsRepository){
$repoConfig = $this->getRepoConfig($repository);
}
$this->perforce = Perforce::createPerforce($repoConfig, $package->getSourceUrl(), $path);
}
private function getRepoConfig(VcsRepository $repository){
return $repository->getRepoConfig();
}
/**
* {@inheritDoc}
*/

View File

@ -42,7 +42,7 @@ class PerforceDriver extends VcsDriver {
$this->branch = $this->repoConfig['branch'];
}
$this->initPerforce();
$this->initPerforce($this->repoConfig);
$this->perforce->p4Login($this->io);
$this->perforce->checkStream($this->depot);
@ -52,14 +52,14 @@ class PerforceDriver extends VcsDriver {
return TRUE;
}
private function initPerforce()
private function initPerforce($repoConfig)
{
if (isset($this->perforce)) {
return;
}
$repoDir = $this->config->get('cache-vcs-dir') . "/$this->depot";
$this->perforce = Perforce::createPerforce($this->repoConfig, $this->getUrl(), $repoDir, $this->process);
$this->perforce = Perforce::createPerforce($repoConfig, $this->getUrl(), $repoDir, $this->process);
}
/**
@ -122,7 +122,8 @@ class PerforceDriver extends VcsDriver {
$source = array(
'type' => 'perforce',
'url' => $this->repoConfig['url'],
'reference' => $identifier
'reference' => $identifier,
'p4user' => $this->perforce->getUser()
);
return $source;

View File

@ -42,30 +42,34 @@ class Perforce {
$process = new ProcessExecutor;
}
$isWindows = defined('PHP_WINDOWS_VERSION_BUILD');
if (isset($repoConfig['unique_perforce_client_name'])){
$unique_perforce_client_name = $repoConfig['unique_perforce_client_name'];
} else {
$unique_perforce_client_name = gethostname() . "_" . time();
$repoConfig['unique_perforce_client_name'] = $unique_perforce_client_name;
}
$perforce = new Perforce($repoConfig, $port, $path, $process, $isWindows, $unique_perforce_client_name);
$perforce = new Perforce($repoConfig, $port, $path, $process, $isWindows);
return $perforce;
}
public function __construct($repoConfig, $port, $path, ProcessExecutor $process, $isWindows, $unique_perforce_client_name) {
public function __construct($repoConfig, $port, $path, ProcessExecutor $process, $isWindows) {
$this->windowsFlag = $isWindows;
$this->unique_perforce_client_name = $unique_perforce_client_name;
$this->p4Port = $port;
$this->path = $path;
$fs = new Filesystem();
$fs->ensureDirectoryExists($path);
$this->process = $process;
$this->initialize($repoConfig);
}
if (isset($repoConfig['depot'])) {
public function initialize($repoConfig){
$this->unique_perforce_client_name = $this->generateUniquePerforceClientName();
if (!isset ($repoConfig)){
return;
}
if (isset($repoConfig['unique_perforce_client_name'])){
$this->unique_perforce_client_name = $repoConfig['unique_perforce_client_name'];
}
if (isset($repoConfig['depot'])){
$this->p4Depot = $repoConfig['depot'];
}
if (isset($repoConfig['branch'])) {
if (isset($repoConfig['branch'])){
$this->p4Branch = $repoConfig['branch'];
}
if (isset($repoConfig['p4user'])) {
@ -79,6 +83,19 @@ class Perforce {
}
}
public function initializeDepotAndBranch($depot, $branch){
if (isset($depot)) {
$this->p4Depot = $depot;
}
if (isset($branch)) {
$this->p4Branch = $branch;
}
}
public function generateUniquePerforceClientName(){
return gethostname() . "_" . time();
}
public function cleanupClientSpec(){
$client = $this->getClient();
$command = "p4 client -d $client";
@ -114,7 +131,11 @@ class Perforce {
public function setStream($stream) {
$this->p4Stream = $stream;
$this->p4DepotType = "stream";
$index = strrpos($stream, "/");
//Stream format is //depot/stream, while non-streaming depot is //depot
if ($index > 2){
$this->p4DepotType = "stream";
}
}
public function isStream() {

View File

@ -28,8 +28,8 @@ class PerforceTest extends \PHPUnit_Framework_TestCase {
public function setUp() {
$this->processExecutor = $this->getMock('Composer\Util\ProcessExecutor');
$repoConfig = array("depot"=>"depot", "branch"=>"branch", "p4user"=>"user");
$this->perforce = new Perforce($repoConfig, "port", "path", $this->processExecutor, true, "TEST");
$repoConfig = array("depot"=>"depot", "branch"=>"branch", "p4user"=>"user", "unique_perforce_client_name" => "TEST");
$this->perforce = new Perforce($repoConfig, "port", "path", $this->processExecutor, true);
}
public function testGetClientWithoutStream() {