Permalink
Browse files

Added FileList support to the TouchTask (#756)

  • Loading branch information...
siad007 authored and mrook committed Aug 24, 2017
1 parent 76f90f5 commit 48be70f42117ed77061c5d41a3347aeb42c8e688
@@ -45,6 +45,9 @@ class TouchTask extends Task
private $mkdirs = false;
private $verbose = true;
/** @var FileList[] $filelists */
private $filelists = [];
/**
*
*/
@@ -119,6 +122,17 @@ public function addFileSet(FileSet $fs)
$this->filesets[] = $fs;
}
/**
* Nested adder, adds a set of files (nested fileset attribute).
*
* @param FileSet $fs
* @return void
*/
public function addFileList(FileList $fl)
{
$this->filelists[] = $fl;
}
/**
* Execute the touch operation.
* @throws BuildException
@@ -127,8 +141,8 @@ public function main()
{
$savedMillis = $this->millis;
if ($this->file === null && count($this->filesets) === 0) {
throw new BuildException("Specify at least one source - a file or a fileset.");
if ($this->file === null && count($this->filesets) === 0 && count($this->filelists) === 0) {
throw new BuildException("Specify at least one source - a file, a fileset or a filelist.");
}
if ($this->file !== null && $this->file->exists() && $this->file->isDirectory()) {
@@ -194,6 +208,17 @@ public function _touch()
}
}
// deal with the filelists
foreach ($this->filelists as $fl) {
$fromDir = $fl->getDir($this->getProject());
$srcFiles = $fl->getFiles($this->getProject());
for ($j = 0, $_j = count($srcFiles); $j < $_j; $j++) {
$this->touchFile(new PhingFile($fromDir, (string) $srcFiles[$j]));
}
}
if ($resetMillis) {
$this->millis = -1;
}
View
@@ -1721,6 +1721,7 @@
<choice>
<attribute name="file"/>
<ref name="fileset"/>
<ref name="filelist"/>
</choice>
<optional>
<attribute name="datetime"/>
@@ -1731,12 +1732,12 @@
</attribute>
</optional>
<optional>
<attribute name="mkdirs">
<attribute name="mkdirs" a:defaultValue="false">
<data type="boolean"/>
</attribute>
</optional>
<optional>
<attribute name="verbose">
<attribute name="verbose" a:defaultValue="true">
<data type="boolean"/>
</attribute>
</optional>
@@ -73,4 +73,22 @@ public function testMkdirsFails()
. "/etc/tasks/system/tmp/this/is/a/test/file"
);
}
public function testFilelist()
{
$this->executeTarget(__FUNCTION__);
$this->assertFileExists(
PHING_TEST_BASE
. "/etc/tasks/system/tmp/simple-file"
);
}
public function testFileset()
{
$this->executeTarget(__FUNCTION__);
$this->assertFileExists(
PHING_TEST_BASE
. "/etc/tasks/system/tmp/simple-file"
);
}
}
@@ -22,5 +22,17 @@
<touch file="${tmp.dir}/this/is/a/test/file"/>
</target>
<target name="testFilelist">
<touch millis="662256000000" >
<filelist dir="${tmp.dir}" files="simple-file"/>
</touch>
</target>
<target name="testFileset" depends="testSimpleTouch">
<touch millis="946080000000" >
<fileset dir="${tmp.dir}" includes="simple-file"/>
</touch>
</target>
<target name="main"/>
</project>

0 comments on commit 48be70f

Please sign in to comment.