Changeset 367

Show
Ignore:
Timestamp:
05/18/08 17:14:13 (8 months ago)
Author:
bender
Message:

#248 - Extend taskdef task to allow property file style imports

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/2.4/classes/phing/tasks/system/TaskdefTask.php

    r144 r367  
    2222  
    2323require_once 'phing/Task.php'; 
     24include_once 'phing/system/io/PhingFile.php'; 
    2425 
    2526/** 
     
    6970     */ 
    7071    private $classpathId; 
     72 
     73    /** 
     74     * Name of file to load multiple definitions from. 
     75     * @var string 
     76     */ 
     77    private $typeFile; 
    7178     
    7279    /** 
     
    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} 
  • branches/2.4/docs/phing_guide/book/chapters/appendixes/AppendixB-CoreTasks.html

    r360 r367  
    14911491     the $PHP_CLASSPATH --&gt; 
    14921492&lt;taskdef classname=&quot;user.sometasks.RebootTask&quot; name=&quot;reboot&quot; /&gt; 
     1493 
     1494&lt;!-- Includes all tasks from the property file. Each line in the property  
     1495file defines a task in the format: name=path.to.Task --&gt; 
     1496&lt;taskdef file=&quot;/path/to/mytasks.properties&quot; /&gt; 
     1497 
    14931498</pre> 
    14941499<h3>Attributes</h3> 
     
    15111516      </td> 
    15121517      <td>n/a</td> 
    1513       <td>Yes</td> 
     1518      <td>Yes, unless the <code>file</code> attribute has been specified.</td> 
    15141519    </tr> 
    15151520    <tr> 
     
    15221527      </td> 
    15231528      <td>n/a</td> 
    1524       <td>Yes</td> 
     1529      <td>Yes, unless the <code>file</code> attribute has been specified.</td> 
     1530    </tr> 
     1531    <tr> 
     1532      <td>file</td> 
     1533      <td>String</td> 
     1534      <td> 
     1535      Name of the file to load definitions from. 
     1536      </td> 
     1537      <td>n/a</td> 
     1538      <td>No</td> 
    15251539    </tr> 
    15261540        <tr> 
  • branches/2.4/test/classes/example/tasks/TaskdefTestSimpleTask.php

    r144 r367  
    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 
  • branches/2.4/test/run-tests.php

    r123 r367  
    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