From f737e49aae56666d86803058dd07069a836f3e41 Mon Sep 17 00:00:00 2001 From: matt-whittom Date: Thu, 22 Aug 2013 09:49:22 -0500 Subject: [PATCH] Fixed issue with downloader assuming repository would be VcsRepository --- .../Downloader/PerforceDownloader.php | 13 ++++-- .../Repository/Vcs/PerforceDriver.php | 9 ++-- src/Composer/Util/Perforce.php | 45 ++++++++++++++----- tests/Composer/Test/Util/PerforceTest.php | 4 +- 4 files changed, 50 insertions(+), 21 deletions(-) diff --git a/src/Composer/Downloader/PerforceDownloader.php b/src/Composer/Downloader/PerforceDownloader.php index e68315668..1a7cee65c 100644 --- a/src/Composer/Downloader/PerforceDownloader.php +++ b/src/Composer/Downloader/PerforceDownloader.php @@ -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} */ diff --git a/src/Composer/Repository/Vcs/PerforceDriver.php b/src/Composer/Repository/Vcs/PerforceDriver.php index 4918cca5c..35f1389f7 100644 --- a/src/Composer/Repository/Vcs/PerforceDriver.php +++ b/src/Composer/Repository/Vcs/PerforceDriver.php @@ -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; diff --git a/src/Composer/Util/Perforce.php b/src/Composer/Util/Perforce.php index 6acee208f..99c640cf1 100644 --- a/src/Composer/Util/Perforce.php +++ b/src/Composer/Util/Perforce.php @@ -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() { diff --git a/tests/Composer/Test/Util/PerforceTest.php b/tests/Composer/Test/Util/PerforceTest.php index 62df75f69..e4e0e36b3 100644 --- a/tests/Composer/Test/Util/PerforceTest.php +++ b/tests/Composer/Test/Util/PerforceTest.php @@ -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() {