如何对动态定位的文件执行多个操作



我正试图在ant中构建以下内容,但老实说,我不知道如何最好地进行:

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

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

使用

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

相关内容

  • 没有找到相关文章

最新更新