[ Index ]
 

Code source de Symfony 1.0.0

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

title

Body

[fermer]

/lib/vendor/phing/util/ -> SourceFileScanner.php (source)

   1  <?php
   2  /*
   3   *  $Id: SourceFileScanner.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  /**
  23   *  Utility class that collects the functionality of the various
  24   *  scanDir methods that have been scattered in several tasks before.
  25   *
  26   *  The only method returns an array of source files. The array is a
  27   *  subset of the files given as a parameter and holds only those that
  28   *  are newer than their corresponding target files.
  29   *  @package   phing.util
  30   */
  31  class SourceFileScanner {
  32  
  33      /** Instance of FileUtils */
  34      private $fileUtils;
  35      
  36      /** Task this class is working for -- for logging purposes. */
  37      private $task;
  38  
  39      /**
  40       * @param task The task we should log messages through
  41       */
  42      function __construct($task) {
  43          $this->task = $task;
  44          $this->fileUtils = new FileUtils();
  45      }
  46  
  47      /**
  48       * Restrict the given set of files to those that are newer than
  49       * their corresponding target files.
  50       *
  51       * @param files   the original set of files
  52       * @param srcDir  all files are relative to this directory
  53       * @param destDir target files live here. if null file names
  54       *                returned by the mapper are assumed to be absolute.
  55       * @param FilenameMapper  knows how to construct a target file names from
  56       *                source file names.
  57       * @param force   Boolean that determines if the files should be
  58       *                forced to be copied.
  59       */
  60      function restrict(&$files, $srcDir, $destDir, $mapper, $force = false) {
  61          $now = time();
  62          $targetList = "";
  63  
  64          /*
  65            If we're on Windows, we have to munge the time up to 2 secs to
  66            be able to check file modification times.
  67            (Windows has a max resolution of two secs for modification times)
  68          */
  69          $osname = strtolower(Phing::getProperty('os.name'));
  70  
  71          // indexOf()
  72          $index = ((($res = strpos($osname, 'win')) === false) ? -1 : $res);
  73          if ($index  >= 0 ) {
  74              $now += 2000;
  75          }
  76  
  77          $v = array();
  78  
  79          for ($i=0, $size=count($files); $i < $size; $i++) {
  80          
  81              $targets = $mapper->main($files[$i]);
  82              if (empty($targets)) {
  83                  $this->task->log($files[$i]." skipped - don't know how to handle it", PROJECT_MSG_VERBOSE);
  84                  continue;
  85              }
  86  
  87              $src = null;
  88              try {
  89                  if ($srcDir === null) {
  90                      $src = new PhingFile($files[$i]);
  91                  } else {
  92                      $src = $this->fileUtils->resolveFile($srcDir, $files[$i]);
  93                  }
  94      
  95                  if ($src->lastModified() > $now) {
  96                      $this->task->log("Warning: ".$files[$i]." modified in the future (".$src->lastModified()." > ".$now.")", PROJECT_MSG_WARN);
  97                  }
  98              } catch (IOException $ioe) {
  99                  $this->task->log("Unable to read file ".$files[$i]." (skipping): " . $ioe->getMessage());
 100                  continue;
 101              }
 102              
 103              $added = false;
 104              $targetList = "";
 105  
 106              for ($j=0,$_j=count($targets); (!$added && $j < $_j); $j++) {
 107  
 108                  $dest = null;
 109                  if ($destDir === null) {
 110                      $dest = new PhingFile($targets[$j]);
 111                  } else {
 112                      $dest = $this->fileUtils->resolveFile($destDir, $targets[$j]);
 113                  }
 114  
 115                  if (!$dest->exists()) {
 116                      $this->task->log($files[$i]." added as " . $dest->__toString() . " doesn't exist.", PROJECT_MSG_VERBOSE);
 117                      $v[] =$files[$i];
 118                      $added = true;
 119                  } elseif ($src->lastModified() > $dest->lastModified()) {
 120                      $this->task->log($files[$i]." added as " . $dest->__toString() . " is outdated.", PROJECT_MSG_VERBOSE );
 121                      $v[]=$files[$i];
 122                      $added = true;
 123                  } elseif ($force === true) {
 124                      $this->task->log($files[$i]." added as " . $dest->__toString() . " is forced to be overwritten.", PROJECT_MSG_VERBOSE );
 125                      $v[]=$files[$i];
 126                      $added = true;
 127                  } else {
 128                      if (strlen($targetList) > 0) {
 129                          $targetList .= ", ";
 130                      }
 131                      $targetList .= $dest->getAbsolutePath();
 132                  }
 133              }
 134  
 135              if (!$added) {
 136                  $this->task->log($files[$i]." omitted as ".$targetList." ".(count($targets) === 1 ? " is " : " are ")."up to date.",  PROJECT_MSG_VERBOSE);
 137              }
 138  
 139          }
 140          $result = array();
 141          $result = $v;
 142          return $result;
 143      }
 144  
 145      /**
 146       * Convenience layer on top of restrict that returns the source
 147       * files as PhingFile objects (containing absolute paths if srcDir is
 148       * absolute).
 149       */
 150      function restrictAsFiles(&$files, &$srcDir, &$destDir, &$mapper) {
 151          $res = $this->restrict($files, $srcDir, $destDir, $mapper);
 152          $result = array();
 153          for ($i=0; $i<count($res); $i++) {
 154              $result[$i] = new PhingFile($srcDir, $res[$i]);
 155          }
 156          return $result;
 157      }
 158  }
 159  ?>


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