Changeset 133

Show
Ignore:
Timestamp:
02/02/07 19:33:05 (2 years ago)
Author:
hans
Message:

Fixes #63: Configured -logger can get overridden
Fixes #64: Build listeners currently not working

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/2.2/classes/phing/Phing.php

    r51 r133  
    6363    /** The default build file name */ 
    6464    const DEFAULT_BUILD_FILENAME = "build.xml"; 
    65  
     65         
    6666    /** Our current message output status. Follows PROJECT_MSG_XXX */ 
    6767    private static $msgOutputLevel = PROJECT_MSG_INFO; 
     
    223223            } elseif ($arg == "-logfile") { 
    224224                try { // try to set logfile 
     225                        // TODO - This is slated to be overhauled for 2.3.0 
     226                        // see: http://phing.info/trac/ticket/65 
    225227                    if (!isset($args[$i+1])) { 
    226228                        print("You must specify a log file when using the -logfile argument\n"); 
     
    228230                    } else { 
    229231                        $logFile = new PhingFile($args[++$i]); 
    230                         $this->loggerClassname = 'phing.listener.PearLogger'; 
    231                         $this->setDefinedProperty('pear.log.name', $logFile->getAbsolutePath()); 
     232                        $this->setDefinedProperty('phing.listener.logfile', $logFile->getAbsolutePath()); 
    232233                    } 
    233234                } catch (IOException $ioe) { 
     
    249250                    $this->listeners[] = $args[++$i]; 
    250251                } 
    251                  
    252252            } elseif (StringHelper::startsWith("-D", $arg)) { 
    253253                $name = substr($arg, 2); 
     
    472472     
    473473    /** 
    474      * Bind any default build listeners to this project. 
    475      * Currently this means adding the logger. 
     474     * Bind any registered build listeners to this project. 
     475     *  
     476     * This means adding the logger and any build listeners that were specified 
     477     * with -listener arg. 
     478     *  
    476479     * @param Project $project 
    477480     * @return void 
     
    480483        // Add the default listener 
    481484        $project->addBuildListener($this->createLogger()); 
     485         
     486        foreach($this->listeners as $listenerClassname) { 
     487                try { 
     488                        $clz = Phing::import($listenerClassname); 
     489                        $listener = new $clz(); 
     490                        $project->addBuildListener($listener); 
     491                } catch (Exception $e) { 
     492                        $msg = "Unable to instantiate specified listener " 
     493                    . "class " . $listenerClassname . " : " 
     494                    . $e->getMessage(); 
     495                throw new BuildException($msg); 
     496                } 
     497        } 
    482498    } 
    483499     
  • branches/2.2/classes/phing/listener/DefaultLogger.php

    r1 r133  
    3030 * 
    3131 *  @author    Andreas Aderhold <andi@binarycloud.com> 
    32  *  @copyright © 2001,2002 THYRELL. All rights reserved 
     32 *  @copyright ᅵ 2001,2002 THYRELL. All rights reserved 
    3333 *  @version   $Revision: 1.11 $ $Date: 2005/08/25 19:33:43 $ 
    3434 *  @see       BuildEvent 
     
    131131            } 
    132132        } 
    133         print($this->lSep . "Total time: " .$this->_formatTime(Phing::currentTimeMillis() - $this->startTime) . $this->lSep); 
     133        print($this->lSep . "Total time: " .self::formatTime(Phing::currentTimeMillis() - $this->startTime) . $this->lSep); 
    134134    } 
    135135 
     
    207207     *  @access private 
    208208     */ 
    209     function _formatTime($micros) { 
     209    public static function formatTime($micros) { 
    210210        $seconds = $micros; 
    211211        $minutes = $seconds / 60; 
  • branches/2.2/classes/phing/listener/PearLogger.php

    r1 r133  
    5656     *  @var int 
    5757     */ 
    58     protected $msgOutputLevel = PROJECT_MSG_ERR
     58    protected $msgOutputLevel = PROJECT_MSG_DEBUG
    5959 
    6060    /** 
     
    8585    protected function configureLogging() { 
    8686     
     87        $logfile = Phing::getDefinedProperty('phing.listener.logfile'); 
     88         
    8789        $type = Phing::getDefinedProperty('pear.log.type'); 
    8890        $name = Phing::getDefinedProperty('pear.log.name'); 
     
    9193         
    9294        if ($type === null) $type = 'file'; 
    93         if ($name === null) $name = 'phing.log'; 
     95         
     96        if ($name === null) { 
     97                if ($logfile === null) { 
     98                        $name = 'phing.log'; 
     99                } else { 
     100                        $name = $logfile; 
     101                } 
     102        } 
    94103        if ($ident === null) $ident = 'phing'; 
    95104        if ($conf === null) $conf = array(); 
     
    165174            $msg = "Build failed. [reason: " . $error->getMessage() ."]"; 
    166175        } 
    167         $this->logger()->log($msg . " Total time: " . $this->_formatTime(Phing::currentTimeMillis() - $this->startTime)); 
     176        $this->logger()->log($msg . " Total time: " . DefaultLogger::formatTime(Phing::currentTimeMillis() - $this->startTime)); 
    168177    } 
    169178 
     
    226235        } 
    227236    } 
    228  
    229     /** 
    230      *  Formats a time micro integer to human readable format. 
    231      * 
    232      *  @param  integer The time stamp 
    233      *  @access private 
    234      */ 
    235     function _formatTime($micros) { 
    236         $seconds = $micros; 
    237         $minutes = $seconds / 60; 
    238         if ($minutes > 1) { 
    239             return sprintf("%1.0f minute%s %0.2f second%s", 
    240                                     $minutes, ($minutes === 1 ? " " : "s "), 
    241                                     $seconds - floor($seconds/60) * 60, ($seconds%60 === 1 ? "" : "s")); 
    242         } else { 
    243             return sprintf("%0.4f second%s", $seconds, ($seconds%60 === 1 ? "" : "s")); 
    244         } 
    245     }          
    246237} 
  • branches/2.2/classes/phing/listener/XmlLogger.php

    r82 r133  
    6767                 
    6868                /** 
     69                 * @var string Name of filename to create. 
     70                 */ 
     71                private $outFilename; 
     72                 
     73                /** 
    6974                 *  Constructs a new BuildListener that logs build events to an XML file. 
    7075                 */ 
     
    7782                        $this->targetTimer = new Timer(); 
    7883                        $this->taskTimer = new Timer(); 
     84                         
     85                         
     86                         
     87                         
     88                        $outFilename = Phing::getDefinedProperty('phing.listener.logfile'); 
     89                        if ($outFilename === null) { 
     90                                $outFilename = Phing::getDefinedProperty("XmlLogger.file"); 
     91                                if ($outFilename === null) { 
     92                                        $outFilename = "log.xml"; 
     93                                } 
     94                        } 
     95                         
     96                        $this->outFilename = $outFilename; 
     97                         
    7998                } 
    8099                 
     
    104123                        $elapsedTime = Phing::currentTimeMillis() - $this->buildTimerStart; 
    105124                         
    106                         $this->buildElement->setAttribute(XmlLogger::TIME_ATTR, DefaultLogger::_formatTime($elapsedTime)); 
     125                        $this->buildElement->setAttribute(XmlLogger::TIME_ATTR, DefaultLogger::formatTime($elapsedTime)); 
    107126                         
    108127                        if ($event->getException() != null) 
     
    116135                        } 
    117136                         
    118                         $outFilename = $event->getProject()->getProperty("XmlLogger.file"); 
    119                          
    120                         if ($outFilename == "") 
    121                         { 
    122                                 $outFilename = "log.xml"; 
    123                         } 
    124                         $writer = new FileWriter($outFilename); 
     137                        $writer = new FileWriter($this->outFilename); 
    125138                         
    126139                        $writer->write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); 
     
    157170                        $elapsedTime = Phing::currentTimeMillis() - $this->targetTimerStart; 
    158171                         
    159                         $this->targetElement->setAttribute(XmlLogger::TIME_ATTR, DefaultLogger::_formatTime($elapsedTime)); 
     172                        $this->targetElement->setAttribute(XmlLogger::TIME_ATTR, DefaultLogger::formatTime($elapsedTime)); 
    160173                         
    161174                        $this->buildElement->appendChild($this->targetElement); 
     
    190203                         
    191204                        $elapsedTime = Phing::currentTimeMillis() - $this->taskTimerStart; 
    192                         $this->taskElement->setAttribute(XmlLogger::TIME_ATTR, DefaultLogger::_formatTime($elapsedTime)); 
     205                        $this->taskElement->setAttribute(XmlLogger::TIME_ATTR, DefaultLogger::formatTime($elapsedTime)); 
    193206                         
    194207                        $this->targetElement->appendChild($this->taskElement);