SvnCommitTask.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <?php
  2. /**
  3. * $Id: SvnCommitTask.php 905 2010-10-05 16:28:03Z mrook $
  4. *
  5. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  6. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  7. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  8. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  9. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  10. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  11. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  12. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  13. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  14. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  15. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  16. *
  17. * This software consists of voluntary contributions made by many individuals
  18. * and is licensed under the LGPL. For more information please see
  19. * <http://phing.info>.
  20. */
  21. require_once 'phing/Task.php';
  22. require_once 'phing/tasks/ext/svn/SvnBaseTask.php';
  23. /**
  24. * Commits changes in a local working copy to the repository
  25. *
  26. * @author Johan Persson <johanp@aditus.nu>
  27. * @version $Id: SvnCommitTask.php 905 2010-10-05 16:28:03Z mrook $
  28. * @package phing.tasks.ext.svn
  29. * @since 2.4.0
  30. */
  31. class SvnCommitTask extends SvnBaseTask
  32. {
  33. /**
  34. * Commit message
  35. */
  36. private $message = '';
  37. /**
  38. * Property name where we store the revision number of the just
  39. * commited version.
  40. */
  41. private $propertyName = "svn.committedrevision";
  42. /**
  43. * Sets the commit message
  44. */
  45. function setMessage($message)
  46. {
  47. $this->message = $message;
  48. }
  49. /**
  50. * Gets the commit message
  51. */
  52. function getMessage()
  53. {
  54. return $this->message;
  55. }
  56. /**
  57. * Sets the name of the property to use for returned revision
  58. */
  59. function setPropertyName($propertyName)
  60. {
  61. $this->propertyName = $propertyName;
  62. }
  63. /**
  64. * Returns the name of the property to use for returned revision
  65. */
  66. function getPropertyName()
  67. {
  68. return $this->propertyName;
  69. }
  70. /**
  71. * The main entry point
  72. *
  73. * @throws BuildException
  74. */
  75. function main()
  76. {
  77. if( trim($this->message) === '' )
  78. {
  79. throw new BuildException('SVN Commit message can not be empty.');
  80. }
  81. $this->setup('commit');
  82. $this->log("Commiting SVN working copy at '" . $this->getWorkingCopy() . "' with message '".$this->GetMessage()."'");
  83. $output = $this->run(array(), array('message' => $this->GetMessage() ) );
  84. if( preg_match('/[\s]*Committed revision[\s]+([\d]+)/', $output, $matches) )
  85. {
  86. $this->project->setProperty($this->getPropertyName(), $matches[1]);
  87. }
  88. else
  89. {
  90. /**
  91. * If no new revision was committed set revision to "empty". Remember that
  92. * this is not necessarily an error. It could be that the specified working
  93. * copy is identical to to the copy in the repository and in that case
  94. * there will be no update and no new revision number.
  95. */
  96. $this->project->setProperty($this->getPropertyName(), '' );
  97. }
  98. }
  99. }