Show
Ignore:
Timestamp:
06/16/06 13:49:48 (2 years ago)
Author:
hans
Message:

#26 - Fixing strange behavior with "dir" attribute of <phing> task.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/2.2/classes/phing/tasks/system/PhingTask.php

    r59 r78  
    205205        $savedTarget = $this->newTarget; 
    206206         
     207                $savedBasedirAbsPath = null; // this is used to save the basedir *if* we change it 
     208         
    207209        try { 
     210         
    208211            if ($this->newProject === null) { 
    209212                $this->reinit(); 
    210213            } 
    211214 
    212             if (($this->dir === null) && ($this->inheritAll)) { 
    213                 $this->dir = $this->getProject()->getBaseDir(); 
    214             } 
    215215            $this->initializeProject(); 
     216             
    216217            if ($this->dir !== null) { 
    217                 $this->newProject->setBaseDir($this->dir); 
     218                 
     219                $dirAbsPath = $this->dir->getAbsolutePath(); 
     220                 
     221                // BE CAREFUL! -- when the basedir is changed for a project, 
     222                // all calls to getAbsolutePath() on a relative-path dir will 
     223                // be made relative to the project's basedir!  This means 
     224                // that subsequent calls to $this->dir->getAbsolutePath() will be WRONG! 
     225                 
     226                // We need to save the current project's basedir first. 
     227                $savedBasedirAbsPath = $this->getProject()->getBasedir()->getAbsolutePath(); 
     228                                  
     229                $this->newProject->setBasedir($this->dir); 
     230                 
     231                // Now we must reset $this->dir so that it continues to resolve to the same 
     232                // path. 
     233                $this->dir = new PhingFile($dirAbsPath); 
     234                 
    218235                if ($savedDir !== null) { // has been set explicitly 
    219236                    $this->newProject->setInheritedProperty("project.basedir", $this->dir->getAbsolutePath()); 
    220                 }                                 
     237                } 
     238                 
    221239            } else { 
    222                 $this->dir = $this->getProject()->getBaseDir(); 
     240                 
     241                // Since we're not changing the basedir here (for file resolution), 
     242                // we don't need to worry about any side-effects in this scanrio. 
     243                $this->dir = $this->getProject()->getBasedir();    
    223244            } 
    224245 
     
    258279            $this->log($e->getMessage(), PROJECT_MSG_ERR); 
    259280             
    260             // important!!! continue on to perform cleanup 
    261             // tasks.     
    262            } 
    263          
    264         //  } finally { 
    265         // restore values (prevent side-effects) 
    266         // !this must match code in catch () {}  block! 
     281            // important!!! continue on to perform cleanup tasks.     
     282                } 
     283         
     284         
     285        // reset environment values to prevent side-effects. 
     286         
    267287        $this->newProject = null; 
    268288        $pkeys = array_keys($this->properties); 
    269289        foreach($pkeys as $k) { 
    270290            $this->properties[$k]->setProject(null); 
    271         }         
     291        } 
     292         
    272293        $this->dir = $savedDir;         
    273294        $this->phingFile = $savedPhingFile; 
    274295        $this->newTarget = $savedTarget; 
    275296         
    276         // [HL] change back to correct dir 
    277         if ($this->dir !== null) { 
    278             chdir($this->dir->getAbsolutePath()); 
    279         } 
    280  
    281         if ($this->haltOnFailure == true && $buildFailed == true) 
    282             throw new BuildException("Execution of the target buildfile failed. Aborting."); 
     297        // If the basedir for any project was changed, we need to set that back here. 
     298        if ($savedBasedirAbsPath !== null) { 
     299            chdir($savedBasedirAbsPath); 
     300        } 
     301 
     302        if ($this->haltOnFailure && $buildFailed) { 
     303                        throw new BuildException("Execution of the target buildfile failed. Aborting."); 
     304                } 
    283305    } 
    284306