我有要求用户输入一个ant脚本。我想,以确保正确的输入类型已经由用户输入,如果没有,提示他们输入的东西是正确的。如何检查输入任务中的输入是否为空?
<input message="secure-input:" addproperty="the.password" >
</input>
我必须检查输入是否为空然后我会提示他们重新输入。
是否有可能在蚂蚁输入任务?
我有要求用户输入一个ant脚本。我想,以确保正确的输入类型已经由用户输入,如果没有,提示他们输入的东西是正确的。如何检查输入任务中的输入是否为空?
<input message="secure-input:" addproperty="the.password" >
</input>
我必须检查输入是否为空然后我会提示他们重新输入。
是否有可能在蚂蚁输入任务?
大多数条件子句的最好,让您fail脚本如果不符合某些条件。我想象你正在收集用户的一些输入,所以如果用户提供空密码失败可能不是最好的可用性体验,因为他将不得不重新输入一切......
此外,只是测试一个空字符串似乎是一个糟糕的验证,如果用户提交了一堆空格呢?
我(诚然hackish的)建议如下:
<target name="askPassword">
<local name="passwordToValidate"/>
<input message="secure-input:" addproperty="passwordToValidate"/>
<script language="javascript">
<![CDATA[
passwordToValidate = project.getProperty("passwordToValidate");
//You can add more validations here...
if(passwordToValidate.isEmpty()){
println("The password cannot be empty.");
project.executeTarget('askPassword');
}
]]>
</script>
<property name="the.password" value="${passwordToValidate}"/>
</target>
所以亮点:
我的2美分。
看看Conditions - 为condition
任务。
您可以使用条件任务以检查输入是不是空的,但你也可以使用antcontrib添加的if/else和显示用户相应的消息:
<if>
<not>
<length string="${the.password}" trim="true" when="greater" length="0" />
</not>
</if>
<then>
<echo>Your password is empty!</echo>
</then>
感谢Paulp ..我从来没有想过的JavaScript可以Ant构建内部使用... :) – Shashi 2013-03-15 05:46:27