Date: 2004-10-19T23:15:09 Editor: JanMatèrne <[EMAIL PROTECTED]> Wiki: Ant Wiki Page: AntTasks URL: http://wiki.apache.org/ant/AntTasks
Execut a target depending on the value of a property Change Log: ------------------------------------------------------------------------------ @@ -46,5 +46,44 @@ BUILD SUCCESSFUL Total time: 3 seconds }}} + +== The AntCall Task == + +[http://ant.apache.org/manual/CoreTasks/antcall.html] + +Sometimes on the mailinglists there is a question on how to invoke a special target depending +on the '''value''' of a property. Because there could be more than two values, you can´t use +the usual if/unless-attributes of the target. + +But the solution is quite easy: compound the name of the target by a common term and the value +itself and let antcall do the job. + +__Ant Example Target__ +{{{ +<project default="call"> + <target name="foo-upload"><echo>FOO upload</echo></target> + <target name="bar-upload"><echo>BAR upload</echo></target> + <target name="test-upload"><echo>TEST upload</echo></target> + + <target name="call"> + <input message="Please choose the server " + validargs="foo,bar,test" + addproperty="server" + defaultvalue="test" + /> + <antcall target="${server}-upload"/> + </target> +</project> +}}} + +You have only to ensure, that there are valid values for that property, e.g. a ''blabla'' would call the +non existing ''blabla-upload'' which results in an error. But the input task here will ensure that. + +BTW - the same can be used for loading platform specific properties: +{{{ +<property file="${os.name}.properties"/> +<property file="default.properties"/> +}}} + ---- CategoryCategory --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]