How to use custom ant rule regexpression to change property in propertyfile

徘徊边缘 提交于 2019-12-20 04:13:54

问题


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.

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

What would be the Macro for doing this?

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

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


回答1:


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>


来源:https://stackoverflow.com/questions/10629726/how-to-use-custom-ant-rule-regexpression-to-change-property-in-propertyfile

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!