title: Ant/Subversion hook: How does ${user.dir} get set?
body: <p>My company is transitioning from Visual Source Safe to Subversion; our pipeline management tools rely on the existence of the 'shadow folder' that VSS provides in order to move code from version control out to the various test environments. Note: we use an interpreted language and translate our source code into object code -- currently, both source and object code are under version control (specifically for the needs of the pipeline management machinery).</p>
  
  <p>As an iterative step, I am trying to mimic the shadow folder feature with a bit of flair in that I'm looking to kick off translation upon commit, so that we need not store both source and object code in Subversion. Note: I had to hack the process from performing a clean 'build' of everything to just translate the affected files during the commit, though, because it otherwise took too long to be a realtime commit operation (in the future I expect we will drop this process in favor of something a little less interactive, e.g. hourly builds or whatnot).</p>
  
  <p>All of this backstory is simply to ask the question: how does the ${user.dir} property get setup?</p>
  
  <p>This is my post-commit hook batch file (everything is done on Windows):</p>
  
  <pre><code>SET REPO=%1
  SET REV=%2
  
  FOR %%* IN (%REPO%) DO SET REPONAME=%%~n*
  
  SET BUILDROOT=E:\builds
  IF NOT EXIST %BUILDROOT% ( MKDIR %BUILDROOT% )
  SET BUILDDIR=%BUILDROOT%\%REPONAME%
  IF NOT EXIST %BUILDDIR% ( MKDIR %BUILDDIR% )
  CD %BUILDDIR%
  
  ECHO %CD%
  ECHO %BUILDDIR%
  
  C:\apache-ant-1.8.3\bin\ant -f C:\dev\shadow\build.xml -DWorkingDir=%BUILDDIR%\!build_work_dir -DSvnRepoUrl=file:///%REPO% -DFromRevision=%REV% &gt; %BUILDDIR%\!last_build_result.txt 2&gt;&amp;1
  </code></pre>
  
  <p>the last line is the actual Ant call; you can see that I'm redirecting the output to a file, which lives in the %BUILDDIR%, or E:\builds\. This file gets created as expected, which indicates to me that %BUILDDIR% was correctly setup and thus the:</p>
  
  <pre><code>CD %BUILDDIR%
  </code></pre>
  
  <p>line should have executed. I understand that SVN kicks off the post-commit hook with an <a href="http://svnbook.red-bean.com/en/1.1/ch05s02.html" rel="nofollow">empty environment</a>, but I would expect that changing the directory within it should preserve the state once kicking off Ant.</p>
  
  <p>Later, in my Ant script, I setup my ${build.dir} property thusly:</p>
  
  <pre><code>&lt;property name="build.dir" value="${user.dir}\.build.${build.time}" /&gt;
  &lt;!-- delete the build.dir, just in case we attempt a new build within the same minute...
       TODO: we may need to account for concurrent builds; does SVN single-thread commits? --&gt;
  &lt;delete dir="${build.dir}" /&gt;
  &lt;mkdir dir="${build.dir}" /&gt;
  </code></pre>
  
  <p>If %REPONAME% (in the batch file) was DEMO, I expected the current working directory to be: E:\builds\DEMO and thus ${build.dir} should be something like: E:\builds\DEMO.build.20120622.1127, but it is: C:\dev\shadow.build.20120622.1127, instead.</p>
  
  <p>As I understand it, Ant is simply pulling in the <a href="http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/System.html#getProperties%28%29" rel="nofollow">System.Properties</a> from Java for things like ${user.dir} -- ${user.dir} is described as <em>User's current working directory</em>. Clearly, based on my experimentation, something is getting crossed between the initial setup within the batch file and the invocation of Java with regards to the working directory. </p>
  
  <p>Does Ant change the working directory to the build file's location? I did not find any documentation to suggest it does, but it's possible I simply overlooked something. I have %ANT_HOME% defined, but given Subversion's 'empty environment', it wouldn't be loaded...perhaps that has an effect? I will need to investigate, but was hoping somebody might simply <em>know</em> how this works.</p>
  
  <p>Edit (2012-06-22-16:38):</p>
  
  <p>I tried setting up %ANT_HOME%, %JAVA_HOME% and %JAVA_CMD%, but to no avail.</p>