2011-06-08 124 views
1

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

这里是所需要的结构:

initially load Master.properties 
generate new.properties 


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

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

阅读this没有帮助,因为我不知道我怎样才能加载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">将运行硕士。 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> 

回答

2

您应该能够通过查看您加载(或规定)的属性值,以解决此问题。您可能根本不需要重写属性值,这是核心Ant不支持的。

也许你可以分割你的Master.properties成两个文件 - 一个你生成new.properties前装和后一个装?

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

你能否提供一些你需要做的更多细节?

因为你最终派生新的Ant过程(EXEC antc.bat),这是否不反正启动一个新的环境?如果它只是加载Master.properties,那么它将是唯一的属性。

不知道你antc.bat做什么,但它是非常不寻常以这种方式从蚂蚁蚂蚁exec的。有两个标准任务可能有用 - AntAntCall

确定从后来的评论上运行...

比方说,而不是做这样的:

<exec executable="antc.bat"> 

你,而不是做了这样的事情:

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

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

如果您在加载new.properties之前仍然存在定义了Product_Version的问题,那么我会说让您的脚本生成new.properties以输出具有不同名称的版本,例如New_Product_Version。然后调用你的主构建是这样的:

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

请参阅我的编辑以获得更好的理解。作为要求的一部分,我无法分割这个Master.properties – jeremychan 2011-06-08 09:11:20

+0

为什么你需要加载目标init1中的Master.properties?为什么你需要在new.properties之前加载它? – sudocode 2011-06-08 09:34:33

+0

哎呀抱歉,我编辑$ {Product_Tip}应该在 – jeremychan 2011-06-08 09:40:16

1

可能这是一个老问题。希望OP在读这个。

您可以使用ant任务“propertyfile”。 reference

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

+0

这是此部分所说的更正确的版本: ' ant file =“Master.xml”inheritall =“false”>' 编辑:更正和世卫组织思考按ENTER键是提交评论的好方法! – 2012-11-20 13:44:08