我正在使用一个Ant构建脚本来整理我的基于Eclipse的应用程序以进行分发。
构建的一个步骤是检查构建文件夹中是否存在正确的库。我目前使用的是Ant命令。不幸的是,每次切换到新的Eclipse版本时,我都必须修改脚本(因为版本号将会更新)。
我不需要检查版本号,我只需要检查文件是否在那里。
那么,我该如何检查:
org.eclipse.rcp_3.5.0.*
而不是:
org.eclipse.rcp_3.5.0.v20090519-9SA0FwxFv6x089WEf-TWh11
使用Ant?
干杯,伊恩
发布于 2009-07-02 08:08:25
你的意思是,像这样的东西(基于pathconvert task,在this idea之后):
<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>
发布于 2013-10-07 16:02:35
使用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>
发布于 2013-08-30 23:12:24
在大多数情况下,路径转换任务可能是首选的方法。但是,当目录树非常大并且使用echoproperties任务时,它会产生一个小问题。对于非常大的目录树,pathconvert生成的字符串可能很大。然后,echoproperties会喷出这个巨大的字符串,使得输出更加难以处理。我在Linux上使用了一个宏定义,如果目录中有文件,它会创建一个设置为"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/目录中有文件,执行"test“目标将生成以下will属性行:
[echoproperties] files.exist=1
“测试”的作用:它生成一个临时文件名${temp.file},稍后可以将其用作属性文件。然后,它执行宏定义,该宏定义调用外壳来检查dirPath目录的内容。如果dirPath中有任何文件或目录,它会在临时文件中为propertyName属性赋值1。然后,它读取该文件并设置文件中给定的属性。如果文件为空,则未定义任何属性。
请注意,如果需要,可以将临时文件重用于后续的宏定义调用。当然,另一方面,一旦属性被设置,它就是不可变的。
https://stackoverflow.com/questions/1073077
复制相似问题