Ant Eclipse Firefox
From Fxp Wiki
A lot of actions can be performed in eclipse through an Ant building process.
Here is how I build extensions for Firefox(xpi) with Eclipse:
As a reminder, let's review the directory structure of a simple extension:
+- Empty/
+- install.rdf
+- chrome.manifest
+- chrome/
+- content/
+- default.js
+- default.xul
+- skin/
+- default.css
I have simply made an empty set, which will be filled by the building script
Contents |
chrome.manifest
content @app.name@ chrome/content/ overlay chrome://browser/content/browser.xul chrome://@app.name@/content/@app.name@.xul
install.rdf
<?xml version="1.0" encoding="UTF-8" standalone="no"?><RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:em="http://www.mozilla.org/2004/em-rdf#"> <Description about="urn:mozilla:install-manifest"> <em:name>@app.name@</em:name> <em:version>1.0</em:version> <em:description>An example toolbar extension.</em:description> <em:creator>fx</em:creator> <em:id>@app.name@@fxparlant.net</em:id> <em:targetApplication> <!-- Firefox --> <Description> <em:id>{ec8030f7-c20a-464f-9b0e-13a3a9e97384}</em:id> <em:minVersion>1.5</em:minVersion> <em:maxVersion>3.0.*</em:maxVersion> </Description> </em:targetApplication> <em:iconURL/> <em:homepageURL>http://www.fxparlant.net/My_Firefox_Extensions/</em:homepageURL> <em:optionsURL/><em:aboutURL/><em:updateURL/><em:updateKey/><em:hidden/><em:localized><RDF:Description xmlns:RDF="http://www.w3.org/1999/02/22-rdf-syntax-ns#"><em:locale/><em:name/><em:description/></RDF:Description></em:localized><em:localized><RDF:Description xmlns:RDF="http://www.w3.org/1999/02/22-rdf-syntax-ns#"><em:locale/><em:name/><em:description/></RDF:Description></em:localized><em:localized><RDF:Description xmlns:RDF="http://www.w3.org/1999/02/22-rdf-syntax-ns#"><em:locale/><em:name/><em:description/></RDF:Description></em:localized><em:localized><RDF:Description xmlns:RDF="http://www.w3.org/1999/02/22-rdf-syntax-ns#"><em:locale/><em:name/><em:description/></RDF:Description></em:localized><em:developer>François PARLANT</em:developer><em:developer/><em:targetPlatform/></Description> </RDF>
default.css
#@app.prefix@-MainMenu { list-style-image: url("chrome://@app.name@/skin/main.png"); }
default.xul
<?xml version="1.0"?> <overlay id="@app.prefix@-Overlay" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> <toolbox id="navigator-toolbox"> <toolbar id="@app.prefix@-Toolbar" toolbarname="Tutorial Toolbar" accesskey="T" class="chromeclass-toolbar" context="toolbar-context-menu" hidden="false" persist="hidden">
build_one.xml
<?xml version="1.0" ?> <project name="tuttoolbar" default="chrome"> <property name="src.dir" value="." /> <property name="dist.dir" value="dist" /> <property name="app.name" value="extensionname" /><!-- change this to your extension name. ONLY SMALL LETTERS!! --> <property name="app.prefix" value="myPrefix" /><!-- change this to your the prefix for your variables --> <property name="ff.dir" value="G:\PortableApps\Firefox3DevPortable\Data\profile\extensions" /><!-- I have two version of dev firefox, one portable, one fix. --> <property name="ffasus.dir" value="C:\Documents and Settings\fx\Application Data\Mozilla\Firefox\Profiles\h65b9yao.Dev\extensions" /> <!-- Each group of action is called a "target --> <target name="chrome"> <!-- move is the current command for "rename" (which is deprecated) --> <!-- I rename the default files with the name of the extension --> <!-- On a previous version of eclipse I had a "not in sync" error, because eclipse didn't understand the renamed filed had to be kept in the workspace: to solve this I checked the "automatic refresh" box in preferences / general / workspace. Note the I usually have to refresh the project (F5 or right click on the project folder) for the renamed file to appear correctly --> <move file="${src.dir}/chrome/skin/default.css" tofile="${src.dir}/chrome/skin/${app.name}.css"/> <move file="${src.dir}/chrome/content/default.xul" tofile="${src.dir}/chrome/content/${app.name}.xul"/> <move file="${src.dir}/chrome/content/default.js" tofile="${src.dir}/chrome/content/${app.name}.js"/> <!-- I replace the @app.name@ variable by the value set at the top of this file --> <!-- Note that these changes are made to all files except the build files --> <replace dir="${src.dir}" token="@app.name@" value="${app.name}"> <exclude name="build*.xml"/> <include name="**/*.*"/> </replace> <!-- same with the prefix variable --> <replace dir="${src.dir}" token="@app.prefix@" value="${app.prefix}"> <exclude name="build*.xml"/> <include name="**/*.*"/> </replace> </target> <!-- The second group of action will create the file for dynamic developpment in my portable firefox profile --> <target name="linktofirefox"> <!-- First check that the firefox path is set (at the top of this file) and check that the folder exists. --> <condition property="ff.present"> <and> <isset property="ff.dir" /> <available file="${ff.dir}" type="dir" /> </and> </condition> <!-- If it exists, create a file named after the extension and add the path of the current folder in it. --> <!-- Note that carefully removed any spaces of carriage return on this line. Any character between the start and the end of the echo, would be added to the file, causing the extension NOT to be loaded by firefox --> <echo file="${ff.dir}/${app.name}@fxparlant.net" append="false">${basedir}</echo> </target> <target name="linktofirefoxAsus"> <!-- This second group is just because I have a second firefox testing version. You shouldn't need it --> <condition property="ffasus.present"> <and> <isset property="ffasus.dir" /> <available file="${ffasus.dir}" type="dir" /> </and> </condition> <echo file="${ffasus.dir}/${app.name}@fxparlant.net" append="false">${basedir}</echo> </target> </project>
Usage
- I just copy this empty project and paste it in the workspace. Eclipse asks me for the name of the copied project: I give the name of the new extension.
- I change the app.name and the app.prefix values in the build_one.xml file.
- I right click on the build_one.xml file and I choose run as menu, and ant build
- The last window allows me to choose which actions I want to do (you can uncheck the default one if you don't want it).
