gpt4 book ai didi

phing - 将所有构建文件导入目录-phing

转载 作者:行者123 更新时间:2023-12-01 10:02:09 26 4
gpt4 key购买 nike

我需要使用ImportTask在我当前的build.xml中包括目录中的所有xml文件(我不知道文件的名称和数量)。

这是我的build.xml文件:

<?xml version="1.0" encoding="utf-8"?>
<project name="New Project" basedir="." default="myimport">
<target name="myimport" description="dummy to import other build files">
<if>
<isset property="file" />
<then>
<echo msg="Importing ${file}" />
<import file="${file}" />
</then>
</if>
</target>

<if>
<not>
<isset property="dummy.property" />
</not>
<then>
<echo msg="Now include all files in ./dev/build directory" />
<property name="dummy.property" value="true" />
<foreach param="msg" absparam="file" target="myimport">
<fileset dir="./dev/build/">
<include name="*.xml"/>
</fileset>
</foreach>
</then>
</if>
</project>

和目标目录中的示例文件:
<?xml version="1.0" encoding="utf-8"?>
<project name="test" basedir="." default="dummy">
<target name="dummy" description="Dummy task">
<echo msg="Dummy task, just for test" />
</target>

<echo msg="Imported!" />
</project>

当我运行 phing -l时,结果是:
Buildfile: /home/f0rud/workspace/s/build.xml
[echo] Now include all files in ./dev/build directory
[foreach] Calling Buildfile '/home/f0rud/workspace/s/build.xml' with target 'myimport'

New Project > myimport:

[echo] Importing ./dev/build/test.xml
[echo] Imported!
Default target:
----------------------------------------------------------------------------
myimport dummy to import other build files

Main targets:
----------------------------------------------------------------------------
myimport dummy to import other build files

但是没有伪目标(或test.dummy),为什么?

注意:有一个有趣的错误,如果删除if部分,则会得到 Maximum function nesting level of '100' reached, aborting! error,但这不是我的问题(if解决了该问题。)

最佳答案

问题是在全球范围内导入工作。

当我在目标内部调用它时,它在全局上下文中不可用。

因此,我编写了一个简单的Phing任务来加载文件集的所有文件,如下所示:

class ImportDirTask extends Task {

/** Array of filesets */
private $filesets = array();

/**
* Nested creator, adds a set of files (nested fileset attribute).
*/
function createFileSet() {
$num = array_push($this->filesets, new FileSet());
return $this->filesets[$num-1];
}

/**
* Parse a Phing build file and copy the properties, tasks, data types and
* targets it defines into the current project.
*
* @return void
*/
public function main () {
// filesets
foreach ($this->filesets as $fs) {
$ds = $fs->getDirectoryScanner($this->project);
$srcFiles = $ds->getIncludedFiles();
$srcDirs = $ds->getIncludedDirectories();
foreach ($srcFiles as $f)
{
$task = new ImportTask();
$task->setProject($this->project);
$task->init();
$task->setFile($this->file = $fs->getDir($this->project) . FileSystem::getFileSystem()->getSeparator() . $f);
$task->main();
}

}
} //end main

} //end ImportDirTask

就是这样。

关于phing - 将所有构建文件导入目录-phing,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10690150/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com