123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318 |
- <?php
- include_once 'phing/TaskContainer.php';
- class Target implements TaskContainer {
-
-
- private $name;
-
-
- private $dependencies = array();
-
-
- private $children = array();
-
-
- private $ifCondition = "";
-
-
- private $unlessCondition = "";
-
-
- private $description;
-
-
- private $project;
-
- public function setProject(Project $project) {
- $this->project = $project;
- }
-
- public function getProject() {
- return $this->project;
- }
-
- public function setDepends($depends) {
-
- $deps = explode(',', $depends);
- for ($i=0, $size=count($deps); $i < $size; $i++) {
- $trimmed = trim($deps[$i]);
- if ($trimmed === "") {
- throw new BuildException("Syntax Error: Depend attribute for target ".$this->getName()." is malformed.");
- }
- $this->addDependency($trimmed);
- }
- }
-
- public function addDependency($dependency) {
- $this->dependencies[] = (string) $dependency;
- }
-
- public function getDependencies() {
- return $this->dependencies;
- }
-
- public function setName($name) {
- $this->name = (string) $name;
- }
-
- function getName() {
- return (string) $this->name;
- }
-
- function addTask(Task $task) {
- $this->children[] = $task;
- }
-
- function addDataType($rtc) {
- $this->children[] = $rtc;
- }
-
- public function getTasks() {
- $tasks = array();
- for ($i=0,$size=count($this->children); $i < $size; $i++) {
- $tsk = $this->children[$i];
- if ($tsk instanceof Task) {
-
- $tasks[] = clone $tsk;
- }
- }
- return $tasks;
- }
-
- public function setIf($property) {
- $this->ifCondition = ($property === null) ? "" : $property;
- }
-
- public function setUnless($property) {
- $this->unlessCondition = ($property === null) ? "" : $property;
- }
-
- public function setDescription($description) {
- if ($description !== null && strcmp($description, "") !== 0) {
- $this->description = (string) $description;
- } else {
- $this->description = null;
- }
- }
-
- public function getDescription() {
- return $this->description;
- }
-
- function toString() {
- return (string) $this->name;
- }
-
- public function main() {
- if ($this->testIfCondition() && $this->testUnlessCondition()) {
- foreach($this->children as $o) {
- if ($o instanceof Task) {
-
- $o->perform();
- } else {
-
- $o->maybeConfigure($this->project);
- }
- }
- } elseif (!$this->testIfCondition()) {
- $this->project->log("Skipped target '".$this->name."' because property '".$this->ifCondition."' not set.", Project::MSG_VERBOSE);
- } else {
- $this->project->log("Skipped target '".$this->name."' because property '".$this->unlessCondition."' set.", Project::MSG_VERBOSE);
- }
- }
-
- public function performTasks() {
- try {
- $this->project->fireTargetStarted($this);
- $this->main();
- $this->project->fireTargetFinished($this, $null=null);
- } catch (BuildException $exc) {
-
- $this->project->fireTargetFinished($this, $exc);
- throw $exc;
- }
- }
-
- private function testIfCondition() {
- if ($this->ifCondition === "") {
- return true;
- }
- $properties = explode(",", $this->ifCondition);
- $result = true;
- foreach ($properties as $property) {
- $test = ProjectConfigurator::replaceProperties($this->getProject(), $property, $this->project->getProperties());
- $result = $result && ($this->project->getProperty($test) !== null);
- }
- return $result;
- }
-
- private function testUnlessCondition() {
- if ($this->unlessCondition === "") {
- return true;
- }
-
- $properties = explode(",", $this->unlessCondition);
- $result = true;
- foreach ($properties as $property) {
- $test = ProjectConfigurator::replaceProperties($this->getProject(), $property, $this->project->getProperties());
- $result = $result && ($this->project->getProperty($test) === null);
- }
- return $result;
- }
- }
|