1
<?php
2
/**
3
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14
 *
15
 * This software consists of voluntary contributions made by many individuals
16
 * and is licensed under the LGPL. For more information please see
17
 * <http://phing.info>.
18
 */
19

20
/**
21
 * Stores the number of the last revision of a workingcopy in a property
22
 *
23
 * @author  Michiel Rook <mrook@php.net>
24
 * @package phing.tasks.ext.svn
25
 * @see     VersionControl_SVN
26
 * @since   2.1.0
27
 */
28
class SvnLastRevisionTask extends SvnBaseTask
29
{
30
    private $propertyName = "svn.lastrevision";
31
    private $lastChanged = false;
32

33
    /**
34
     * Sets the name of the property to use
35
     *
36
     * @param string $propertyName
37
     */
38 0
    public function setPropertyName($propertyName)
39
    {
40 0
        $this->propertyName = $propertyName;
41
    }
42

43
    /**
44
     * Returns the name of the property to use
45
     *
46
     * @return string
47
     */
48 0
    public function getPropertyName()
49
    {
50 0
        return $this->propertyName;
51
    }
52

53
    /**
54
     * Sets whether to retrieve the last changed revision
55
     *
56
     * @param bool $lastChanged
57
     */
58 0
    public function setLastChanged(bool $lastChanged)
59
    {
60 0
        $this->lastChanged = $lastChanged;
61
    }
62

63
    /**
64
     * The main entry point
65
     *
66
     * @throws BuildException
67
     */
68 0
    public function main()
69
    {
70 0
        $this->setup('info');
71

72 0
        if ($this->oldVersion) {
73 0
            $output = $this->run(['--xml']);
74

75 0
            if (!($xmlObj = @simplexml_load_string($output))) {
76 0
                throw new BuildException("Failed to parse the output of 'svn info --xml'.");
77
            }
78

79 0
            if ($this->lastChanged) {
80 0
                $found = (int) $xmlObj->entry->commit['revision'];
81
            } else {
82 0
                $found = (int) $xmlObj->entry['revision'];
83
            }
84
        } else {
85 0
            $output = $this->run();
86

87 0
            if (empty($output) || !isset($output['entry'][0])) {
88 0
                throw new BuildException("Failed to parse the output of 'svn info'.");
89
            }
90

91 0
            if ($this->lastChanged) {
92 0
                $found = $output['entry'][0]['commit']['revision'];
93
            } else {
94 0
                $found = $output['entry'][0]['revision'];
95
            }
96
        }
97

98 0
        $this->project->setProperty($this->getPropertyName(), $found);
99
    }
100
}

Read our documentation on viewing source code .

Loading