Passed
Push — master ( a0b722...864342 )
by Michiel
11:10
created

PhingTask::init()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 5
ccs 4
cts 4
cp 1
crap 1
rs 10
c 0
b 0
f 0
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
 * Task that invokes phing on another build file.
22
 *
23
 * Use this task, for example, if you have nested buildfiles in your project. Unlike
24
 * AntTask, PhingTask can even support filesets:
25
 *
26
 * <pre>
27
 *   <phing>
28
 *    <fileset dir="${srcdir}">
29
 *      <include name="** /build.xml" /> <!-- space added after ** is there because of PHP comment syntax -->
30
 *      <exclude name="build.xml" />
31
 *    </fileset>
32
 *   </phing>
33
 * </pre>
34
 *
35
 * @author  Hans Lellelid <[email protected]>
36
 * @package phing.tasks.system
37
 */
38
class PhingTask extends Task
39
{
40
    use FileSetAware;
41
42
    /**
43
     * the basedir where is executed the build file
44
     * @var PhingFile
45
     */
46
    private $dir;
47
48
    /**
49
     * build.xml (can be absolute) in this case dir will be ignored
50
     */
51
    private $phingFile;
52
53
    /**
54
     * the target to call if any
55
     * @var Target
56
     */
57
    protected $newTarget;
58
59
    /**
60
     * should we inherit properties from the parent ?
61
     */
62
    private $inheritAll = true;
63
64
    /**
65
     * should we inherit references from the parent ?
66
     */
67
    private $inheritRefs = false;
68
69
    /**
70
     * the properties to pass to the new project
71
     */
72
    private $properties = [];
73
74
    /**
75
     * the references to pass to the new project
76
     */
77
    private $references = [];
78
79
    /**
80
     * The temporary project created to run the build file
81
     *
82
     * @var Project
83
     */
84
    private $newProject;
85
86
    /**
87
     * Fail the build process when the called build fails?
88
     */
89
    private $haltOnFailure = false;
90
91
    /**
92
     * Whether the basedir of the new project should be the same one
93
     * as it would be when running the build file directly -
94
     * independent of dir and/or inheritAll settings.
95
     */
96
    private $useNativeBasedir = false;
97
98
    /**
99
     * @var OutputStream
100
     */
101
    private $out;
102
103
    /** @var string */
104
    private $output;
105
106
    /**
107
     * @var array
108
     */
109
    private $locals;
110
111 28
    public function __construct(Task $owner = null)
112
    {
113 28
        if ($owner !== null) {
114 13
            $this->bindToOwner($owner);
115
        }
116 28
        parent::__construct();
117 28
    }
118
119
    /**
120
     *  If true, abort the build process if there is a problem with or in the target build file.
121
     *  Defaults to false.
122
     *
123
     * @param bool $hof new value
124
     */
125 14
    public function setHaltOnFailure($hof)
126
    {
127 14
        $this->haltOnFailure = (bool) $hof;
128 14
    }
129
130
    /**
131
     * Whether the basedir of the new project should be the same one
132
     * as it would be when running the build file directly -
133
     * independent of dir and/or inheritAll settings.
134
     *
135
     * @param bool $b
136
     */
137
    public function setUseNativeBasedir(bool $b)
138
    {
139
        $this->useNativeBasedir = $b;
140
    }
141
142
    /**
143
     * Creates a Project instance for the project to call.
144
     *
145
     * @return void
146
     */
147 28
    public function init()
148
    {
149 28
        $this->newProject = $this->getProject()->createSubProject();
150 28
        $tdf = $this->project->getTaskDefinitions();
151 28
        $this->newProject->addTaskDefinition("property", $tdf["property"]);
152 28
    }
153
154
    /**
155
     * Called in execute or createProperty if newProject is null.
156
     *
157
     * <p>This can happen if the same instance of this task is run
158
     * twice as newProject is set to null at the end of execute (to
159
     * save memory and help the GC).</p>
160
     *
161
     * <p>Sets all properties that have been defined as nested
162
     * property elements.</p>
163
     */
164 6
    private function reinit()
165
    {
166 6
        $this->init();
167
168 6
        $count = count($this->properties);
169 6
        for ($i = 0; $i < $count; $i++) {
170
            /**
171
             * @var PropertyTask $p
172
             */
173 6
            $p = $this->properties[$i] ?? null;
174 6
            if ($p !== null) {
175
                /** @var PropertyTask $newP */
176 6
                $newP = $this->newProject->createTask("property");
177 6
                $newP->setName($p->getName());
178 6
                if ($p->getValue() !== null) {
179 6
                    $newP->setValue($p->getValue());
180
                }
181 6
                if ($p->getFile() !== null) {
182
                    $newP->setFile($p->getFile());
183
                }
184 6
                if ($p->getPrefix() !== null) {
185
                    $newP->setPrefix($p->getPrefix());
186
                }
187 6
                if ($p->getRefid() !== null) {
188
                    $newP->setRefid($p->getRefid());
189
                }
190 6
                if ($p->getEnvironment() !== null) {
191
                    $newP->setEnvironment($p->getEnvironment());
192
                }
193 6
                if ($p->getUserProperty() !== null) {
194 6
                    $newP->setUserProperty($p->getUserProperty());
195
                }
196 6
                $newP->setOverride($p->getOverride());
197 6
                $newP->setLogoutput($p->getLogoutput());
198 6
                $newP->setQuiet($p->getQuiet());
199
200 6
                $this->properties[$i] = $newP;
201
            }
202
        }
203 6
    }
204
205
    /**
206
     * Main entry point for the task.
207
     *
208
     * @return void
209
     */
210 25
    public function main()
211
    {
212
        // Call Phing on the file set with the attribute "phingfile"
213 25
        if ($this->phingFile !== null || $this->dir !== null) {
214 25
            $this->processFile();
215
        }
216
217
        // if no filesets are given stop here; else process filesets
218 22
        if (!empty($this->filesets)) {
219
            // preserve old settings
220
            $savedDir = $this->dir;
221
            $savedPhingFile = $this->phingFile;
222
            $savedTarget = $this->newTarget;
223
224
            // set no specific target for files in filesets
225
            // [HL] I'm commenting this out; I don't know why this should not be supported!
226
            // $this->newTarget = null;
227
228
            foreach ($this->filesets as $fs) {
229
                $ds = $fs->getDirectoryScanner($this->project);
230
231
                $fromDir = $fs->getDir($this->project);
0 ignored issues
show
Unused Code introduced by
The assignment to $fromDir is dead and can be removed.
Loading history...
232
                $srcFiles = $ds->getIncludedFiles();
233
234
                foreach ($srcFiles as $fname) {
235
                    $f = new PhingFile($ds->getbasedir(), $fname);
236
                    $f = $f->getAbsoluteFile();
237
                    $this->phingFile = $f->getAbsolutePath();
238
                    $this->dir = $f->getParentFile();
239
                    $this->processFile(); // run Phing!
240
                }
241
            }
242
243
            // side effect free programming ;-)
244
            $this->dir = $savedDir;
245
            $this->phingFile = $savedPhingFile;
246
            $this->newTarget = $savedTarget;
247
248
            // [HL] change back to correct dir
249
            if ($this->dir !== null) {
250
                chdir($this->dir->getAbsolutePath());
251
            }
252
        }
253
254
        // Remove any dangling references to help the GC
255 22
        foreach ($this->properties as $property) {
256 12
            $property->setFallback(null);
257
        }
258 22
    }
259
260
    /**
261
     * Execute phing file.
262
     *
263
     * @throws BuildException
264
     */
265 25
    private function processFile(): void
266
    {
267 25
        $buildFailed = false;
268 25
        $savedDir = $this->dir;
269 25
        $savedPhingFile = $this->phingFile;
270 25
        $savedTarget = $this->newTarget;
271
272 25
        $savedBasedirAbsPath = null; // this is used to save the basedir *if* we change it
273
274
        try {
275 25
            $this->getNewProject();
276
277 25
            $this->initializeProject();
278
279 25
            if ($this->dir !== null) {
280 4
                if (!$this->useNativeBasedir) {
281 4
                    $this->newProject->setBasedir($this->dir);
282 4
                    if ($savedDir !== null) { // has been set explicitly
283 4
                        $this->newProject->setInheritedProperty('project.basedir', $this->dir->getAbsolutePath());
284
                    }
285
                }
286
            } else {
287
                // Since we're not changing the basedir here (for file resolution),
288
                // we don't need to worry about any side-effects in this scanrio.
289 22
                $this->dir = $this->getProject()->getBasedir();
290
            }
291
292 25
            $this->overrideProperties();
293 25
            $this->phingFile = $this->phingFile ?? 'build.xml';
294
295 25
            $fu = new FileUtils();
296 25
            $file = $fu->resolveFile($this->dir, $this->phingFile);
297 25
            $this->phingFile = $file->getAbsolutePath();
298 25
            $this->log('calling target(s) '
299 25
                . (empty($this->locals) ? '[default]' : implode(', ', $this->locals))
300 25
                . ' in build file ' . $this->phingFile, Project::MSG_VERBOSE);
301
302 25
            $this->newProject->setUserProperty("phing.file", $this->phingFile);
303
304 25
            if (empty($this->locals)) {
305 25
                $defaultTarget = $this->newProject->getDefaultTarget();
306 25
                if ($defaultTarget !== null) {
0 ignored issues
show
introduced by
The condition $defaultTarget !== null is always true.
Loading history...
307 25
                    $this->locals[] = $defaultTarget;
308
                }
309
            }
310
311 25
            $thisPhingFile = $this->getProject()->getProperty('phing.file');
312
            // Are we trying to call the target in which we are defined (or
313
            // the build file if this is a top level task)?
314
            if (
315 25
                $thisPhingFile !== null
316 25
                && $this->getOwningTarget() !== null
317 25
                && $thisPhingFile === $file->getPath()
318 17
                && $this->getOwningTarget()->getName() === ''
319
            ) {
320
                if ('phingcall' === $this->getTaskName()) {
321
                    throw new BuildException('phingcall must not be used at the top level.');
322
                }
323
                throw new BuildException(
324
                    '%s task at the top level must not invoke its own build file.',
325
                    $this->getTaskName()
0 ignored issues
show
Bug introduced by
$this->getTaskName() of type string is incompatible with the type Exception|Location|null expected by parameter $p2 of BuildException::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

325
                    /** @scrutinizer ignore-type */ $this->getTaskName()
Loading history...
326
                );
327
            }
328
329 25
            ProjectConfigurator::configureProject($this->newProject, new PhingFile($this->phingFile));
330
331 24
            if ($this->newTarget === null) {
332
                $this->newTarget = $this->newProject->getDefaultTarget();
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->newProject->getDefaultTarget() of type string is incompatible with the declared type Target of property $newTarget.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
333
            }
334
335
            // Are we trying to call the target in which we are defined?
336
            if (
337 24
                $this->newProject->getBasedir()->equals($this->project->getBasedir())
338 20
                && $this->newProject->getProperty('phing.file') === $this->project->getProperty('phing.file')
339 17
                && $this->getOwningTarget() !== null
340
            ) {
341 17
                $owningTargetName = $this->getOwningTarget()->getName();
342 17
                if ($this->newTarget === $owningTargetName) {
343 2
                    throw new BuildException(
344 2
                        sprintf(
345 2
                            "%s task calling its own parent target",
346 2
                            $this->getTaskName()
347
                        )
348
                    );
349
                }
350
351 15
                $targets = $this->getProject()->getTargets();
352 15
                $taskName = $this->getTaskName();
353
354 15
                foreach ($this->locals as $local) {
355 15
                    if (isset($targets[$local])) {
356 7
                        if ($targets[$local]->dependsOn($owningTargetName)) {
357
                            throw new BuildException(
358
                                sprintf(
359
                                    "%s task calling a target that depends on its parent target '%s'.",
360
                                    $taskName,
361
                                    $owningTargetName
362
                                )
363
                            );
364
                        }
365
                    }
366
                }
367
            }
368
369 22
            $this->addReferences();
370 22
            $this->newProject->executeTarget($this->newTarget);
371 4
        } catch (Exception $e) {
372 4
            $buildFailed = true;
373 4
            $this->log($e->getMessage(), Project::MSG_ERR);
374 4
            if (Phing::getMsgOutputLevel() <= Project::MSG_DEBUG) {
375 4
                $lines = explode("\n", $e->getTraceAsString());
376 4
                foreach ($lines as $line) {
377 4
                    $this->log($line, Project::MSG_DEBUG);
378
                }
379
            }
380 22
        } finally {
381
            // reset environment values to prevent side-effects.
382
383 25
            $this->newProject = null;
384 25
            $pkeys = array_keys($this->properties);
385 25
            foreach ($pkeys as $k) {
386 12
                $this->properties[$k]->setProject(null);
387
            }
388
389 25
            if ($this->output !== null && $this->out !== null) {
390 1
                $this->out->close();
391
            }
392
393 25
            $this->dir = $savedDir;
394 25
            $this->phingFile = $savedPhingFile;
395 25
            $this->newTarget = $savedTarget;
396
397
            // If the basedir for any project was changed, we need to set that back here.
398 25
            if ($savedBasedirAbsPath !== null) {
0 ignored issues
show
introduced by
The condition $savedBasedirAbsPath !== null is always false.
Loading history...
399
                chdir($savedBasedirAbsPath);
400
            }
401
402 25
            if ($this->haltOnFailure && $buildFailed) {
403 25
                throw new BuildException('Execution of the target buildfile failed. Aborting.');
404
            }
405
        }
406 22
    }
407
408
    /**
409
     * Get the (sub)-Project instance currently in use.
410
     *
411
     * @return Project
412
     */
413 25
    protected function getNewProject(): \Project
414
    {
415 25
        if ($this->newProject === null) {
416 6
            $this->reinit();
417
        }
418 25
        return $this->newProject;
419
    }
420
421
    /**
422
     * Configure the Project, i.e. make intance, attach build listeners
423
     * (copy from father project), add Task and Datatype definitions,
424
     * copy properties and references from old project if these options
425
     * are set via the attributes of the XML tag.
426
     *
427
     * Developer note:
428
     * This function replaces the old methods "init", "_reinit" and
429
     * "_initializeProject".
430
     */
431 25
    private function initializeProject()
432
    {
433 25
        $this->newProject->setInputHandler($this->project->getInputHandler());
434
435 25
        foreach ($this->project->getBuildListeners() as $listener) {
436 25
            $this->newProject->addBuildListener($listener);
437
        }
438
439
        /* Copy things from old project. Datatypes and Tasks are always
440
         * copied, properties and references only if specified so/not
441
         * specified otherwise in the XML definition.
442
         */
443
        // Add Datatype definitions
444 25
        foreach ($this->project->getDataTypeDefinitions() as $typeName => $typeClass) {
445 25
            $this->newProject->addDataTypeDefinition($typeName, $typeClass);
446
        }
447
448
        // Add Task definitions
449 25
        foreach ($this->project->getTaskDefinitions() as $taskName => $taskClass) {
450 25
            if ($taskClass === 'phing.tasks.system.PropertyTask') {
451
                // we have already added this taskdef in init()
452 25
                continue;
453
            }
454 25
            $this->newProject->addTaskDefinition($taskName, $taskClass);
455
        }
456
457 25
        if ($this->output !== null) {
458
            try {
459 1
                if ($this->dir !== null) {
460 1
                    $outfile = (new FileUtils())->resolveFile($this->dir, $this->output);
461
                } else {
462 1
                    $outfile = $this->getProject()->resolveFile($this->output);
463
                }
464 1
                $this->out = new FileOutputStream($outfile);
465 1
                $logger = new DefaultLogger();
466 1
                $logger->setMessageOutputLevel(Project::MSG_INFO);
467 1
                $logger->setOutputStream($this->out);
468 1
                $logger->setErrorStream($this->out);
469 1
                $this->newProject->addBuildListener($logger);
470
            } catch (Exception $ex) {
471
                $this->log("Phing: Can't set output to " . $this->output);
472
            }
473
        }
474
475 25
        if ($this->useNativeBasedir) {
476
            $this->addAlmostAll($this->getProject()->getUserProperties(), 'user');
477
        } else {
478 25
            $this->project->copyUserProperties($this->newProject);
479
        }
480
481 25
        if (!$this->inheritAll) {
482
            // set System built-in properties separately,
483
            // b/c we won't inherit them.
484 13
            $this->newProject->setSystemProperties();
485
        } else {
486 13
            $this->addAlmostAll($this->getProject()->getProperties(), 'plain');
487
        }
488 25
    }
489
490
    /**
491
     * Copies all properties from the given table to the new project -
492
     * omitting those that have already been set in the new project as
493
     * well as properties named basedir or phing.file.
494
     * @param array $props properties <code>Hashtable</code> to copy to the
495
     * new project.
496
     * @param string $type the type of property to set (a plain Phing property, a
497
     * user property or an inherited property).
498
     */
499 13
    private function addAlmostAll(array $props, string $type): void
500
    {
501 13
        foreach ($props as $name => $value) {
502 13
            if ($name === 'basedir' || $name === 'phing.file' || $name === 'phing.version') {
503
                // basedir and phing.file get special treatment in main()
504 13
                continue;
505
            }
506 13
            if ($type === 'plain') {
507
                // don't re-set user properties, avoid the warning message
508 13
                if ($this->newProject->getProperty($name) === null) {
509
                    // no user property
510 13
                    $this->newProject->setNewProperty($name, $value);
511
                }
512
            } elseif ($type === 'user') {
513
                $this->newProject->setUserProperty($name, $value);
514
            } elseif ($type === 'inherited') {
515
                $this->newProject->setInheritedProperty($name, $value);
516
            }
517
        }
518 13
    }
519
520
    /**
521
     * Override the properties in the new project with the one
522
     * explicitly defined as nested elements here.
523
     *
524
     * @return void
525
     * @throws BuildException
526
     */
527 25
    private function overrideProperties()
528
    {
529
        // remove duplicate properties - last property wins
530 25
        $properties = array_reverse($this->properties);
531 25
        $set = [];
532 25
        foreach ($properties as $i => $p) {
533 12
            if ($p->getName() !== null && $p->getName() !== '') {
534 12
                if (in_array($p->getName(), $set)) {
535 7
                    unset($this->properties[$i]);
536
                } else {
537 12
                    $set[] = $p->getName();
538
                }
539
            }
540 12
            $p->setProject($this->newProject);
541 12
            $p->main();
542
        }
543 25
        if ($this->useNativeBasedir) {
544
            $this->addAlmostAll($this->getProject()->getInheritedProperties(), 'inherited');
545
        } else {
546 25
            $this->project->copyInheritedProperties($this->newProject);
547
        }
548 25
    }
549
550
    /**
551
     * Add the references explicitly defined as nested elements to the
552
     * new project.  Also copy over all references that don't override
553
     * existing references in the new project if inheritrefs has been
554
     * requested.
555
     *
556
     * @return void
557
     * @throws BuildException
558
     */
559 22
    private function addReferences()
560
    {
561
562
        // parent project references
563 22
        $projReferences = $this->project->getReferences();
564
565 22
        $newReferences = $this->newProject->getReferences();
566
567 22
        $subprojRefKeys = [];
568
569 22
        if (count($this->references) > 0) {
570
            for ($i = 0, $count = count($this->references); $i < $count; $i++) {
571
                /** @var Reference $ref */
572
                $ref = $this->references[$i];
573
                $refid = $ref->getRefId();
574
575
                if ($refid === null) {
576
                    throw new BuildException('the refid attribute is required for reference elements');
577
                }
578
                if (!isset($projReferences[$refid])) {
579
                    $this->log("Parent project doesn't contain any reference '" . $refid . "'", Project::MSG_WARN);
580
                    continue;
581
                }
582
583
                $subprojRefKeys[] = $refid;
584
                unset($this->references[$i]);//thisReferences.remove(refid);
585
                $toRefid = $ref->getToRefid();
0 ignored issues
show
Bug introduced by
The method getToRefid() does not exist on Reference. Did you maybe mean getRefId()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

585
                /** @scrutinizer ignore-call */ 
586
                $toRefid = $ref->getToRefid();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
586
                if ($toRefid === null) {
587
                    $toRefid = $refid;
588
                }
589
                $this->copyReference($refid, $toRefid);
590
            }
591
        }
592
593
        // Now add all references that are not defined in the
594
        // subproject, if inheritRefs is true
595 22
        if ($this->inheritRefs) {
596
            // get the keys that are were not used by the subproject
597 2
            $unusedRefKeys = array_diff(array_keys($projReferences), $subprojRefKeys);
598
599 2
            foreach ($unusedRefKeys as $key) {
600 2
                if (isset($newReferences[$key])) {
601 2
                    continue;
602
                }
603 2
                $this->copyReference($key, $key);
604
            }
605
        }
606 22
    }
607
608
    /**
609
     * Try to clone and reconfigure the object referenced by oldkey in
610
     * the parent project and add it to the new project with the key
611
     * newkey.
612
     *
613
     * <p>If we cannot clone it, copy the referenced object itself and
614
     * keep our fingers crossed.</p>
615
     *
616
     * @param  string $oldKey
617
     * @param  string $newKey
618
     * @throws BuildException
619
     * @return void
620
     */
621 2
    private function copyReference($oldKey, $newKey)
622
    {
623 2
        $orig = $this->project->getReference($oldKey);
624 2
        if ($orig === null) {
625
            $this->log(
626
                "No object referenced by " . $oldKey . ". Can't copy to "
627
                . $newKey,
628
                Project::MSG_WARN
629
            );
630
631
            return;
632
        }
633
634 2
        $copy = clone $orig;
635
636 2
        if ($copy instanceof ProjectComponent) {
637 2
            $copy->setProject($this->newProject);
638 2
        } elseif (in_array('setProject', get_class_methods(get_class($copy)))) {
639
            $copy->setProject($this->newProject);
640 2
        } elseif (!($copy instanceof Project)) {
641
            // don't copy the old "Project" itself
642
            $msg = "Error setting new project instance for "
643
                . "reference with id " . $oldKey;
644
            throw new BuildException($msg);
645
        }
646
647 2
        $this->newProject->addReference($newKey, $copy);
648 2
    }
649
650
    /**
651
     * If true, pass all properties to the new phing project.
652
     * Defaults to true.
653
     *
654
     * @param $value
655
     */
656 20
    public function setInheritAll($value)
657
    {
658 20
        $this->inheritAll = (bool) $value;
659 20
    }
660
661
    /**
662
     * If true, pass all references to the new phing project.
663
     * Defaults to false.
664
     *
665
     * @param $value
666
     */
667 12
    public function setInheritRefs($value)
668
    {
669 12
        $this->inheritRefs = (bool) $value;
670 12
    }
671
672
    /**
673
     * The directory to use as a base directory for the new phing project.
674
     * Defaults to the current project's basedir, unless inheritall
675
     * has been set to false, in which case it doesn't have a default
676
     * value. This will override the basedir setting of the called project.
677
     *
678
     * @param PhingFile $d
679
     */
680 4
    public function setDir(PhingFile $d): void
681
    {
682 4
        $this->dir = $d;
683 4
    }
684
685
    /**
686
     * The build file to use.
687
     * Defaults to "build.xml". This file is expected to be a filename relative
688
     * to the dir attribute given.
689
     *
690
     * @param $s
691
     */
692 25
    public function setPhingFile($s)
693
    {
694
        // it is a string and not a file to handle relative/absolute
695
        // otherwise a relative file will be resolved based on the current
696
        // basedir.
697 25
        $this->phingFile = $s;
698 25
    }
699
700
    /**
701
     * Alias function for setPhingfile
702
     *
703
     * @param $s
704
     */
705
    public function setBuildfile($s)
706
    {
707
        $this->setPhingFile($s);
708
    }
709
710
    /**
711
     * The target of the new Phing project to execute.
712
     * Defaults to the new project's default target.
713
     *
714
     * @param string $s
715
     */
716 26
    public function setTarget(string $s)
717
    {
718 26
        if ('' === $s) {
719 1
            throw new BuildException("target attribute must not be empty");
720
        }
721
722 25
        $this->newTarget = $s;
0 ignored issues
show
Documentation Bug introduced by
It seems like $s of type string is incompatible with the declared type Target of property $newTarget.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
723 25
    }
724
725
    /**
726
     * Set the filename to write the output to. This is relative to the value
727
     * of the dir attribute if it has been set or to the base directory of the
728
     * current project otherwise.
729
     * @param string $outputFile the name of the file to which the output should go.
730
     */
731 1
    public function setOutput(string $outputFile): void
732
    {
733 1
        $this->output = $outputFile;
734 1
    }
735
736
    /**
737
     * Property to pass to the new project.
738
     * The property is passed as a 'user property'
739
     */
740 12
    public function createProperty()
741
    {
742 12
        $p = new PropertyTask();
743 12
        $p->setFallback($this->getNewProject());
744 12
        $p->setUserProperty(true);
745 12
        $p->setTaskName('property');
746 12
        $this->properties[] = $p;
747
748 12
        return $p;
749
    }
750
751
    /**
752
     * Reference element identifying a data type to carry
753
     * over to the new project.
754
     *
755
     * @param PhingReference $ref
756
     */
757 1
    public function addReference(PhingReference $ref)
758
    {
759 1
        $this->references[] = $ref;
760 1
    }
761
}
762