• ANT之macrodef


    macrodef 的意思是宏定义, 可以理解为自定义函数。

    对于大型部署,可以提高代码利用率。

    为了方便理解,请看代码示例:

    <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>
    

    name 属性说明这个自定义宏的名字 通过这个name 来调用这个宏

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

    表示宏的输入参数(相当于函数的参数)。在marcodef 中不同通过${}来调用attrbute 的值而要通过@{}。例如显示传入参数userID 是什么通过@{userID}.

    相当于函数的body 就是你这个可以调用常用ant tag 如何copy javac mkdir jar war 等

    补充链接

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

  • 相关阅读:
    分享一个js方法
    微信小程序中如何使用setData修改数组或对象中的某一参数
    微信小程序实现图片上传功能
    微信小程序图片上传放大预览删除代码
    小程序单张图片 和 九宫格图片上传、预览、删除示例
    微信小程序多图上传/朋友圈传图效果【附完整源码】
    shell 和awk性能对比
    超实用的8个Linux命令行性能监测工具
    storm分组模式
    Python程序的执行原理(转)
  • 原文地址:https://www.cnblogs.com/chenjo/p/13409102.html
Copyright © 2020-2023  润新知