123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181 |
- <?php
-
- require_once 'phing/parser/AbstractHandler.php';
- class TargetHandler extends AbstractHandler {
-
- private $target;
-
- private $configurator;
-
- function __construct(AbstractSAXParser $parser, AbstractHandler $parentHandler, ProjectConfigurator $configurator) {
- parent::__construct($parser, $parentHandler);
- $this->configurator = $configurator;
- }
-
- function init($tag, $attrs) {
- $name = null;
- $depends = "";
- $ifCond = null;
- $unlessCond = null;
- $id = null;
- $description = null;
- foreach($attrs as $key => $value) {
- if ($key==="name") {
- $name = (string) $value;
- } else if ($key==="depends") {
- $depends = (string) $value;
- } else if ($key==="if") {
- $ifCond = (string) $value;
- } else if ($key==="unless") {
- $unlessCond = (string) $value;
- } else if ($key==="id") {
- $id = (string) $value;
- } else if ($key==="description") {
- $description = (string)$value;
- } else {
- throw new ExpatParseException("Unexpected attribute '$key'", $this->parser->getLocation());
- }
- }
- if ($name === null) {
- throw new ExpatParseException("target element appears without a name attribute", $this->parser->getLocation());
- }
-
- $project = $this->configurator->project;
-
- 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);
-
- if (strlen($depends) > 0) {
- $this->target->setDepends($depends);
- }
- $usedTarget = false;
-
- $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) {
-
-
- $newName = $this->configurator->getCurrentProjectName() . "." . $name;
- if ($usedTarget) {
-
- $newTarget = clone $this->target;
- } else {
- $newTarget = $this->target;
- }
- $newTarget->setName($newName);
- $ct = $this->configurator->getCurrentTargets();
- $ct[$newName] = $newTarget;
- $project->addTarget($newName, $newTarget);
- }
- }
-
- function startElement($name, $attrs) {
-
- $project = $this->configurator->project;
- $types = $project->getDataTypeDefinitions();
- if (isset($types[$name])) {
- $th = new DataTypeHandler($this->parser, $this, $this->configurator, $this->target);
- $th->init($name, $attrs);
- } else {
- $tmp = new TaskHandler($this->parser, $this, $this->configurator, $this->target, null, $this->target);
- $tmp->init($name, $attrs);
- }
- }
- }
|