繁体   English   中英

覆盖 ANT 属性文件

[英]overwriting ANT properties file

如何用新创建的属性文件覆盖一些现有属性?

这是所需的结构:

initially load Master.properties
generate new.properties


load new.properties and master.properties
run master.xml (ANT script)

这个想法是 Master.properties 生成一些应该被 new.properties 替换的产品版本。 但是,Master.properties 中的其他属性应保持不变。

阅读内容无济于事,因为我不知道如何加载 new.properties 文件

编辑这里是 ANT 脚本:

<project name="nightly_build" default="main" basedir="C:\Work\NightlyBuild">
    <target name="init1">
        <sequential>
                    <property file="C:/Work/NightlyBuild/master.properties"/>
            <exec executable="C:/Work/Searchlatestversion.exe">
                <arg line='"/SASE Lab Tools" "${Product_Tip}/RELEASE_"'/>
            </exec>
            <sleep seconds="10"/>
            <property file="C:/Work/new.properties"/>

        </sequential>
    </target>
    <target name="init" depends="init1">
        <sequential>
            <echo message="The product version is ${Product_Version}"/>
            <exec executable="C:/Work/checksnapshot.exe">
                <arg line='-NightlyBuild ${Product_Version}-AppsMerge' />
            </exec> 
            <sleep seconds="10"/>
            <property file="C:/Work/checksnapshot.properties"/>
            <tstamp>
                <format property="suffix" pattern="yyyy-MM-dd.HHmm"/>
            </tstamp>
        </sequential>
    </target>
    <target name="main" depends="init">
            <echo message="loading properties files.." />
            <echo message="Backing up folder" />
            <move file="C:\NightlyBuild\NightlyBuild" tofile="C:\NightlyBuild\NightlyBuild.${suffix}" failonerror="false" />
                <exec executable="C:/Work/sortfolder.exe">
                    <arg line="6" />
                </exec>
                <exec executable="C:/Work/NightlyBuild/antc.bat">
                </exec> 
    </target>
</project>

在上述脚本中, <exec executable="C:/Work/NightlyBuild/antc.bat">将运行 Master.xml ANT 脚本。 这个 Master.xml 将加载Master.properties

<project name="Master ANT Build" default="main" >               
    <taskdef name="CFileEdit" classname="com.ANT_Tasks.CFileEdit"/>
    <!-- ========================================================== -->
    <!-- init: sets global properties                               -->
    <!-- ========================================================== -->
    <target name="init">
        <property environment="env"/>
        <!-- ========================================================== -->
        <!-- Set the timestamp format                   -->
        <!-- ========================================================== -->
        <property file="Master.properties"/>
         ...
</project>

您应该能够通过查看加载(或以其他方式指定)属性值的顺序来解决此问题。 您可能根本不需要覆盖属性值,这是核心 Ant 不支持的。

也许您可以将 Master.properties 拆分为两个文件 - 一个在生成 new.properties 之前加载,另一个在生成之后加载?

也许您根本不需要生成 new.properties。

您能否详细说明您需要做什么?

既然你最终派生了一个新的 Ant 进程(exec antc.bat),那这不会开始一个新的环境吗? 如果它只加载 Master.properties,这些是它唯一的属性。

不确定您的 antc.bat 做了什么,但是以这种方式从 Ant 执行 Ant 是很不寻常的。 有两个可能有用的标准任务 - AntAntCall

好的,从您以后的评论开始...

让我们说,而不是这样做:

<exec executable="antc.bat">

你反而做了这样的事情:

<ant file="Master.xml" inheritall="false">
   <property name="Product_Version" value="${Product_Version}"/>
</ant>

我认为这正在朝着你想要的方向发展。 您可以选择性地传递通过加载 new.properties 获得的特定值。 请参阅Ant 任务的文档。

如果您仍然存在在加载 new.properties 之前已经定义 Product_Version 的问题,那么我会说获取您拥有的脚本,该脚本生成 new.properties 到 output 具有不同名称的版本,例如New_Product_Version 然后调用您的主构建,如下所示:

<ant file="Master.xml" inheritall="false">
   <property name="Product_Version" value="${New_Product_Version}"/>
</ant>

可能这是一个老问题。 希望OP正在阅读此内容。

您可以只使用 ant 任务“propertyfile”。 参考

它可以从文件中读取属性并将更新的值写回给它们。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM