通辽网站开发0475seo,网站建设适合女生吗,做网站域名还重要吗,福州网站排名推广评注#xff1a; 用c语言的方式来#xff0c;比喻ant...比较好理解 转#xff1a; http://www.smithfox.com/?e176 [备忘] Apache Ant中的逻辑判断 [原创链接: http://www.smithfox.com/?e176 转载请保留此声明, 谢谢!! ] 在写Ant时有时免不了要简单的逻辑, 本文并没有创造…评注 用c语言的方式来比喻ant...比较好理解 转 http://www.smithfox.com/?e176 [备忘] Apache Ant中的逻辑判断 [原创链接: http://www.smithfox.com/?e176 转载请保留此声明, 谢谢!! ] 在写Ant时有时免不了要简单的逻辑, 本文并没有创造什么新的好办法, 只是着眼于将一些 似懂非懂 的概念理清一下. 相信第一次遇到这样的问题时, 你一定能搜索到很多的内容, 零散的concept进入了你的脑中: condition, if, else, else if, then, unless, avaliable, ant-contrib. 先不管这些, 看一段 程序员都能看懂的代码: function test():void {if( (a!null bhello) || ( fileExist(/good.txt) ) ) {printf(11111);} else {printf(33333);}
} 很显然上面这段代码很难直接体现在 Ant这样以XML为载体的描述式脚本中, 再改造一下: function test():void {var flag:Boolean conditaion( or( and(a!null,bhello), fileExist(/good.txt) ) );if( flag ) {printf(11111);} else {printf(33333);}
} 为什么要这样改造, 因为对应的Ant是这样写的: ?xml version1.0 encodingUTF-8?project nameanttest defaultprintf11111!-- 这个Ant Project的默认target是printf11111, 为了使Ant能自动调用 printf33333将 printf33333 放到它的 depends --target nameprintf1111 dependsgetflag, printf33333 ifflagecho message11111//targettarget nameprintf33333 dependsgetflag unlessflagecho message33333//targettarget namegetflagcondition propertyflagorandisset propertya/equals arg1${b} arg2hello //andavailable file/good.txt typefile//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 version1.0 encodingUTF-8?project nameanttest defaultprintproperty namea valuesomevalue/property nameb valuehello/taskdef resourcenet/sf/antcontrib/antlib.xml classpath${basedir}/ant-contrib-1.0b3.jar /target nameprintiforandisset propertya/equals arg1${b} arg2hello //andavailable file/good.txt typefile//orthenecho message11111 //thenelseecho message33333 //else/if/target/project 你会发现用ant-contrib比直接用 ant内置的简洁多了, 而且可读性也增强了. 这主要是因为, if, else 这样的逻辑分支已经是 ant task 级别了. [原创链接: http://www.smithfox.com/?e176 转载请保留此声明, 谢谢!! ]转载于:https://www.cnblogs.com/jhj117/p/5626109.html