My favorites | Sign in
Project Logo
          
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
Index: test/run-tests.php
===================================================================
--- test/run-tests.php (revision 365)
+++ test/run-tests.php (working copy)
@@ -69,6 +71,8 @@
$tasksSuite->addTestSuite(new ReflectionClass('PropertyTaskTest'));


+include_once 'phing/tasks/ImportTaskTest.php';
+$tasksSuite->addTestSuite(new ReflectionClass('ImportTaskTest'));

$suite = new PHPUnit2_Framework_TestSuite('Phing Tests');
$suite->addTest($coreSuite);
Index: test/etc/tasks/imports/imported.xml
===================================================================
--- test/etc/tasks/imports/imported.xml (revision 0)
+++ test/etc/tasks/imports/imported.xml (revision 0)
@@ -0,0 +1,27 @@
+<?xml version="1.0"?>
+<project name="imported" default="" basedir=".">
+
+ <php function="dirname" returnProperty="imported.basedir">
+ <param value="${phing.file.imported}"/>
+ </php>
+ <property file="${imported.basedir}/imported.properties"/>
+
+ <target name="main">
+ <echo>${imported.echo}</echo>
+ <echo>This is ${phing.file.imported} main target.</echo>
+ </target>
+
+ <target name="imported">
+ <echo>phing.file.imported=${phing.file.imported}</echo>
+ <echo>imported.basedir=${imported.basedir}</echo>
+ </target>
+
+ <target name="flip" depends="flop">
+ <echo>This is ${phing.file.imported} flip target.</echo>
+ </target>
+ <target name="flop">
+ <echo>This is ${phing.file.imported} flop target.</echo>
+ </target>
+
+ <import file="imports/importedImport.xml"/>
+</project>

Property changes on: test/etc/tasks/imports/imported.xml
___________________________________________________________________
Name: svn:keywords
+ Id Author Date Revision HeadURL

Index: test/etc/tasks/imports/importedImport.xml
===================================================================
--- test/etc/tasks/imports/importedImport.xml (revision 0)
+++ test/etc/tasks/imports/importedImport.xml (revision 0)
@@ -0,0 +1,12 @@
+<?xml version="1.0"?>
+<project name="imported2" default="" basedir=".">
+
+ <target name="imported2">
+ <echo>This is ${phing.file.imported2} imported2 target.</echo>
+ </target>
+
+ <target name="main">
+ <echo>This is ${phing.file.imported2} main target.</echo>
+ </target>
+</project>
+

Property changes on: test/etc/tasks/imports/importedImport.xml
___________________________________________________________________
Name: svn:keywords
+ Id Author Date Revision HeadURL

Index: test/etc/tasks/imports/imported.properties
===================================================================
--- test/etc/tasks/imports/imported.properties (revision 0)
+++ test/etc/tasks/imports/imported.properties (revision 0)
@@ -0,0 +1 @@
+imported.echo=This comes from the imported.properties file
Index: test/etc/tasks/importing.xml
===================================================================
--- test/etc/tasks/importing.xml (revision 0)
+++ test/etc/tasks/importing.xml (revision 0)
@@ -0,0 +1,20 @@
+<?xml version="1.0"?>
+<project name="importing" default="" basedir=".">
+
+ <import file="imports/imported.xml"/>
+
+ <target name="main">
+ <echo>This is ${phing.file} main target.</echo>
+ </target>
+
+ <target name="cascade" depends="imported.main">
+ <echo>This is ${phing.file} cascade target.</echo>
+ </target>
+
+ <target name="flipflop" depends="flip">
+ <echo>This is ${phing.file} flipflop target.</echo>
+ </target>
+ <target name="flop">
+ <echo>This is ${phing.file} flop target.</echo>
+ </target>
+</project>
Index: test/classes/phing/tasks/ImportTaskTest.php
===================================================================
--- test/classes/phing/tasks/ImportTaskTest.php (revision 0)
+++ test/classes/phing/tasks/ImportTaskTest.php (revision 0)
@@ -0,0 +1,66 @@
+<?php
+
+/*
+ * $Id$
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * and is licensed under the LGPL. For more information please see
+ * <http://phing.info>.
+ */
+
+require_once 'phing/BuildFileTest.php';
+
+/**
+ * @author Bryan Davis <bender@casadebender.com>
+ */
+class ImportTaskTest extends BuildFileTest {
+
+ public function setUp() {
+ $this->configureProject(PHING_TEST_BASE . "/etc/tasks/importing.xml");
+ }
+
+ public function testOverloadedTarget () {
+ $this->executeTarget("main");
+ $this->assertInLogs("This is " . PHING_TEST_BASE . "/etc/tasks/importing.xml main target.");
+ }
+
+ public function testImportedTarget () {
+ $this->executeTarget("imported");
+ $this->assertInLogs("phing.file.imported=" . PHING_TEST_BASE . "/etc/tasks/imports/imported.xml");
+ $this->assertInLogs("imported.basedir=" . PHING_TEST_BASE . "/etc/tasks/imports");
+ }
+
+ public function testImported2Target () {
+ $this->executeTarget("imported2");
+ $this->assertInLogs("This is " . PHING_TEST_BASE . "/etc/tasks/imports/importedImport.xml imported2 target.");
+ }
+
+ public function testCascadeTarget () {
+ $this->executeTarget("cascade");
+ $this->assertInLogs("This comes from the imported.properties file");
+ $this->assertInLogs("This is " . PHING_TEST_BASE . "/etc/tasks/imports/imported.xml main target.");
+ $this->assertInLogs("This is " . PHING_TEST_BASE . "/etc/tasks/importing.xml cascade target.");
+ }
+
+ public function testFlipFlopTarget () {
+ // calls target in main that depends on target in import that depends on
+ // target orverridden in main
+ $this->executeTarget("flipflop");
+ $this->assertInLogs("This is " . PHING_TEST_BASE . "/etc/tasks/importing.xml flop target.");
+ $this->assertInLogs("This is " . PHING_TEST_BASE . "/etc/tasks/imports/imported.xml flip target.");
+ $this->assertInLogs("This is " . PHING_TEST_BASE . "/etc/tasks/importing.xml flipflop target.");
+
+ }
+}
Index: docs/phing_guide/book/chapters/appendixes/AppendixB-CoreTasks.html
===================================================================
--- docs/phing_guide/book/chapters/appendixes/AppendixB-CoreTasks.html (revision 365)
+++ docs/phing_guide/book/chapters/appendixes/AppendixB-CoreTasks.html (working copy)
@@ -901,6 +901,90 @@
&lt;/if&gt;
</pre>

+<h2><a name="ImportTask"></a>ImportTask</h2>
+<p>Imports another build file into the current project.</p>
+<p>On execution it will read another Phing file into the same Project.
+Functionally it is nearly the same as copy and pasting the imported file onto
+the end of the importing file.</p>
+<h3>Target Overriding</h3>
+<p>If a target in the main file is also present in at least one of the imported files, the one from the main file takes precedence.</p>
+
+<p>So if I import for example a <em>docs/build.xml</em> file named
+<strong>builddocs</strong>, that contains a "<strong>docs</strong>" target, I
+can redefine it in my main buildfile and that is the one that will be called.
+This makes it easy to keep the same target name, so that the overriding target
+is still called by any other targets--in either the main or imported
+buildfile(s)--for which it is a dependency, with a different implementation.
+The target from <em>docs/build.xml</em> is made available by the name
+"<strong>builddocs.docs</strong>". This enables the new implementation to call
+the old target, thus enhancing it with tasks called before or after it.</p>
+<h3>Special Properties</h3>
+<p>Imported files are treated as they are present in the main buildfile. This makes it easy to understand, but it makes it impossible for them to reference files and resources relative to their path. Because of this, for every imported file, Phing adds a property that contains the path to the imported buildfile. With this path, the imported buildfile can keep resources and be able to reference them relative to its position.</p>
+
+<p>So if I import for example a <em>docs/build.xml</em> file named <strong>builddocs</strong>, I can get its path as <strong>phing.file.builddocs</strong>, similarly to the <strong>phing.file</strong> property of the main buildfile.</p>
+
+<p>Note that "builddocs" is not the filename, but the name attribute present in the imported project tag.</p>
+
+<p>If import file does not have a name attribute, the phing.file.projectname property will not be set.</p>
+<h3>Resolving Files Against the Imported File</h3>
+<p>Suppose your main build file called <code>importing.xml</code> imports a build file <code>imported.xml</code>, located anywhere on the file system, and <code>imported.xml</code> reads a set of properties from <code>imported.properties</code>:
+<pre>
+&lt;!-- importing.xml --&gt;
+&lt;project name=&quot;importing&quot; basedir=&quot;.&quot; default=&quot;...&quot;&gt;
+ &lt;import file=&quot;${path_to_imported}/imported.xml&quot;/&gt;
+&lt;/project&gt;
+
+&lt;!-- imported.xml --&gt;
+&lt;project name=&quot;imported&quot; basedir=&quot;.&quot; default=&quot;...&quot;&gt;
+ &lt;property file=&quot;imported.properties&quot;/&gt;
+&lt;/project&gt;
+</pre>
+
+<p>This snippet however will resolve <code>imported.properties</code> against the basedir of <code>importing.xml</code>, because the basedir of <code>imported.xml</code> is ignored by Phing. The right way to use <code>imported.properties</code> is:
+<pre>
+&lt;!-- imported.xml --&gt;
+&lt;project name=&quot;imported&quot; basedir=&quot;.&quot; default=&quot;...&quot;&gt;
+ &lt;php function=&quot;dirname&quot; returnProperty=&quot;imported.basedir&quot;&gt;
+ &lt;param value=&quot;${phing.file.imported}&quot;/&gt;
+ &lt;/php&gt;
+ &lt;property file=&quot;${imported.basedir}/imported.properties&quot;/&gt;
+&lt;/project&gt;
+</pre>
+<p>As explained above <code>${phing.file.imported}</code> stores the path of the build script, that defines the project called <strong>imported</strong>, (in short it stores the path to <em>imported.xml</em>) and &lt;php function="dirname"&gt; takes its directory. This technique also allows <em>imported.xml</em> to be used as a standalone file (without being imported in other project).</p>
+<h3>Example</h3>
+<pre>
+&lt;import file=&quot;path/to/build.xml&quot;/&gt;
+&lt;import file=&quot;path/to/build.xml&quot; optional=&quot;true&quot;/&gt;
+</pre>
+<h3>Attributes</h3>
+<table>
+ <thead>
+ <tr>
+ <th>Name</th>
+ <th>Type</th>
+ <th>Description</th>
+ <th>Default</th>
+ <th>Required</th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr>
+ <td>file</td>
+ <td>String</td>
+ <td>The file to import.</td>
+ <td>n/a</td>
+ <td>Yes</td>
+ </tr>
+ <tr>
+ <td>optional</td>
+ <td>Boolean</td>
+ <td>If true, do not stop the build if the file does not exist.</td>
+ <td>false</td>
+ <td>No</td>
+ </tr>
+ </tbody>
+</table>
+
<h2><a name="IncludePathTask"></a>IncludePathTask</h2>
<p>Sets the PHP include_path configuration option for the duration of this phing run.</p>
<h3>Example</h3>
Index: classes/phing/tasks/defaults.properties
===================================================================
--- classes/phing/tasks/defaults.properties (revision 365)
+++ classes/phing/tasks/defaults.properties (working copy)
@@ -40,6 +40,7 @@
xslt=phing.tasks.system.XsltTask
if=phing.tasks.system.IfTask
warn=phing.tasks.system.WarnTask
+import=phing.tasks.system.ImportTask

; "Core" contributed tasks
; -- i.e. no taskdef needed.
Index: classes/phing/tasks/system/ImportTask.php
===================================================================
--- classes/phing/tasks/system/ImportTask.php (revision 0)
+++ classes/phing/tasks/system/ImportTask.php (revision 0)
@@ -0,0 +1,133 @@
+<?php
+/*
+ * $Id$
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * and is licensed under the LGPL. For more information please see
+ * <http://phing.info>.
+ */
+
+require_once 'phing/Task.php';
+require_once 'phing/system/io/FileSystem.php';
+require_once 'phing/system/io/PhingFile.php';
+require_once 'phing/parser/ProjectConfigurator.php';
+
+/**
+ * Imports another build file into the current project.
+ *
+ * Targets and properties of the imported file can be overrridden
+ * by targets and properties of the same name declared in the importing file.
+ *
+ * The imported file will have a new synthetic property of
+ * "phing.file.<projectname>" declared which gives the full path to the
+ * imported file. Additionally each target in the imported file will be
+ * declared twice: once with the normal name and once with "<projectname>."
+ * prepended. The "<projectname>.<targetname>" synthetic targets allow the
+ * importing file a mechanism to call the imported files targets as
+ * dependencies or via the <phing> or <phingcall> task mechanisms.
+ *
+ * @author Bryan Davis <bender@casadebender.com>
+ * @version $Revision$
+ * @package phing.tasks.system
+ */
+class ImportTask extends Task {
+
+ /**
+ * @var FileSystem
+ */
+ protected $fs;
+
+ /**
+ * @var PhingFile
+ */
+ protected $file = null;
+
+ /**
+ * @var bool
+ */
+ protected $optional = false;
+
+ /**
+ * Initialize task.
+ * @return void
+ */
+ public function init () {
+ $this->fs = FileSystem::getFileSystem();
+ } //end init
+
+
+ /**
+ * Set the file to import.
+ * @param string $f Path to file
+ * @return void
+ */
+ public function setFile ($f) {
+ $this->file = $f;
+ }
+
+ /**
+ * Is this include optional?
+ * @param bool $opt If true, do not stop the build if the file does not
+ * exist
+ * @return void
+ */
+ public function setOptional ($opt) {
+ $this->optional = $opt;
+ }
+
+ /**
+ * Parse a Phing build file and copy the properties, tasks, data types and
+ * targets it defines into the current project.
+ *
+ * @return void
+ */
+ public function main () {
+ if (!isset($this->file)) {
+ throw new BuildException("Missing attribute 'file'");
+ }
+
+ $base = $this->project->getBasedir();
+ $file = new PhingFile($this->project->getBasedir(), $this->file);
+ if (!$file->exists()) {
+ $msg = "Unable to find build file: {$this->file->getName()}";
+ if ($this->optional) {
+ $this->log($msg . '... skipped');
+ } else {
+ throw new BuildException($msg);
+ }
+ }
+
+ $ctx = $this->project->getReference("phing.parsing.context");
+ $cfg = $ctx->getConfigurator();
+ if (null !== $cfg && $cfg->isParsing()) {
+ // because there isn't a top level implicit target in phing like there is
+ // in Ant 1.6, we will be called as soon as our xml is parsed. This isn't
+ // really what we want to have happen. Instead we will register ourself
+ // with the parse context to be called at the end of the current file's
+ // parse phase.
+ $cfg->delayTaskUntilParseEnd($this);
+
+ } else {
+ // Import xml file into current project scope
+ // Since this is delayed until after the importing file has been
+ // processed, the properties and targets of this new file may not take
+ // effect if they have alreday been defined in the outer scope.
+ $this->log("Importing configuration from {$file->getName()}", Project::MSG_VERBOSE);
+ ProjectConfigurator::configureProject($this->project, $file);
+ $this->log("Configuration imported.", Project::MSG_VERBOSE);
+ }
+ } //end main
+
+} //end ImportTask
Index: classes/phing/parser/ProjectConfigurator.php
===================================================================
--- classes/phing/parser/ProjectConfigurator.php (revision 365)
+++ classes/phing/parser/ProjectConfigurator.php (working copy)
@@ -24,6 +24,8 @@
include_once 'phing/BuildException.php';
include_once 'phing/system/lang/FileNotFoundException.php';
include_once 'phing/system/io/PhingFile.php';
+include_once 'phing/parser/PhingXMLContext.php';
+include_once 'phing/IntrospectionHelper.php';

/**
* The datatype handler class.
@@ -44,8 +46,25 @@

public $buildFile;
public $buildFileParent;
-
+
+ /** Targets in current file */
+ private $currentTargets;
+
+ /** Synthetic target that will be called at the end to the parse phase */
+ private $parseEndTarget;
+
+ /** Name of the current project */
+ private $currentProjectName;
+
+ private $isParsing = true;
+
/**
+ * Indicates whether the project tag attributes are to be ignored
+ * when processing a particular build file.
+ */
+ private $ignoreProjectTag = false;
+
+ /**
* Static call to ProjectConfigurator. Use this to configure a
* project. Do not use the new operator.
*
@@ -71,9 +90,67 @@
$this->project = $project;
$this->buildFile = new PhingFile($buildFile->getAbsolutePath());
$this->buildFileParent = new PhingFile($this->buildFile->getParent());
+ $this->currentTargets = array();
+ $this->parseEndTarget = new Target();
}

/**
+ * find out the build file
+ * @return the build file to which the xml context belongs
+ */
+ public function getBuildFile() {
+ return $this->buildFile;
+ }
+
+ /**
+ * find out the parent build file of this build file
+ * @return the parent build file of this build file
+ */
+ public function getBuildFileParent() {
+ return $this->buildFileParent;
+ }
+
+ /**
+ * find out the current project name
+ * @return current project name
+ */
+ public function getCurrentProjectName() {
+ return $this->currentProjectName;
+ }
+
+ /**
+ * set the name of the current project
+ * @param name name of the current project
+ */
+ public function setCurrentProjectName($name) {
+ $this->currentProjectName = $name;
+ }
+
+ /**
+ * tells whether the project tag is being ignored
+ * @return whether the project tag is being ignored
+ */
+ public function isIgnoringProjectTag() {
+ return $this->ignoreProjectTag;
+ }
+
+ /**
+ * sets the flag to ignore the project tag
+ * @param flag to ignore the project tag
+ */
+ public function setIgnoreProjectTag($flag) {
+ $this->ignoreProjectTag = $flag;
+ }
+
+ public function &getCurrentTargets () {
+ return $this->currentTargets;
+ }
+
+ public function isParsing () {
+ return $this->isParsing;
+ }
+
+ /**
* Creates the ExpatParser, sets root handler and kick off parsing
* process.
*
@@ -82,7 +159,26 @@
* @access private
*/
protected function parse() {
- try {
+ try {
+ // get parse context
+ $ctx = $this->project->getReference("phing.parsing.context");
+ if (null == $ctx) {
+ // make a new context and register it with project
+ $ctx = new PhingXMLContext($this->project);
+ $this->project->addReference("phing.parsing.context", $ctx);
+ }
+
+ //record this parse with context
+ $ctx->addImport($this->buildFile);
+
+ if (count($ctx->getImportStack()) > 1) {
+ // this is an imported file
+ // modify project tag parse behavior
+ $this->setIgnoreProjectTag(true);
+ }
+ // push action onto global stack
+ $ctx->startConfigure($this);
+
$reader = new BufferedReader(new FileReader($this->buildFile));
$parser = new ExpatParser($reader);
$parser->parserSetOption(XML_OPTION_CASE_FOLDING,0);
@@ -90,12 +186,29 @@
$this->project->log("parsing buildfile ".$this->buildFile->getName(), Project::MSG_VERBOSE);
$parser->parse();
$reader->close();
+
+ // mark parse phase as completed
+ $this->isParsing = false;
+ // execute delayed tasks
+ $this->parseEndTarget->main();
+ // pop this action from the global stack
+ $ctx->endConfigure();
} catch (Exception $exc) {
throw new BuildException("Error reading project file", $exc);
}
}

/**
+ * Delay execution of a task until after the current parse phase has
+ * completed.
+ *
+ * @param Task $task Task to execute after parse
+ */
+ public function delayTaskUntilParseEnd ($task) {
+ $this->parseEndTarget->addTask($task);
+ }
+
+ /**
* Configures an element and resolves eventually given properties.
*
* @param object the element to configure
Index: classes/phing/parser/PhingXMLContext.php
===================================================================
--- classes/phing/parser/PhingXMLContext.php (revision 0)
+++ classes/phing/parser/PhingXMLContext.php (revision 0)
@@ -0,0 +1,81 @@
+<?php
+/*
+ * $Id$
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * and is licensed under the LGPL. For more information please see
+ * <http://phing.info>.
+ */
+
+/**
+ * Track the current state of the Xml parse operation.
+ *
+ * @author Bryan Davis <bender@casadebender.com>
+ * @version $Revision$ $Date$
+ * @access public
+ * @package phing.parser
+ */
+class PhingXMLContext {
+
+ /**
+ * Constructor
+ * @param $project the project to which this antxml context belongs to
+ */
+ public function __construct ($project) {
+ $this->project = $project;
+ }
+
+ /** The project to configure. */
+ private $project;
+
+ private $configurators = array();
+
+ public function startConfigure ($cfg) {
+ $this->configurators[] = $cfg;
+ }
+
+ public function endConfigure () {
+ array_pop($this->configurators);
+ }
+
+ public function getConfigurator () {
+ $l = count($this->configurators);
+ if (0 == $l) {
+ return null;
+ } else {
+ return $this->configurators[$l - 1];
+ }
+ }
+
+ /** Impoerted files */
+ private $importStack = array();
+
+ public function addImport ($file) {
+ $this->importStack[] = $file;
+ }
+
+ public function getImportStack () {
+ return $this->importStack;
+ }
+
+ /**
+ * find out the project to which this context belongs
+ * @return project
+ */
+ public function getProject() {
+ return $this->project;
+ }
+
+} //end PhingXMLContext
Index: classes/phing/parser/ProjectHandler.php
===================================================================
--- classes/phing/parser/ProjectHandler.php (revision 365)
+++ classes/phing/parser/ProjectHandler.php (working copy)
@@ -89,38 +89,50 @@
throw new ExpatParseException("Unexpected attribute '$key'");
}
}
- if ($def === null) {
- throw new ExpatParseException("The default attribute of project is required");
+ // these things get done no matter what
+ if (null != $name) {
+ $canonicalName = self::canonicalName($name);
+ $this->configurator->setCurrentProjectName($canonicalName);
+ $project->setUserProperty("phing.file.{$canonicalName}",
+ (string) $this->configurator->getBuildFile());
}
- $project->setDefaultTarget($def);

- if ($name !== null) {
+ if (!$this->configurator->isIgnoringProjectTag()) {
+ if ($def === null) {
+ throw new ExpatParseException(
+ "The default attribute of project is required");
+ }
+ $project->setDefaultTarget($def);
+
+ if ($name !== null) {
$project->setName($name);
$project->addReference($name, $project);
- }

- if ($id !== null) {
+ }
+
+ if ($id !== null) {
$project->addReference($id, $project);
- }
-
- if ($desc !== null) {
+ }
+
+ if ($desc !== null) {
$project->setDescription($desc);
- }
+ }

- if ($project->getProperty("project.basedir") !== null) {
+ if ($project->getProperty("project.basedir") !== null) {
$project->setBasedir($project->getProperty("project.basedir"));
- } else {
+ } else {
if ($baseDir === null) {
- $project->setBasedir($buildFileParent->getAbsolutePath());
+ $project->setBasedir($buildFileParent->getAbsolutePath());
} else {
- // check whether the user has specified an absolute path
- $f = new PhingFile($baseDir);
- if ($f->isAbsolute()) {
- $project->setBasedir($baseDir);
- } else {
- $project->setBaseDir($project->resolveFile($baseDir, $buildFileParent));
- }
+ // check whether the user has specified an absolute path
+ $f = new PhingFile($baseDir);
+ if ($f->isAbsolute()) {
+ $project->setBasedir($baseDir);
+ } else {
+ $project->setBaseDir($project->resolveFile($baseDir, $buildFileParent));
+ }
}
+ }
}
}

@@ -149,5 +161,9 @@
$tf->init($name, $attrs);
}
}
+
+ static function canonicalName ($name) {
+ return preg_replace('/\W/', '_', strtolower($name));
+ }
}

Index: classes/phing/parser/TargetHandler.php
===================================================================
--- classes/phing/parser/TargetHandler.php (revision 365)
+++ classes/phing/parser/TargetHandler.php (working copy)
@@ -108,22 +108,53 @@
// shorthand
$project = $this->configurator->project;

+ // check to see if this target is a dup within the same file
+ if (isset($this->configurator->getCurrentTargets[$name])) {
+ throw new BuildException("Duplicate target: $targetName",
+ $this->parser->getLocation());
+ }
+
$this->target = new Target();
$this->target->setName($name);
$this->target->setIf($ifCond);
$this->target->setUnless($unlessCond);
$this->target->setDescription($description);
-
- $project->addTarget($name, $this->target);
-
- if ($id !== null && $id !== "") {
- $project->addReference($id, $this->target);
- }
// take care of dependencies
if (strlen($depends) > 0) {
$this->target->setDepends($depends);
}

+ $usedTarget = false;
+ // check to see if target with same name is already defined
+ $projectTargets = $project->getTargets();
+ if (isset($projectTargets[$name])) {
+ $project->log("Already defined in main or a previous import, " .
+ "ignore {$name}", Project::MSG_VERBOSE);
+ } else {
+ $project->addTarget($name, $this->target);
+ if ($id !== null && $id !== "") {
+ $project->addReference($id, $this->target);
+ }
+ $usedTarget = true;
+ }
+
+ if ($this->configurator->isIgnoringProjectTag() &&
+ $this->configurator->getCurrentProjectName() != null &&
+ strlen($this->configurator->getCurrentProjectName()) != 0) {
+ // In an impored file (and not completely
+ // ignoring the project tag)
+ $newName = $this->configurator->getCurrentProjectName() . "." . $name;
+ if ($usedTarget) {
+ // clone needs to make target->children a shared reference
+ $newTarget = clone $this->target;
+ } else {
+ $newTarget = $this->target;
+ }
+ $newTarget->setName($newName);
+ $ct = $this->configurator->getCurrentTargets();
+ $ct[$newName] = $newTarget;
+ $project->addTarget($newName, $newTarget);
+ }
}

/**
Index: classes/phing/parser/Location.php
===================================================================
--- classes/phing/parser/Location.php (revision 365)
+++ classes/phing/parser/Location.php (working copy)
@@ -69,4 +69,8 @@
}
return (string) $buf;
}
+
+ function __toString () {
+ return $this->toString();
+ }
}
Index: classes/phing/Project.php
===================================================================
--- classes/phing/Project.php (revision 365)
+++ classes/phing/Project.php (working copy)
@@ -535,7 +538,7 @@
$this->typedefs[$typeName] = $typeClass;
$this->log(" +User datatype: $typeName ($typeClass)", Project::MSG_DEBUG);
} else {
- $this->log("Type $name ($class) already registerd, skipping", Project::MSG_VERBOSE);
+ $this->log("Type $typeName ($typeClass) already registerd, skipping", Project::MSG_VERBOSE);
}
}

@@ -555,6 +558,10 @@
$this->log(" +Target: $targetName", Project::MSG_DEBUG);
$target->setProject($this);
$this->targets[$targetName] = $target;
+
+ $ctx = $this->getReference("phing.parsing.context");
+ $current = $ctx->getConfigurator()->getCurrentTargets();
+ $current[$targetName] = $target;
}

function getTargets() {
Show details Hide details

Change log

r6 by casadebender on May 12, 2008   Diff
Phing 2.3.0 patches.
Go to: 
Project members, sign in to write a code review

Older revisions

All revisions of this file

File info

Size: 31592 bytes, 859 lines
Hosted by Google Code