Added ability to pass p4user and p4password in composer.json
parent
53d6fcd6d3
commit
bab10dd9f8
|
@ -28,7 +28,25 @@ class PerforceDownloader extends VcsDownloader
|
||||||
$ref = $package->getSourceReference();
|
$ref = $package->getSourceReference();
|
||||||
$label = $package->getPrettyVersion();
|
$label = $package->getPrettyVersion();
|
||||||
|
|
||||||
$perforce = new Perforce("", "", $package->getSourceUrl(), $path);
|
$repository = $package->getRepository();
|
||||||
|
//assume repository is a Perforce Repository
|
||||||
|
|
||||||
|
$reflector = new \ReflectionClass($repository);
|
||||||
|
$repoConfigProperty = $reflector->getProperty("repoConfig");
|
||||||
|
$repoConfigProperty->setAccessible(true);
|
||||||
|
$repoConfig = $repoConfigProperty->getValue($repository);
|
||||||
|
|
||||||
|
$p4user = "";
|
||||||
|
if (isset($repoConfig['p4user'])) {
|
||||||
|
$p4user = $repoConfig['p4user'];
|
||||||
|
}
|
||||||
|
$p4password = "";
|
||||||
|
if (isset($repoConfig['p4password'])) {
|
||||||
|
$p4password = $repoConfig['p4password'];
|
||||||
|
}
|
||||||
|
|
||||||
|
// print("Perforce Downloader:doDownload - repoConfig:" . var_dump($repoConfig, true) . "\n\n");
|
||||||
|
$perforce = new Perforce("", "", $package->getSourceUrl(), $path, null, $p4user, $p4password);
|
||||||
$perforce->setStream($ref);
|
$perforce->setStream($ref);
|
||||||
$perforce->queryP4User($this->io);
|
$perforce->queryP4User($this->io);
|
||||||
$perforce->writeP4ClientSpec();
|
$perforce->writeP4ClientSpec();
|
||||||
|
|
|
@ -37,10 +37,18 @@ class PerforceDriver extends VcsDriver {
|
||||||
if (isset($this->repoConfig['branch'])) {
|
if (isset($this->repoConfig['branch'])) {
|
||||||
$this->branch = $this->repoConfig['branch'];
|
$this->branch = $this->repoConfig['branch'];
|
||||||
}
|
}
|
||||||
|
$p4user = "";
|
||||||
|
if (isset($this->repoConfig['p4user'])) {
|
||||||
|
$p4user = $this->repoConfig['p4user'];
|
||||||
|
}
|
||||||
|
$p4password = "";
|
||||||
|
if (isset($this->repoConfig['p4password'])) {
|
||||||
|
$p4password = $this->repoConfig['p4password'];
|
||||||
|
}
|
||||||
|
|
||||||
$repoDir = $this->config->get('cache-vcs-dir') . "/$this->depot";
|
$repoDir = $this->config->get('cache-vcs-dir') . "/$this->depot";
|
||||||
if (!isset($this->perforce)) {
|
if (!isset($this->perforce)) {
|
||||||
$this->perforce = new Perforce($this->depot, $this->branch, $this->getUrl(), $repoDir, $this->process);
|
$this->perforce = new Perforce($this->depot, $this->branch, $this->getUrl(), $repoDir, $this->process, $p4user, $p4password);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->perforce->p4Login($this->io);
|
$this->perforce->p4Login($this->io);
|
||||||
|
|
|
@ -17,6 +17,7 @@ class Perforce {
|
||||||
protected $path;
|
protected $path;
|
||||||
protected $p4client;
|
protected $p4client;
|
||||||
protected $p4user;
|
protected $p4user;
|
||||||
|
protected $p4password;
|
||||||
protected $p4port;
|
protected $p4port;
|
||||||
protected $p4stream;
|
protected $p4stream;
|
||||||
protected $p4clientSpec;
|
protected $p4clientSpec;
|
||||||
|
@ -24,7 +25,7 @@ class Perforce {
|
||||||
protected $p4branch;
|
protected $p4branch;
|
||||||
protected $process;
|
protected $process;
|
||||||
|
|
||||||
public function __construct($depot, $branch, $port, $path, ProcessExecutor $process = null) {
|
public function __construct($depot, $branch, $port, $path, ProcessExecutor $process = null, $p4user = null, $p4password = null) {
|
||||||
$this->p4depot = $depot;
|
$this->p4depot = $depot;
|
||||||
$this->p4branch = $branch;
|
$this->p4branch = $branch;
|
||||||
$this->p4port = $port;
|
$this->p4port = $port;
|
||||||
|
@ -32,6 +33,14 @@ class Perforce {
|
||||||
$this->process = $process ? : new ProcessExecutor;
|
$this->process = $process ? : new ProcessExecutor;
|
||||||
$fs = new Filesystem();
|
$fs = new Filesystem();
|
||||||
$fs->ensureDirectoryExists($path);
|
$fs->ensureDirectoryExists($path);
|
||||||
|
if (isset($p4user)){
|
||||||
|
$this->p4user = $p4user;
|
||||||
|
} else {
|
||||||
|
$this->p4user = $this->getP4variable("P4USER");
|
||||||
|
}
|
||||||
|
if (isset($p4password)){
|
||||||
|
$this->p4password = $p4password;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getRandomValue() {
|
protected function getRandomValue() {
|
||||||
|
@ -55,14 +64,6 @@ class Perforce {
|
||||||
return $this->p4client;
|
return $this->p4client;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getUser() {
|
|
||||||
if (!isset($this->p4user)) {
|
|
||||||
$this->p4user = $this->getP4variable("P4USER");
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->p4user;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function getPath() {
|
protected function getPath() {
|
||||||
return $this->path;
|
return $this->path;
|
||||||
}
|
}
|
||||||
|
@ -100,6 +101,10 @@ class Perforce {
|
||||||
return $p4clientSpec;
|
return $p4clientSpec;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getUser() {
|
||||||
|
return $this->p4user;
|
||||||
|
}
|
||||||
|
|
||||||
public function queryP4User(IOInterface $io) {
|
public function queryP4User(IOInterface $io) {
|
||||||
$this->getUser();
|
$this->getUser();
|
||||||
if (strlen($this->p4user) <= 0) {
|
if (strlen($this->p4user) <= 0) {
|
||||||
|
@ -113,11 +118,41 @@ class Perforce {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function getP4variable($name){
|
||||||
|
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
|
||||||
|
$command = "p4 set";
|
||||||
|
$result = $this->executeCommand($command);
|
||||||
|
$resArray = explode("\n", $result);
|
||||||
|
foreach ($resArray as $line) {
|
||||||
|
$fields = explode("=", $line);
|
||||||
|
if (strcmp($name, $fields[0]) == 0){
|
||||||
|
$index = strpos($fields[1], " ");
|
||||||
|
if ($index === false){
|
||||||
|
$value = $fields[1];
|
||||||
|
} else {
|
||||||
|
$value = substr($fields[1], 0, $index);
|
||||||
|
}
|
||||||
|
$value = trim($value);
|
||||||
|
return $value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$command = 'echo $' . $name;
|
||||||
|
$result = trim($this->executeCommand($command));
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
protected function queryP4Password(IOInterface $io) {
|
protected function queryP4Password(IOInterface $io) {
|
||||||
|
if (isset($this->p4password)){
|
||||||
|
return $this->p4password;
|
||||||
|
}
|
||||||
$password = $this->getP4variable("P4PASSWD");
|
$password = $this->getP4variable("P4PASSWD");
|
||||||
if (strlen($password) <= 0) {
|
if (strlen($password) <= 0) {
|
||||||
$password = $io->askAndHideAnswer("Enter password for Perforce user " . $this->getUser() . ": ");
|
$password = $io->askAndHideAnswer("Enter password for Perforce user " . $this->getUser() . ": ");
|
||||||
}
|
}
|
||||||
|
$this->p4password = $password;
|
||||||
return $password;
|
return $password;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -209,31 +244,6 @@ class Perforce {
|
||||||
fclose($spec);
|
fclose($spec);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getP4variable($name){
|
|
||||||
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
|
|
||||||
$command = "p4 set";
|
|
||||||
$result = $this->executeCommand($command);
|
|
||||||
$resArray = explode("\n", $result);
|
|
||||||
foreach ($resArray as $line) {
|
|
||||||
$fields = explode("=", $line);
|
|
||||||
if (strcmp($name, $fields[0]) == 0){
|
|
||||||
$index = strpos($fields[1], " ");
|
|
||||||
if ($index === false){
|
|
||||||
$value = $fields[1];
|
|
||||||
} else {
|
|
||||||
$value = substr($fields[1], 0, $index);
|
|
||||||
}
|
|
||||||
$value = trim($value);
|
|
||||||
return $value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$command = 'echo $' . $name;
|
|
||||||
$result = trim($this->executeCommand($command));
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function read($pipe, $name){
|
protected function read($pipe, $name){
|
||||||
if (feof($pipe)) {
|
if (feof($pipe)) {
|
||||||
|
|
Loading…
Reference in New Issue