我使用Ant构建脚本整理分发我基于Eclipse的应用程序。
构建的一个步骤是检查正确的库都存在于构建文件夹。 我目前使用Ant命令这一点。 不幸的是,我有我每次切换到一个新的Eclipse构建时修改脚本(因为版本号将已更新)。
我并不需要检查版本号,我只需要检查该文件的存在。
所以,我怎么检查:
org.eclipse.rcp_3.5.0.*
代替:
org.eclipse.rcp_3.5.0.v20090519-9SA0FwxFv6x089WEf-TWh11
使用Ant?
欢呼声中,伊恩
你的意思是,像(基于pathconvert任务后, 这个想法 ):
<target name="checkEclipseRcp">
<pathconvert property="foundRcp" setonempty="false" pathsep=" ">
<path>
<fileset dir="/folder/folder/eclipse"
includes="org.eclipse.rcp_3.5.0.*" />
</path>
</pathconvert>
</target>
<target name="process" depends="checkEclipseRcp" if="foundRcp">
<!-- do something -->
</target>
一个稍微更短,更直接的方法resourcecount条件:
<target name="checkEclipseRcp">
<condition property="foundRcp">
<resourcecount when="greater" count="0">
<fileset file="/folder/folder/eclipse/org.eclipse.rcp_3.5.0.*"/>
</resourcecount>
</condition>
</target>
<target name="process" depends="checkEclipseRcp" if="foundRcp">
<!-- do something -->
</target>
该pathconvert任务可能是在大多数情况下,去的首选方式。 但是,当目录树是非常大的,一个使用echoproperties任务它创建了一个小问题。 具有非常大的目录树,通过pathconvert生成的字符串可以是巨大的。 然后echoproperties喷洒巨大的字符串,使输出更加困难的工作。 我使用Linux上的macrodef创建一个属性设置为“1”,如果有目录中的文件:
<macrodef name="chkDirContents" >
<attribute name="propertyName" />
<attribute name="dirPath" />
<attribute name="propertyFile" />
<sequential>
<exec executable="sh" dir="." failonerror="false" >
<arg value="-c" />
<arg value='fyles=`ls -1 @{dirPath} | head -1` ; if [ "$fyles" != "" ] ; then echo @{propertyName}=1 > @{propertyFile} ; fi' />
</exec>
</sequential>
</macrodef>
<target name="test" >
<tempfile destdir="." property="temp.file" deleteonexit="true" />
<chkDirContents propertyName="files.exist" dirPath="./target_dir" propertyFile="${temp.file}" />
<property file="${temp.file}" />
<echoproperties/>
</target>
执行“测试”的目标,如果有在./target_dir/目录中的文件会生成以下echoproperties行:
[echoproperties] files.exist=1
什么“测试”的作用:它会产生一个临时文件名,$ {} temp.file,以后可以用作属性文件。 然后,它执行macrodef,它调用外壳检查dirPath目录的内容。 如果有dirPath任何文件或目录,它分配propertyName的属性在临时文件中值为1。 然后读取该文件,并设置文件中给出的属性。 如果该文件是空的,没有财产的定义。
需要注意的是,如果需要的临时文件,可以重新用于macrodef的后续调用。 在另一方面,当然,一旦属性设置,这是不可改变的。