Ticket #118 (closed defect: fixed)

Opened 2 years ago

Last modified 4 months ago

custom tasks have this->project == null

Reported by: development@domain51.com Assigned to: hans
Priority: major Milestone: 2.3.0
Component: phing-core Version: devel
Keywords: tasks Cc:

Description

Running against a build from the latest SVN, I ran into an issue when creating a new task[1], it was caused in UnknownElement at line 133 when $this->project was equal to NULL. The issue arose when I add <include /> elements to a <fileset> within the new task. Adjusting the code as follows worked, but introduced another issue:

@@ -130,7 +130,8 @@
                 $realChild = $this->makeTask($child, $childWrapper, false);
                 $parent->addTask($realChild);
             } else {
-                $realChild = $ih->createElement($this->project, $parent, $child->getTag());
+                $project = is_null($this->project) ? $parent->project : $this->project;
+                $realChild = $ih->createElement($project, $parent, $child->getTag());
             }
 
             $childWrapper->setProxy($realChild);

The issue that it introduces is at line 142, but can be addressed via:

@@ -138,7 +139,9 @@
                 $realChild->setRuntimeConfigurableWrapper($childWrapper);
             }
 
-            $child->handleChildren($realChild, $childWrapper);
+            if ($realChild instanceof ProjectComponent) {
+                $child->handleChildren($realChild, $childWrapper);
+            }
             if ($realChild instanceof Task) {
                 $realChild->maybeConfigure();
             }

It appears that if you just specify that handleChildren() should only be called when the $realChild variable is a ProjectComponent, you can avoid any warnings from the logger.

It's entirely possible that my Task is not properly formatted for some reason. I was following the instructions available in the current manual along with some investigation into the tasks system with the current code. Applying the above patches and re-building the package fixes the issue I was having.

Below is the original fatal error that started my looking through the code:

[PHP Error] Argument 1 passed to IntrospectionHelper::createElement() must be an instance of Project, null given, called in /usr/share/php/phing/UnknownElement.php on line 133 and defined [line 384 of /usr/share/php/phing/IntrospectionHelper.php]

Fatal error: Call to a member function log() on a non-object in /usr/share/php/phing/IntrospectionHelper.php on line 394

Call Stack:
    0.0005      68700   1. {main}() /usr/share/php/phing.php:0
    0.1051    4174556   2. Phing::fire() /usr/share/php/phing.php:41
    0.1051    4174804   3. Phing::start() /usr/share/php/phing/Phing.php:262
    0.1071    4242392   4. Phing->runBuild() /usr/share/php/phing/Phing.php:164
    0.7476   21538208   5. Project->executeTargets() /usr/share/php/phing/Phing.php:516
    0.7476   21538208   6. Project->executeTarget() /usr/share/php/phing/Project.php:682
    0.9150   21571944   7. Target->performTasks() /usr/share/php/phing/Project.php:709
    0.9154   21571944   8. Target->main() /usr/share/php/phing/Target.php:263
    0.9196   21612728   9. Task->perform() /usr/share/php/phing/Target.php:240
    0.9196   21612728  10. UnknownElement->maybeConfigure() /usr/share/php/phing/Task.php:253
    0.9202   21613376  11. UnknownElement->handleChildren() /usr/share/php/phing/UnknownElement.php:76
    0.9213   21623428  12. UnknownElement->handleChildren() /usr/share/php/phing/UnknownElement.php:141
    0.9215   21623592  13. IntrospectionHelper->createElement() /usr/share/php/phing/UnknownElement.php:133

[1]: https://svn.domain51.com/pear/trunk/src/Domain51/Phing/Task/AddNamespaceTask.php

Attachments

patch (1.1 kB) - added by development@domain51.com on 06/06/07 04:35:14.
A patch created from svn diff

Change History

06/06/07 04:35:14 changed by development@domain51.com

  • attachment patch added.

A patch created from svn diff

07/29/07 20:53:10 changed by hans

  • status changed from new to assigned.

07/29/07 21:06:01 changed by hans

  • status changed from assigned to closed.
  • resolution set to fixed.

Ok, this fix looks good. Thanks (and sorry it took so long to get this into the codebase). I've added this in [205] and will report if there are any unintended consequences of this as I run through more complex examples later in the week.


Add/Change #118 (custom tasks have this->project == null)




Action