<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <title>app</title>
  <id>http://127.0.0.1</id>
  <updated>2010-02-11T00:00:00-08:00</updated>
  <author>
    <name></name>
  </author>
  <entry>
    <title>Making a better ant file</title>
    <link href="http://127.0.0.1/2010/02/11/making-a-better-ant-file/" rel="alternate"/>
    <id>http://127.0.0.1/2010/02/11/making-a-better-ant-file/</id>
    <published>2010-02-11T00:00:00-08:00</published>
    <updated>2010-02-11T00:00:00-08:00</updated>
    <author>
      <name></name>
    </author>
    <summary type="html">&lt;p&gt;Ant files are commonly used to manage Java projects, not always I&amp;rsquo;ll grant you, but I&amp;rsquo;ve no personal experience of Maven, and as far as I can tell Ant does everything that I need. What I struggled with when I first started using them though was how to structure them, and furthermore how do you manage them between multiple developer workspaces&amp;hellip;&lt;/p&gt;
</summary>
    <content type="html">&lt;p&gt;Ant files are commonly used to manage Java projects, not always I&amp;rsquo;ll grant you, but I&amp;rsquo;ve no personal experience of Maven, and as far as I can tell Ant does everything that I need. What I struggled with when I first started using them though was how to structure them, and furthermore how do you manage them between multiple developer workspaces.&lt;/p&gt;

&lt;h2&gt;Developer Specific Settings&lt;/h2&gt;

&lt;p&gt;Full Disclosure: This technique isn&amp;rsquo;t my own, it was shown to me by a very talented programmer called David Harrigan who I worked with a couple of years back. Sadly I can&amp;rsquo;t find a blog with his name on.&lt;/p&gt;

&lt;p&gt;Let&amp;rsquo;s take an example where your project depends on a load of external graphical assets, the kind of stuff that would be absolute insanity to actually put into source control, and they get should be copied into the assets directory of any build, like so:&lt;/p&gt;

&lt;script type="syntaxhighlighter" class="brush: xml"&gt;&lt;![CDATA[
&lt;target name="package-assets"&gt;
    &lt;copy todir="${dist.assets.dir}" overwrite="false"&gt;
        &lt;fileset dir="${assets.dir}" /&gt;
    &lt;/copy&gt;
&lt;/target&gt;
]]&gt;&lt;/script&gt;


&lt;p&gt;So each developer copies the relevant graphics onto their own hard disk, but of course they&amp;rsquo;re all in different folders. So we need to set the &lt;code&gt;assets.dir&lt;/code&gt; property for each developer individually, there&amp;rsquo;s loads of ways to do this. Firstly we could do it as a command to the ant argument:&lt;/p&gt;

&lt;script type="syntaxhighlighter" class="brush: bash"&gt;&lt;![CDATA[
ant -Dassets.dir=/path/to/assets
]]&gt;&lt;/script&gt;


&lt;p&gt;But this is going to get very cumbersome very quickly. We really don&amp;rsquo;t want to have to be retyping all these arguments every time we want to run a build. So on to phase two, put them in a properties file&lt;/p&gt;

&lt;p&gt;&lt;small&gt;build.properties&lt;/small&gt;&lt;/p&gt;

&lt;script type="syntaxhighlighter" class="brush: plain"&gt;&lt;![CDATA[
assets.dir=/path/to/assets
]]&gt;&lt;/script&gt;


&lt;p&gt;Then we include this at the top of the build file like this&lt;/p&gt;

&lt;p&gt;&lt;small&gt;build.xml&lt;/small&gt;&lt;/p&gt;

&lt;script type="syntaxhighlighter" class="brush: xml"&gt;&lt;![CDATA[   
&lt;project name="example_project" default="build"&gt;

    &lt;property file="build.properties" /&gt;
    
&lt;/project&gt;
]]&gt;&lt;/script&gt;


&lt;p&gt;Now here&amp;rsquo;s the important bit &lt;strong&gt;make sure the &lt;code&gt;build.properties&lt;/code&gt; file never gets committed&lt;/strong&gt;. Add it to the ignore list for your version control (here&amp;rsquo;s how to do that in &lt;a href="http://github.com/guides/ignore-for-git"&gt;git&lt;/a&gt; and &lt;a href="http://sdesmedt.wordpress.com/2006/12/10/how-to-make-subversion-ignore-files-and-folders/"&gt;subversion&lt;/a&gt;). This means that individual developers can define their own version of the file and it will automatically be loaded when they run ant.&lt;/p&gt;

&lt;p&gt;Of course it&amp;rsquo;s best not to leave developers guessing at what the correct structure of the build.properties file should be, so it&amp;rsquo;s generally useful to include an example file&lt;/p&gt;

&lt;p&gt;&lt;small&gt;build.properties-example&lt;/small&gt;&lt;/p&gt;

&lt;script type="syntaxhighlighter" class="brush: plain"&gt;&lt;![CDATA[
assets.dir=/path/to/assets
]]&gt;&lt;/script&gt;


&lt;h2&gt;Dependency Management&lt;/h2&gt;

&lt;p&gt;Ivy is an absolutely awesome tool for handling dependent libraries, though there are a couple of tweaks you&amp;rsquo;ll need to make to get the behaviour you expect by default. First things first however, here&amp;rsquo;s &lt;a href="http://ant.apache.org/ivy/history/latest-milestone/install.html"&gt;a very good page on how to get ivy installed in seconds&lt;/a&gt;. So now all we have to do is define a task to actually invoke ivy.&lt;/p&gt;

&lt;script type="syntaxhighlighter" class="brush: xml"&gt;&lt;![CDATA[
&lt;target name="fetch-libs" depends="init-ivy"&gt;
    &lt;ivy:retrieve file="ivy.xml" pattern="${libs.dir}/[artifact].[ext]" type="jar" transitive="false" /&gt;
&lt;/target&gt;
]]&gt;&lt;/script&gt;


&lt;p&gt;The most important bit here is &lt;code&gt;transitive="false"&lt;/code&gt;. This stops ivy downloading any jars that are marked up as dependent by your resource. So for example if you use the dependency&lt;/p&gt;

&lt;script type="syntaxhighlighter" class="brush: xml"&gt;&lt;![CDATA[
&lt;dependency org="org.springframework" name="spring-core" rev="2.5.6" /&gt;
]]&gt;&lt;/script&gt;


&lt;p&gt;It&amp;rsquo;ll also try and download &lt;a href="http://mvnrepository.com/artifact/org.springframework/spring-core/2.5.6"&gt;all of these&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="http://mvnrepository.com/artifact/asm/asm/2.2.3"&gt;asm&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://mvnrepository.com/artifact/asm/asm-commons/2.2.3"&gt;asm-commons&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://mvnrepository.com/artifact/asm/asm-util/2.2.3"&gt;asm-util&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://mvnrepository.com/artifact/backport-util-concurrent/backport-util-concurrent/3.0"&gt;backport-util-concurrent&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://mvnrepository.com/artifact/commons-collections/commons-collections/3.2"&gt;commons-collections&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://mvnrepository.com/artifact/commons-logging/commons-logging/1.1.1"&gt;commons-logging&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://mvnrepository.com/artifact/log4j/log4j/1.2.15"&gt;log4j&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;which really starts to pump up the download times, because you&amp;rsquo;ll also need to download all the dependencies for each of these sub-dependencies, of which there are another 11. It&amp;rsquo;s enough to make a man cry.&lt;/p&gt;

&lt;p&gt;The other useful bit of info in the ivy declaration is &lt;code&gt;pattern="${libs.dir}/[artifact].[ext]"&lt;/code&gt; this tells ivy to download your dependencies into the &lt;code&gt;libs.dir&lt;/code&gt; folder (which for the sake of outright insanity let&amp;rsquo;s assume is libs/), and structure them as such:&lt;/p&gt;

&lt;script type="syntaxhighlighter" class="brush: xml"&gt;&lt;![CDATA[
libs/
    commons-jxpath.jar
    commons-lang.jar
    jackson-core-asl.jar
    jackson-mapper-asl.jar
    jetty-util.jar
    jetty.jar
    jruby.jar
    junit.jar
    mongo-java-driver.jar
    velocity.jar
]]&gt;&lt;/script&gt;


&lt;p&gt;Because ivy names jars uniformly using this scheme we avoid any problems with two versions of a library being loaded (other schemes I&amp;rsquo;ve seen include a version number in the jar name, which can end up with both being in the classpath, which can get a little weird). One thing to remember though is do remember to add the &lt;code&gt;libs/&lt;/code&gt; directory to your source control ignore list. Running diffs on large binary files can really slow down SCM systems.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>Getting launchd to play nicely with mysql 5 osx</title>
    <link href="http://127.0.0.1/2010/02/11/getting-launchd-to-play-nicely-with-mysql-5-osx/" rel="alternate"/>
    <id>http://127.0.0.1/2010/02/11/getting-launchd-to-play-nicely-with-mysql-5-osx/</id>
    <published>2010-02-11T00:00:00-08:00</published>
    <updated>2010-02-11T00:00:00-08:00</updated>
    <author>
      <name></name>
    </author>
    <summary type="html">&lt;p&gt;Recently I was trying to install Mysql 5 installed via MacPorts, and I found a very helpful &lt;a href="http://hivelogic.com/articles/compiling-mysql-on-snow-leopard"&gt;tutorial from hivelogic&lt;/a&gt;. Which all worked beautifully, but to get the server to launch properly at startup I needed to do a couple more steps. After googling around the errors I was getting I found out that I needed to run mysql_upgrade&amp;hellip;&lt;/p&gt;
</summary>
    <content type="html">&lt;p&gt;Recently I was trying to install Mysql 5 installed via MacPorts, and I found a very helpful &lt;a href="http://hivelogic.com/articles/compiling-mysql-on-snow-leopard"&gt;tutorial from hivelogic&lt;/a&gt;. Which all worked beautifully, but to get the server to launch properly at startup I needed to do a couple more steps. After googling around the errors I was getting I found out that I needed to run mysql_upgrade.&lt;/p&gt;

&lt;p&gt;I got an error when I first tried to run myql_upgrade, so there were a couple of preparatory steps I needed to run:&lt;/p&gt;

&lt;script type="syntaxhighlighter" class="brush: bash"&gt;&lt;![CDATA[
sudo mkdir -p /opt/local/var/db/mysql5
sudo chown mysql /opt/local/var/db/mysql5
sudo mkdir -p /opt/local/var/run/mysql5
sudo chown mysql /opt/local/var/run/mysql5
]]&gt;&lt;/script&gt;


&lt;p&gt;Now run mysql_upgrade to repair the user tables.&lt;/p&gt;

&lt;script type="syntaxhighlighter" class="brush: bash"&gt;&lt;![CDATA[
sudo /opt/local/lib/mysql5/bin/mysql_upgrade
]]&gt;&lt;/script&gt;


&lt;p&gt;Next I had to link the mysql database to the location that mysql looks for the user data by default&lt;/p&gt;

&lt;script type="syntaxhighlighter" class="brush: bash"&gt;&lt;![CDATA[
sudo ln -s /opt/local/var/db/mysql5/mysql /opt/local/libexec/mysql
]]&gt;&lt;/script&gt;


&lt;p&gt;Then finally I had to change the ownership of the database files to the user that mysql server runs as.&lt;/p&gt;

&lt;script type="syntaxhighlighter" class="brush: bash"&gt;&lt;![CDATA[
sudo chown -R mysql /opt/local/var/db/mysql5/mysql
]]&gt;&lt;/script&gt;

</content>
  </entry>
</feed>

