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"
="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">
includes="content/**" />

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

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

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

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

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


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.
is simple -
just remove this directory. Restarting firefox in my script
is just killing windows app with taskkill command.

No comments: