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  
    5757 
    5858include_once 'phing/tasks/TypedefTaskTest.php'; 
    5959$tasksSuite->addTestSuite(new ReflectionClass('TypedefTaskTest')); 
     60include_once 'phing/tasks/TaskdefTaskTest.php'; 
     61$tasksSuite->addTestSuite(new ReflectionClass('TaskdefTaskTest')); 
    6062 
    6163 
    6264// 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  
     1tdfile=example.tasks.TaskdefTestSimpleTask 
     2tdfile2=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  
     22require_once 'phing/BuildFileTest.php'; 
     23 
     24/** 
     25 * @version $Revision$ 
     26 */ 
     27class 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  
    3535    } 
    3636     
    3737    public function main() { 
    38         $this->log("simpletask: " . $echo->message, Project::MSG_INFO); 
     38      $this->log("simpletask: " . $this->echo->message, Project::MSG_INFO); 
    3939    } 
    4040 
    4141} 
  • docs/phing_guide/book/chapters/appendixes/AppendixB-CoreTasks.html

    old new  
    14901574&lt;!-- Includes the Task &quot;RebootTask&quot; from &quot;user/sometasks&quot; somewhere inside 
    14911575     the $PHP_CLASSPATH --&gt; 
    14921576&lt;taskdef classname=&quot;user.sometasks.RebootTask&quot; name=&quot;reboot&quot; /&gt; 
     1577 
     1578&lt;!-- Includes all tasks from the property file. Each line in the property  
     1579file defines a task in the format: name=path.to.Task --&gt; 
     1580&lt;taskdef file=&quot;/path/to/mytasks.properties&quot; /&gt; 
     1581 
    14931582</pre> 
    14941583<h3>Attributes</h3> 
    14951584<table> 
     
    15101599        The path to the class that defines the TaskClass. 
    15111600      </td> 
    15121601      <td>n/a</td> 
    1513       <td>Yes</td> 
     1602      <td>Yes, unless the <code>file</code> attribute has been specified.</td> 
    15141603    </tr> 
    15151604    <tr> 
    15161605      <td>name</td> 
     
    15211610        the task imported here with <code>&lt;validate&gt;</code>. 
    15221611      </td> 
    15231612      <td>n/a</td> 
    1524       <td>Yes</td> 
     1613      <td>Yes, unless the <code>file</code> attribute has been specified.</td> 
    15251614    </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> 
    15261624        <tr> 
    15271625      <td>classpath</td> 
    15281626      <td>String</td> 
  • classes/phing/tasks/system/TaskdefTask.php

    old new  
    2121 */ 
    2222  
    2323require_once 'phing/Task.php'; 
     24include_once 'phing/system/io/PhingFile.php'; 
    2425 
    2526/** 
    2627 * Register a task for use within a buildfile. 
     
    6869     * Refid to already defined classpath 
    6970     */ 
    7071    private $classpathId; 
     72 
     73    /** 
     74     * Name of file to load multiple definitions from. 
     75     * @var string 
     76     */ 
     77    private $typeFile; 
    7178     
    7279    /** 
    7380     * Set the classpath to be used when searching for component being defined 
     
    116123        $this->classname = $class; 
    117124    } 
    118125     
     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     
    119134    /** Main entry point */ 
    120135    public function main() { 
    121         if ($this->name === null || $this->classname === null) { 
     136        if ($this->typeFile === null &&  
     137            ($this->name === null || $this->classname === null)) { 
    122138            throw new BuildException("You must specify name and class attributes for <taskdef>."); 
    123139        } 
    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        } 
    126162    } 
    127163}