У меня есть список файлов из 25 файлов. Мне нужно выполнить определенную финговую цель, когда изменилось время изменения одного из этих файлов. Каков наилучший способ сделать это?Выполнение финговой цели при изменении файла
0
A
ответ
1
1
Расширение phing путем написания собственной задачи. Что-то вроде этого, которое использует набор файлов. Ограниченный просмотр файлов только для изменений.
<?php
/**
Example target:
<target name="mytarget">
<react refresh="1.7" cmd="dosomething.sh">
<fileset dir=".">
<include name="*.txt" />
</fileset>
</react>
</target>
Will call dosomething.sh script when a txt file has changed in the current
directory every 1.7 seconds.
$Id: ReactTask.php 123 2013-07-22 08:16:26Z gregory.vincic $
*/
require_once "phing/Task.php";
class ReactTask extends Task {
/** Command to execute */
private $cmd = null;
public function setCmd($str) {
$this->cmd = $str;
}
/** Refresh time in microseconds, defaults to 1 second. */
private $refresh = 1000000;
public function setRefresh($str) {
if($str != null && is_numeric($str)) {
$this->refresh = $str*1000000;
}
}
/** Any filesets of files that should be appended. */
private $filesets = array();
function createFileSet() {
$num = array_push($this->filesets, new FileSet());
return $this->filesets[$num-1];
}
/** Uses phps passthru to execute the configured command every X seconds */
public function main() {
$lastmtime = null;
$this->log("Refreshing every " . $this->refresh/1000000 . " seconds.\n", Project::MSG_WARN);
while(1) {
$mtimes = $this->rlist();
if(count($mtimes) > 0 && max($mtimes) > $lastmtime) {
passthru($this->cmd);
$lastmtime = max($mtimes);
}
usleep($this->refresh);
}
}
/** Lists modification times of all the files defined by your filesets. */
private function rlist() {
$res = array();
foreach($this->filesets as $fs) {
try {
$files = $fs->getDirectoryScanner($this->project)->getIncludedFiles();
foreach ($files as $file) {
$path = $fs->dir . "/" . $file;
$res[] = filemtime($path);
}
} catch (BuildException $be) {
$this->log($be->getMessage(), Project::MSG_WARN);
}
}
return $res;
}
}
?>
В какой ОС вы находитесь? –
Ubuntu, но скрипт сборки может использоваться совместно с людьми, которые используют Windows. –