如何使用自定义蚂蚁规则正则表达式更改属性文件中的属性 [英] How to use custom ant rule regexpression to change property in propertyfile

查看:25
本文介绍了如何使用自定义蚂蚁规则正则表达式更改属性文件中的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 Android 项目中,我在 project.properties 文件中设置了以下属性

In my Android project I have the following property set in my project.properties file

proguard.config=proguard.cfg

而且我需要一个自定义宏来以某种方式设置和取消设置此属性.

and I need a custom macro that will somehow set and unset this property.

如何使用宏和正则表达式取消设置此属性?我不清楚的两件事是如何将其设置为空属性值.将那只是 proguard.config=或 proguard.config=''

How do I set unset this property using macro and regular expression? two things I am not clear on is how to set this to an empty property value. Would that be just proguard.config= or proguard.config=''

这样做的宏是什么?

 <macrodef name="turn-on-proguard">
    <sequential>    
       <replaceregexp file="./project.properties"
                            match='proguard.config="(.*)"'
                            replace='proguard.config=proguard.cfg'
                            byline="false">         
        </replaceregexp>
    </sequential>
</macrodef>



 <macrodef name="turn-off-proguard">
    <sequential>    
       <replaceregexp file="./project.properties"
                            match='proguard.config="(.*)"'
                            replace='proguard.config='
                            byline="false">         
        </replaceregexp>
    </sequential>
</macrodef>

这行得通吗?更新.turn-proguard-off 什么都不做.

Would this work? Update. turn-proguard-off does nothing.

推荐答案

你的解决方案对我来说很不清楚.为什么不转义点字符?为什么在正则表达式中使用引号和分组?这是工作脚本:

Your solution is very unclear for me. Why don't you escape the dot character? Why do you use quotation marks and grouping in your regexp? This is working script:

<macrodef name="turnonproguard">
    <sequential>    
       <replaceregexp file="project.properties"
                match='proguard\.config=.*'
                replace='proguard.config=proguard.cfg'
                byline="false"/>
    </sequential>
</macrodef>

<macrodef name="turnoffproguard">
    <sequential>    
       <replaceregexp file="project.properties"
                match='proguard\.config=.*'
                replace='proguard.config='
                byline="false"/>
    </sequential>
</macrodef>

<target name="on">
    <turnonproguard/>
</target>

<target name="off">
    <turnoffproguard/>
</target>

这篇关于如何使用自定义蚂蚁规则正则表达式更改属性文件中的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆