Apache Ant – Check if a file exists with wildcard

The <available> command can help you to check if a file or folder exists. Unfortunately it doesn’t support wildcard checking. Here is an workaround using the <pathconvert> such that we can check if a file or folder exists with wildcard.

<pathconvert property="filePath" setonempty="false" pathsep=" ">
  <path>
    <fileset dir="./" includes="a_file_name_with_wildcard*" />
  </path>
</pathconvert>
<condition property="fileExists">
  <resourcecount when="greater" count="0">
    <fileset file="${filePath}"/>
  </resourcecount>
</condition>
<if>
  <istrue value="${fileExists}"/>
  <then>
    <echo message="File exists"/>
  </then>
  <else>
    <echo message="File NOT exists"/>
  </else>
</if>

 

Please note that it only works if there is only one file matched the wildcard file name. This is because the <pathconvert> would returns more than one file path if there are more than one file. So it’s not a perfect solution but should be good enough for you to explore more from this example.

Done =)

Reference: StackOverflow – How to use wildcard in Ant’s Available command

Drupal 7 – Alter the module execution order

Sometimes you may have 2 different modules implementing hook_form_alter() on the same form. In that case, the order of the module execution would follow the alphabetic order of the module name. If you want to alter the execution order, you could either update the system table in database or install the Modules Weight module.

1. Download and install the Modules Weight.
drupal7-module-execution-order-1
 

2. Go to admin/config/system/modules-weight to adjust the module weight.
drupal7-module-execution-order-2
 

Done =)

Reference:

陶傑 – 上智障而下愚

邱震海博士的「中國人成熟嗎?」,書名是一個老問題。中國人如果「成熟」,不會有人以此為論題,由梁啟超、魯迅和林語堂開始,「論述」了一百年。

中國人之不成熟,源自中國「知識份子」帶頭之愚昧。本來孔子希望「上智下愚」,由讀書人引領農民階級,一起進步,安居樂業。

但是民國知識份子丁文江,是礦學家,留學英國,他的名言:「中國國家弄到這般田地,完全是知識階級的責任。」當時這樣講,在民國北平和上海,引起一陣爭議,同是留學英國的北大教授陳西瀅和應:與中國的知識份子交談,「他們的見解和知識幾乎全部趕不上一般的學生。」

一九八九年,蘇聯共產集團崩潰。其後約有十年,中國的「知識份子」跟着他們的統治者對外宣傳:中國不可以走西方議會民主之路,否則就會步蘇聯解體的後塵。
Continue reading 陶傑 – 上智障而下愚

李怡 – 你不是答案一部份,就是問題一部份

陳淑莊在《我們有份令她墮落》一文中說,她數日前坐的士,司機破口大罵建制派、工聯會尤其是陳婉嫻在特權法動議中支持政府:「呢個陳婉嫻,成日自稱為勞工,投票就變臉!」陳淑莊問他:「你是選民嗎?」他答:「陳小姐,我幾年前載過你,你當時問我做選民未,到𠵱家都未做呀,因為我覺得都冇乜用啦。」陳說,她登時「無名火起。你明知是非黑白,卻選擇沉默妥協,平時將這些公義大事當做吹水題目,關鍵選舉就置之不理。就是這些沉默大多數,令立法會內的保皇黨肆無忌憚」

有港視員工說這是他第一次參加示威集會,網上有人說:過去香港發生這麼多不公平、不公義的事,你都置若罔聞,直到跟自己利益相關的事你才參加。這些示威的缺席者是不是也「有份令香港墮落」?

早前,范國威提出促請政府制訂政策時以港人優先為依歸的動議,遭到立法會否決。這本是一個常識性的動議。全世界包括中國大陸各城市在內,都是當地人優先,因為當地人持續多年交稅或對當地作貢獻。范的動議,要點在要求減少大陸移民配額,要求取回大陸人的入境審批權。但反對的議員認為,不應將社會問題歸咎於新移民,更批評范的本土主義和排外思想撕裂社會。建制派之外,連泛民的22位議員也召開記者會,以「反歧視、反分化、反排外」作口號,譴責將中港矛盾的問題歸咎於新移民,又批評范、毛(孟靜)二人提出減少新移民來港配額,「令港人蒙羞」。他們的理由是支持家庭團聚。
Continue reading 李怡 – 你不是答案一部份,就是問題一部份

Apache Ant – Using scp and sshexec tasks in build.xml

Unlike the Ant Contrib library which could be included thru the <taskdef>, the <scp> and <sshexec> tasks could not be included in this way or it will throw the following errors.

  • A class needed by class org.apache.tools.ant.taskdefs.optional.ssh.Scp
    cannot be found: com/jcraft/jsch/…

 

If you want to make use of the SCP protocol to do file transfer in Apache Ant, first, visit JCraft and download the jsch-0.1.50.jar.

There are 2 ways to enable the <scp> and <sshexec> tasks in the Ant build.xml.
Continue reading Apache Ant – Using scp and sshexec tasks in build.xml

Selenium – Element not found in the cache

You probably will come across the following error frequently when writing Selenium test case for a Ajax-rich website.

  • Error: Element not found in the cache – perhaps the page has changed since it was looked up

 

This is because the Selenium WebDriver reference to your element would now be stale as the DOM has been modified by Ajax. To resolve the problem in Java, you can make us of the WebDriverWait and find the element each time before you use it.
Continue reading Selenium – Element not found in the cache

Dream BIG and go for it =)