ant 脚本 available 及条件判断功能
1. 通过<available property="属性名" file | classname | resource = "被判定是否存在的东西" value="给属性名显示指定一个值" ..... /> 存在性判断语句,如果判定的东西存在,则以默认值true/或指定的属性值设置指定的属性;若判定的东西不存在,则不设置该属性。
我们可以根据这个属性是否被设置(通过<isset property="属性名" />判断)、这个属性已被设置的值(<equals arg1="${属性名}" arg2="true|指定的属性值">),执行 if - then - else 判断逻辑。
<project name="test" basedir="." default="copy">
<!--
为了使用ant的 if [isset] - then - else 功能,定义任务,并将其引入urn:contrib-ant命名空间
-->
<taskdef resource="net/sf/antcontrib/antcontrib.properties" uri="urn:contrib-ant">
<classpath>
<pathelement location="D:\osesbinaction\libraries\ant-contrib\lib\ant-contrib.jar" />
</classpath>
</taskdef>
<!--
Sets a property if a resource is available at runtime.
在运行时,如果一个资源(文件、目录、类、JVM系统资源等)可以得到,
就设置一个属性,其属性值默认设为true,否则不设置
This resource can be a file, a directory, a class in the classpath, or a JVM system resource.
If the resource is present, the property value is set to true by default; otherwise, the property is not set.
You can set the value to something other than the default by specifying the value attribute.
除了默认值,你还能够通过指定value属性,设置为其他值
如果./test/target/test-1.0.jar存在,则设置属性test.exist,并让其取默认值true,否则不设置该属性,此处设测试值xxxxx
-->
<available property="test.exist" file="test-1.0.jar" filepath="./test/target" value="xxxxx"/>
<target name="copy" description="Test Copy" xmlns:c="urn:contrib-ant">
<c:if>
<!--
如果当前上下文中存在test.exit属性,则返回true,则返回false
<c:equals arg1="${test.exist}" arg2="xxxxx" /> 可完成相同判断功能
-->
<c:isset property="test.exist" />
<c:then>
<!-- 如果存在test.exit属性,则拷贝到test/libdb目录 -->
<copy todir="test/libdb" preservelastmodified="true">
<fileset dir="test/target">
<include name="test-1.0.jar" />
</fileset>
</copy>
<echo>属性test.exist的值为: ${test.exist}</echo>
</c:then>
<c:else>
<!-- 如果不存在test.exit属性,则拷贝到test/libdb目录 -->
<echo>./test/target/test-1.0.jar文件不存在,无法进行拷贝</echo>
</c:else>
</c:if>
</target>
<path id="runtime.path">
<fileset dir="../resources">
<include name="**/*.jar" />
</fileset>
</path>
<target name="test-available" description="a test of the task available">
<!-- 如果在runtime.path引用的类路径中存在esb.chapter3.Person类,则设person.class.present属性为exist -->
<available classname="esb.chapter3.Person"
property="person.class.present"
classpathref="runtime.path" value="exist"/>
<echo>${person.class.present}</echo>
<property name="workspace.home" value="D:/eclipse-luna-jee/workspace/z_servicemix" />
<available classname="esb.chapter3.Order" property="order.exist">
<classpath>
<path refid="runtime.path" />
<!--
pathelement
location属性,接收一个文件或目录
path属性,功能相当于一个内嵌的<path>元素,使用起来比较随意,接收一个分号分隔的位置列表
注: location和path属性一般可以通用,当涉及到一个分号分隔的位置列表时,只能用path属性
-->
<pathelement location="D:\osesbinaction\libraries\ant-contrib\lib\ant-contrib.jar" />
<pathelement location="${workspace.home}/resources" />
<pathelement path="${workspace.home}/src:${workspace.home}/bin" />
</classpath>
</available>
<echo>${order.exist}</echo>
<!-- 如果./lib/jaxp11/jaxp.jar文件存在,设jaxp.jar.present属性为true -->
<property name="jaxp.jar" value="./lib/jaxp11/jaxp.jar"/>
<available file="${jaxp.jar}" property="jaxp.jar.present"/>
<!-- 如果/usr/local/lib目录存在,设local.lib.present属性为true -->
<available file="/usr/local/lib" type="dir" property="local.lib.present"/>
<!-- 如果xxx\lib\ant-contrib.jar包中存在net/sf/antcontrib/antcontrib.properties资源文件,设have.res属性为true -->
<available property="have.res" resource="net/sf/antcontrib/antcontrib.properties">
<classpath>
<pathelement location="D:\osesbinaction\libraries\ant-contrib\lib\ant-contrib.jar" />
</classpath>
</available>
<echo>have.extras = ${have.res}</echo>
</target>
</project>
2. 也可通往<condition property="属性名" />, <target name="target1" if | unless ="属性名" /> 完成判断分支功能
<project name="test" basedir="." default="copy">
<target name="copy">
<condition property="test.exist">
<and>
<available file="test-1.0.jar" filepath="test/target" />
</and>
</condition>
<!-- 下面的2个任务都尝试执行,但只有测试条件通过的任务体才会被执行 -->
<antcall target="copy-target" />
<antcall target="echoUnexiting" />
</target>
<target name="copy-target" if="test.exist" description="Test Copy">
<copy todir="test/libdb" preservelastmodified="true">
<fileset dir="test/target">
<include name="test-1.0.jar"/>
</fileset>
</copy>
</target>
<target name="echoUnexiting" unless="test.exist">
<echo>./test/target/test-1.0.jar文件不存在,无法进行拷贝</echo>
</target>
</project>
ant 脚本 available 及条件判断功能的更多相关文章
- Linuxshell脚本之if条件判断
IF条件判断 .基本语法: if [ command ]; then 符合该条件执行的语句 fi .扩展语法: if [ command ];then 符合该条件执行的语句 elif [ comman ...
- shell脚本编程之条件判断
条件测试类型: 整数测试 字符测试 文件测试 条件测试的表达式的三种方法: 1.[ expression ] 命令测试 2.[[ expression ]] 关键字测试 3.test expressi ...
- shell 脚本基础与条件判断
#!shell脚本格式决定专业性 #!/bin/bash #filename:脚本名 #author:作者 #date:时间 #脚本作用 脚本的执行方式 #脚本名为wk.sh 绝对路径 /root/ ...
- Linux shell脚本之 if条件判断 (转)
IF条件判断 1.基本语法: if [ command ]; then 符合该条件执行的语句 fi 2.扩展语法: if [ command ];then 符合该条件执行的语句 elif [ comm ...
- shell脚本--分支、条件判断
在看选择判断结构之前,请务必先看一下数值比较与文件测试 if....else... #!/bin/bash #文件名:test.sh score=66 # //格式一 if [ $score -lt ...
- 5-4 bash脚本编程之三 条件判断及算术运算
1. 反引号是引用执行结果,并非是返回值 如下是错误的,结果是一行行记录,不是返回值 放大为: 练习 2. shell中如何进行算术运算 A=3 B=4 1. let算术运算表达式 2. $[算术运算 ...
- css3条件判断_@supports的用法 以及 Window.CSS.supports()的使用
为了判断浏览器是否支持css3的一些新属性样式,当不兼容该样式的时候,我们可以更优雅的降级处理.这就需要使用到css3的条件判断功能:在css中支持@supports标记.或者在js中使用CSS.su ...
- css3条件判断_@supports的用法/Window.CSS.supports()的使用
为了判断浏览器是否支持css3的一些新属性样式,当不兼容该样式的时候,我们可以更优雅的降级处理.这就需要使用到css3的条件判断功能:在css中支持@supports标记.或者在js中使用CSS.su ...
- Shell脚本IF条件判断和判断条件总结
转自:http://m.jb51.net/article/56553.htm 这篇文章主要介绍了Shell脚本IF条件判断和判断条件总结,本文先是给出了IF条件判断的语法,然后给出了常用的判断条件总结 ...
随机推荐
- Java.控制层.响应工具类.
Java.控制层.响应工具类. package cn.com.spdbccc.cds.index.web.base; public class ApiResponse { private int co ...
- vue 根据数组中某一项的值进行排序
一.前言 我在vue项目中遇到了一个表格排序的需求,根据某一项的值的大小从大到小调整数组顺序. 二.代码 表格大概是这个样子,样式和图片在代码中简化了. <table class="r ...
- 抽象类 abstract class 接口
一.抽象类 1.没有具体的实例. 不可实例化,不能创建对象. 2.抽象类有构造器. 二.abstract 方法. 1.没有方法体. 子类必须重写抽象类的所有抽象方法,才能实例化,否则子类也为抽象类. ...
- layers.py cs231n
如果有错误,欢迎指出,不胜感激. import numpy as np def affine_forward(x, w, b): 第一个最简单的 affine_forward简单的前向传递,返回 ou ...
- js自定义滚动条
今天听到别人说自定义滚动条,所以就在吃饭的时间写了个 html部分 <div class="out" id="out"> <div class ...
- 电影的微信小程序
最近,工作没有那么忙,学习了一下小程序开发,感觉上手比较简单. 在项目中学习是最好的方式,于是就自己模仿豆瓣电影开发一款微信小程序版的豆瓣电影 准备工作: 数据来源:豆瓣电影API 功能: 电影榜单列 ...
- 洛谷 P3434 [POI2006]KRA-The Disks 贪心
目录 题面 题目链接 题目描述 输入输出格式 输入格式 输出格式 输入输出样例 输出样例 输出样例 说明 思路 AC代码 题面 题目链接 P3434 [POI2006]KRA-The Disks 题目 ...
- typeof与js数据类型
js有6种数据类型有null.undefied.string.number.boolean.object. 然而我之前的[误区]: typeof的返回值和JS的数据类型是一样的.但是并不是(⊙o⊙)哦 ...
- The World's Top 15 Stock Exchanges by Domestic Market Capitalization
The World's Top 15 Stock Exchanges by Domestic Market Capitalization in 2008 4 Euronext Belgium, Fr ...
- get请求url中带有中文参数出现乱码情况
在项目中经常会遇到中文传参数,在后台接收到乱码问题.那么在遇到这种情况下我们应该怎么进行处理让我们传到后台接收到的参数不是乱码是我们想要接收的到的,下面就是我的一些认识和理解. get请求url中带有 ...