tags:

views:

320

answers:

3

I am trying to write an ant script which builds our project and will save the new build in a dist folder which gets committed to svn. As the name of the file changes for each build I need to delete all the old files in the dist folder (without knowing the names).

For this I was using the following code:

<exec executable="svn" outputproperty="__ignoreSvnDeleteDist">
    <arg value="delete"/>
<arg value="../dist/*"/>
</exec>

This is working fine as long as I use it on a windows machine but as soon as I try it under Mac Os X I'm getting the following error:

[echo] SVN Delete res: svn: '../dist/*' does not exist

I have compared that I use the same ant version on both machines (1.7.1) and the same Java version (1.6.0_12 for the Windows box and 1.6.0_15 for the Mac).

+1  A: 

Ok after some search I found the answer. I think you will need to keep in mind that the exec command is not creating a shell in which it executes your command but it will execute the command directly?

And the * is evaluated by the shell under unix like systems. Opposite to the windows platform wildcard gets evaluated without the command line interpreter (http://wiki.apache.org/ant/AntOddities).

This script should work:

<exec executable="sh" outputproperty="__ignoreSvnDeleteDist">
    <arg value="-c"/>
    <arg value="svn delete ../dist/*"/>
</exec>

Here we create a shell and give it the command to it should execute. Unfortunately this will now only work under unix like systems.

Chris
A: 

There is a simple solution: Don't commit the builds to SVN.

If your build process is too fragile to be able to recreate any distribution from the sources, then you should fix your build process. Consider to setup a CI server like hudson.

Aaron Digulla
We can recreate the distribution from sources but the name on the build changes as we include the build number in the name. Thats the reason for the name changes between builds.We already use hudson have just set it up 3 weeks ago. But this problem is not really related to hudson its more an ant problem with between the to platforms windows and mac os x.
Chris
Put the build number in a file "buildnumber" in the artifact. It would be great if tools like ant or maven could create a "build checksum": A number derived from the files of all involved build tools, sources, libraries, etc. but excluding any time stamps. That would allow to see quickly if a build has changed or not.
Aaron Digulla
+1  A: 

Instead of executing "svn" commands yourself you might consider the excellent SvnAnt task from the Subclipse project http://subclipse.tigris.org/svnant.html. It makes it much easier to handle svn related tasks. The code for your problem might look like

<svn>
  <delete> 
    <fileset dir="../dist">
      <include name="**/*"/>
    </fileset>
  </delete>
  <commit message="commit deleted files" dir="../dist"/>
</svn>
akr
Yes thats would be the best way to solve it (and also the cleanest). Unfortunately I cannot use other task than the core task of ant in this case.
Chris