2013-07-24 15:06:35 +00:00
|
|
|
<?php
|
2013-08-15 17:16:15 +00:00
|
|
|
/*
|
|
|
|
* This file is part of Composer.
|
|
|
|
*
|
|
|
|
* (c) Nils Adermann <naderman@naderman.de>
|
|
|
|
* Jordi Boggiano <j.boggiano@seld.be>
|
|
|
|
*
|
|
|
|
* Contributor: Matt Whittom <Matt.Whittom@veteransunited.com>
|
|
|
|
* Date: 7/17/13
|
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
2013-07-24 15:06:35 +00:00
|
|
|
*/
|
|
|
|
|
2013-08-15 17:16:15 +00:00
|
|
|
|
2013-07-24 15:06:35 +00:00
|
|
|
namespace Composer\Util;
|
|
|
|
|
2013-07-25 20:25:09 +00:00
|
|
|
use Composer\IO\IOInterface;
|
|
|
|
|
2013-08-15 17:16:15 +00:00
|
|
|
/**
|
|
|
|
* @author Matt Whittom <Matt.Whittom@veteransunited.com>
|
|
|
|
*/
|
2013-07-24 15:06:35 +00:00
|
|
|
class Perforce {
|
2013-07-25 20:25:09 +00:00
|
|
|
|
|
|
|
protected $path;
|
2013-08-15 17:16:15 +00:00
|
|
|
protected $p4Depot;
|
|
|
|
protected $p4Client;
|
|
|
|
protected $p4User;
|
|
|
|
protected $p4Password;
|
|
|
|
protected $p4Port;
|
|
|
|
protected $p4Stream;
|
|
|
|
protected $p4ClientSpec;
|
|
|
|
protected $p4DepotType;
|
|
|
|
protected $p4Branch;
|
2013-08-13 15:50:47 +00:00
|
|
|
protected $process;
|
2013-08-15 17:16:15 +00:00
|
|
|
protected $unique_perforce_client_name;
|
|
|
|
protected $windowsFlag;
|
|
|
|
|
|
|
|
|
|
|
|
public static function createPerforce($repoConfig, $port, $path, ProcessExecutor $process = NULL) {
|
|
|
|
if (!isset($process)){
|
|
|
|
$process = new ProcessExecutor;
|
|
|
|
}
|
|
|
|
$isWindows = defined('PHP_WINDOWS_VERSION_BUILD');
|
|
|
|
|
2013-08-22 14:49:22 +00:00
|
|
|
$perforce = new Perforce($repoConfig, $port, $path, $process, $isWindows);
|
2013-08-15 17:16:15 +00:00
|
|
|
return $perforce;
|
|
|
|
}
|
2013-07-25 20:25:09 +00:00
|
|
|
|
2013-08-22 14:49:22 +00:00
|
|
|
public function __construct($repoConfig, $port, $path, ProcessExecutor $process, $isWindows) {
|
2013-08-15 17:16:15 +00:00
|
|
|
$this->windowsFlag = $isWindows;
|
|
|
|
$this->p4Port = $port;
|
2013-07-25 20:25:09 +00:00
|
|
|
$this->path = $path;
|
|
|
|
$fs = new Filesystem();
|
|
|
|
$fs->ensureDirectoryExists($path);
|
2013-08-15 17:16:15 +00:00
|
|
|
$this->process = $process;
|
2013-08-22 14:49:22 +00:00
|
|
|
$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'];
|
|
|
|
}
|
2013-08-13 15:54:35 +00:00
|
|
|
|
2013-08-22 14:49:22 +00:00
|
|
|
if (isset($repoConfig['depot'])){
|
2013-08-15 17:16:15 +00:00
|
|
|
$this->p4Depot = $repoConfig['depot'];
|
2013-08-13 15:54:35 +00:00
|
|
|
}
|
2013-08-22 14:49:22 +00:00
|
|
|
if (isset($repoConfig['branch'])){
|
2013-08-15 17:16:15 +00:00
|
|
|
$this->p4Branch = $repoConfig['branch'];
|
2013-08-13 15:54:35 +00:00
|
|
|
}
|
|
|
|
if (isset($repoConfig['p4user'])) {
|
2013-08-15 17:16:15 +00:00
|
|
|
$this->p4User = $repoConfig['p4user'];
|
2013-08-13 15:54:35 +00:00
|
|
|
}
|
|
|
|
else {
|
2013-08-15 17:16:15 +00:00
|
|
|
$this->p4User = $this->getP4variable("P4USER");
|
2013-08-08 20:35:21 +00:00
|
|
|
}
|
2013-08-13 15:54:35 +00:00
|
|
|
if (isset($repoConfig['p4password'])) {
|
2013-08-15 17:16:15 +00:00
|
|
|
$this->p4Password = $repoConfig['p4password'];
|
2013-08-08 20:35:21 +00:00
|
|
|
}
|
2013-07-25 20:25:09 +00:00
|
|
|
}
|
|
|
|
|
2013-08-22 14:49:22 +00:00
|
|
|
public function initializeDepotAndBranch($depot, $branch){
|
|
|
|
if (isset($depot)) {
|
|
|
|
$this->p4Depot = $depot;
|
|
|
|
}
|
|
|
|
if (isset($branch)) {
|
|
|
|
$this->p4Branch = $branch;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function generateUniquePerforceClientName(){
|
|
|
|
return gethostname() . "_" . time();
|
|
|
|
}
|
|
|
|
|
2013-08-15 17:16:15 +00:00
|
|
|
public function cleanupClientSpec(){
|
|
|
|
$client = $this->getClient();
|
|
|
|
$command = "p4 client -d $client";
|
|
|
|
$this->executeCommand($command);
|
|
|
|
$clientSpec = $this->getP4ClientSpec();
|
|
|
|
$fileSystem = new FileSystem($this->process);
|
|
|
|
$fileSystem->remove($clientSpec);
|
2013-08-13 15:54:35 +00:00
|
|
|
}
|
|
|
|
|
2013-08-13 15:50:47 +00:00
|
|
|
protected function executeCommand($command) {
|
|
|
|
$result = "";
|
|
|
|
$this->process->execute($command, $result);
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
2013-08-15 17:16:15 +00:00
|
|
|
public function getClient() {
|
|
|
|
if (!isset($this->p4Client)) {
|
2013-08-13 15:50:47 +00:00
|
|
|
$clean_stream_name = str_replace("@", "", str_replace("/", "_", str_replace("//", "", $this->getStream())));
|
2013-08-15 17:16:15 +00:00
|
|
|
$this->p4Client = "composer_perforce_" . $this->unique_perforce_client_name . "_" . $clean_stream_name;
|
2013-07-25 20:25:09 +00:00
|
|
|
}
|
2013-08-13 15:50:47 +00:00
|
|
|
|
2013-08-15 17:16:15 +00:00
|
|
|
return $this->p4Client;
|
2013-07-25 20:25:09 +00:00
|
|
|
}
|
|
|
|
|
2013-08-13 15:50:47 +00:00
|
|
|
protected function getPath() {
|
2013-07-25 20:25:09 +00:00
|
|
|
return $this->path;
|
|
|
|
}
|
2013-07-31 16:01:18 +00:00
|
|
|
|
2013-08-13 15:50:47 +00:00
|
|
|
protected function getPort() {
|
2013-08-15 17:16:15 +00:00
|
|
|
return $this->p4Port;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setStream($stream) {
|
|
|
|
$this->p4Stream = $stream;
|
2013-08-22 14:49:22 +00:00
|
|
|
$index = strrpos($stream, "/");
|
|
|
|
//Stream format is //depot/stream, while non-streaming depot is //depot
|
|
|
|
if ($index > 2){
|
|
|
|
$this->p4DepotType = "stream";
|
|
|
|
}
|
2013-07-25 20:25:09 +00:00
|
|
|
}
|
|
|
|
|
2013-08-15 17:16:15 +00:00
|
|
|
public function isStream() {
|
|
|
|
return (strcmp($this->p4DepotType, "stream") === 0);
|
2013-08-13 15:54:35 +00:00
|
|
|
}
|
|
|
|
|
2013-08-15 17:16:15 +00:00
|
|
|
public function getStream() {
|
|
|
|
if (!isset($this->p4Stream)) {
|
2013-08-13 15:50:47 +00:00
|
|
|
if ($this->isStream()) {
|
2013-08-15 17:16:15 +00:00
|
|
|
$this->p4Stream = "//$this->p4Depot/$this->p4Branch";
|
2013-08-13 15:50:47 +00:00
|
|
|
}
|
|
|
|
else {
|
2013-08-15 17:16:15 +00:00
|
|
|
$this->p4Stream = "//$this->p4Depot";
|
2013-07-31 16:01:18 +00:00
|
|
|
}
|
|
|
|
}
|
2013-08-15 17:16:15 +00:00
|
|
|
return $this->p4Stream;
|
2013-07-25 20:25:09 +00:00
|
|
|
}
|
2013-07-31 16:01:18 +00:00
|
|
|
|
2013-08-15 17:16:15 +00:00
|
|
|
public function getStreamWithoutLabel($stream) {
|
2013-07-31 16:01:18 +00:00
|
|
|
$index = strpos($stream, "@");
|
2013-08-13 15:50:47 +00:00
|
|
|
if ($index === FALSE) {
|
2013-07-31 16:01:18 +00:00
|
|
|
return $stream;
|
|
|
|
}
|
2013-08-13 15:50:47 +00:00
|
|
|
|
2013-07-31 16:01:18 +00:00
|
|
|
return substr($stream, 0, $index);
|
|
|
|
}
|
|
|
|
|
2013-08-15 17:16:15 +00:00
|
|
|
public function getP4ClientSpec() {
|
2013-07-25 20:25:09 +00:00
|
|
|
$p4clientSpec = $this->path . "/" . $this->getClient() . ".p4.spec";
|
2013-08-13 15:50:47 +00:00
|
|
|
|
2013-07-25 20:25:09 +00:00
|
|
|
return $p4clientSpec;
|
|
|
|
}
|
|
|
|
|
2013-08-08 20:35:21 +00:00
|
|
|
public function getUser() {
|
2013-08-15 17:16:15 +00:00
|
|
|
return $this->p4User;
|
2013-08-08 20:35:21 +00:00
|
|
|
}
|
|
|
|
|
2013-08-13 15:50:47 +00:00
|
|
|
public function queryP4User(IOInterface $io) {
|
2013-07-31 16:01:18 +00:00
|
|
|
$this->getUser();
|
2013-08-15 17:16:15 +00:00
|
|
|
if (strlen($this->p4User) > 0) {
|
2013-08-13 15:54:35 +00:00
|
|
|
return;
|
|
|
|
}
|
2013-08-15 17:16:15 +00:00
|
|
|
$this->p4User = $this->getP4variable("P4USER");
|
|
|
|
if (strlen($this->p4User) > 0) {
|
2013-08-13 15:54:35 +00:00
|
|
|
return;
|
|
|
|
}
|
2013-08-15 17:16:15 +00:00
|
|
|
$this->p4User = $io->ask("Enter P4 User:");
|
|
|
|
if ($this->windowsFlag) {
|
|
|
|
$command = "p4 set P4USER=$this->p4User";
|
2013-08-13 15:54:35 +00:00
|
|
|
}
|
|
|
|
else {
|
2013-08-15 17:16:15 +00:00
|
|
|
$command = "export P4USER=$this->p4User";
|
2013-07-31 16:01:18 +00:00
|
|
|
}
|
2013-08-13 15:54:35 +00:00
|
|
|
$result = $this->executeCommand($command);
|
2013-07-31 16:01:18 +00:00
|
|
|
}
|
|
|
|
|
2013-08-13 15:54:35 +00:00
|
|
|
protected function getP4variable($name) {
|
2013-08-15 17:16:15 +00:00
|
|
|
if ($this->windowsFlag) {
|
2013-08-08 20:35:21 +00:00
|
|
|
$command = "p4 set";
|
|
|
|
$result = $this->executeCommand($command);
|
|
|
|
$resArray = explode("\n", $result);
|
|
|
|
foreach ($resArray as $line) {
|
|
|
|
$fields = explode("=", $line);
|
2013-08-13 15:54:35 +00:00
|
|
|
if (strcmp($name, $fields[0]) == 0) {
|
2013-08-08 20:35:21 +00:00
|
|
|
$index = strpos($fields[1], " ");
|
2013-08-13 15:54:35 +00:00
|
|
|
if ($index === FALSE) {
|
2013-08-08 20:35:21 +00:00
|
|
|
$value = $fields[1];
|
2013-08-13 15:54:35 +00:00
|
|
|
}
|
|
|
|
else {
|
2013-08-08 20:35:21 +00:00
|
|
|
$value = substr($fields[1], 0, $index);
|
|
|
|
}
|
|
|
|
$value = trim($value);
|
2013-08-13 15:54:35 +00:00
|
|
|
|
2013-08-08 20:35:21 +00:00
|
|
|
return $value;
|
|
|
|
}
|
|
|
|
}
|
2013-08-13 15:54:35 +00:00
|
|
|
}
|
|
|
|
else {
|
2013-08-08 20:35:21 +00:00
|
|
|
$command = 'echo $' . $name;
|
|
|
|
$result = trim($this->executeCommand($command));
|
2013-08-13 15:54:35 +00:00
|
|
|
|
2013-08-08 20:35:21 +00:00
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-15 17:16:15 +00:00
|
|
|
public function queryP4Password(IOInterface $io) {
|
|
|
|
if (isset($this->p4Password)) {
|
|
|
|
return $this->p4Password;
|
2013-08-08 20:35:21 +00:00
|
|
|
}
|
2013-08-13 15:50:47 +00:00
|
|
|
$password = $this->getP4variable("P4PASSWD");
|
|
|
|
if (strlen($password) <= 0) {
|
|
|
|
$password = $io->askAndHideAnswer("Enter password for Perforce user " . $this->getUser() . ": ");
|
2013-07-31 16:01:18 +00:00
|
|
|
}
|
2013-08-15 17:16:15 +00:00
|
|
|
$this->p4Password = $password;
|
2013-07-31 16:01:18 +00:00
|
|
|
|
2013-08-13 15:54:35 +00:00
|
|
|
return $password;
|
2013-07-31 16:01:18 +00:00
|
|
|
}
|
|
|
|
|
2013-08-15 17:16:15 +00:00
|
|
|
public function generateP4Command($command, $useClient = TRUE) {
|
2013-07-31 16:01:18 +00:00
|
|
|
$p4Command = "p4 ";
|
|
|
|
$p4Command = $p4Command . "-u " . $this->getUser() . " ";
|
2013-08-13 15:50:47 +00:00
|
|
|
if ($useClient) {
|
|
|
|
$p4Command = $p4Command . "-c " . $this->getClient() . " ";
|
2013-07-31 16:01:18 +00:00
|
|
|
}
|
|
|
|
$p4Command = $p4Command . "-p " . $this->getPort() . " ";
|
|
|
|
$p4Command = $p4Command . $command;
|
2013-08-13 15:50:47 +00:00
|
|
|
|
2013-07-31 16:01:18 +00:00
|
|
|
return $p4Command;
|
|
|
|
}
|
|
|
|
|
2013-08-15 17:16:15 +00:00
|
|
|
public function isLoggedIn() {
|
2013-08-13 15:50:47 +00:00
|
|
|
$command = $this->generateP4Command("login -s", FALSE);
|
|
|
|
$result = trim($this->executeCommand($command));
|
2013-07-31 16:01:18 +00:00
|
|
|
$index = strpos($result, $this->getUser());
|
2013-08-13 15:50:47 +00:00
|
|
|
if ($index === FALSE) {
|
|
|
|
return FALSE;
|
2013-07-31 16:01:18 +00:00
|
|
|
}
|
2013-08-13 15:50:47 +00:00
|
|
|
return TRUE;
|
2013-07-31 16:01:18 +00:00
|
|
|
}
|
|
|
|
|
2013-08-13 15:50:47 +00:00
|
|
|
public function connectClient() {
|
|
|
|
$p4CreateClientCommand = $this->generateP4Command("client -i < " . $this->getP4ClientSpec());
|
|
|
|
$this->executeCommand($p4CreateClientCommand);
|
|
|
|
}
|
2013-07-24 15:06:35 +00:00
|
|
|
|
2013-08-13 15:50:47 +00:00
|
|
|
public function syncCodeBase($label) {
|
2013-07-24 15:06:35 +00:00
|
|
|
$prevDir = getcwd();
|
2013-07-25 20:25:09 +00:00
|
|
|
chdir($this->path);
|
2013-07-24 15:06:35 +00:00
|
|
|
|
2013-08-13 15:50:47 +00:00
|
|
|
$this->executeCommand("pwd");
|
2013-07-24 15:06:35 +00:00
|
|
|
|
2013-08-13 15:50:47 +00:00
|
|
|
$p4SyncCommand = $this->generateP4Command("sync -f ");
|
|
|
|
if (isset($label)) {
|
|
|
|
if (strcmp($label, "dev-master") != 0) {
|
2013-07-31 16:01:18 +00:00
|
|
|
$p4SyncCommand = $p4SyncCommand . "@" . $label;
|
|
|
|
}
|
|
|
|
}
|
2013-08-13 15:50:47 +00:00
|
|
|
$this->executeCommand($p4SyncCommand);
|
2013-07-24 15:06:35 +00:00
|
|
|
|
|
|
|
chdir($prevDir);
|
|
|
|
}
|
|
|
|
|
2013-08-15 17:16:15 +00:00
|
|
|
public function writeClientSpecToFile($spec) {
|
2013-08-13 15:50:47 +00:00
|
|
|
fwrite($spec, "Client: " . $this->getClient() . "\n\n");
|
|
|
|
fwrite($spec, "Update: " . date("Y/m/d H:i:s") . "\n\n");
|
|
|
|
fwrite($spec, "Access: " . date("Y/m/d H:i:s") . "\n");
|
|
|
|
fwrite($spec, "Owner: " . $this->getUser() . "\n\n");
|
|
|
|
fwrite($spec, "Description:\n");
|
|
|
|
fwrite($spec, " Created by " . $this->getUser() . " from composer.\n\n");
|
|
|
|
fwrite($spec, "Root: " . $this->getPath() . "\n\n");
|
|
|
|
fwrite($spec, "Options: noallwrite noclobber nocompress unlocked modtime rmdir\n\n");
|
|
|
|
fwrite($spec, "SubmitOptions: revertunchanged\n\n");
|
|
|
|
fwrite($spec, "LineEnd: local\n\n");
|
|
|
|
if ($this->isStream()) {
|
|
|
|
fwrite($spec, "Stream:\n");
|
2013-08-15 17:16:15 +00:00
|
|
|
fwrite($spec, " " . $this->getStreamWithoutLabel($this->p4Stream) . "\n");
|
2013-08-13 15:50:47 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
fwrite(
|
|
|
|
$spec, "View: " . $this->getStream() . "/... //" . $this->getClient() . "/" . str_replace(
|
|
|
|
"//", "", $this->getStream()
|
|
|
|
) . "/... \n"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function writeP4ClientSpec() {
|
2013-08-15 17:16:15 +00:00
|
|
|
$clientSpec = $this->getP4ClientSpec();
|
|
|
|
$spec = fopen($clientSpec, 'w');
|
2013-07-24 15:06:35 +00:00
|
|
|
try {
|
2013-08-13 15:50:47 +00:00
|
|
|
$this->writeClientSpecToFile($spec);
|
|
|
|
} catch (Exception $e) {
|
2013-07-24 15:06:35 +00:00
|
|
|
fclose($spec);
|
|
|
|
throw $e;
|
|
|
|
}
|
|
|
|
fclose($spec);
|
|
|
|
}
|
|
|
|
|
2013-08-13 15:50:47 +00:00
|
|
|
|
2013-08-13 15:54:35 +00:00
|
|
|
protected function read($pipe, $name) {
|
2013-08-13 15:50:47 +00:00
|
|
|
if (feof($pipe)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$line = fgets($pipe);
|
2013-08-13 15:54:35 +00:00
|
|
|
while ($line != FALSE) {
|
2013-08-13 15:50:47 +00:00
|
|
|
$line = fgets($pipe);
|
|
|
|
}
|
2013-08-13 15:54:35 +00:00
|
|
|
|
2013-08-13 15:50:47 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-08-13 15:54:35 +00:00
|
|
|
public function windowsLogin($password) {
|
2013-08-13 15:50:47 +00:00
|
|
|
$descriptorspec = array(
|
|
|
|
0 => array("pipe", "r"),
|
|
|
|
1 => array("pipe", "w"),
|
|
|
|
2 => array("pipe", "a")
|
|
|
|
);
|
|
|
|
$command = $this->generateP4Command(" login -a");
|
|
|
|
$process = proc_open($command, $descriptorspec, $pipes);
|
2013-08-13 15:54:35 +00:00
|
|
|
if (!is_resource($process)) {
|
|
|
|
return FALSE;
|
2013-07-31 16:01:18 +00:00
|
|
|
}
|
2013-08-13 15:50:47 +00:00
|
|
|
fwrite($pipes[0], $password);
|
|
|
|
fclose($pipes[0]);
|
|
|
|
|
|
|
|
$this->read($pipes[1], "Output");
|
|
|
|
$this->read($pipes[2], "Error");
|
|
|
|
|
|
|
|
fclose($pipes[1]);
|
|
|
|
fclose($pipes[2]);
|
|
|
|
|
|
|
|
$return_code = proc_close($process);
|
|
|
|
|
|
|
|
return $return_code;
|
2013-07-25 20:25:09 +00:00
|
|
|
}
|
|
|
|
|
2013-08-13 15:50:47 +00:00
|
|
|
|
|
|
|
public function p4Login(IOInterface $io) {
|
2013-07-31 16:01:18 +00:00
|
|
|
$this->queryP4User($io);
|
2013-08-13 15:50:47 +00:00
|
|
|
if (!$this->isLoggedIn()) {
|
2013-07-31 16:01:18 +00:00
|
|
|
$password = $this->queryP4Password($io);
|
2013-08-15 17:16:15 +00:00
|
|
|
if ($this->windowsFlag) {
|
2013-08-13 15:50:47 +00:00
|
|
|
$this->windowsLogin($password);
|
2013-08-13 15:54:35 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
$command = "echo $password | " . $this->generateP4Command(" login -a", FALSE);
|
2013-08-13 15:50:47 +00:00
|
|
|
$this->executeCommand($command);
|
|
|
|
}
|
2013-07-25 20:25:09 +00:00
|
|
|
}
|
|
|
|
}
|
2013-07-24 15:06:35 +00:00
|
|
|
|
2013-08-13 15:50:47 +00:00
|
|
|
public static function checkServerExists($url, ProcessExecutor $process_executor) {
|
|
|
|
$process = $process_executor ? : new ProcessExecutor;
|
|
|
|
$result = "";
|
|
|
|
$process->execute("p4 -p $url info -s", $result);
|
2013-07-25 20:25:09 +00:00
|
|
|
$index = strpos($result, "error");
|
2013-08-13 15:50:47 +00:00
|
|
|
if ($index === FALSE) {
|
|
|
|
return TRUE;
|
2013-07-25 20:25:09 +00:00
|
|
|
}
|
2013-08-13 15:50:47 +00:00
|
|
|
|
|
|
|
return FALSE;
|
2013-07-25 20:25:09 +00:00
|
|
|
}
|
|
|
|
|
2013-08-13 15:50:47 +00:00
|
|
|
public function getComposerInformation($identifier) {
|
2013-07-31 16:01:18 +00:00
|
|
|
$index = strpos($identifier, "@");
|
2013-08-13 15:50:47 +00:00
|
|
|
if ($index === FALSE) {
|
|
|
|
$composer_json = "$identifier/composer.json";
|
|
|
|
|
2013-07-31 18:26:44 +00:00
|
|
|
return $this->getComposerInformationFromPath($composer_json);
|
2013-08-13 15:50:47 +00:00
|
|
|
}
|
|
|
|
else {
|
2013-07-31 18:26:44 +00:00
|
|
|
return $this->getComposerInformationFromLabel($identifier, $index);
|
2013-07-31 16:01:18 +00:00
|
|
|
}
|
|
|
|
}
|
2013-08-13 15:50:47 +00:00
|
|
|
|
|
|
|
public function getComposerInformationFromPath($composer_json) {
|
|
|
|
$command = $this->generateP4Command(" print $composer_json");
|
|
|
|
$result = $this->executeCommand($command);
|
2013-07-31 16:01:18 +00:00
|
|
|
$index = strpos($result, "{");
|
2013-08-13 15:50:47 +00:00
|
|
|
if ($index === FALSE) {
|
2013-07-31 16:01:18 +00:00
|
|
|
return "";
|
|
|
|
}
|
2013-08-13 15:50:47 +00:00
|
|
|
if ($index >= 0) {
|
2013-07-31 16:01:18 +00:00
|
|
|
$rawData = substr($result, $index);
|
2013-08-13 15:50:47 +00:00
|
|
|
$composer_info = json_decode($rawData, TRUE);
|
|
|
|
|
2013-07-31 16:01:18 +00:00
|
|
|
return $composer_info;
|
|
|
|
}
|
2013-08-13 15:50:47 +00:00
|
|
|
|
2013-07-31 16:01:18 +00:00
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2013-08-13 15:50:47 +00:00
|
|
|
public function getComposerInformationFromLabel($identifier, $index) {
|
2013-07-31 18:26:44 +00:00
|
|
|
$composer_json_path = substr($identifier, 0, $index) . "/composer.json" . substr($identifier, $index);
|
2013-08-13 15:50:47 +00:00
|
|
|
$command = $this->generateP4Command(" files $composer_json_path", FALSE);
|
|
|
|
$result = $this->executeCommand($command);
|
2013-07-31 16:01:18 +00:00
|
|
|
$index2 = strpos($result, "no such file(s).");
|
2013-08-13 15:50:47 +00:00
|
|
|
if ($index2 === FALSE) {
|
2013-07-31 16:01:18 +00:00
|
|
|
$index3 = strpos($result, "change");
|
2013-08-13 15:50:47 +00:00
|
|
|
if (!($index3 === FALSE)) {
|
2013-07-31 16:01:18 +00:00
|
|
|
$phrase = trim(substr($result, $index3));
|
|
|
|
$fields = explode(" ", $phrase);
|
|
|
|
$id = $fields[1];
|
|
|
|
$composer_json = substr($identifier, 0, $index) . "/composer.json@" . $id;
|
2013-08-13 15:50:47 +00:00
|
|
|
|
2013-07-31 18:26:44 +00:00
|
|
|
return $this->getComposerInformationFromPath($composer_json);
|
2013-07-31 16:01:18 +00:00
|
|
|
}
|
|
|
|
}
|
2013-08-13 15:50:47 +00:00
|
|
|
|
2013-07-31 16:01:18 +00:00
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2013-08-13 15:50:47 +00:00
|
|
|
public function getBranches() {
|
2013-07-31 18:26:44 +00:00
|
|
|
$possible_branches = array();
|
2013-08-13 15:50:47 +00:00
|
|
|
if (!$this->isStream()) {
|
2013-08-15 17:16:15 +00:00
|
|
|
$possible_branches[$this->p4Branch] = $this->getStream();
|
2013-08-13 15:50:47 +00:00
|
|
|
}
|
|
|
|
else {
|
2013-08-15 17:16:15 +00:00
|
|
|
$command = $this->generateP4Command("streams //$this->p4Depot/...");
|
|
|
|
$result = $this->executeCommand($command);
|
2013-07-31 16:01:18 +00:00
|
|
|
$resArray = explode("\n", $result);
|
2013-08-13 15:50:47 +00:00
|
|
|
foreach ($resArray as $line) {
|
2013-07-31 16:01:18 +00:00
|
|
|
$resBits = explode(" ", $line);
|
2013-08-13 15:50:47 +00:00
|
|
|
if (count($resBits) > 4) {
|
|
|
|
$branch = preg_replace("/[^A-Za-z0-9 ]/", '', $resBits[4]);
|
2013-07-31 18:26:44 +00:00
|
|
|
$possible_branches[$branch] = $resBits[1];
|
2013-07-31 16:01:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-07-31 18:26:44 +00:00
|
|
|
$branches = array();
|
2013-08-15 17:16:15 +00:00
|
|
|
$branches['master'] = $possible_branches[$this->p4Branch];
|
2013-08-13 15:50:47 +00:00
|
|
|
|
2013-07-31 16:01:18 +00:00
|
|
|
return $branches;
|
|
|
|
}
|
|
|
|
|
2013-08-13 15:50:47 +00:00
|
|
|
public function getTags() {
|
2013-07-31 16:01:18 +00:00
|
|
|
$command = $this->generateP4Command("labels");
|
2013-08-13 15:50:47 +00:00
|
|
|
$result = $this->executeCommand($command);
|
2013-07-31 16:01:18 +00:00
|
|
|
$resArray = explode("\n", $result);
|
2013-07-31 18:26:44 +00:00
|
|
|
$tags = array();
|
2013-08-13 15:50:47 +00:00
|
|
|
foreach ($resArray as $line) {
|
2013-07-31 16:01:18 +00:00
|
|
|
$index = strpos($line, "Label");
|
2013-08-13 15:50:47 +00:00
|
|
|
if (!($index === FALSE)) {
|
2013-07-31 16:01:18 +00:00
|
|
|
$fields = explode(" ", $line);
|
2013-08-13 15:50:47 +00:00
|
|
|
$tags[$fields[1]] = $this->getStream() . "@" . $fields[1];
|
2013-07-31 16:01:18 +00:00
|
|
|
}
|
|
|
|
}
|
2013-08-13 15:54:35 +00:00
|
|
|
|
2013-07-31 16:01:18 +00:00
|
|
|
return $tags;
|
|
|
|
}
|
|
|
|
|
2013-08-13 15:50:47 +00:00
|
|
|
public function checkStream() {
|
|
|
|
$command = $this->generateP4Command("depots", FALSE);
|
|
|
|
$result = $this->executeCommand($command);
|
2013-07-31 16:01:18 +00:00
|
|
|
$resArray = explode("\n", $result);
|
2013-08-13 15:50:47 +00:00
|
|
|
foreach ($resArray as $line) {
|
2013-07-31 16:01:18 +00:00
|
|
|
$index = strpos($line, "Depot");
|
2013-08-13 15:50:47 +00:00
|
|
|
if (!($index === FALSE)) {
|
2013-07-31 16:01:18 +00:00
|
|
|
$fields = explode(" ", $line);
|
2013-08-15 17:16:15 +00:00
|
|
|
if (strcmp($this->p4Depot, $fields[1]) === 0) {
|
|
|
|
$this->p4DepotType = $fields[3];
|
2013-08-13 15:50:47 +00:00
|
|
|
|
2013-07-31 16:01:18 +00:00
|
|
|
return $this->isStream();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-08-13 15:50:47 +00:00
|
|
|
|
|
|
|
return FALSE;
|
2013-07-25 20:25:09 +00:00
|
|
|
}
|
2013-08-12 18:28:09 +00:00
|
|
|
|
|
|
|
protected function getChangeList($reference){
|
|
|
|
$index = strpos($reference, "@");
|
|
|
|
if ($index === false){
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$label = substr($reference, $index);
|
|
|
|
$command = $this->generateP4Command(" changes -m1 $label");
|
|
|
|
$changes = $this->executeCommand($command);
|
|
|
|
if (strpos($changes, "Change") !== 0){
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$fields = explode(" ", $changes);
|
|
|
|
$changeList = $fields[1];
|
|
|
|
return $changeList;
|
|
|
|
}
|
|
|
|
public function getCommitLogs($fromReference, $toReference){
|
|
|
|
$fromChangeList = $this->getChangeList($fromReference);
|
|
|
|
if ($fromChangeList == null){
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$toChangeList = $this->getChangeList($toReference);
|
|
|
|
if ($toChangeList == null){
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$index = strpos($fromReference, "@");
|
|
|
|
$main = substr($fromReference, 0, $index) . "/...";
|
|
|
|
$command = $this->generateP4Command("filelog $main@$fromChangeList,$toChangeList");
|
|
|
|
$result = $this->executeCommand($command);
|
|
|
|
return $result;
|
|
|
|
}
|
2013-07-24 15:06:35 +00:00
|
|
|
}
|