PerforceDownloader.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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\Repository\VcsRepository;
  14. use Composer\Util\Perforce;
  15. /**
  16. * @author Matt Whittom <Matt.Whittom@veteransunited.com>
  17. */
  18. class PerforceDownloader extends VcsDownloader
  19. {
  20. protected $perforce;
  21. // protected $perforceInjected = false;
  22. /**
  23. * {@inheritDoc}
  24. */
  25. public function doDownload(PackageInterface $package, $path)
  26. {
  27. $ref = $package->getSourceReference();
  28. $label = $package->getPrettyVersion();
  29. $this->io->write(' Cloning ' . $ref);
  30. $this->initPerforce($package, $path);
  31. $this->perforce->setStream($ref);
  32. $this->perforce->p4Login($this->io);
  33. $this->perforce->writeP4ClientSpec();
  34. $this->perforce->connectClient();
  35. $this->perforce->syncCodeBase($label);
  36. $this->perforce->cleanupClientSpec();
  37. }
  38. public function initPerforce($package, $path)
  39. {
  40. if (!empty($this->perforce)) {
  41. $this->perforce->initializePath($path);
  42. return;
  43. }
  44. $repository = $package->getRepository();
  45. $repoConfig = null;
  46. if ($repository instanceof VcsRepository) {
  47. $repoConfig = $this->getRepoConfig($repository);
  48. }
  49. $this->perforce = Perforce::create($repoConfig, $package->getSourceUrl(), $path, $this->process, $this->io);
  50. }
  51. private function getRepoConfig(VcsRepository $repository)
  52. {
  53. return $repository->getRepoConfig();
  54. }
  55. /**
  56. * {@inheritDoc}
  57. */
  58. public function doUpdate(PackageInterface $initial, PackageInterface $target, $path)
  59. {
  60. $this->doDownload($target, $path);
  61. }
  62. /**
  63. * {@inheritDoc}
  64. */
  65. public function getLocalChanges(PackageInterface $package, $path)
  66. {
  67. $this->io->write('Perforce driver does not check for local changes before overriding', true);
  68. return;
  69. }
  70. /**
  71. * {@inheritDoc}
  72. */
  73. protected function getCommitLogs($fromReference, $toReference, $path)
  74. {
  75. $commitLogs = $this->perforce->getCommitLogs($fromReference, $toReference);
  76. return $commitLogs;
  77. }
  78. public function setPerforce($perforce)
  79. {
  80. $this->perforce = $perforce;
  81. }
  82. }