Ant Replace Multiple Lines of Text
Continuous Integration, Eclipse October 25th, 2008Yesterday I needed to uncomment multiple lines in the applicationcontext of a Prana XML. After some searching I found the Ant Task I needed: replaceregexp.
Threre were four blocks that I needed to uncomment:
-
...
-
</value>
-
<value>
-
<object class="edumatic.backoffice.view.modules.NavigationModuleInfo">
-
<property name="url"
-
value="edumatic/backoffice/view/modules/support/ManagementNavigationModule.swf" />
-
<property name="icon"
-
value="edumatic/backoffice/view/modules/support/assets/management.png" />
-
<property name="title" value="Management" />
-
<property name="pluginID" value="MANAGEMENT" />
-
</object>
-
</value>
-
<value>
-
<object
-
class="edumatic.backoffice.view.modules.ContentModuleInfo">
-
<property name="url"
-
value="edumatic/backoffice/view/modules/support/ManagementContentModule.swf" />
-
<property name="pluginID" value="MANAGEMENT" />
-
</object>
-
</value>
-
<value>
-
<object
-
class="edumatic.backoffice.view.modules.NavigationModuleInfo">
-
<property name="url"
-
value="edumatic/backoffice/view/modules/support/MetaDataNavigationModule.swf" />
-
<property name="icon"
-
value="edumatic/backoffice/view/modules/support/assets/metadata.png" />
-
<property name="title" value="Metadata" />
-
<property name="pluginID" value="METADATA" />
-
</object>
-
</value>
-
<value>
-
<object
-
class="edumatic.backoffice.view.modules.ContentModuleInfo">
-
<property name="url"
-
value="edumatic/backoffice/view/modules/support/MetaDataContentModule.swf" />
-
<property name="pluginID" value="METADATA" />
-
</object>
-
</value>
-
<value>
-
...
I couldn't just search for
So here are the replaceregexp tasks that made it work:
-
<replaceregexp file="${selor-salto-test-deploy-folder.dir}/backend/application-context-backoffice.xml"
-
byline="false" flags="s">
-
<regexp pattern="<value>.{1,250}ManagementNavigationModule"/>
-
<substitution expression="<!--value>
-
<object class="edumatic.backoffice.view.modules.NavigationModuleInfo">
-
<property name="url"
-
value="edumatic/backoffice/view/modules/support/ManagementNavigationModule"/>
-
</replaceregexp>
-
<replaceregexp file="${selor-salto-test-deploy-folder.dir}/backend/application-context-backoffice.xml"
-
byline="false" flags="s">
-
<regexp pattern="ManagementContentModule.swf.{1,150}</value>"/>
-
<substitution expression="ManagementContentModule.swf" />
-
<property name="pluginID" value="MANAGEMENT" />
-
</object>
-
</value-->"/>
-
</replaceregexp>
-
<replaceregexp file="${selor-salto-test-deploy-folder.dir}/backend/application-context-backoffice.xml"
-
byline="false" flags="s">
-
<regexp pattern="<value>.{1,250}MetaDataNavigationModule"/>
-
<substitution expression="<!--value>
-
<object class="edumatic.backoffice.view.modules.NavigationModuleInfo">
-
<property name="url"
-
value="edumatic/backoffice/view/modules/support/ManagementNavigationModule"/>
-
</replaceregexp>
-
<replaceregexp file="${selor-salto-test-deploy-folder.dir}/backend/application-context-backoffice.xml"
-
byline="false" flags="s">
-
<regexp pattern="MetaDataContentModule.swf.{1,150}</value>"/>
-
<substitution expression="MetaDataContentModule.swf" />
-
<property name="pluginID" value="METADATA" />
-
</object>
-
</value-->"/>
-
</replaceregexp>
The thing me and a colleague searched on for a while was the s flag that was needed to make it work. I will try the other flags because I'm really not sure what this s flag means... (trial and error yeah!). I've seen that after the task ran the layout was messed up (no newlines anymore in the replaced text).
The .{1,150} means that a maximum of 150 characters may occur between for example MetaDataContentModule.swf and </value>.
Ciao!
July 9th, 2009 at 5:15 am
Thanks, I never would have tried the s-flag myself, but just what I needed.
/Trym