How to compare strings in ANT script

烈酒焚心 提交于 2019-12-11 16:46:52

问题


I am writing an ANT script to build my iOS app. I want the user to enter the environment name for which the ipa file should be created. e.g. development or production or QA or UAT. I have the below snippet to accept user input and store it in a property named environment:

<input
message="Enter targeted environment (dev or QA1 or QA2 or UAT1 or UAT2 or staging or perf or prod)"
addproperty="environment"
/>

After the user enters the environment name, I have to check what the user has entered. Then I have to call different targets depending on the user input. Something like:

if (environment== "development")
  // call dev target
else if (environment== "production")
 // call prod target
else if (environment== "QA")
 // call QA target
else if (environment== "UAT")
 // call UAT target

How can I achieve this? Can somebody please help me… Thanks..


回答1:


I strongly urge you to abandon your plan of taking user input. builds shouldn't take user input, what happens if you want to automate it? I assume all builds take no interactive inputs.

Your best plan would be to always specify the target you want.

ant QA

next best would be to specify the environment property on the commandline

ant -Denv="dev"

There is no if in ant. You may be lured into ant-contrib, this isn't the path. If you find yourself needing it, likely you would be better suited with a different build tool or writing your own ant task.

If you wanted to implement the scheme you described you could setup conditions to set properties and then change your targets to conditionally run them with the if attribute like this:

<condition property="env.is.dev"> 
    <equals arg1="${env}" arg2="dev"/> 
</condition> 

<target name="dev" if="${env.is.dev}">

the if attribute executes the target if the property is set.



来源:https://stackoverflow.com/questions/21466526/how-to-compare-strings-in-ant-script

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!