|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
4
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
5
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|
6
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
|
7
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
8
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
9
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
10
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|
11
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
12
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|
13
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
14
|
|
|
* |
|
15
|
|
|
* This software consists of voluntary contributions made by many individuals |
|
16
|
|
|
* and is licensed under the LGPL. For more information please see |
|
17
|
|
|
* <http://phing.info>. |
|
18
|
|
|
*/ |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Register a task for use within a buildfile. |
|
22
|
|
|
* |
|
23
|
|
|
* This is for registering your own tasks -- or any non-core Task -- for use within a buildfile. |
|
24
|
|
|
* If you find that you are using a particular class frequently, you may want to edit the |
|
25
|
|
|
* phing/tasks/defaults.properties file so that it is included by default. You may also |
|
26
|
|
|
* want to submit it (if LGPL or compatible license) to be included in Phing distribution. |
|
27
|
|
|
* |
|
28
|
|
|
* <pre> |
|
29
|
|
|
* <taskdef name="mytag" classname="path.to.MyHandlingClass"/> |
|
30
|
|
|
* . |
|
31
|
|
|
* . |
|
32
|
|
|
* <mytag param1="val1" param2="val2"/> |
|
33
|
|
|
* </pre> |
|
34
|
|
|
* |
|
35
|
|
|
* TODO: |
|
36
|
|
|
* -- possibly refactor since this is almost the same as TypeDefTask |
|
37
|
|
|
* (right now these are just too simple to really justify creating an abstract class) |
|
38
|
|
|
* |
|
39
|
|
|
* @author Hans Lellelid <[email protected]> |
|
40
|
|
|
* @package phing.tasks.system |
|
41
|
|
|
*/ |
|
42
|
|
|
class TaskdefTask extends Task |
|
43
|
|
|
{ |
|
44
|
|
|
use ClasspathAware; |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Tag name for task that will be used in XML |
|
48
|
|
|
*/ |
|
49
|
|
|
private $name; |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Classname of task to register. |
|
53
|
|
|
* This can be a dot-path -- relative to a location on PHP include_path. |
|
54
|
|
|
* E.g. path.to.MyClass -> path/to/MyClass.php |
|
55
|
|
|
* |
|
56
|
|
|
* @var string |
|
57
|
|
|
*/ |
|
58
|
|
|
private $classname; |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Name of file to load multiple definitions from. |
|
62
|
|
|
* |
|
63
|
|
|
* @var string |
|
64
|
|
|
*/ |
|
65
|
|
|
private $typeFile; |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* Sets the name that will be used in XML buildfile. |
|
69
|
|
|
* |
|
70
|
|
|
* @param string $name |
|
71
|
|
|
*/ |
|
72
|
32 |
|
public function setName($name) |
|
73
|
|
|
{ |
|
74
|
32 |
|
$this->name = $name; |
|
75
|
32 |
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* Sets the class name / dotpath to use. |
|
79
|
|
|
* |
|
80
|
|
|
* @param string $class |
|
81
|
|
|
*/ |
|
82
|
32 |
|
public function setClassname($class) |
|
83
|
|
|
{ |
|
84
|
32 |
|
$this->classname = $class; |
|
85
|
32 |
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* Sets the file of definitionas to use to use. |
|
89
|
|
|
* |
|
90
|
|
|
* @param string $file |
|
91
|
|
|
*/ |
|
92
|
|
|
public function setFile($file) |
|
93
|
|
|
{ |
|
94
|
|
|
$this->typeFile = $file; |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* Main entry point |
|
99
|
|
|
*/ |
|
100
|
32 |
|
public function main() |
|
101
|
|
|
{ |
|
102
|
|
|
if ( |
|
103
|
32 |
|
$this->typeFile === null |
|
104
|
32 |
|
&& ($this->name === null |
|
105
|
32 |
|
|| $this->classname === null) |
|
106
|
|
|
) { |
|
107
|
3 |
|
throw new BuildException("You must specify name and class attributes for <taskdef>."); |
|
108
|
|
|
} |
|
109
|
32 |
|
if ($this->typeFile == null) { |
|
110
|
32 |
|
$this->log("Task " . $this->name . " will be handled by class " . $this->classname, Project::MSG_VERBOSE); |
|
111
|
32 |
|
$this->project->addTaskDefinition($this->name, $this->classname, $this->classpath); |
|
112
|
|
|
} else { |
|
113
|
|
|
try { // try to load taskdefs given in file |
|
114
|
|
|
$props = new Properties(); |
|
115
|
|
|
$in = new PhingFile((string) $this->typeFile); |
|
116
|
|
|
|
|
117
|
|
|
if ($in === null) { |
|
118
|
|
|
throw new BuildException("Can't load task list {$this->typeFile}"); |
|
119
|
|
|
} |
|
120
|
|
|
$props->load($in); |
|
121
|
|
|
|
|
122
|
|
|
$enum = $props->propertyNames(); |
|
123
|
|
|
foreach ($enum as $key) { |
|
124
|
|
|
$value = $props->getProperty($key); |
|
125
|
|
|
$this->project->addTaskDefinition($key, $value, $this->classpath); |
|
126
|
|
|
} |
|
127
|
|
|
} catch (IOException $ioe) { |
|
128
|
|
|
throw new BuildException("Can't load task list {$this->typeFile}"); |
|
129
|
|
|
} |
|
130
|
|
|
} |
|
131
|
32 |
|
} |
|
132
|
|
|
} |
|
133
|
|
|
|