7

在以下 phing xml 中,在“skel”目标内,我检查应用程序是否已配置,如果未配置,则调用配置目标,然后将配置应用于多个文件。

问题是db.host在 phingcall 之后没有设置属性,即使它是在属性提示之后设置的。

我错过了什么?

<!-- base configuration -->
<property name="paths.config" value="config" />
<property name="paths.config.file" value="${paths.config}/environment.ini" />

<available file="${paths.config.file}" property="configured" />

<target name="configure">
    <if>
     <equals arg1="${configured}" arg2="true" />
     <then>
       <echo message="Reconfigure ..." />
     </then>
     <else>
       <echo message="Configure ..." />
     </else>
    </if>

    <propertyprompt propertyName="db.host" defaultValue="localhost" promptText="Mysql Server Host" />
</target>

<target name="skel">
    <echo msg="Skel files..." />

    <if>
     <equals arg1="${configured}" arg2="${configured}" />
     <then>
       <echo message="Missing config file ..." />
       <phingcall target="configure" />
     </then>
    </if>

    <echo message="${db.host}" />
    <copy todir="config">
        <mapper type="glob" from="*.skel" to="*"/>
        <filterchain>
            <expandproperties />
        </filterchain>

        <fileset dir="config">
            <include name="*.skel" />
        </fileset>
    </copy>
</target>
4

2 回答 2

6

I think the phingcall will create a new environment internally. When the configure target is done, this environment is out of scope.

This means it is not possible to use a separate configure target as you are suggesting.

The only solution might be to make the configure target create a configuration file which is used by the other targets.

于 2010-01-05T11:23:20.573 回答
2

在目标内部设置的属性的范围仅限于这些目标,并且在其父目标之外无法访问。

文档中PropertyTask

关于作用域的重要说明:<property>标记在标记内被调用时<phingcall>,任何属性都会在新的本地作用域中设置。<phingcall>因此,一旦父标签完成,在该范围内设置的任何属性或其他变量都将不复存在(或恢复为之前的值) 。

于 2012-10-11T16:32:17.233 回答