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 output of a list command on a workingcopy or repositoryurl in a property.
22
 * This stems from the SvnLastRevisionTask.
23
 *
24
 * @author  Anton Stöckl <anton@stoeckl.de>
25
 * @author  Michiel Rook <mrook@php.net> (SvnLastRevisionTask)
26
 * @package phing.tasks.ext.svn
27
 * @see     VersionControl_SVN
28
 * @since   2.1.0
29
 */
30
class SvnListTask extends SvnBaseTask
31
{
32
    private $propertyName = "svn.list";
33
    private $limit = null;
34
    private $orderDescending = false;
35

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

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

54
    /**
55
     * Sets the max num of tags to display
56
     *
57
     * @param $limit
58
     */
59 0
    public function setLimit($limit)
60
    {
61 0
        $this->limit = (int) $limit;
62
    }
63

64
    /**
65
     * Sets whether to sort tags in descending order
66
     *
67
     * @param $orderDescending
68
     */
69 0
    public function setOrderDescending($orderDescending)
70
    {
71 0
        $this->orderDescending = $orderDescending;
72
    }
73

74
    /**
75
     * The main entry point
76
     *
77
     * @throws BuildException
78
     */
79 0
    public function main()
80
    {
81 0
        $this->setup('list');
82

83 0
        if ($this->oldVersion) {
84 0
            $this->svn->setOptions(['fetchmode' => VERSIONCONTROL_SVN_FETCHMODE_XML]);
85 0
            $output = $this->run(['--xml']);
86

87 0
            if (!($xmlObj = @simplexml_load_string($output))) {
88 0
                throw new BuildException("Failed to parse the output of 'svn list --xml'.");
89
            }
90

91 0
            $objects = $xmlObj->list->entry;
92 0
            $entries = [];
93

94 0
            foreach ($objects as $object) {
95 0
                $entries[] = [
96
                    'commit' => [
97 0
                        'revision' => (string) $object->commit['revision'],
98 0
                        'author' => (string) $object->commit->author,
99 0
                        'date' => (string) $object->commit->date
100
                    ],
101 0
                    'name' => (string) $object->name
102
                ];
103
            }
104
        } else {
105 0
            $output = $this->run([]);
106 0
            $entries = $output['list'][0]['entry'];
107
        }
108

109 0
        if ($this->orderDescending) {
110 0
            $entries = array_reverse($entries);
111
        }
112

113 0
        $result = null;
114 0
        $count = 0;
115

116 0
        foreach ($entries as $entry) {
117 0
            if ($this->limit > 0 && $count >= $this->limit) {
118 0
                break;
119
            }
120

121 0
            $result .= (!empty($result)) ? "\n" : '';
122 0
            $result .= $entry['commit']['revision'] . ' | ' . $entry['commit']['author'] . ' | ' . $entry['commit']['date'] . ' | ' . $entry['name'];
123 0
            $count++;
124
        }
125

126 0
        if (!empty($result)) {
127 0
            $this->project->setProperty($this->getPropertyName(), $result);
128
        } else {
129 0
            throw new BuildException("Failed to parse the output of 'svn list'.");
130
        }
131
    }
132
}

Read our documentation on viewing source code .

Loading