Changeset 335 for trunk/classes

Show
Ignore:
Timestamp:
01/04/08 16:13:27 (8 months ago)
Author:
arnoschn
Message:

Refs #195: switching to parse xml output from svn info (svn info --xml). more reliable than any localized string output.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/classes/phing/tasks/ext/svn/SvnLastRevisionTask.php

    r309 r335  
    2727 * 
    2828 * @author Michiel Rook <michiel.rook@gmail.com> 
     29 * @author Arno Schneider <arnoschn@gmail.com> 
    2930 * @version $Id$ 
    3031 * @package phing.tasks.ext.svn 
     
    6162                $this->setup('info'); 
    6263                 
    63                 $output = $this->run(); 
    64                  
    65                 if (preg_match('/Rev:[\s]+([\d]+)/', $output, $matches)) 
     64                /** 
     65                 * run in xml mode, allows us to retrieve workingcopy info in  
     66                 * a unified xml format, so we dont have to fight with internationalized 
     67                 * versions of svn info output 
     68                 */ 
     69                $output = $this->run(array('--xml')); 
     70                try  
    6671                { 
    67                         $this->project->setProperty($this->getPropertyName(), $matches[1]); 
     72                        $xml = new SimpleXMLElement($output); 
     73                        /** 
     74                         * walk the xml towards the last commit element 
     75                         */ 
     76                        $commits = $xml->xpath('/info/entry/commit'); 
     77                        if (count($commits)>0) { 
     78                                $commit = $commits[0]; 
     79                                /** 
     80                                 * get the attributes of the commit element 
     81                                 */ 
     82                                $attributes = $commit->attributes(); 
     83                                $this->project->setProperty($this->getPropertyName(), $attributes->revision); 
     84                        } else { 
     85                                throw new BuildException("Failed to parse the output of 'svn info'."); 
     86                        } 
     87                         
    6888                } 
    69                 else 
     89                catch (Exception $e) 
    7090                { 
    7191                        throw new BuildException("Failed to parse the output of 'svn info'.");