如何在动态定位文件上进行多个操作?

时间:2011-05-31 10:36:15

标签: scripting ant

我正在尝试用ant构建以下内容,但老实说,不知道如何最好地继续:

  • 根据设定的标准获取文件名(最新的日期和正则表达式字符串比较)并将文件名分开(文件以我用来检查有效性的数字开头)。
  • 在不同的目录中获取文件夹名称并分开以获取编号 如果文件验证号码大于文件夹号,则复制文件。

到目前为止,我可以将正确的文件复制到临时目录,但我需要帮助比较文件名和文件夹名称的部分内容。

1 个答案:

答案 0 :(得分:0)

使用它:

<project name="test1" basedir="." default="check_if_new_sdk_needed">

    <property file="../local.properties" />

    <target name="check_if_new_sdk_needed" depends="check_local_sdk, compute_remote_sdk_properties">
        <echo message="Need to grab SDK: ${updateNeeded}" />
        <antcall target="process_sdk" />
    </target>

    <target name="check_local_sdk" depends="local_sdk_found, local_sdk_not_found">
    </target>

    <target name="local_sdk_found" depends="compute_local_sdk_properties" if="local.sdk.found">
        <echo message="Local SDK found" />
        <script language="javascript"><![CDATA[
          var localVersion = parseInt(project.getProperty('local.sdk.version.number'));
          var remoteVersion = parseInt(project.getProperty('remote.sdk.version.number'));
          project.setProperty('updateNeeded', remoteVersion > localVersion);
      ]]></script>
    </target>

    <target name="local_sdk_not_found" depends="compute_local_sdk_properties" unless="local.sdk.found">
        <property name="updateNeeded" value="true" />
        <echo message="Need to grab SDK" />
    </target>

    <target name="compute_local_sdk_properties">
        <path id="local_sdk_folder_name">
            <dirset dir="${local.sdk.dir}">
                <include name="*"/>
            </dirset>
        </path>
        <property name="local.sdk.folder.name" refid="local_sdk_folder_name"/>
        <pathconvert property="local.sdk.version.number">
            <path path="${local.sdk.folder.name}" />
            <chainedmapper>
                <flattenmapper />
                <mapper type="regexp" from="(.*?)-.*" to="\1" />
            </chainedmapper>
        </pathconvert>
        <condition property="local.sdk.found">
            <length string="${local.sdk.version.number}" trim="true" when="greater"
                length="0" />
        </condition>
    </target>

    <target name="compute_remote_sdk_properties">
        <echo message="renaming ${sdk_folder_name} to ${remote.sdk.file.name}"/>
        <pathconvert property="remote.sdk.version.number">
            <path path="${remote.sdk.file.name}" />
            <chainedmapper>
                <flattenmapper />
                <mapper type="regexp" from="(.*?)-.*" to="\1" />
            </chainedmapper>
        </pathconvert>
    </target>
</project>