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\Task\System; |
22
|
|
|
|
23
|
|
|
use Exception; |
24
|
|
|
use Phing\Exception\BuildException; |
25
|
|
|
use Phing\Io\File; |
26
|
|
|
use Phing\Io\FileParserFactory; |
27
|
|
|
use Phing\Io\FileParserFactoryInterface; |
28
|
|
|
use Phing\Io\FileReader; |
29
|
|
|
use Phing\Io\FileUtils; |
30
|
|
|
use Phing\Io\IOException; |
31
|
|
|
use Phing\Io\StringReader; |
32
|
|
|
use Phing\Project; |
33
|
|
|
use Phing\PropertyHelper; |
34
|
|
|
use Phing\Task; |
35
|
|
|
use Phing\Type\Element\FilterChainAware; |
36
|
|
|
use Phing\Type\Reference; |
37
|
|
|
use Phing\Util\Properties; |
38
|
|
|
use Phing\Util\StringHelper; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Task for setting properties in buildfiles. |
42
|
|
|
* |
43
|
|
|
* @author Andreas Aderhold <[email protected]> |
44
|
|
|
* @author Hans Lellelid <[email protected]> |
45
|
|
|
*/ |
46
|
|
|
class PropertyTask extends Task |
47
|
|
|
{ |
48
|
|
|
use FilterChainAware; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @var string name of the property |
52
|
|
|
*/ |
53
|
|
|
protected $name; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @var string of the property |
57
|
|
|
*/ |
58
|
|
|
protected $value; |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @var Reference |
62
|
|
|
*/ |
63
|
|
|
protected $reference; |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @var string environment |
67
|
|
|
*/ |
68
|
|
|
protected $env; |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @var File |
72
|
|
|
*/ |
73
|
|
|
protected $file; |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @var string |
77
|
|
|
*/ |
78
|
|
|
protected $prefix; |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @var Project |
82
|
|
|
*/ |
83
|
|
|
protected $fallback; |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Whether to force overwrite of existing property. |
87
|
|
|
*/ |
88
|
|
|
protected $override = false; |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* Whether property should be treated as "user" property. |
92
|
|
|
*/ |
93
|
|
|
protected $userProperty = false; |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* Whether to log messages as INFO or VERBOSE. |
97
|
|
|
*/ |
98
|
|
|
protected $logOutput = true; |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @var FileParserFactoryInterface |
102
|
|
|
*/ |
103
|
|
|
private $fileParserFactory; |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* Whether a warning should be displayed when the property ismissing. |
107
|
|
|
*/ |
108
|
|
|
private $quiet = false; |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* Whether the task should fail when the property file is not found. |
112
|
|
|
*/ |
113
|
|
|
private $required = false; |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* @param FileParserFactoryInterface|null $fileParserFactory |
117
|
|
|
*/ |
118
|
|
|
public function __construct(?FileParserFactoryInterface $fileParserFactory = null) |
119
|
|
|
{ |
120
|
|
|
parent::__construct(); |
121
|
|
|
$this->fileParserFactory = $fileParserFactory ?? new FileParserFactory(); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* @return string |
126
|
|
|
*/ |
127
|
|
|
public function __toString() |
128
|
|
|
{ |
129
|
|
|
return $this->value; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* File required or not. |
134
|
|
|
* |
135
|
|
|
* @param string $d |
136
|
|
|
*/ |
137
|
|
|
public function setRequired($d) |
138
|
|
|
{ |
139
|
|
|
$this->required = $d; |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* @return string |
144
|
|
|
*/ |
145
|
|
|
public function getRequired() |
146
|
|
|
{ |
147
|
|
|
return $this->required; |
|
|
|
|
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* Sets a the name of current property component. |
152
|
|
|
*/ |
153
|
|
|
public function setName(string $name): void |
154
|
|
|
{ |
155
|
|
|
$this->name = $name; |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* Get property component name. |
160
|
|
|
*/ |
161
|
|
|
public function getName() |
162
|
|
|
{ |
163
|
|
|
return $this->name; |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
/** |
167
|
|
|
* Sets a the value of current property component. |
168
|
|
|
* |
169
|
|
|
* @param string $value Value of name, all scalars allowed |
170
|
|
|
*/ |
171
|
|
|
public function setValue(string $value): void |
172
|
|
|
{ |
173
|
|
|
$this->value = $value; |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
/** |
177
|
|
|
* Sets value of property to CDATA tag contents. |
178
|
|
|
* |
179
|
|
|
* @since 2.2.0 |
180
|
|
|
*/ |
181
|
|
|
public function addText(string $value): void |
182
|
|
|
{ |
183
|
|
|
$this->setValue($value); |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
/** |
187
|
|
|
* Get the value of current property component. |
188
|
|
|
*/ |
189
|
|
|
public function getValue() |
190
|
|
|
{ |
191
|
|
|
return $this->value; |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
/** |
195
|
|
|
* Set a file to use as the source for properties. |
196
|
|
|
* |
197
|
|
|
* @param File|string $file |
198
|
|
|
* |
199
|
|
|
* @throws IOException |
200
|
|
|
*/ |
201
|
|
|
public function setFile($file) |
202
|
|
|
{ |
203
|
|
|
if (is_string($file)) { |
204
|
|
|
$file = new File($file); |
205
|
|
|
} |
206
|
|
|
$this->file = $file; |
207
|
|
|
} |
208
|
|
|
|
209
|
|
|
/** |
210
|
|
|
* Get the PhingFile that is being used as property source. |
211
|
|
|
*/ |
212
|
|
|
public function getFile() |
213
|
|
|
{ |
214
|
|
|
return $this->file; |
215
|
|
|
} |
216
|
|
|
|
217
|
|
|
public function setRefid(Reference $ref): void |
218
|
|
|
{ |
219
|
|
|
$this->reference = $ref; |
220
|
|
|
} |
221
|
|
|
|
222
|
|
|
public function getRefid() |
223
|
|
|
{ |
224
|
|
|
return $this->reference; |
225
|
|
|
} |
226
|
|
|
|
227
|
|
|
/** |
228
|
|
|
* Prefix to apply to properties loaded using <code>file</code>. |
229
|
|
|
* A "." is appended to the prefix if not specified. |
230
|
|
|
* |
231
|
|
|
* @param string $prefix prefix string |
232
|
|
|
* |
233
|
|
|
* @since 2.0 |
234
|
|
|
*/ |
235
|
|
|
public function setPrefix(string $prefix): void |
236
|
|
|
{ |
237
|
|
|
$this->prefix = $prefix; |
238
|
|
|
if (!StringHelper::endsWith('.', $prefix)) { |
239
|
|
|
$this->prefix .= '.'; |
240
|
|
|
} |
241
|
|
|
} |
242
|
|
|
|
243
|
|
|
/** |
244
|
|
|
* @return string |
245
|
|
|
* |
246
|
|
|
* @since 2.0 |
247
|
|
|
*/ |
248
|
|
|
public function getPrefix() |
249
|
|
|
{ |
250
|
|
|
return $this->prefix; |
251
|
|
|
} |
252
|
|
|
|
253
|
|
|
/** |
254
|
|
|
* the prefix to use when retrieving environment variables. |
255
|
|
|
* Thus if you specify environment="myenv" |
256
|
|
|
* you will be able to access OS-specific |
257
|
|
|
* environment variables via property names "myenv.PATH" or |
258
|
|
|
* "myenv.TERM". |
259
|
|
|
* <p> |
260
|
|
|
* Note that if you supply a property name with a final |
261
|
|
|
* "." it will not be doubled. ie environment="myenv." will still |
262
|
|
|
* allow access of environment variables through "myenv.PATH" and |
263
|
|
|
* "myenv.TERM". This functionality is currently only implemented |
264
|
|
|
* on select platforms. Feel free to send patches to increase the number of platforms |
265
|
|
|
* this functionality is supported on ;).<br> |
266
|
|
|
* Note also that properties are case sensitive, even if the |
267
|
|
|
* environment variables on your operating system are not, e.g. it |
268
|
|
|
* will be ${env.Path} not ${env.PATH} on Windows 2000. |
269
|
|
|
*/ |
270
|
|
|
public function setEnvironment(string $env): void |
271
|
|
|
{ |
272
|
|
|
$this->env = $env; |
273
|
|
|
} |
274
|
|
|
|
275
|
|
|
public function getEnvironment() |
276
|
|
|
{ |
277
|
|
|
return $this->env; |
278
|
|
|
} |
279
|
|
|
|
280
|
|
|
/** |
281
|
|
|
* Set whether this is a user property (ro). |
282
|
|
|
* This is deprecated in Ant 1.5, but the userProperty attribute |
283
|
|
|
* of the class is still being set via constructor, so Phing will |
284
|
|
|
* allow this method to function. |
285
|
|
|
*/ |
286
|
|
|
public function setUserProperty(bool $v): void |
287
|
|
|
{ |
288
|
|
|
$this->userProperty = $v; |
289
|
|
|
} |
290
|
|
|
|
291
|
|
|
/** |
292
|
|
|
* @return bool |
293
|
|
|
*/ |
294
|
|
|
public function getUserProperty() |
295
|
|
|
{ |
296
|
|
|
return $this->userProperty; |
297
|
|
|
} |
298
|
|
|
|
299
|
|
|
public function setOverride(bool $override): void |
300
|
|
|
{ |
301
|
|
|
$this->override = $override; |
302
|
|
|
} |
303
|
|
|
|
304
|
|
|
/** |
305
|
|
|
* @return bool |
306
|
|
|
*/ |
307
|
|
|
public function getOverride() |
308
|
|
|
{ |
309
|
|
|
return $this->override; |
310
|
|
|
} |
311
|
|
|
|
312
|
|
|
/** |
313
|
|
|
* @param Project $p |
314
|
|
|
*/ |
315
|
|
|
public function setFallback($p): void |
316
|
|
|
{ |
317
|
|
|
$this->fallback = $p; |
318
|
|
|
} |
319
|
|
|
|
320
|
|
|
public function getFallback() |
321
|
|
|
{ |
322
|
|
|
return $this->fallback; |
323
|
|
|
} |
324
|
|
|
|
325
|
|
|
public function setLogoutput(bool $logOutput): void |
326
|
|
|
{ |
327
|
|
|
$this->logOutput = $logOutput; |
328
|
|
|
} |
329
|
|
|
|
330
|
|
|
/** |
331
|
|
|
* @return bool |
332
|
|
|
*/ |
333
|
|
|
public function getLogoutput() |
334
|
|
|
{ |
335
|
|
|
return $this->logOutput; |
336
|
|
|
} |
337
|
|
|
|
338
|
|
|
/** |
339
|
|
|
* Set quiet mode, which suppresses warnings if chmod() fails. |
340
|
|
|
* |
341
|
|
|
* @see setFailonerror() |
342
|
|
|
*/ |
343
|
|
|
public function setQuiet(bool $bool): void |
344
|
|
|
{ |
345
|
|
|
$this->quiet = $bool; |
346
|
|
|
} |
347
|
|
|
|
348
|
|
|
public function getQuiet(): bool |
349
|
|
|
{ |
350
|
|
|
return $this->quiet; |
351
|
|
|
} |
352
|
|
|
|
353
|
|
|
/** |
354
|
|
|
* set the property in the project to the value. |
355
|
|
|
* if the task was give a file or env attribute |
356
|
|
|
* here is where it is loaded. |
357
|
|
|
*/ |
358
|
|
|
public function main() |
359
|
|
|
{ |
360
|
|
|
$this->validate(); |
361
|
|
|
|
362
|
|
|
if (null !== $this->name && null !== $this->value) { |
363
|
|
|
$this->addProperty($this->name, $this->value); |
364
|
|
|
} |
365
|
|
|
|
366
|
|
|
if (null !== $this->file) { |
367
|
|
|
$this->loadFile($this->file); |
368
|
|
|
} |
369
|
|
|
|
370
|
|
|
if (null !== $this->env) { |
371
|
|
|
$this->loadEnvironment($this->env); |
372
|
|
|
} |
373
|
|
|
|
374
|
|
|
if (null !== $this->name && null !== $this->reference) { |
375
|
|
|
// get the refereced property |
376
|
|
|
try { |
377
|
|
|
$referencedObject = $this->reference->getReferencedObject($this->project); |
378
|
|
|
|
379
|
|
|
if ($referencedObject instanceof Exception) { |
380
|
|
|
$reference = $referencedObject->getMessage(); |
381
|
|
|
} else { |
382
|
|
|
$reference = (string) $referencedObject; |
383
|
|
|
} |
384
|
|
|
|
385
|
|
|
$this->addProperty($this->name, $reference); |
386
|
|
|
} catch (BuildException $be) { |
387
|
|
|
if (null !== $this->fallback) { |
388
|
|
|
$referencedObject = $this->reference->getReferencedObject($this->fallback); |
389
|
|
|
|
390
|
|
|
if ($referencedObject instanceof Exception) { |
391
|
|
|
$reference = $referencedObject->getMessage(); |
392
|
|
|
} else { |
393
|
|
|
$reference = (string) $referencedObject; |
394
|
|
|
} |
395
|
|
|
$this->addProperty($this->name, $reference); |
396
|
|
|
} else { |
397
|
|
|
throw $be; |
398
|
|
|
} |
399
|
|
|
} |
400
|
|
|
} |
401
|
|
|
} |
402
|
|
|
|
403
|
|
|
/** |
404
|
|
|
* load the environment values. |
405
|
|
|
* |
406
|
|
|
* @param string $prefix prefix to place before them |
407
|
|
|
*/ |
408
|
|
|
protected function loadEnvironment(string $prefix) |
409
|
|
|
{ |
410
|
|
|
$props = new Properties(); |
411
|
|
|
if ('.' === substr($prefix, strlen($prefix) - 1)) { |
412
|
|
|
$prefix .= '.'; |
413
|
|
|
} |
414
|
|
|
$this->log("Loading Environment {$prefix}", Project::MSG_VERBOSE); |
415
|
|
|
foreach (getenv() as $key => $value) { |
416
|
|
|
$props->setProperty($prefix . '.' . $key, $value); |
417
|
|
|
} |
418
|
|
|
$this->addProperties($props); |
419
|
|
|
} |
420
|
|
|
|
421
|
|
|
/** |
422
|
|
|
* iterate through a set of properties, |
423
|
|
|
* resolve them then assign them. |
424
|
|
|
* |
425
|
|
|
* @param Properties $props |
426
|
|
|
* |
427
|
|
|
* @throws BuildException |
428
|
|
|
*/ |
429
|
|
|
protected function addProperties($props) |
430
|
|
|
{ |
431
|
|
|
$this->resolveAllProperties($props); |
432
|
|
|
foreach ($props->keys() as $name) { |
433
|
|
|
$value = $props->getProperty($name); |
434
|
|
|
$v = $this->project->replaceProperties($value); |
435
|
|
|
if (null !== $this->prefix) { |
436
|
|
|
$name = $this->prefix . $name; |
437
|
|
|
} |
438
|
|
|
$this->addProperty($name, $v); |
439
|
|
|
} |
440
|
|
|
} |
441
|
|
|
|
442
|
|
|
/** |
443
|
|
|
* add a name value pair to the project property set. |
444
|
|
|
* |
445
|
|
|
* @param string $name name of property |
446
|
|
|
* @param string $value value to set |
447
|
|
|
*/ |
448
|
|
|
protected function addProperty($name, $value) |
449
|
|
|
{ |
450
|
|
|
if (null === $this->file && count($this->filterChains) > 0) { |
451
|
|
|
$in = FileUtils::getChainedReader(new StringReader($value), $this->filterChains, $this->project); |
452
|
|
|
$value = $in->read(); |
453
|
|
|
} |
454
|
|
|
|
455
|
|
|
$ph = PropertyHelper::getPropertyHelper($this->getProject()); |
456
|
|
|
if ($this->userProperty) { |
457
|
|
|
if (null === $ph->getUserProperty(null, $name) || $this->override) { |
458
|
|
|
$ph->setInheritedProperty(null, $name, $value); |
459
|
|
|
} else { |
460
|
|
|
$this->log('Override ignored for ' . $name, Project::MSG_VERBOSE); |
461
|
|
|
} |
462
|
|
|
} else { |
463
|
|
|
if ($this->override) { |
464
|
|
|
$ph->setProperty(null, $name, $value, true); |
465
|
|
|
} else { |
466
|
|
|
$ph->setNewProperty(null, $name, $value); |
467
|
|
|
} |
468
|
|
|
} |
469
|
|
|
} |
470
|
|
|
|
471
|
|
|
/** |
472
|
|
|
* load properties from a file. |
473
|
|
|
* |
474
|
|
|
* @throws BuildException |
475
|
|
|
*/ |
476
|
|
|
protected function loadFile(File $file) |
477
|
|
|
{ |
478
|
|
|
$fileParser = $this->fileParserFactory->createParser($file->getFileExtension()); |
479
|
|
|
$props = new Properties(null, $fileParser); |
480
|
|
|
$this->log('Loading ' . $file->getAbsolutePath(), $this->logOutput ? Project::MSG_INFO : Project::MSG_VERBOSE); |
481
|
|
|
|
482
|
|
|
try { // try to load file |
483
|
|
|
if ($file->exists()) { |
484
|
|
|
$value = null; |
485
|
|
|
if (count($this->filterChains) > 0) { |
486
|
|
|
$in = FileUtils::getChainedReader(new FileReader($file), $this->filterChains, $this->project); |
487
|
|
|
$value = $in->read(); |
488
|
|
|
} |
489
|
|
|
if ($value) { |
490
|
|
|
foreach (array_filter(explode(PHP_EOL, $value)) as $line) { |
491
|
|
|
[$key, $prop] = explode('=', $line); |
492
|
|
|
$props->setProperty($key, $prop); |
493
|
|
|
} |
494
|
|
|
} else { |
495
|
|
|
$props->load($file); |
496
|
|
|
} |
497
|
|
|
$this->addProperties($props); |
498
|
|
|
} else { |
499
|
|
|
if ($this->required) { |
500
|
|
|
throw new BuildException('Unable to find property file: ' . $file->getAbsolutePath()); |
501
|
|
|
} |
502
|
|
|
|
503
|
|
|
$this->log( |
504
|
|
|
'Unable to find property file: ' . $file->getAbsolutePath() . '... skipped', |
505
|
|
|
$this->quiet ? Project::MSG_VERBOSE : Project::MSG_WARN |
506
|
|
|
); |
507
|
|
|
} |
508
|
|
|
} catch (IOException $ioe) { |
509
|
|
|
throw new BuildException('Could not load properties from file.', $ioe); |
510
|
|
|
} |
511
|
|
|
} |
512
|
|
|
|
513
|
|
|
/** |
514
|
|
|
* Given a Properties object, this method goes through and resolves |
515
|
|
|
* any references to properties within the object. |
516
|
|
|
* |
517
|
|
|
* @param Properties $props the collection of Properties that need to be resolved |
518
|
|
|
* |
519
|
|
|
* @throws BuildException |
520
|
|
|
*/ |
521
|
|
|
protected function resolveAllProperties(Properties $props) |
522
|
|
|
{ |
523
|
|
|
foreach ($props->keys() as $name) { |
524
|
|
|
// There may be a nice regex/callback way to handle this |
525
|
|
|
// replacement, but at the moment it is pretty complex, and |
526
|
|
|
// would probably be a lot uglier to work into a preg_replace_callback() |
527
|
|
|
// system. The biggest problem is the fact that a resolution may require |
528
|
|
|
// multiple passes. |
529
|
|
|
|
530
|
|
|
$value = $props->getProperty($name); |
531
|
|
|
$resolved = false; |
532
|
|
|
$resolveStack = []; |
533
|
|
|
|
534
|
|
|
while (!$resolved) { |
535
|
|
|
$fragments = []; |
536
|
|
|
$propertyRefs = []; |
537
|
|
|
|
538
|
|
|
PropertyHelper::getPropertyHelper($this->project)->parsePropertyString( |
539
|
|
|
$value, |
|
|
|
|
540
|
|
|
$fragments, |
541
|
|
|
$propertyRefs |
542
|
|
|
); |
543
|
|
|
|
544
|
|
|
$resolved = true; |
545
|
|
|
if (0 === count($propertyRefs)) { |
546
|
|
|
continue; |
547
|
|
|
} |
548
|
|
|
|
549
|
|
|
$sb = ''; |
550
|
|
|
|
551
|
|
|
$j = $propertyRefs; |
552
|
|
|
|
553
|
|
|
foreach ($fragments as $fragment) { |
554
|
|
|
if (null !== $fragment) { |
555
|
|
|
$sb .= $fragment; |
556
|
|
|
|
557
|
|
|
continue; |
558
|
|
|
} |
559
|
|
|
|
560
|
|
|
$propertyName = array_shift($j); |
561
|
|
|
if (in_array($propertyName, $resolveStack)) { |
562
|
|
|
// Should we maybe just log this as an error & move on? |
563
|
|
|
// $this->log("Property ".$name." was circularly defined.", Project::MSG_ERR); |
564
|
|
|
throw new BuildException('Property ' . $propertyName . ' was circularly defined.'); |
565
|
|
|
} |
566
|
|
|
|
567
|
|
|
if ($props->containsKey($propertyName)) { |
568
|
|
|
$fragment = $props->getProperty($propertyName); |
569
|
|
|
if (false !== strpos($fragment, '${')) { |
|
|
|
|
570
|
|
|
$resolveStack[] = $propertyName; |
571
|
|
|
$resolved = false; // parse again (could have been replaced w/ another var) |
572
|
|
|
} |
573
|
|
|
|
574
|
|
|
$sb .= $fragment; |
575
|
|
|
|
576
|
|
|
continue; |
577
|
|
|
} |
578
|
|
|
|
579
|
|
|
$fragment = $this->getProject()->getProperty($propertyName); |
580
|
|
|
if (null !== $fragment) { |
581
|
|
|
$sb .= $fragment; |
582
|
|
|
|
583
|
|
|
continue; |
584
|
|
|
} |
585
|
|
|
|
586
|
|
|
$fragment = '${' . $propertyName . '}'; |
587
|
|
|
$sb .= $fragment; |
588
|
|
|
} |
589
|
|
|
|
590
|
|
|
$this->log("Resolved Property \"{$value}\" to \"{$sb}\"", Project::MSG_DEBUG); |
591
|
|
|
$value = $sb; |
592
|
|
|
$props->setProperty($name, $value); |
593
|
|
|
} // while (!$resolved) |
594
|
|
|
} // while (count($keys) |
595
|
|
|
} |
596
|
|
|
|
597
|
|
|
/** |
598
|
|
|
* @throws BuildException |
599
|
|
|
*/ |
600
|
|
|
private function validate(): void |
601
|
|
|
{ |
602
|
|
|
if (null !== $this->name) { |
603
|
|
|
if (null === $this->value && null === $this->reference) { |
604
|
|
|
throw new BuildException( |
605
|
|
|
'You must specify value or refid with the name attribute', |
606
|
|
|
$this->getLocation() |
607
|
|
|
); |
608
|
|
|
} |
609
|
|
|
} elseif (null === $this->file && null === $this->env) { |
610
|
|
|
throw new BuildException( |
611
|
|
|
'You must specify file or environment when not using the name attribute', |
612
|
|
|
$this->getLocation() |
613
|
|
|
); |
614
|
|
|
} |
615
|
|
|
|
616
|
|
|
if (null === $this->file && null !== $this->prefix) { |
617
|
|
|
throw new BuildException('Prefix is only valid when loading from a file.', $this->getLocation()); |
618
|
|
|
} |
619
|
|
|
} |
620
|
|
|
} |
621
|
|
|
|