I have an Ant task in Eclipse to get version from file:
<loadfile property="version" srcfile="version.txt">
  <filterchain>
    <linecontainsregexp>
      <regexp pattern="^#define version .(\d{1,10})\.(\d{1,10})\.(\d{1,10})\.(\d{1,10})."/>
    </linecontainsregexp>
    <replaceregex 
         pattern="^#define version .(\d{1,10})\.(\d{1,10})\.(\d{1,10})\.(\d{1,10})..*$" 
         replace="\1.\2.\3.\4" />
  </filterchain>
</loadfile>  
<echo message="Version ${version}"/>    
The version displays without a newline. Further in the code I want to use the property with the move task:
<move file="${dir}\file.exe"
      tofile="${outputdir}\output-${version}-xxx.exe" 
      overwrite="true" 
      force="true" />
But it fails with the message
BUILD FAILED build.xml:26: Failed to copy path\file.exe to path\output_directory\output-1.0.0.0
-xxx.exe due to output-1.0.0.0
-xxx.exe (Název souboru či adresáře nebo jmenovka svazku je nesprávná)
(the last line means that the file name is invalid, obviously it contains newline in the middle).
Where am I going wrong? Is it the property itself? Even adding the line
<replaceregex pattern="
" replace="" flags="s"/>    
or other attempts to remove newlines from the property did not change anything.
You need to strip line breaks, e.g.:
<filterchain>
  <linecontainsregexp ... />
  <replaceregex ... />
  <striplinebreaks />
</filterchain>
If you modify your <echo> to:
<echo message="Version -${version}-"/>
you'll see the affect clearly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With