Ticket #248: taskdef.patch
| File taskdef.patch, 10.0 kB (added by Bryan Davis <bender@casadebender.com>, 3 months ago) |
|---|
-
test/run-tests.php
old new 57 57 58 58 include_once 'phing/tasks/TypedefTaskTest.php'; 59 59 $tasksSuite->addTestSuite(new ReflectionClass('TypedefTaskTest')); 60 include_once 'phing/tasks/TaskdefTaskTest.php'; 61 $tasksSuite->addTestSuite(new ReflectionClass('TaskdefTaskTest')); 60 62 61 63 62 64 // Conditions -
test/etc/tasks/taskdef.xml
old new 1 <?xml version="1.0"?> 2 3 <project name="test" basedir="." default="invalid"> 4 5 <target name="invalid"> 6 <fail>This file should only be run via a testcase</fail> 7 </target> 8 9 <target name="empty"> 10 <taskdef /> 11 </target> 12 13 <target name="noClassname"> 14 <taskdef name="dummy" /> 15 </target> 16 17 <target name="noName"> 18 <taskdef classname="example.tasks.TaskdefTestSimpleTask"/> 19 </target> 20 21 <target name="classNotFound"> 22 <taskdef name="" classname="oops"/> 23 </target> 24 25 <path id="testclasses"> 26 <pathelement dir="../../classes" /> 27 </path> 28 29 <taskdef name="global" classname="example.tasks.TaskdefTestSimpleTask"> 30 <classpath refid="testclasses" /> 31 </taskdef> 32 33 <target name="testGlobal"> 34 <global id="global"> 35 <echo message="testGlobal echo"/> 36 </global> 37 </target> 38 39 <target name="testLocal"> 40 <taskdef name="local" classname="example.tasks.TaskdefTestSimpleTask"> 41 <classpath refid="testclasses" /> 42 </taskdef> 43 <local id="local" /> 44 </target> 45 46 <target name="testFile"> 47 <taskdef file="${phing.file}/taskdef.properties"> 48 <classpath refid="testclasses" /> 49 </taskdef> 50 <tdfile id="tdfile"> 51 <echo message="testTdfile echo"/> 52 </tdfile> 53 <tdfile2 id="tdfile2"/> 54 </target> 55 56 </project> -
test/etc/tasks/taskdef.properties
old new 1 tdfile=example.tasks.TaskdefTestSimpleTask 2 tdfile2=example.tasks.TaskdefTestSimpleTask -
test/classes/phing/tasks/TaskdefTaskTest.php
old new 1 <?php 2 /* 3 * $Id$ 4 * 5 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 6 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 7 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 8 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 9 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 10 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 11 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 12 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 13 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 14 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 15 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 16 * 17 * This software consists of voluntary contributions made by many individuals 18 * and is licensed under the LGPL. For more information please see 19 * <http://phing.info>. 20 */ 21 22 require_once 'phing/BuildFileTest.php'; 23 24 /** 25 * @version $Revision$ 26 */ 27 class TaskdefTaskTest extends BuildFileTest { 28 29 public function setUp() { 30 $this->configureProject(PHING_TEST_BASE . "/etc/tasks/taskdef.xml"); 31 } 32 33 public function testEmpty() { 34 $this->expectBuildException("empty", "required argument not specified"); 35 } 36 37 public function testNoName() { 38 $this->expectBuildException("noName", "required argument not specified"); 39 } 40 41 public function testNoClassname() { 42 $this->expectBuildException("noClassname", "required argument not specified"); 43 } 44 45 public function testClassNotFound() { 46 try { 47 $this->expectBuildException("classNotFound", "classname specified doesn't exist"); 48 } catch (ConfigurationException $e) { 49 //ignored 50 } 51 } 52 53 public function testGlobal() { 54 $this->expectLog("testGlobal", "simpletask: testGlobal echo"); 55 $refs = $this->project->getReferences(); 56 $ref = $refs["global"]; 57 $this->assertNotNull("ref is not null", $ref); 58 $this->assertEquals("TaskdefTestSimpleTask", get_class($ref)); 59 } 60 61 public function testLocal() { 62 $this->expectLog("testLocal", "Task local will be handled by class example.tasks.TaskdefTestSimpleTask"); 63 $refs = $this->project->getReferences(); 64 $ref = $refs["local"]; 65 $this->assertNotNull("ref is not null", $ref); 66 $this->assertEquals("TaskdefTestSimpleTask", get_class($ref)); 67 } 68 69 public function tesFile() { 70 $this->expectLog("testFile", "simpletask: testTdfile echo"); 71 $refs = $this->project->getReferences(); 72 $ref = $refs["tdfile"]; 73 $this->assertNotNull("ref is not null", $ref); 74 $this->assertEquals("TaskdefTestSimpleTask", get_class($ref)); 75 $ref = $refs["tdfile2"]; 76 $this->assertNotNull("ref is not null", $ref); 77 $this->assertEquals("TaskdefTestSimpleTask", get_class($ref)); 78 } 79 } -
test/classes/example/tasks/TaskdefTestSimpleTask.php
old new 35 35 } 36 36 37 37 public function main() { 38 $this->log("simpletask: " . $echo->message, Project::MSG_INFO);38 $this->log("simpletask: " . $this->echo->message, Project::MSG_INFO); 39 39 } 40 40 41 41 } -
docs/phing_guide/book/chapters/appendixes/AppendixB-CoreTasks.html
old new 1490 1574 <!-- Includes the Task "RebootTask" from "user/sometasks" somewhere inside 1491 1575 the $PHP_CLASSPATH --> 1492 1576 <taskdef classname="user.sometasks.RebootTask" name="reboot" /> 1577 1578 <!-- Includes all tasks from the property file. Each line in the property 1579 file defines a task in the format: name=path.to.Task --> 1580 <taskdef file="/path/to/mytasks.properties" /> 1581 1493 1582 </pre> 1494 1583 <h3>Attributes</h3> 1495 1584 <table> … … 1510 1599 The path to the class that defines the TaskClass. 1511 1600 </td> 1512 1601 <td>n/a</td> 1513 <td>Yes </td>1602 <td>Yes, unless the <code>file</code> attribute has been specified.</td> 1514 1603 </tr> 1515 1604 <tr> 1516 1605 <td>name</td> … … 1521 1610 the task imported here with <code><validate></code>. 1522 1611 </td> 1523 1612 <td>n/a</td> 1524 <td>Yes </td>1613 <td>Yes, unless the <code>file</code> attribute has been specified.</td> 1525 1614 </tr> 1615 <tr> 1616 <td>file</td> 1617 <td>String</td> 1618 <td> 1619 Name of the file to load definitions from. 1620 </td> 1621 <td>n/a</td> 1622 <td>No</td> 1623 </tr> 1526 1624 <tr> 1527 1625 <td>classpath</td> 1528 1626 <td>String</td> -
classes/phing/tasks/system/TaskdefTask.php
old new 21 21 */ 22 22 23 23 require_once 'phing/Task.php'; 24 include_once 'phing/system/io/PhingFile.php'; 24 25 25 26 /** 26 27 * Register a task for use within a buildfile. … … 68 69 * Refid to already defined classpath 69 70 */ 70 71 private $classpathId; 72 73 /** 74 * Name of file to load multiple definitions from. 75 * @var string 76 */ 77 private $typeFile; 71 78 72 79 /** 73 80 * Set the classpath to be used when searching for component being defined … … 116 123 $this->classname = $class; 117 124 } 118 125 126 /** 127 * Sets the file of definitionas to use to use. 128 * @param string $file 129 */ 130 public function setFile($file) { 131 $this->typeFile = $file; 132 } 133 119 134 /** Main entry point */ 120 135 public function main() { 121 if ($this->name === null || $this->classname === null) { 136 if ($this->typeFile === null && 137 ($this->name === null || $this->classname === null)) { 122 138 throw new BuildException("You must specify name and class attributes for <taskdef>."); 123 139 } 124 $this->log("Task " . $this->name . " will be handled by class " . $this->classname, Project::MSG_VERBOSE); 125 $this->project->addTaskDefinition($this->name, $this->classname, $this->classpath); 140 if ($this->typeFile == null) { 141 $this->log("Task " . $this->name . " will be handled by class " . $this->classname, Project::MSG_VERBOSE); 142 $this->project->addTaskDefinition($this->name, $this->classname, $this->classpath); 143 } else { 144 try { // try to load taskdefs given in file 145 $props = new Properties(); 146 $in = new PhingFile((string) $this->typeFile); 147 148 if ($in === null) { 149 throw new BuildException("Can't load task list {$this->typeFile}"); 150 } 151 $props->load($in); 152 153 $enum = $props->propertyNames(); 154 foreach($enum as $key) { 155 $value = $props->getProperty($key); 156 $this->project->addTaskDefinition($key, $value, $this->classpath); 157 } 158 } catch (IOException $ioe) { 159 throw new BuildException("Can't load task list {$this->typeFile}"); 160 } 161 } 126 162 } 127 163 }
