I’ve recently been messing around with GWT and Mercurial, and came across the age old dilemma: “add libraries to version control or not …”. On one hand it’s easier to deploy and get new people to use it, on the other hand it’s pretty redundant and down right ugly. So, the only other solutions are A: tell people to install it manually, which is bound to end in tears, anger, and frustration; or B: make an auto installation script. I’ve written a few of these before, but it’s a horribly dull task. So with the GWT’s SDK pretty much forcing me to use Ant anyway, I thought it might be up for the job, and here is the build.xml script I came up with:
- <?xml version="1.0" encoding="utf-8" ?>
- <project name="test" default="build" basedir=".">
- <property name="dir.lib" value="lib" />
-
- <!-- GWT version, source, and destination -->
- <property name="gwt.version" value="2.0.3" /> <!-- Version number for easy reference -->
- <property name="gwt.depfolder" value="gwt-${gwt.version}" /> <!-- The folder that the archive will produce -->
- <property name="gwt.deparchive" value="${gwt.depfolder}.zip" /> <!-- Filename of the archive, both local and on server -->
- <property name="gwt.depsource" value="http://google-web-toolkit.googlecode.com/files/${gwt.deparchive}" /> <!-- The URL to fetch the archive from -->
- <property name="gwt.sdk" location="${dir.lib}/gwt" /> <!-- Final location -->
-
- <target name="installdeps" description="Install dependencies">
- <delete dir="${gwt.sdk}" />
- <get src="${gwt.depsource}" dest="${dir.lib}/${gwt.deparchive}" usetimestamp="true" />
- <unzip src="${dir.lib}/${gwt.deparchive}" dest="${dir.lib}" />
- <move file="${dir.lib}/${gwt.depfolder}" tofile="${gwt.sdk}" />
- <!-- <symlink link="${gwt.sdk}" resource="${dir.lib}/gwt-${gwt.version}" /> -->
- </target>
- </project>
plainThe script is actually quite simple:
- Line 6-10: Figure out where to get it from and where to put it. This might look a bit complicated, but it should allow you to control pretty much anything from those five lines, leaving the actual target to do its work.
- Line 12: The actual Ant target. This will be run when you execute ant installdeps.
- Line 13: Delete the old SDK directory.
- Line 14: Fetch the zip file from the source specified in line 9, unless the file already exists or is older than the one on the server.
- Line 15: Extract into lib folder.
- Line 16: Move it to a generic folder from where it can be easily accessed. I personally like symlinks (line 17), but I know they can be a pain to deal with on Windows, so I opted for just moving it.