How to compare strings in ANT script

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..

Answers


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.


Need Your Help

Exception Message: TF270015: 'MSBuild.SonarQube.Runner.exe' returned an unexpected exit code. Expected '0'; actual '-532462766'

msbuild ldap sonarqube sonarqube-msbuild-runner sonarqube5.2

I am trying to integrate SonarQube MSBuild runner with TFS 2013 and I am using SonarQube 5.2 version and MSBuild.SonarQube.Runner-1.0.2 with all the required plug-ins for LDAP, .NET and C#. I get t...

rpy2 on pycharm generates segmentation fault error

python-2.7 pycharm rpy2

I am using (osx) pycharm as ide and anaconda as python (2.7.10) distribution.