Wednesday, July 18, 2007

Ant Build Script for Mozilla Extensions

I play with Mozilla Extensions in EclipseIDE and generally like the Ant build system. Not an expect at Ant by any means so if anyone out there wants to make improvements to these, please share. The relative paths to directories are set in the build.properties file so that it shouldn't matter what folder layout one uses. If I make improvements to this over time, will post updates, feel free to drop feedback.

build.xml
<?xml version="1.0"?>

<project name="Firefox Extension Builder" basedir="." default="package">
<property file="build.properties" />

<target name="setup" description="create dir structure for project">
<mkdir dir="${content.dir}"/>
<mkdir dir="${skin.dir}"/>
<mkdir dir="${install.dir}"/>
<mkdir dir="${locale.dir}"/>
<mkdir dir="${defaults.dir}"/>
</target>
<target name="clean" description="Delete previously generated jars">
<delete file="${install.dir}/**" verbose="true"/>
</target>
<target name="createjar">
<delete file="${install.dir}/${project.name}.jar" verbose="true" failonerror="false"/>
<zip destfile="${install.dir}/${project.name}.jar" excludes="*CVS*/**">
<zipfileset dir="."
includes="${content.dir}/**, ${skin.dir}/**, ${locale.dir}/**"/>
</zip>
</target>

<target name="createxpi" depends="gen_manifest,createjar">
<zip destfile="${install.dir}/${project.name}.xpi">
<zipfileset dir="${install.dir}" includes="${project.name}.jar"
prefix="chrome" />
<zipfileset dir="${install.dir}" includes="${manifest.src}"/>
<zipfileset dir="." includes="${install.src}" />

</zip>
</target>

<target name="gen_manifest">
<copy file="${manifest.src}" tofile="${install.dir}/${manifest.src}" overwrite="true"/>
<replaceregexp file="${install.dir}/${manifest.src}"
match="^(content\s+\S*\s+)(\S*/)$"
replace="\1jar:chrome/${project.name}.jar!/\2"
flags="g" byline="true"/>
<replaceregexp file="${install.dir}/${manifest.src}"
match="^(skin|locale)(\s+\S*\s+\S*\s+)(.*/)$"
replace="\1\2jar:chrome/${project.name}.jar!/\3"
flags="g" byline="true"/>
</target>
<target name="package" depends="clean,createjar,gen_manifest,createxpi"/>
</project>


build.properties
project.name=${your_project_name}
content.dir=chrome/content
skin.dir=chrome/skin
locale.dir=locale
defaults.dir=defaults
install.dir=install
manifest.src=chrome.manifest
install.src=install.rdf

No comments:

Post a Comment