|
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
|
|
|
* Call another target in the same project. |
|
22
|
|
|
* |
|
23
|
|
|
* <samp> |
|
24
|
|
|
* <target name="foo"> |
|
25
|
|
|
* <phingcall target="bar"> |
|
26
|
|
|
* <property name="property1" value="aaaaa" /> |
|
27
|
|
|
* <property name="foo" value="baz" /> |
|
28
|
|
|
* </phingcall> |
|
29
|
|
|
* </target> |
|
30
|
|
|
* |
|
31
|
|
|
* <target name="bar" depends="init"> |
|
32
|
|
|
* <echo message="prop is ${property1} ${foo}" /> |
|
33
|
|
|
* </target> |
|
34
|
|
|
* </samp> |
|
35
|
|
|
* |
|
36
|
|
|
* This only works as expected if neither property1 nor foo are defined in the project itself. |
|
37
|
|
|
* |
|
38
|
|
|
* @author Andreas Aderhold <[email protected]> |
|
39
|
|
|
* @copyright 2001,2002 THYRELL. All rights reserved |
|
40
|
|
|
* @package phing.tasks.system |
|
41
|
|
|
*/ |
|
42
|
|
|
class PhingCallTask extends Task |
|
43
|
|
|
{ |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* The called Phing task. |
|
47
|
|
|
* |
|
48
|
|
|
* @var PhingTask |
|
49
|
|
|
*/ |
|
50
|
|
|
private $callee; |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* The target to call. |
|
54
|
|
|
* |
|
55
|
|
|
* @var string |
|
56
|
|
|
*/ |
|
57
|
|
|
private $subTarget; |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Whether to inherit all properties from current project. |
|
61
|
|
|
* |
|
62
|
|
|
* @var boolean |
|
63
|
|
|
*/ |
|
64
|
|
|
private $inheritAll = true; |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* Whether to inherit refs from current project. |
|
68
|
|
|
* |
|
69
|
|
|
* @var boolean |
|
70
|
|
|
*/ |
|
71
|
|
|
private $inheritRefs = false; |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* If true, pass all properties to the new Phing project. |
|
75
|
|
|
* Defaults to true. Future use. |
|
76
|
|
|
* |
|
77
|
|
|
* @param boolean new value |
|
78
|
|
|
*/ |
|
79
|
8 |
|
public function setInheritAll($inherit) |
|
80
|
|
|
{ |
|
81
|
8 |
|
$this->inheritAll = (bool) $inherit; |
|
82
|
8 |
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* If true, pass all references to the new Phing project. |
|
86
|
|
|
* Defaults to false. Future use. |
|
87
|
|
|
* |
|
88
|
|
|
* @param boolean new value |
|
89
|
|
|
*/ |
|
90
|
8 |
|
public function setInheritRefs($inheritRefs) |
|
91
|
|
|
{ |
|
92
|
8 |
|
$this->inheritRefs = (bool) $inheritRefs; |
|
93
|
8 |
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* Alias for createProperty |
|
97
|
|
|
* |
|
98
|
|
|
* @see createProperty() |
|
99
|
|
|
*/ |
|
100
|
|
|
public function createParam() |
|
101
|
|
|
{ |
|
102
|
|
|
if ($this->callee === null) { |
|
103
|
|
|
$this->init(); |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
return $this->callee->createProperty(); |
|
|
|
|
|
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* Property to pass to the invoked target. |
|
111
|
|
|
*/ |
|
112
|
7 |
|
public function createProperty() |
|
113
|
|
|
{ |
|
114
|
7 |
|
if ($this->callee === null) { |
|
115
|
|
|
$this->init(); |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
7 |
|
return $this->callee->createProperty(); |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
/** |
|
122
|
|
|
* Target to execute, required. |
|
123
|
|
|
* |
|
124
|
|
|
* @param string $target |
|
125
|
|
|
*/ |
|
126
|
9 |
|
public function setTarget(string $target): void |
|
127
|
|
|
{ |
|
128
|
9 |
|
if ($this->callee === null) { |
|
129
|
|
|
$this->init(); |
|
130
|
|
|
} |
|
131
|
9 |
|
$this->callee->setTarget($target); |
|
|
|
|
|
|
132
|
9 |
|
$this->subTarget = $target; |
|
133
|
9 |
|
} |
|
134
|
|
|
|
|
135
|
|
|
/** |
|
136
|
|
|
* Reference element identifying a data type to carry |
|
137
|
|
|
* over to the invoked target. |
|
138
|
|
|
* |
|
139
|
|
|
* @param PhingReference $r the specified `PhingReference`. |
|
140
|
|
|
*/ |
|
141
|
1 |
|
public function addReference(PhingReference $r) |
|
142
|
|
|
{ |
|
143
|
1 |
|
if ($this->callee === null) { |
|
144
|
|
|
$this->init(); |
|
145
|
|
|
} |
|
146
|
1 |
|
$this->callee->addReference($r); |
|
|
|
|
|
|
147
|
1 |
|
} |
|
148
|
|
|
|
|
149
|
|
|
/** |
|
150
|
|
|
* init this task by creating new instance of the phing task and |
|
151
|
|
|
* configuring it's by calling its own init method. |
|
152
|
|
|
*/ |
|
153
|
9 |
|
public function init() |
|
154
|
|
|
{ |
|
155
|
9 |
|
$this->callee = $this->project->createTask("phing"); |
|
156
|
9 |
|
$this->callee->setOwningTarget($this->getOwningTarget()); |
|
157
|
9 |
|
$this->callee->setTaskName($this->getTaskName()); |
|
158
|
9 |
|
$this->callee->setHaltOnFailure(true); |
|
|
|
|
|
|
159
|
9 |
|
$this->callee->setLocation($this->getLocation()); |
|
160
|
9 |
|
$this->callee->init(); |
|
161
|
9 |
|
} |
|
162
|
|
|
|
|
163
|
|
|
/** |
|
164
|
|
|
* hand off the work to the phing task of ours, after setting it up |
|
165
|
|
|
* |
|
166
|
|
|
* @throws BuildException on validation failure or if the target didn't |
|
167
|
|
|
* execute |
|
168
|
|
|
*/ |
|
169
|
8 |
|
public function main() |
|
170
|
|
|
{ |
|
171
|
8 |
|
if ($this->getOwningTarget()->getName() === "") { |
|
172
|
|
|
$this->log("Cowardly refusing to call target '{$this->subTarget}' from the root", Project::MSG_WARN); |
|
173
|
|
|
return; |
|
174
|
|
|
} |
|
175
|
|
|
|
|
176
|
8 |
|
$this->log("Running PhingCallTask for target '" . $this->subTarget . "'", Project::MSG_DEBUG); |
|
177
|
8 |
|
if ($this->callee === null) { |
|
178
|
|
|
$this->init(); |
|
179
|
|
|
} |
|
180
|
|
|
|
|
181
|
8 |
|
if ($this->subTarget === null) { |
|
182
|
|
|
throw new BuildException("Attribute target is required.", $this->getLocation()); |
|
183
|
|
|
} |
|
184
|
|
|
|
|
185
|
8 |
|
$this->callee->setPhingFile($this->project->getProperty("phing.file")); |
|
|
|
|
|
|
186
|
8 |
|
$this->callee->setTarget($this->subTarget); |
|
187
|
8 |
|
$this->callee->setInheritAll($this->inheritAll); |
|
|
|
|
|
|
188
|
8 |
|
$this->callee->setInheritRefs($this->inheritRefs); |
|
|
|
|
|
|
189
|
8 |
|
$this->callee->main(); |
|
190
|
8 |
|
} |
|
191
|
|
|
} |
|
192
|
|
|
|