日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

转: ant condition使用

發布時間:2023/11/29 编程问答 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 转: ant condition使用 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

評注: 用c語言的方式來,比喻ant...比較好理解

轉:?http://www.smithfox.com/?e=176

[備忘] Apache Ant中的邏輯判斷

?

[原創鏈接:?http://www.smithfox.com/?e=176 轉載請保留此聲明, 謝謝!!?]

在寫Ant時有時免不了要簡單的邏輯,?本文并沒有創造什么新的好辦法, 只是著眼于將一些 "似懂非懂" 的概念理清一下.

相信第一次遇到這樣的問題時, 你一定能搜索到很多的內容, 零散的concept進入了你的腦中: condition, if, else, else if, then, unless, avaliable, ant-contrib.

先不管這些, 看一段 ?程序員都能看懂的代碼:

function test():void {if( (a!=null && b=="hello") || ( fileExist("/good.txt") ) ) {printf("11111");} else {printf("33333");} }

很顯然上面這段代碼很難直接體現在 Ant這樣以XML為載體的描述式腳本中, 再改造一下:

function test():void {var flag:Boolean = conditaion( or( and(a!=null,b=="hello"), fileExist("/good.txt") ) );if( flag ) {printf("11111");} else {printf("33333");} }

為什么要這樣改造, 因為對應的Ant是這樣寫的:

<?xml version="1.0" encoding="UTF-8"?><project name="anttest" default="printf11111"><!-- 這個Ant Project的默認target是printf11111, 為了使Ant能自動調用 printf33333將 printf33333 放到它的 depends --><target name="printf1111" depends="getflag, printf33333" if="flag"><echo message="11111"/></target><target name="printf33333" depends="getflag" unless="flag"><echo message="33333"/></target><target name="getflag"><condition property="flag"><or><and><isset property="a"/><equals arg1="${b}" arg2="hello" /></and><available file="/good.txt" type="file"/></or></condition></target> </project>

你肯定會有兩點感受: 一是,覺得這個真的很啰嗦, 二是, 這么多的新出來的字眼, 我到哪去找呀?

好吧, 先解決第二個問題, 給幾個鏈接:

http://ant.apache.org/manual/Tasks/conditions.html

http://ant.apache.org/manual/targets.html

再看第一個問題, 在啰嗦中找點規律:

1. Ant的邏輯分支的粒度是 target,?因為 if 和 unless(作用相當于else) 是 target的屬性

2. Ant的邏輯體現在 property(相當于變量)上, 因為 if 和 unless 只接受 property

3. condition這個task, 是邏輯組合器, 它的作用相當于: var flag:Boolean = (xxx);

你會發現寫一個這么簡單的東東, 都要搞好幾個target, 主要還是因為: "Ant的邏輯分支持粒度是 target", 在Ant中比target小的粒度是 task, 那有沒有task級別的 邏輯分支呢? 這時候 ant-contrib 就華麗登場了.

其實ant-contrib 重用了 Ant的conditions(不是condition task), 而廢棄了 condition 這個 task, 代之以 if, else, elseif再加then 這樣的task.

用 ant-conrib的例子如下:

<?xml version="1.0" encoding="UTF-8"?><project name="anttest" default="print"><property name="a" value="somevalue"/><property name="b" value="hello"/><taskdef resource="net/sf/antcontrib/antlib.xml" classpath="${basedir}/ant-contrib-1.0b3.jar" /><target name="print"><if><or><and><isset property="a"/><equals arg1="${b}" arg2="hello" /></and><available file="/good.txt" type="file"/></or><then><echo message="11111" /></then><else><echo message="33333" /></else></if></target></project>

你會發現用ant-contrib比直接用 ant內置的簡潔多了, 而且可讀性也增強了. 這主要是因為, if, else 這樣的邏輯分支已經是?ant task 級別了.

[原創鏈接:?http://www.smithfox.com/?e=176 轉載請保留此聲明, 謝謝!!?]

轉載于:https://www.cnblogs.com/jhj117/p/5626109.html

總結

以上是生活随笔為你收集整理的转: ant condition使用的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。