• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

ant, how to do multi-stage command pipe, create file

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am converting a long time batch file build to using jenkins and ant.. so far all good.

but I have this little problem I just can't seem to find a good solution for..
as part of my build process, I generate a version.txt file that contains content from one of the source files.

here is the batch file version
rem put int he fixed text
echo -n 'version=' >version.txt
rem find the source line 'my $version = "x.yz"'
rem get the number part without the quotes
grep -i 'my $version' $source_file | grep -o -P '(?<=\").+?(?=\")' >>version.txt

so, I grep the file, get the one line, then regex extract just the x.yz part, then append it to the file created in step one.
this gets published along with the install file so that the automated installers can get for my package release level.
(without having to open my tar.gz to read the same file).

so I have tried (echo followed by real exec),
get [exec] grep missing ')'
the echoed data works cut/paste at the common prompt

<echo> "&quot;grep -i &apos;my $version&apos; ${src.file} | grep -o -P &apos;(?&lt;=\&quot;).+?(?=\&")&apos; &gt;&gt; version.txt&quot;"</echo>
<exec executable="sh">
<arg value="-c" />
<arg line="&quot;grep -i &apos;my $version&apos; ${src.file} | grep -o -P &apos;(?&lt;=\&quot;).+?(?=\&quot;)&apos; &gt;&gt; version.txt&quot;"/>
</exec>

which looks like this after the expansion
"grep -i 'my $version' ${src.file} | grep -o -P '(?<=\").+?(?=\")' >> version.txt"
 
author
Posts: 5856
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If I understand this correctly, you want to create a new file name version.txt that has the contents:



where <version-nbr> if a value that was plucked out of another file that contains the version number value.

Here is what I would do. First, I would place the version.txt under source control with the following contents:



I would also modify the file that contains the line 'my $version = "x.yz"' to read 'my $version = "${version.nbr}"'.

Then I would pass the desired value for ${version.nbr} to the script (In our builds, we hard-code release number part of the version number and let Jenkins supply the Subversion revision numger for the rest of the version number) and then <copy> both files with the <expandProperties> <filterchain>. The key here is to not embed the version number in any files but to use property values any place you need version numbers, then supply the version number externally, and make Ant replace the version numbers.
 
If you're gonna buy things, buy this thing and I get a fat kickback:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic