|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
5
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
6
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|
7
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
|
8
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
9
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
10
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
11
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|
12
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
13
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|
14
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
15
|
|
|
* |
|
16
|
|
|
* This software consists of voluntary contributions made by many individuals |
|
17
|
|
|
* and is licensed under the LGPL. For more information please see |
|
18
|
|
|
* <http://phing.info>. |
|
19
|
|
|
*/ |
|
20
|
|
|
|
|
21
|
|
|
namespace Phing\Tasks\Ext; |
|
22
|
|
|
|
|
23
|
|
|
use Phing\Exception\BuildException; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Parses the output of 'svn info --xml' and |
|
27
|
|
|
* |
|
28
|
|
|
* @author Michiel Rook <[email protected]> |
|
29
|
|
|
* |
|
30
|
|
|
* @package phing.tasks.ext.svn |
|
31
|
|
|
* |
|
32
|
|
|
* @see VersionControl_SVN |
|
33
|
|
|
* @since 2.4.9 |
|
34
|
|
|
*/ |
|
35
|
|
|
class SvnInfoTask extends SvnBaseTask |
|
36
|
|
|
{ |
|
37
|
|
|
private $propertyName = "svn.info"; |
|
38
|
|
|
|
|
39
|
|
|
private $element = 'url'; |
|
40
|
|
|
private $subElement = null; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Sets the name of the property to use |
|
44
|
|
|
* |
|
45
|
|
|
* @param $propertyName |
|
46
|
|
|
*/ |
|
47
|
|
|
public function setPropertyName($propertyName) |
|
48
|
|
|
{ |
|
49
|
|
|
$this->propertyName = $propertyName; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* Returns the name of the property to use |
|
54
|
|
|
*/ |
|
55
|
|
|
public function getPropertyName() |
|
56
|
|
|
{ |
|
57
|
|
|
return $this->propertyName; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Sets the name of the xml element to use. |
|
62
|
|
|
* |
|
63
|
|
|
* @param string $element |
|
64
|
|
|
* |
|
65
|
|
|
* @return void |
|
66
|
|
|
*/ |
|
67
|
|
|
public function setElement($element) |
|
68
|
|
|
{ |
|
69
|
|
|
$this->element = $element; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* Returns the name of the xml element to use. |
|
74
|
|
|
* |
|
75
|
|
|
* @return string |
|
76
|
|
|
*/ |
|
77
|
|
|
public function getElement() |
|
78
|
|
|
{ |
|
79
|
|
|
return $this->element; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* Sets the name of the xml sub element to use. |
|
84
|
|
|
* |
|
85
|
|
|
* @param $subElement |
|
86
|
|
|
* |
|
87
|
|
|
* @return void |
|
88
|
|
|
*/ |
|
89
|
|
|
public function setSubElement($subElement) |
|
90
|
|
|
{ |
|
91
|
|
|
$this->subElement = $subElement; |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* Returns the name of the xml sub element to use. |
|
96
|
|
|
* |
|
97
|
|
|
* @return string |
|
98
|
|
|
*/ |
|
99
|
|
|
public function getSubElement() |
|
100
|
|
|
{ |
|
101
|
|
|
return $this->subElement; |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* The main entry point. |
|
106
|
|
|
* |
|
107
|
|
|
* @return void |
|
108
|
|
|
* |
|
109
|
|
|
* @throws BuildException |
|
110
|
|
|
*/ |
|
111
|
|
|
public function main() |
|
112
|
|
|
{ |
|
113
|
|
|
$this->setup('info'); |
|
114
|
|
|
|
|
115
|
|
|
if ($this->oldVersion) { |
|
116
|
|
|
$output = $this->run(['--xml', '--incremental']); |
|
117
|
|
|
|
|
118
|
|
|
if (!($xmlObj = @simplexml_load_string($output))) { |
|
|
|
|
|
|
119
|
|
|
throw new BuildException("Failed to parse the output of 'svn info --xml'."); |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
$object = $xmlObj->{$this->element}; |
|
123
|
|
|
|
|
124
|
|
|
if (!empty($this->subElement)) { |
|
125
|
|
|
$object = $object->{$this->subElement}; |
|
126
|
|
|
} |
|
127
|
|
|
} else { |
|
128
|
|
|
$output = $this->run(); |
|
129
|
|
|
|
|
130
|
|
|
if (empty($output) || !isset($output['entry'][0])) { |
|
131
|
|
|
throw new BuildException("Failed to parse the output of 'svn info'."); |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
$object = $output['entry'][0][$this->element]; |
|
135
|
|
|
|
|
136
|
|
|
if (!empty($this->subElement)) { |
|
137
|
|
|
$object = $object[$this->subElement]; |
|
138
|
|
|
} |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
$this->project->setProperty($this->getPropertyName(), (string) $object); |
|
142
|
|
|
} |
|
143
|
|
|
} |
|
144
|
|
|
|