. */ require_once 'phing/tasks/system/AdhocTask.php'; /** * A class for creating adhoc tasks in build file. * * * bar = $bar; * } * * function main() { * $this->log("In FooTest: " . $this->bar); * } * } * * ]]> * * * * * @author Hans Lellelid * @version $Id$ * @package phing.tasks.system */ class AdhocTaskdefTask extends AdhocTask { /** * The tag that refers to this task. */ private $name; /** * Set the tag that will represent this adhoc task/type. * @param string $name */ public function setName($name) { $this->name = $name; } /** Main entry point */ public function main() { if ($this->name === null) { throw new BuildException("The name attribute is required for adhoc task definition.",$this->location); } $taskdefs = $this->getProject()->getTaskDefinitions(); if (!isset($taskdefs[$this->name])) { $this->execute(); $classes = $this->getNewClasses(); if (count($classes) < 1) { throw new BuildException("You must define at least one class for AdhocTaskdefTask."); } $classname = array_pop($classes); // instantiate it to make sure it is an instance of Task $t = new $classname(); if (!($t instanceof Task)) { throw new BuildException("The adhoc class you defined must be an instance of phing.Task", $this->location); } $this->log("Task " . $this->name . " will be handled by class " . $classname, Project::MSG_VERBOSE); $this->project->addTaskDefinition($this->name, $classname); } } }