PerforceDownloader.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. /*
  3. * This file is part of Composer.
  4. *
  5. * (c) Nils Adermann <naderman@naderman.de>
  6. * Jordi Boggiano <j.boggiano@seld.be>
  7. *
  8. * For the full copyright and license information, please view the LICENSE
  9. * file that was distributed with this source code.
  10. */
  11. namespace Composer\Downloader;
  12. use Composer\Package\PackageInterface;
  13. use Composer\Util\Perforce;
  14. #use Composer\Util\GitHub;
  15. #use Composer\Util\Git as GitUtil;
  16. /**
  17. * @author Jordi Boggiano <j.boggiano@seld.be>
  18. */
  19. class PerforceDownloader extends VcsDownloader
  20. {
  21. private $hasStashedChanges = false;
  22. /**
  23. * {@inheritDoc}
  24. */
  25. public function doDownload(PackageInterface $package, $path)
  26. {
  27. print ("Perforce Downloader:doDownload - path:" . var_export($path, true) . "\n");
  28. $ref = $package->getSourceReference();
  29. $p4client = "composer_perforce_dl_" . str_replace("/", "_", str_replace("//", "", $ref));
  30. $clientSpec = "$path/$p4client.p4.spec";
  31. print ("PerforceDownloader:doDownload - clientSpec: $clientSpec, targetDir: $path, p4Client: $p4client\n\n");
  32. $perforce = new Perforce();
  33. $perforce->writeP4ClientSpec($clientSpec, $path, $p4client, $ref);
  34. $perforce->syncCodeBase($clientSpec, $path, $p4client);
  35. }
  36. /**
  37. * {@inheritDoc}
  38. */
  39. public function doUpdate(PackageInterface $initial, PackageInterface $target, $path)
  40. {
  41. print("PerforceDownloader:doUpdate\n");
  42. // $this->cleanEnv();
  43. // $path = $this->normalizePath($path);
  44. //
  45. // $ref = $target->getSourceReference();
  46. // $this->io->write(" Checking out ".$ref);
  47. // $command = 'git remote set-url composer %s && git fetch composer && git fetch --tags composer';
  48. //
  49. // // capture username/password from URL if there is one
  50. // $this->process->execute('git remote -v', $output, $path);
  51. // if (preg_match('{^(?:composer|origin)\s+https?://(.+):(.+)@([^/]+)}im', $output, $match)) {
  52. // $this->io->setAuthentication($match[3], urldecode($match[1]), urldecode($match[2]));
  53. // }
  54. //
  55. // $commandCallable = function($url) use ($command) {
  56. // return sprintf($command, escapeshellarg($url));
  57. // };
  58. //
  59. // $this->runCommand($commandCallable, $target->getSourceUrl(), $path);
  60. // $this->updateToCommit($path, $ref, $target->getPrettyVersion(), $target->getReleaseDate());
  61. }
  62. /**
  63. * {@inheritDoc}
  64. */
  65. public function getLocalChanges($path)
  66. {
  67. print("PerforceDownloader:getLocalChanges\n");
  68. // $this->cleanEnv();
  69. // $path = $this->normalizePath($path);
  70. // if (!is_dir($path.'/.git')) {
  71. // return;
  72. // }
  73. //
  74. // $command = 'git status --porcelain --untracked-files=no';
  75. // if (0 !== $this->process->execute($command, $output, $path)) {
  76. // throw new \RuntimeException('Failed to execute ' . $command . "\n\n" . $this->process->getErrorOutput());
  77. // }
  78. //
  79. // return trim($output) ?: null;
  80. }
  81. /**
  82. * {@inheritDoc}
  83. */
  84. protected function getCommitLogs($fromReference, $toReference, $path)
  85. {
  86. print("PerforceDownloader:getCommitLogs\n");
  87. // $path = $this->normalizePath($path);
  88. // $command = sprintf('git log %s..%s --pretty=format:"%%h - %%an: %%s"', $fromReference, $toReference);
  89. //
  90. // if (0 !== $this->process->execute($command, $output, $path)) {
  91. // throw new \RuntimeException('Failed to execute ' . $command . "\n\n" . $this->process->getErrorOutput());
  92. // }
  93. //
  94. // return $output;
  95. }
  96. }