I'm trying to create an ant build target that supports var substitution dynamically.
<target name="replace_property" depends="init_ant_contrib">
<propertyregex input="${replace_inboundproperty"
property="${replace_outboundproperty}"
regex="${replace_match}"
replace="${replace_target}"
global="true"
override="true" />
</target>
so I load the properties file and i'm basically setting the vars as such:
replace_inboundproperty="/target/path/targetfile"
replace_outboundproperty=blah
replace_match="/target/(.*)/targetfile"
replace_target="\1"
so when I echo blah, I'm getting "1". Now if I actually do this:
<target name="replace_property" depends="init_ant_contrib">
<propertyregex input="${replace_inboundproperty"
property="${replace_outboundproperty}"
regex="${replace_match}"
replace="\1"
global="true"
override="true" />
</target>
and echo blah, I'll get "path".
Can anyone tell me what I'm missing to allow the replace to use capture groups from a properties file / ant -D? Using ant-contrib 1.0b3.
Thanks!
Found out that in the properties file, if you double escape it, it'll function correctly:
replace_target=\\1
Related
I have setup this ANT build.xml file which pulls in version info from a txt file , reads the first line, trims it and copies it into a variable called 'versionVal' with below code:
<target name="clean"
.
. do something more
.
<loadfile property="versionValTxt" srcfile="version.txt">
<filterchain>
<filterreader classname="org.apache.tools.ant.filters.HeadFilter">
<param name="lines" value="1" />
</filterreader>
</filterchain>
</loadfile>
<loadresource property="versionVal">
<propertyresource name="versionValTxt"/>
<filterchain>
<tokenfilter>
<filetokenizer/>
<replacestring from="V" to=""/>
</tokenfilter>
<striplinebreaks/>
</filterchain>
</loadresource>
<echo>"Building for version: ${versionVal}"</echo>
</target>
And in one of the targets I am trying to refer a resolver artifact which uses this versionVal to find a file with that specific version in its name as shown below:
<resolver:artifacts id="producedArtifacts" >
<resolver:artifact file="${dist.dir}/App.${versionVal}.zip"/>
</resolver:artifacts>
<target name="nexus">
<echo>"versionVal: ${versionVal}"</echo>
<resolver:deploy artifactsref="producedArtifacts">
<resolver:remoterepo refid="ossrh"/>
</resolver:deploy>
</target>
And the build keeps failing as below, where it shows the variable versionVal is undefined.
C:\Users\XYZ\git\App\WebContent\dist\App.${versionVal}.zip does not exist
Note that the block is able to recognize ${dist.dir} but it doesnt recognize ${versionVal}. However I am able to print the value using an echo inside the target-nexus.
Much appreciated if anyone can point me in the right direction. I am not able to figure out why this variable is not recognized under "resolver:artifact file" and if there are any alternatives to this problem.
Realised I had to include below resolver artifact inside a target block and then use that as depends in the nexus block. After making this change the variable 'versionVal' was recognized.
Solution:
<target name="packagedArtifact" >
<resolver:artifacts id="producedArtifacts" >
<resolver:artifact file="${dist.dir}/App.${versionVal}.zip"/>
</resolver:artifacts>
</target>
<target name="nexus" depends="packagedArtifact">
<resolver:deploy artifactsref="producedArtifacts">
<resolver:remoterepo refid="ossrh"/>
</resolver:deploy>
</target>
Dear stackoverflow crowd,
I have a rather difficult RegEx to build, at least difficult to me ;-).
Goal:
Search an XML file (actually XLIFF) for tags where the attribute approved="yes" is missing and enhancing the tag with a state="new" attribute. At the same time deleting the text that might be present in the tag.
Here is an example:
Find this:
<trans-unit id="2c5b6ff1">
<source xml:lang="de-de">Fehler im Aufgabe</source>
<target xml:lang="en-us">Fehler im Aufgabe</target>
</trans-unit>
and create this output as a replacement:
<trans-unit id="2c5b6ff1" approved="no">
<source xml:lang="de-de">Fehler im Aufgabe</source>
<target state="new" xml:lang="en-us"></target>
</trans-unit>
I do not want to find structures where the approved value is already set:
<trans-unit id="77d29d58-ea84-47b0-a415-1de68425fae0" approved="yes">
<source xml:lang="de-de">Frequenzumrichter in Störung</source>
<target xml:lang="en-us" state="translated">Frequency inverter on disturbance</target>
</trans-unit>
I go to this, so far, which is not working properly.
(<trans-unit(?!.*?approved=\"yes\".*?\2)[^>]*?)(/?>\r\n <source xml:lang=\"de-de\">(.*?)<\/source>\r\n<\/trans-unit>) <target xml:lang=\"en-us\">(.*?)<\/target>\r\n <\/trans-unit>”
What do I need to do differently?
Your help is much appreciated.
Thanks a mil!
This works:
SEARCH for:
(<trans-unit id=\"(.*?)\"(?!.*?approved=\"yes\".*?))>\r\n <source xml:lang=\"de-de\">(.*?)<\/source>\r\n <target xml:lang=\"en-us\">(.*?)<\/target>\r\n <\/trans-unit>
REPLACE with:
(<trans-unit id=\"\2" approved=\"no\">\r\n <source xml:lang=\"de-de\">\3<\/source>\r\n <target state=\"new\" xml:lang=\"en-us\"><\/target>\r\n <\/trans-unit>
Not very elegant, but it does the job.
I'm trying to change an xml element value from "true" to "false" using ANT replaceregexp task but am having difficulties matching across a new line. The relevant part of the XML node in question:
<validationRules>
<fullName>CAReversaApprovallLockdown</fullName>
<active>true</active>
In my text editor (sublime), I'm able to use the following regex to find/replace but I can't figure out how to replicate this in ANT replaceregexp:
/fullname>\n <active>true
I can't figure out the correct syntax to match the combination of the newline and the spacing afterwards. The spacing after the newline is always the same, if that makes things easier.
Looking at https://ant.apache.org/manual/Tasks/replaceregexp.html I've tried various combinations of ^ and $ with m flag, \s+ for spaces etc but just can't hit the right combo....any ideas?
My current progress is below but no luck unfortunately...
<target name="deactivate_val_rules">
<echo message="deactivating validation rules..." />
<replaceregexp match="/fullname>\r\n\s+<active>true" flags="gim" byline="false">
<substitution expression="/fullname>\r\n <active>false"/>
<fileset dir="src\objects" includes="Claim_Approvals__c.object"/>
</replaceregexp>
</target>
Got it - the following gave the correct result:
<target name="deactivate_val_rules">
<echo message="deactivating workflows..." />
<replaceregexp match="/fullname>\r\n\s+<active>true" flags="gis" byline="false">
<substitution expression="/fullname>${line.separator} <active>false"/>
<fileset dir="src\objects" includes="Claim_Approvals__c.object"/>
</replaceregexp>
</target>
The output viewed via diff is:
- <fullName>the_name</fullName>
- <active>true</active>
+ <fullName>the_name</fullname>
+ <active>false</active>
To Use replaceregexp you need to define the value to be changed as reference.
For Example:
<validationRules>
<fullName>CAReversaApprovallLockdown</fullName>
<active>true</active>
Ant:
<target name = "deactivate_val_rules">
<echo message="deactivating validation rules..." />
<replaceregexp file="${FILE_LOACTION}/FILE_NAME.FILE_EXT" match="true" replace="false" />
</target>
I'm having trouble copying some files which match a pattern in my ant script.
I have the following:
<property name="IncludedLocales" value="de_DE|es_ES|fr_FR|it_IT|ja_JP" />
<copy todir="${dest}">
<fileset dir="${src}" includes="**/*.properties" />
<mapper type="regexp" from="(messages(_${IncludedLocales})?\.properties)" to="\1" />
</copy>
${src} contains the files messages.properties, as well as messages_de_DE.properties, messages_es_ES.properties, etc.
But for some reason, only messages.properties, and messages_de_DE.properties get copied (and if I changed IncludedLocales to 'es_ES|de_DE|fr_FR|it_IT|ja_JP', messages_es_ES.properties gets copied instead of messages_de_DE.properties).
Am I missing something really simple?
Yes, I did miss something really simple, (messages(_${IncludedLocales})?\.properties) should have been (messages(_(${IncludedLocales}))?\.properties)
I have the following
<RegexMatch Input="$(Configuration)" Expression="^.*?(?=\.)">
<Output ItemName="Theme" TaskParameter="Output" />
</RegexMatch>
My configuration variable is as follows Theme.Environment
So "Default.Debug"
or "Yellow.Release"
I would like to get the first portion in to a varaible called theme.
I have tested this regex and it works in stand alone regex testers
^.*?(?=\.)
but not when used in my build file.
I am echoing the variable out so that i can see the output
<Exec Command="echo $(Theme)"/>
<Exec Command="echo $(Configuration)"/>
Ideas?
If you should use MSBuild Community tasks for that - check this line: <Output PropertyName="Theme" TaskParameter="Output" />
you should use PropertyName="Theme" if you want to refer it like $(Theme) later.
ItemName will create items set, not property.
But it's much simplier to use MSBuild 4.0 inline functions than Msbuild community tasks for that concrete task. Your code will looks like this (adopt for your script):
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0" DefaultTarget="Play">
<PropertyGroup>
<Configuration>Yellow.Release</Configuration>
</PropertyGroup>
<Target Name="Play">
<PropertyGroup>
<Theme>$([System.Text.RegularExpressions.Regex]::Match($(Configuration), `^.*?(?=\.)`))</Theme>
</PropertyGroup>
<Message Text="$(Theme)" />
<Message Text="$(Configuration)" />
</Target>
</Project>
Just realised that RegexMatch doenst return the matched string but rather returns the entire string if matched.
basically it called IsMatch method not Match method
Have re written as a RegexReplace
<RegexReplace Input="$(Configuration)" Expression="\..*" Replacement="" Count="1">
<Output ItemName="Theme" TaskParameter="Output" />
</RegexReplace>
After that it still wasnt working and then i realised i was doing
$(Theme)
Should have been
#(Theme)