Fixed issue with downloader assuming repository would be VcsRepository

main
matt-whittom 11 years ago committed by mwhittom
parent a543e8bc8f
commit f737e49aae

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

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

@ -42,25 +42,29 @@ class Perforce {
$process = new ProcessExecutor; $process = new ProcessExecutor;
} }
$isWindows = defined('PHP_WINDOWS_VERSION_BUILD'); $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; 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->windowsFlag = $isWindows;
$this->unique_perforce_client_name = $unique_perforce_client_name;
$this->p4Port = $port; $this->p4Port = $port;
$this->path = $path; $this->path = $path;
$fs = new Filesystem(); $fs = new Filesystem();
$fs->ensureDirectoryExists($path); $fs->ensureDirectoryExists($path);
$this->process = $process; $this->process = $process;
$this->initialize($repoConfig);
}
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'])){ if (isset($repoConfig['depot'])){
$this->p4Depot = $repoConfig['depot']; $this->p4Depot = $repoConfig['depot'];
@ -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(){ public function cleanupClientSpec(){
$client = $this->getClient(); $client = $this->getClient();
$command = "p4 client -d $client"; $command = "p4 client -d $client";
@ -114,8 +131,12 @@ class Perforce {
public function setStream($stream) { public function setStream($stream) {
$this->p4Stream = $stream; $this->p4Stream = $stream;
$index = strrpos($stream, "/");
//Stream format is //depot/stream, while non-streaming depot is //depot
if ($index > 2){
$this->p4DepotType = "stream"; $this->p4DepotType = "stream";
} }
}
public function isStream() { public function isStream() {
return (strcmp($this->p4DepotType, "stream") === 0); return (strcmp($this->p4DepotType, "stream") === 0);

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

Loading…
Cancel
Save