“if-else”如何实现?使用“条件”来模拟逻辑?

发布于 2024-09-08 13:41:38 字数 234 浏览 1 评论 0原文

我知道有ant-contrib,它为ant提供了“if-else”逻辑。 但我需要实现相同的没有ant-contrib。这可能吗?

我需要工作的伪代码:

if(property-"myProp"-is-true){
  do-this;
}else{
  do-that;
}

谢谢!

I know that there is ant-contrib, which provides "if-else" logic for ant.
But I need to achieve the same without ant-contrib. Is that possible?

Pseudocode which I need to work:

if(property-"myProp"-is-true){
  do-this;
}else{
  do-that;
}

Thank you!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

烂柯人 2024-09-15 13:41:38

无论如何,我强烈建议使用 ant-contribs,但如果您正在测试一个始终具有值的属性,我会考虑使用 ant 宏参数作为您随后测试的新属性的名称的一部分

<macrodef name="create-myprop-value">
 <attribute name="prop"/>
 <sequential>
      <!-- should create a property called optional.myprop.true or -->
      <!-- optional.myprop.false -->
      <property name="optional.myprop.@{prop}" value="set" />
 </sequential>
</macrodef>

<target name="load-props">
  <create-myprop-value prop="${optional.myprop}" /> 
</target>

<target name="when-myprop-true" if="optional.myprop.true" depends="load-props">
...
</target>

<target name="when-myprop-false" if="optional.myprop.false" depends="load-props">
...
</target>

<target name="do-if-else" depends="when-myprop-true,when-myprop-false">
...
</target>

I would strongly recommend using ant-contribs anyway but if you are testing a property that always has a value I would look into using an ant macro parameter as part of the name of a new property that you then test for

<macrodef name="create-myprop-value">
 <attribute name="prop"/>
 <sequential>
      <!-- should create a property called optional.myprop.true or -->
      <!-- optional.myprop.false -->
      <property name="optional.myprop.@{prop}" value="set" />
 </sequential>
</macrodef>

<target name="load-props">
  <create-myprop-value prop="${optional.myprop}" /> 
</target>

<target name="when-myprop-true" if="optional.myprop.true" depends="load-props">
...
</target>

<target name="when-myprop-false" if="optional.myprop.false" depends="load-props">
...
</target>

<target name="do-if-else" depends="when-myprop-true,when-myprop-false">
...
</target>
倦话 2024-09-15 13:41:38

您可以在目标中添加“if”属性。

<target name="do-this-when-myProp-is-true" if="myProp">
...
</target>

仅当设置了“myProp”时才会触发。您需要在其他地方定义 myProp,以便在您希望触发此目标时对其进行设置。如果你不这样做就不会。您可以使用 except 作为替代情况:

<target name="do-this-when-myProp-is-false" unless="myProp">
...
</target>

You can put an "if" attribute in your targets.

<target name="do-this-when-myProp-is-true" if="myProp">
...
</target>

This will fire only if "myProp" is set. You'll need to define myProp elsewhere such that it's set if you want this target to fire & not if you don't. You can use unless for the alternate case:

<target name="do-this-when-myProp-is-false" unless="myProp">
...
</target>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文