File:  [mozdev] / blocky / src / build.xml
Revision 1.1: download - view: text, annotated - select for diffs - revision graph
Sat Oct 22 07:25:47 2005 UTC (13 years, 5 months ago) by henrik
Branches: MAIN
CVS tags: HEAD
initial framework

<?xml version="1.0"?>

<project default="all">
	<taskdef resource="net/sf/antcontrib/antlib.xml" />
	<taskdef name="fmpp" classname="fmpp.tools.AntTask" />
	<taskdef name="fileinfo" className="org.digitalsoul.ant.FileInfo"/>

	<target depends="build" name="all" />

	<property file="build.properties" />
	<property file="build.apps.properties" />
	<property name="xpifilename" value="${project}" />
	<property name="xpifilename.localized" value="${project}-localized" />

	<tstamp>
		<format property="buildversion" pattern="yyyyMMddkkmm" locale="en" />
		<format property="year" pattern="yyyy" locale="en" />
	</tstamp>

	<target name="-init">
		<propertyregex property="versionstrip" input="${version}" regexp="\." replace="" />
		<filterset id="common.filters">
			<filtersfile file="build.properties" />
			<filtersfile file="build.apps.properties" />
			<filter token="version" value="${version}" />
			<filter token="versionstrip" value="${versionstrip}" />
		</filterset>
	</target>

	<target name="-zipxpi">
		<zip destfile="${xpifile}.xpi" includes="chrome/**/*, defaults/**/*, searchplugins/**/*" basedir=".">
			<zipfileset file="license.txt" />
			<zipfileset file="chrome.manifest" />
			<zipfileset file="install.js" />
			<zipfileset file="install.rdf" />
		</zip>
		<delete dir="chrome" failonerror="false" />
		<delete file="license.txt" />
		<delete file="chrome.manifest" />
		<delete file="install.js" />
		<delete file="install.rdf" />
		<echo level="info" message="${xpifile}.xpi is ready to install" />
	</target>

	<target name="-copydir">
		<echo level="info" message="Copying from ${param1}/${param2} to chrome/${param1}/${param2}" />
		<fmpp sourceRoot="${param1}/${param2}" outputRoot="chrome/${param1}/${param2}" data="antProperties(), proj:antProject(), task:antTask()">
			<exclude name="**/*.bak" />
		</fmpp>
	</target>

	<target name="-clean">
		<echo level="info" message="Cleaing up" />
		<delete dir="chrome" failonerror="false" />
		<delete file="chrome.manifest" />
		<delete file="install.js" />
		<delete file="install.rdf" />
		<delete file="${xpifile}.xpi" />
		<delete file="${xpifile}.jar" />
	</target>

	<target name="clean">
		<echo level="info" message="Cleaing up" />
		<delete dir="chrome" failonerror="false" />
		<delete file="${xpifilename}.xpi" />
		<delete file="${xpifilename.localized}.xpi" />
	</target>

	<target name="-zipjar">
		<zip destfile="chrome/${project}.jar">
			<zipfileset dir="chrome" />
		</zip>
		<delete dir="chrome/content" />
		<delete dir="chrome/locale" />
		<delete dir="chrome/skin" />
	</target>

	<target name="-buildinstall">
		<fileinfo path="chrome/${project}.jar" rootProperty="jar" param="size" />
		<var name="jarsize" value="${jar.size}" />
		<fileinfo path="defaults/preferences/${project}.js" rootProperty="js" param="size" />
		<var name="jssize" value="${js.size}" />
		<for list="${localfiles}" param="local" trim="true">
			<sequential>
				<echo>Copying @{local}.in to @{local}</echo>
				<fmpp sourceFile="@{local}.in" outputFile="@{local}" data="antProperties(), proj:antProject(), task:antTask()" />
			</sequential>
		</for>
	</target>

	<target name="-buildupdate">
		<exec executable="shash" outputproperty="sha256temp" failifexecutionfails="false">
			<arg line="--algorithm sha256 --binary"/>
			<arg file="${xpifilename}.xpi" />
		</exec>
		<propertyregex property="sha256" input="${sha256temp}" regexp="[\n|\r]\\?(.*?)\s.*" select="\1" />
		<echo>Copying ${updatefile}.in to ${updatefiledir}${updatefile}</echo>
		<fmpp sourceFile="${updatefile}.in" outputFile="${updatefiledir}${updatefile}" data="antProperties(), proj:antProject(), task:antTask()" />
	</target>

	<target name="-build">
		<antcall target="-clean" />
		<antcall target="-copydir">
			<param name="param1" value="content" />
			<param name="param2" value="" />
		</antcall>
		<if>
			<and>
				<isset property="locales" />
				<not>
					<equals arg1="${locales}" arg2="" />
				</not>
			</and>
			<then>
				<for list="${locales}" param="locale" trim="true">
					<sequential>
						<antcall target="-copydir">
							<param name="param1" value="locale" />
							<param name="param2" value="@{locale}" />
						</antcall>
					</sequential>
				</for>
			</then>
		</if>
		<if>
			<and>
				<isset property="skins" />
				<not>
					<equals arg1="${skins}" arg2="" />
				</not>
			</and>
			<then>
				<antcall target="-copydir">
					<param name="param1" value="skin" />
					<param name="param2" value="" />
				</antcall>
			</then>
		</if>
		<antcall target="-zipjar" />
		<antcall target="-buildinstall" />
		<antcall target="-zipxpi" />
		<if>
			<and>
				<isset property="dist" />
				<isset property="updatefile" />
				<not>
					<equals arg1="${updatefile}" arg2="" />
				</not>
			</and>
			<then>
				<antcall target="-buildupdate" />
			</then>
		</if>
	</target>

	<target depends="-init" name="build" description="Build the extension">
		<if>
			<not>
				<isset property="dist" />
			</not>
			<then>
				<var name="version" value="${version}.${buildversion}" />
			</then>
		</if>
		<echo>Using version: ${version}</echo>
		<property name="xpifile" value="${xpifilename}" />
		<echo>Using XPI file: ${xpifile}.xpi</echo>
		<property name="xpilocale" value="${localesdefault}" />
		<echo>Using locales: ${locales}</echo>
		<antcall target="-build" />
	</target>

	<target depends="-init" name="build-localized" description="Build the extension - localized">
		<if>
			<not>
				<isset property="dist" />
			</not>
			<then>
				<var name="version" value="${version}.${buildversion}" />
			</then>
		</if>
		<echo>Using version: ${version}</echo>
		<property name="xpifile" value="${xpifilename.localized}" />
		<echo>Using XPI file: ${xpifile}.xpi</echo>
		<var name="locales" value="${locales-localized}" />
		<echo>Using locales: ${locales}</echo>
		<antcall target="-build" />
	</target>

	<target name="-testxpi">
		<echo level="info" message="Testing" />
		<exec executable="unzip">
			<arg value="-t" />
			<arg file="${xpifile}.xpi" />
		</exec>
		<unzip src="${xpifile}.xpi" dest="chrome">
			<patternset>
				<include name="**/${xpifilename}.jar" />
			</patternset>
		</unzip>
		<exec executable="unzip">
			<arg value="-t" />
			<arg file="chrome/chrome/${xpifilename}.jar" />
		</exec>
		<delete dir="chrome" failonerror="false" />
	</target>

	<target depends="-init,build" name="test" description="Test the extension">
		<antcall target="-testxpi" />
		<for list="${locales}" param="locale" trim="true">
			<sequential>
				<echo>Comparing @{locale}</echo>
				<exec executable="perl">
					<arg file="scripts/compare-locales.pl" />
					<arg value="locale/en-US" />
					<arg value="locale/@{locale}" />
				</exec>
			</sequential>
		</for>
	</target>

	<target depends="-init,build-localized" name="test-localized" description="Test the extension - localized">
		<antcall target="-testxpi" />
	</target>

	<target name="-dist">
		<echo level="info" message="Making distribution" />
		<copy file="${xpifile}.xpi" todir="${downloaddir}" />
		<copy file="${xpifile}.xpi" tofile="${downloaddir}/${xpifile}-${versionstrip}.xpi" />
		<echo level="info" message="${xpifile}.xpi and ${xpifile}-${versionstrip}.xpi are ready in ${downloaddir}" />
	</target>

	<target depends="-init" name="dist" description="Distribute the extension">
		<var name="dist" value="1" />
		<property name="xpifile" value="${xpifilename}" />
		<antcall target="build" />
		<antcall target="-dist" />
	</target>

	<target depends="-init" name="dist-localized" description="Distribute the extension - localized">
		<var name="dist" value="1" />
		<property name="xpifile" value="${xpifilename.localized}" />
		<antcall target="build-localized" />
		<antcall target="-dist" />
	</target>

	<target depends="-init,build" name="install" description="Install the extension">
		<antcall target="-install" />
	</target>

	<target depends="-init" name="installonly" description="Install the extension">
		<antcall target="-install" />
	</target>

	<target name="-install" description="Install the extension">
		<echo level="info" message="Installing" />
		<if>
			<not>
				<isset property="xpifile" />
			</not>
			<then>
				<property name="xpifile" value="${project}" />
			</then>
		</if>
		<for list="${installdirs}" param="installdir" trim="true">
			<sequential>
				<available type="dir" file="@{installdir}" property="test" />
				<if>
					<equals arg1="${test}" arg2="true" />
					<then>
						<var name="test" value="" unset="true" />
						<available file="@{installdir}\extensions\${id}\chrome\${xpifile}.jar" property="test" />
						<if>
							<equals arg1="${test}" arg2="true" />
							<then>
								<delete dir="@{installdir}\extensions\${id}" failonerror="false" />
								<var name="test" value="" unset="true" />
								<available file="@{installdir}\extensions\${id}\chrome\${xpifile}.jar" property="test" />
								<if>
									<equals arg1="${test}" arg2="true" />
									<then>
										<input>Exit your client and press Enter to continue...</input>
										<delete dir="@{installdir}\extensions\${id}" />
									</then>
								</if>
								<unzip src="${xpifile}.xpi" dest="@{installdir}\extensions\${id}" />
								<echo>${name} will be updated on next start</echo>
							</then>
							<else>
								<copy file="${xpifile}.xpi" todir="@{installdir}\extensions" />
								<echo>${name} will be installed on next start</echo>
							</else>
						</if>
						<var name="test" value="" unset="true" />
					</then>
					<else>
						<echo>@{installdir} doesn't exist</echo>
					</else>
				</if>
			</sequential>
		</for>
	</target>
</project>

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>