开发者

Ant pass specific string values from one file to another

I'm trying to configure autoincrement of version number in an Android aplication. I've configured Ant tasks which make a checkout of the file then autoincrement the string with version value and then automatically do check-in in TFS system. So this test.properties file has this contetnt:

versionCode="1"

Autoincrement did this task:

<propertyfile file="${basedir}/src/test.properties">
  <entry key="versionCode" value="1" 开发者_C百科type="int" operation="+" />
</propertyfile>

How would I configure replacement of the value of this string: android:versionCode="1", located in the target file androidmanifest.xml?


I suppose you can use the ReplaceRegExp task in Ant:

Directory-based task for replacing the occurrence of a given regular expression with a substitution pattern in a file or set of files.

It might look something like this:

<replaceregexp file="${src}/androidmanifest.xml"
           match="android:versionCode=&quot;[0-9]+&quot;"
           replace="android:versionCode=&quot;${versionCode}&quot;"
/>

The build.number property could be obtained by reading in the property file before running this task.


A solution with vanilla ant, no Ant addon needed, you may use a propertyfiletemplate that has =

f.e. named props.txt
    ...
    android:versionCode=@versionCode@
    ...

and later on use the property ${versionCode} set by your workflow
and create a propertyfile from your template with copy + nested filterset =

 <!-- somewhere set in your workflow maybe via userproperty -DversionCode=42 -->
  <property name="versionCode" value="42"/>
 ...
  <copy file="props.txt" todir="/some/path" overwrite="true">
   <filterset>
    <filter token="versionCode" value="${versionCode}"/>
   </filterset>
  </copy>

/some/path/props.txt will have =

...
android:versionCode=42
...

see Ant Manual on filtersets

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜