本文介绍了如何比较 ANT 脚本中的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个 ANT 脚本来构建我的 iOS 应用程序.我希望用户输入应为其创建 ipa 文件的环境名称.例如开发或生产或 QA 或 UAT.我有以下代码段来接受用户输入并将其存储在名为 environment 的属性中:

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

推荐答案

我强烈建议您放弃接受用户输入的计划.构建不应该接受用户输入,如果你想自动化它会发生什么?我假设所有构建都不需要交互式输入.

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.

蚂蚁 QA

接下来最好是在命令行中指定环境属性

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

ant -Denv="dev"

在蚂蚁中没有如果.您可能会被引诱到 ant-contrib,这不是路径.如果您发现自己需要它,您可能更适合使用不同的构建工具或编写自己的 ant 任务.

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 属性有条件地运行它们,如下所示:

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}">

if 属性在设置属性时执行目标.

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

这篇关于如何比较 ANT 脚本中的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 16:47