PerforceDownloader.php 2.4 KB

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