ANT之macrodef

macrodef 直接解釋是宏, 理解上能夠是自定義標籤或者自定義函數java

對於大型部署提升代碼利用率web

 

爲了方便理解經過如下代碼:app

<macrodef name="macro-send-file">
  		<attribute name="host" />
		<attribute name="toPath" />
		<attribute name="file" />
		<attribute name="userID" />
		<attribute name="password" />
<sequential>
<echo>@{userID}:@{password}@@@{host}:@{toPath}</echo>
<scp verbose="false" trust="true" localFile="@{file}" todir="@{userID}:@{password}@@@{host}:@{toPath}" failonerror="true" />
<!-- sshexec trust="true" host="@{host}" username="@{userID}" password="@{password}" command="chmod -R u+rw,g+rwx @{toPath}/*.ear"/ --><sshexec trust="true" host="@{host}" username="@{userID}" password="@{password}" command="chown thangamm:wadmfsms  @{toPath}/*.ear"/>
<echo>Sent @{file} to @{host}:@{toPath}</echo>
			
<!-- delete build dir -->
<echo message="clean app project" />
<!-- after done, should clean the preparation folders but keep release folder -->		
<delete dir="${build.dir.app}${file.separator}${name.bin}" failonerror="false" />
<delete dir="${build.dir.app}${file.separator}${name.docs}" failonerror="false" />
<delete dir="${build.dir.app}${file.separator}${name.reports}" failonerror="false" />
<delete dir="${build.dir.app}${file.separator}${name.stage}" failonerror="false" />
		
			<echo message="clean core project" />
			<delete dir="${build.dir.core}" failonerror="false" />		
			
			<echo message="clean web project" />
			<delete dir="${build.dir.web}" failonerror="false" />				
		</sequential>		
	</macrodef>

 

<macrodef name="macro-send-file">  name 屬性說明這個自定義宏的名字 經過這個name 來調用ssh

以下調用這個宏ide

<macro-send-file file="${file}" host="${autodeploy.host}" topath="${autodeploy.path}/${envName}" userid="${autodeploy.userID}" password="${autodeploy.password}" />

<attribute name="host" /> 表示宏的輸入參數(至關於函數的參數)。在marcodef 中不一樣經過${}來調用attrbute 的值而要經過@{}。例如顯示傳入參數userID 是什麼經過<echo>@{userID}.函數

 

<sequential> 至關於函數的body 就是你這個能夠調用經常使用ant tag 如何copy javac mkdir jar war 等ui

 

補充連接code

http://lhq1013.iteye.com/blog/1157234xml

相關文章
相關標籤/搜索