123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160 |
- <?php
- class SourceFileScanner {
-
- private $fileUtils;
-
-
- private $task;
-
- function __construct($task) {
- $this->task = $task;
- $this->fileUtils = new FileUtils();
- }
-
- function restrict(&$files, $srcDir, $destDir, $mapper, $force = false) {
- $now = time();
- $targetList = "";
-
- $osname = strtolower(Phing::getProperty('os.name'));
-
- $index = ((($res = strpos($osname, 'win')) === false) ? -1 : $res);
- if ($index >= 0 ) {
- $now += 2000;
- }
- $v = array();
- for ($i=0, $size=count($files); $i < $size; $i++) {
-
- $targets = $mapper->main($files[$i]);
- if (empty($targets)) {
- $this->task->log($files[$i]." skipped - don't know how to handle it", Project::MSG_VERBOSE);
- continue;
- }
- $src = null;
- try {
- if ($srcDir === null) {
- $src = new PhingFile($files[$i]);
- } else {
- $src = $this->fileUtils->resolveFile($srcDir, $files[$i]);
- }
-
- if ($src->lastModified() > $now) {
- $this->task->log("Warning: ".$files[$i]." modified in the future (".$src->lastModified()." > ".$now.")", Project::MSG_WARN);
- }
- } catch (IOException $ioe) {
- $this->task->log("Unable to read file ".$files[$i]." (skipping): " . $ioe->getMessage());
- continue;
- }
-
- $added = false;
- $targetList = "";
- for ($j=0,$_j=count($targets); (!$added && $j < $_j); $j++) {
- $dest = null;
- if ($destDir === null) {
- $dest = new PhingFile($targets[$j]);
- } else {
- $dest = $this->fileUtils->resolveFile($destDir, $targets[$j]);
- }
- if (!$dest->exists()) {
- $this->task->log($files[$i]." added as " . $dest->__toString() . " doesn't exist.", Project::MSG_VERBOSE);
- $v[] =$files[$i];
- $added = true;
- } elseif ($src->lastModified() > $dest->lastModified()) {
- $this->task->log($files[$i]." added as " . $dest->__toString() . " is outdated.", Project::MSG_VERBOSE );
- $v[]=$files[$i];
- $added = true;
- } elseif ($force === true) {
- $this->task->log($files[$i]." added as " . $dest->__toString() . " is forced to be overwritten.", Project::MSG_VERBOSE );
- $v[]=$files[$i];
- $added = true;
- } else {
- if (strlen($targetList) > 0) {
- $targetList .= ", ";
- }
- $targetList .= $dest->getAbsolutePath();
- }
- }
- if (!$added) {
- $this->task->log($files[$i]." omitted as ".$targetList." ".(count($targets) === 1 ? " is " : " are ")."up to date.", Project::MSG_VERBOSE);
- }
- }
- $result = array();
- $result = $v;
- return $result;
- }
-
- function restrictAsFiles(&$files, &$srcDir, &$destDir, &$mapper) {
- $res = $this->restrict($files, $srcDir, $destDir, $mapper);
- $result = array();
- for ($i=0; $i<count($res); $i++) {
- $result[$i] = new PhingFile($srcDir, $res[$i]);
- }
- return $result;
- }
- }
|