permaculture playing cards*
The moose likes Ant, Maven and Other Build Tools and the fly likes ant, how to do multi-stage command pipe, create file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "ant, how to do multi-stage command pipe, create file" Watch "ant, how to do multi-stage command pipe, create file" New topic
Author

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

sam detweiler
Greenhorn

Joined: Oct 08, 2012
Posts: 5
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"
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5812
    
    7

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.


JBoss In Action
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ant, how to do multi-stage command pipe, create file
 
Similar Threads
Submission Jar: test case + Ant build script
Rather simple ant question
Setting up the Java Web Services tutorial and Sun Java system appn server
ant script not working
Cruise control giving wrong status in email.