[ Index ]
 

Code source de Symfony 1.0.0

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/lib/vendor/phing/tasks/system/ -> ResolvePathTask.php (source)

   1  <?php
   2  /*
   3   *  $Id: ResolvePathTask.php 3076 2006-12-18 08:52:12Z fabien $  
   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  
  22  require_once 'phing/Task.php';
  23  
  24  /**
  25   * Task for resolving relative paths and setting absolute path in property value.
  26   * 
  27   * This task was created to address a need for resolving absolute paths of files / directories.
  28   * In many cases a relative directory (e.g. "./build") is specified, but it needs to be treated
  29   * as an absolute path since other build files (e.g. in subdirs) should all be using the same
  30   * path -- and not treating it as a relative path to their own directory.
  31   * 
  32   * <code>
  33   * <property name="relative_path" value="./dirname"/>
  34   * <resolvepath propertyName="absolute_path" file="${relative_path}"/>
  35   * <echo>Resolved [absolute] path: ${absolute_path}</echo>
  36   * </code>
  37   * 
  38   * TODO:
  39   *      - Possibly integrate this with PackageAsPath, for handling/resolving dot-path paths.
  40   * 
  41   * @author    Hans Lellelid <hans@xmpl.org>
  42   * @version   $Revision: 1.6 $
  43   * @package   phing.tasks.system
  44   */
  45  class ResolvePathTask extends Task {
  46  
  47      /** Name of property to set. */
  48      private $propertyName;
  49      
  50      /** The [possibly] relative file/path that needs to be resolved. */
  51      private $file;
  52      
  53      /** Base directory used for resolution. */
  54      private $dir;
  55      
  56      /**
  57       * Set the name of the property to set.
  58       * @param string $v Property name
  59       * @return void
  60       */
  61      public function setPropertyName($v) {
  62          $this->propertyName = $v;
  63      }
  64      
  65      /**
  66       * Sets a base dir to use for resolution.
  67       * @param PhingFile $d
  68       */
  69      function setDir(PhingFile $d) {
  70          $this->dir = $d;
  71      }
  72      
  73      /**
  74       * Sets a path (file or directory) that we want to resolve.
  75       * This is the same as setFile() -- just more generic name so that it's
  76       * clear that you can also use it to set directory.
  77       * @param string $f
  78       * @see setFile()
  79       */
  80      function setPath($f) {
  81          $this->file = $f;
  82      }
  83      
  84      /**
  85       * Sets a file that we want to resolve.
  86       * @param string $f
  87       */
  88      function setFile($f) {
  89          $this->file = $f;
  90      }
  91  
  92      /**
  93       * Perform the resolution & set property.
  94       */
  95      public function main() {        
  96          
  97          if (!$this->propertyName) {
  98              throw new BuildException("You must specify the propertyName attribute", $this->getLocation());
  99          }
 100          
 101          // Currently only files are supported
 102          if ($this->file === null) {
 103              throw new BuildException("You must specify a path to resolve", $this->getLocation());
 104          }
 105          
 106          $fs = FileSystem::getFileSystem();
 107          
 108          // if dir attribute was specified then we should
 109          // use that as basedir to which file was relative.
 110          // -- unless the file specified is an absolute path
 111          if ($this->dir !== null && !$fs->isAbsolute(new PhingFile($this->file))) {
 112              $resolved = new PhingFile($this->dir->getPath(), $this->file);
 113          } else {
 114              // otherwise just resolve it relative to project basedir
 115              $resolved = $this->project->resolveFile($this->file);
 116          }
 117          
 118          $this->log("Resolved " . $this->file . " to " . $resolved->getAbsolutePath(), PROJECT_MSG_INFO);
 119          $this->project->setProperty($this->propertyName, $resolved->getAbsolutePath());
 120      }
 121  
 122  }


Généré le : Fri Mar 16 22:42:14 2007 par Balluche grâce à PHPXref 0.7