Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ant move puts newline at the end of property

Tags:

eclipse

ant

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="&#10;" replace="" flags="s"/>    

or other attempts to remove newlines from the property did not change anything.

like image 357
comodoro Avatar asked Apr 30 '13 17:04

comodoro


1 Answers

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.

like image 193
martin clayton Avatar answered Sep 27 '22 22:09

martin clayton