Friday, January 26, 2007

Firefox development with Ant

I want to share with you a little build file that saved a lot of time for me.
Firefox extension development assumes that you need to
create two zip archives, install extension, restart firefox, etc.
Entire process can be automated with the help of the following
Ant build file :

<?xml version="1.0"?>
<project name="helloworld" default="xpi">

<property name="firefox" value="C:\...\firefox.exe"/>
<property name="ext_dir"
value
="C:\Program Files\Mozilla Firefox\extensions"/>
<property name="workdir" value="myxpi"/>
<property name="build" value="build"/>
<property name="extension.xpi" value="helloworld.xpi"/>
<property name="extension.jar" value="helloworld.jar"/>
<property name="guid" value="{...}"/>

<target name="jar">
<zip
destfile="${build}\${extension.jar}"
basedir="${workdir}"
includes="content/**" />
</target>

<target name="xpi" depends="jar">
<zip destfile="${build}\${extension.xpi}">
<zipfileset
dir="${build}"
includes="${extension.jar}"
prefix="chrome" />
<zipfileset
dir="${workdir}"
includes="install.rdf" />
</zip>
</target>

<target name="install" depends="xpi, kill">
<exec executable="${firefox}">
<arg value="-install-global-extension"/>
<arg value="${build}\${extension.xpi}"/>
</exec>
</target>

<target name="uninstall">
<delete dir="${ext_dir}\${guid}"/>
</target>

<target name="kill">
<exec executable="taskkill">
<arg value="/F"/>
<arg value="/IM"/>
<arg value="firefox.exe"/>
</exec>
</target>

<target name="start">
<exec executable="${firefox}"/>
</target>

</project>


In target named jar we are creating a jar file to
put into our final xpi.
It is mechanics :) More interesting thing
happens in install target -
installation of extension as global extension
using command line.
When extension is installed in the following way,
it can be found in (for example)
C:\Program Files\Mozilla Firefox\extensions\${guid}.
${guid} actually is the same value as we defined
in our extension in install.rdf in the section em:id.
Uninstall
is simple -
just remove this directory. Restarting firefox in my script
is just killing windows app with taskkill command.

No comments: