Target called via <phingcall> doesn't set properties in calling target
Asked Answered
L

2

7

In the following phing xml, inside the "skel" target I check if the app is configured, if it's not then I call the configure target and then apply the config to several files.

The problem is that property db.host is not set after the phingcall, even though it is set after the propertyprompt.

What am I missing?

<!-- 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>
Lexicologist answered 19/11, 2009 at 14:40 Comment(0)
P
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.

Porcelain answered 5/1, 2010 at 11:23 Comment(0)
W
2

Properties set inside of targets are scoped to those targets and are not accessible outside their parent targets.

From the documentation for PropertyTask:

Important note about scope: when the <property> tag is called inside a <phingcall> tag, any properties are set in a new local scope. Thus, any properties or other variables set inside that scope will cease to exist (or revert to their previous value) once the parent <phingcall> tag completes.

Wingding answered 11/10, 2012 at 16:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.