<commit_before><!-- 
Appcelerator Titanium Mobile

Copyright (c) 2010-2013 by Appcelerator, Inc. All Rights Reserved.
Licensed under the terms of the Apache Public License
Please see the LICENSE included with this distribution for details.

Common ant tasks and macros for building Android-based Titanium modules and projects
-->
<project name="titanium-common" default="dont.run.me">
	<property file="build.properties"/>
	<property name="ti.android.root" location="${basedir}/.." />
	<property name="ti.build.dir" value="${ti.android.root}/build"/>
	<property file="${ti.build.dir}/build.properties"/>

	<taskdef resource="net/sf/antcontrib/antlib.xml">
		<classpath>
			<pathelement location="${ti.build.dir}/lib/ant-contrib-1.0b3.jar" />
		</classpath>
	</taskdef>

	<path id="serialver.path">
		<fileset file="${ti.build.dir}/lib/serialver.jar"/>
	</path>

	<taskdef name="serialver" classname="net.sourceforge.serialver.SerialVer">
		<classpath refid="serialver.path"/>
	</taskdef>

	<path id="ti.build.lib.path">
		<fileset dir="${ti.build.dir}/lib" includes="**/*.jar"/>
	</path>
	
	<property name="v7appcompat.project.dir" location="${ti.android.root}/modules/appcompat"/>
	<property name="titanium.project.dir" location="${ti.android.root}/titanium"/>
	<property name="kroll.apt.project.dir" location="${ti.android.root}/kroll-apt"/>
	<property name="kroll.common.project.dir" location="${ti.android.root}/runtime/common"/>
	<property name="kroll.v8.project.dir" location="${ti.android.root}/runtime/v8"/>
	<property name="kroll.runtime" value="all"/>

	<condition property="ndk.build" value="${kroll.v8.project.dir}/ndk-build.cmd" else="${kroll.v8.project.dir}/ndk-build.sh">
		<os family="windows"/>
	</condition>

	<property name="modules.dir" location="${ti.android.root}/modules"/>
	<property name="ui.module.dir" location="${modules.dir}/ui"/>
	
	<property name="dist.dir" location="${ti.android.root}/../dist/android"/>
	<available property="dist.dir.available" file="${dist.dir}"/>

	<property name="dist.json.dir" location="${dist.dir}/json"/>
	<property name="dist.classes.dir" location="${dist.dir}/classes"/>
	<property name="gen.src.dir" location="${dist.dir}/generated"/>
	<property name="build.version" value="1.0.0"/>
	<property name="dependency.json" location="${ti.android.root}/dependency.json"/>
	<property environment="env"/>

	<path id="ti.build.path">
		<path refid="ti.build.lib.path"/>
		<path path="${dist.classes.dir}/ant-tasks"/>
	</path>

	<property name="android.ndk" value="${env.ANDROID_NDK}"/>

	<if>
		<isset property="env.TI_DEBUG"/>
		<then>
			<property name="ti.debug" value="${env.TI_DEBUG}"/>
		</then>
		<else>
			<property name="ti.debug" value="0"/>
		</else>
	</if>

	<if>
		<isset property="env.ANDROID_PLATFORM"/>
		<then>
			<property name="android.sdk" location="${env.ANDROID_PLATFORM}/../.."/>
			<property name="android.platform" location="${env.ANDROID_PLATFORM}"/>
			<property name="google.apis" location="${env.GOOGLE_APIS}"/>
		</then>
		<else>
			<if>
				<isset property="env.ANDROID_SDK"/>
				<then>
					<property name="android.sdk" location="${env.ANDROID_SDK}"/>
				</then>
				<else>
					<if>
						<not><isset property="android.sdk"/></not>
						<then>
							<echo level="warning">Android SDK not found, using default /opt/android-sdk</echo>
						</then>
					</if>
					<property name="android.sdk" location="/opt/android-sdk"/>
				</else>
			</if>
			<if>
				<isset property="env.ANDROID_PLATFORM"/>
				<then>
					<property name="android.platform" location="${env.ANDROID_PLATFORM}"/>
				</then>
				<else>
					<property name="android.platform" location="${android.sdk}/platforms/android-14"/>
				</else>
			</if>
			<if>
				<isset property="env.GOOGLE_APIS"/>
				<then>
					<property name="google.apis" location="${env.GOOGLE_APIS}"/>
				</then>
				<else>
					<if>
						<not><isset property="google.apis"/></not>
						<then>
							<property name="google.apis" location="${android.sdk}/add-ons/addon-google_apis-google_inc_-8"/>
						</then>
					</if>
				</else>
			</if>
		</else>
	</if>

	<property name="android.jar" location="${android.platform}/android.jar"/>

	<path id="android">
		<pathelement path="${android.jar}"/>
		<pathelement path="${google.apis}/libs/maps.jar"/>
	</path>

	<path id="kroll.apt.path">
		<pathelement path="${dist.classes.dir}/kroll-apt"/>
		<fileset dir="${kroll.apt.project.dir}/lib" includes="**/*.jar"/>
	</path>

	<path id="kroll.common.path">
		<pathelement path="${dist.dir}/kroll-common.jar"/>
	</path>

	<path id="kroll.v8.path">
		<pathelement path="${dist.classes.dir}/kroll-v8"/>
	</path>

	<path id="titanium.path">
		<pathelement path="${dist.classes.dir}/titanium"/>
		<fileset dir="${titanium.project.dir}/lib" includes="**/*.jar"/>
		<fileset dir="${v7appcompat.project.dir}/libs" includes="**/*.jar"/>
	</path>

	<macrodef name="build.project">
		<attribute name="name"/>
		<attribute name="dir" default="${ti.android.root}/@{name}"/>
		<attribute name="build.dir" default="${dist.classes.dir}/@{name}"/>
		<attribute name="src.dir" default="@{dir}/src/java"/>
		<attribute name="includes" default="**/*.java"/>
		<attribute name="excludes" default=""/>
		<attribute name="debug" default="true"/>
		<attribute name="compiler.args" default=""/>

		<element name="javac.args" optional="true"/>
		<element name="javac.classpath" optional="true"/>
		<element name="copy.to.build" optional="true"/>

		<sequential>
			<mkdir dir="@{build.dir}"/>
			<javac destdir="@{build.dir}"
				includes="@{includes}"
				excludes="@{excludes}"
				target="1.6"
				source="1.6"
				debug="@{debug}"
				includeantruntime="false">

				<compilerarg line="@{compiler.args}"/>
				<src path="@{src.dir}"/>
				<classpath>
					<fileset dir="@{dir}">
						<include name="lib/**/*.jar"/>
					</fileset>
				</classpath>
				<javac.classpath/>
				<javac.args/>
			</javac>
			<copy todir="@{build.dir}">
				<fileset dir="@{src.dir}">
					<include name="**/*"/>
					<exclude name="**/*.java"/>
				</fileset>
				<copy.to.build/>
			</copy>
		</sequential>
	</macrodef>

	<macrodef name="build.project.annotations">
		<attribute name="name"/>
		<attribute name="prefix" default=""/>
		<attribute name="dir" default="${ti.android.root}/@{prefix}@{name}"/>
		<attribute name="build.dir" default="${dist.classes.dir}/@{name}"/>
		<attribute name="src.dir" default="@{dir}/src/java"/>
		<attribute name="apt.src.dir" default="${dist.json.dir}"/>
		<attribute name="kroll.jsonFile" default="@{name}.json"/>
		<attribute name="kroll.jsonPackage" default="org.appcelerator.titanium.bindings"/>
		<attribute name="includes" default="**/*.java"/>
		<attribute name="excludes" default=""/>
		<attribute name="debug" default="true"/>
		<attribute name="clean" default="false"/>
		<attribute name="compiler.args" default=""/>
		
		<element name="extra.args" implicit="true" optional="true"/>
		<sequential>
			<if>
				<istrue value="@{clean}"/>
				<then>
					<clean.project name="@{name}" prefix="@{prefix}" dir="@{dir}" apt.src.dir="@{apt.src.dir}" build.dir="@{build.dir}"/>
				</then>
			</if>
			<mkdir dir="@{apt.src.dir}"/>
			<build.project
				name="@{name}"
				dir="@{dir}"
				build.dir="@{build.dir}"
				src.dir="@{src.dir}"
				includes="@{includes}"
				excludes="@{excludes}"
				debug="@{debug}"
				compiler.args="@{compiler.args}">

				<javac.args>
					<compilerarg line="-s &quot;@{apt.src.dir}&quot; -Akroll.jsonFile=@{kroll.jsonFile} -Akroll.jsonPackage=@{kroll.jsonPackage} -proc:only"/>
					<extra.args/>
				</javac.args>
				<javac.classpath>
					<classpath refid="android"/>
					<classpath refid="kroll.apt.path"/>
				</javac.classpath>
				<copy.to.build>
					<fileset dir="@{apt.src.dir}">
						<include name="**/*"/>
						<exclude name="org/appcelerator/titanium/bindings/*.json"/>
						<exclude name="**/*.java"/>
					</fileset>
					<fileset dir="@{apt.src.dir}">
						<include name="**/@{name}.json"/>
					</fileset>
				</copy.to.build>
			</build.project>
		</sequential>
	</macrodef>

	<!-- 
	We do a two-phase module build:
	- Build all classes, and generate code from the annotation processor
	- Build annotation processor code and don't run any further processing
	-->
	<macrodef name="build.module.project">
		<attribute name="name"/>
		<attribute name="dir" default="${ti.android.root}/modules/@{name}"/>
		<attribute name="build.dir" default="${dist.classes.dir}/@{name}"/>
		<attribute name="src.dir" default="@{dir}/src/java"/>
		<attribute name="apt.src.dir" default="${dist.json.dir}"/>
		<attribute name="kroll.jsonFile" default="@{name}.json"/>
		<attribute name="kroll.jsonPackage" default="org.appcelerator.titanium.bindings"/>
		<attribute name="includes" default="**/*.java"/>
		<attribute name="excludes" default=""/>
		<attribute name="debug" default="true"/>
		<attribute name="compiler.args" default=""/>

		<element name="extra.javac.args" optional="true"/>
		<element name="extra.javac.classpath" optional="true"/>
		<element name="extra.copy.to.build" optional="true"/>

		<sequential>
			<build.project.annotations
				name="@{name}"
				dir="@{dir}"
				build.dir="@{build.dir}"
				src.dir="@{src.dir}"
				apt.src.dir="@{apt.src.dir}"
				kroll.jsonFile="@{kroll.jsonFile}"
				kroll.jsonPackage="@{kroll.jsonPackage}"
				includes="@{includes}"
				excludes="@{excludes}"
				debug="@{debug}"
				compiler.args="@{compiler.args}">

				<extra.javac.args/>
				<extra.javac.classpath/>
				<classpath refid="kroll.apt.path"/>
				<classpath refid="titanium.path"/>
				<classpath refid="kroll.common.path"/>
			</build.project.annotations>
			<build.project
				name="@{name}"
				dir="@{dir}"
				build.dir="@{build.dir}"
				includes="@{includes}"
				excludes="@{excludes}"
				debug="@{debug}"
				compiler.args="@{compiler.args}">

				<javac.args>
					<extra.javac.args/>
					<src path="@{apt.src.dir}"/>
					<src path="@{src.dir}"/>
					<compilerarg line="-proc:none"/>
				</javac.args>
				<javac.classpath>
					<extra.javac.classpath/>
					<classpath refid="android"/>
					<classpath refid="kroll.apt.path"/>
					<classpath refid="titanium.path"/>
					<classpath refid="kroll.common.path"/>
					<classpath>
						<pathelement path="@{build.dir}"/>
					</classpath>
				</javac.classpath>
				<copy.to.build>
					<extra.copy.to.build/>
				</copy.to.build>
			</build.project>
		</sequential>
	</macrodef>

	<!-- build targets are designed to be called with <antcall> so multiple projects can be built in the same file -->

	<target name="build.kroll.apt">
		<property name="build.dir" value="${dist.classes.dir}/kroll-apt"/>

		<build.project
			name="kroll-apt"
			build.dir="${build.dir}"
			excludes="org/appcelerator/kroll/apt/Activator.java">
			<copy.to.build>
				<fileset dir="${kroll.apt.project.dir}" includes="META-INF/**/*"/>
			</copy.to.build>
		</build.project>
	</target>

	<target name="build.kroll.apt.jar" depends="build.kroll.apt">
		<property name="dest.file" value="${dist.dir}/kroll-apt.jar"/>
		<jar destfile="${dest.file}" basedir="${build.dir}" manifest="${kroll.apt.project.dir}/META-INF/MANIFEST.MF"/>
	</target>

	<macrodef name="generate.build.properties">
		<attribute name="dir" default="${dist.classes.dir}/titanium"/>
		<sequential>
			<mkdir dir="@{dir}/org/appcelerator/titanium"/>
			<propertyfile file="@{dir}/org/appcelerator/titanium/build.properties"
				comment="Generated by Titanium">
				<entry key="build.version" value="${build.version}"/>
				<entry key="build.timestamp" type="date" value="now"/>
				<entry key="build.githash" value="${build.githash}"/>
			</propertyfile>
		</sequential>
	</macrodef>

	<macrodef name="generate.bindings">
		<attribute name="dest"/>
		<sequential>
			<apply executable="java" parallel="true" failonerror="true">
				<arg value="-classpath"/>
				<arg value="${toString:kroll.apt.path}"/>
				<arg value="org.appcelerator.kroll.annotations.generator.KrollBindingGenerator"/>
				<arg file="@{dest}"/>
				<!-- isModule -->
				<arg value="false"/>
				<!-- moduleId (Titanium for platform) -->
				<arg value="titanium"/>
				<fileset dir="${dist.json.dir}" includes="**/*.json"/>
			</apply>
		</sequential>
	</macrodef>

	<target name="generate.kroll.v8.bindings" depends="build.kroll.apt">
		<generate.bindings dest="${kroll.v8.project.dir}/generated"/>
	</target>

	<target name="build.kroll.v8.so" depends="generate.kroll.v8.bindings">
		<property name="ndk.build.args" value=""/>
		<property name="kroll.v8.build.x86" value=""/>
		<exec executable="${ndk.build}" dir="${kroll.v8.project.dir}" failonerror="true">
			<env key="ANDROID_NDK" file="${android.ndk}"/>
			<env key="ANDROID_PLATFORM" file="${android.platform}"/>
			<env key="BUILD_X86" value="${kroll.v8.build.x86}"/>
			<arg value="TI_DEBUG=${ti.debug}"/>
			<arg line="${ndk.build.args}"/>
		</exec>
		<copy todir="${dist.dir}">
			<fileset dir="${kroll.v8.project.dir}" includes="libs/**/lib*.so"/>
		</copy>
	</target>

	<target name="build.kroll.common.jar">
		<property name="kroll.common.classes.dir" location="${dist.classes.dir}/kroll-common"/>
		<mkdir dir="${kroll.common.classes.dir}"/>
		<javac srcdir="${kroll.common.project.dir}/src/java"
			destdir="${kroll.common.classes.dir}" debug="true"
			source="1.6" target="1.6"
			includeantruntime="false">
			<classpath refid="android"/>
		</javac>

		<property name="kroll.common.dest" value="${dist.dir}/kroll-common.jar"/>
		<jar destfile="${kroll.common.dest}" basedir="${kroll.common.classes.dir}"/>
	</target>

	<target name="build.kroll.v8.jar" depends="build.kroll.common.jar">
		<property name="kroll.v8.classes.dir" location="${dist.classes.dir}/kroll-v8"/>
		<mkdir dir="${kroll.v8.classes.dir}"/>
		<javac srcdir="${kroll.v8.project.dir}/src/java" destdir="${kroll.v8.classes.dir}" debug="true"
			target="1.6" source="1.6" includeantruntime="false">
			<classpath refid="android"/>
			<classpath>
				<fileset file="${dist.dir}/kroll-common.jar"/>
			</classpath>
		</javac>

		<property name="kroll.v8.dest" value="${dist.dir}/kroll-v8.jar"/>
		<jar destfile="${kroll.v8.dest}" basedir="${kroll.v8.classes.dir}"/>
	</target>

	<target name="build.kroll.runtime.v8" depends="build.kroll.v8.jar,build.kroll.v8.so"/>

	<target name="build.kroll.runtime.all"
		depends="build.kroll.runtime.v8"/>

	<target name="build.titanium" depends="build.kroll.common.jar">
		<property name="build.dir" value="${dist.classes.dir}/titanium"/>

		<build.module.project name="titanium" dir="${ti.android.root}/titanium" build.dir="${build.dir}"/>
	</target>

	<target name="build.titanium.javadoc">
		<path id="published.doclet.path">
			<fileset file="${ti.build.dir}/lib/publishedApiDoclet1.5-0.4.jar"/>
		</path>
		<mkdir dir="${dist.dir}/javadoc"/>
		<property file="${ti.build.dir}/javadoc.properties" prefix="javadoc" prefixValues="true"/>

		<property name="kroll.package" value="org/appcelerator/kroll"/>
		<property name="ti.package" value="org/appcelerator/titanium"/>

		<javadoc
			destdir="${dist.dir}/javadoc"
			version="true"
			use="true"
			windowtitle="${javadoc.windowTitle}">

			<doclet name="de.kruis.padoclet.PublishedApiDoclet">
				<path refid="published.doclet.path"/>
				<param name="-padIncludeTag" value="module.api"/>
				<param name="-padDefaultIsExclude"/>
			</doclet>

			<link href="http://java.sun.com/javase/6/docs/api/"/>
			<link href="http://developer.android.com/reference/" offline="true"
				packagelistLoc="${ti.build.dir}/android-reference/"/>

			<sourcefiles>
				<fileset dir="${titanium.project.dir}/src/java" defaultexcludes="yes">
					<include name="**/*.java"/>
					<!-- These don't work in external properties for some reason -->
					<exclude name="${kroll.package}/KrollConvertable.java"/>
					<exclude name="${kroll.package}/KrollModuleInfo.java"/>
					<exclude name="${kroll.package}/KrollNativeConverter.java"/>
					<exclude name="${kroll.package}/KrollProperty.java"/>
					<exclude name="${kroll.package}/util/KrollReflectionUtils.java"/>
					<exclude name="${ti.package}/ContextSpecific.java"/>
					<exclude name="${ti.package}/TiContext.java"/>
					<exclude name="${ti.package}/TiModalActivity.java"/>
					<exclude name="${ti.package}/TiStylesheet.java"/>
					<exclude name="${ti.package}/TiTranslucentActivity.java"/>
					<exclude name="${ti.package}/analytics/**"/>
					<exclude name="${ti.package}/bridge/**"/>
					<exclude name="${ti.package}/kroll/**"/>
					<exclude name="${ti.package}/proxy/DecorViewProxy.java"/>
					<exclude name="${ti.package}/proxy/RProxy.java"/>
					<exclude name="${ti.package}/util/Log.java"/>
					<exclude name="${ti.package}/util/TiAnimationBuilder.java"/>
					<exclude name="${ti.package}/util/TiAnimationPair.java"/>
					<exclude name="${ti.package}/util/TiBindingHelper.java"/>
					<exclude name="${ti.package}/util/TiConfig.java"/>
					<exclude name="${ti.package}/util/TiIntentWrapper.java"/>
					<exclude name="${ti.package}/util/TiResponseCache.java"/>
					<exclude name="${ti.package}/view/ITiWindowHandler.java"/>
					<exclude name="${ti.package}/view/TiUIDecorView.java"/>
				</fileset>

				<fileset dir="${kroll.apt.project.dir}/src/java" defaultexcludes="yes">
					<include name="${kroll.package}/annotations/*"/>
				</fileset>

				<fileset dir="${kroll.common.project.dir}/src/java" defaultexcludes="yes">
					<include name="**/*.java"/>
					<exclude name="${kroll.package}/KrollEvaluator.java"/>
					<exclude name="${kroll.package}/KrollExternalModule.java"/>
					<exclude name="${kroll.package}/KrollLogging.java"/>
					<exclude name="${kroll.package}/common/TiDeployData.java"/>
					<exclude name="${kroll.package}/common/TiFastDev.java"/>
					<exclude name="${kroll.package}/common/TiJSErrorDialog.java"/>
				</fileset>
			</sourcefiles>

			<classpath refid="android"/>
			<classpath refid="titanium.path"/>
			<classpath refid="kroll.apt.path"/>
			<classpath refid="kroll.common.path"/>
			
			<doctitle>${javadoc.docTitle}</doctitle>
			<bottom>${javadoc.bottom}</bottom>
			<tag name="default" description="${javadoc.defaultValueDescription}"/>
		</javadoc>
	</target>

	<target name="build.titanium.jar" depends="build.titanium">
		<!-- TODO: retrieve git hash / value from titanium_version.py -->
		<property name="build.githash" value="HEAD"/>
		<property name="dest.file" value="${dist.dir}/titanium.jar"/>

		<generate.build.properties/>

		<jar destfile="${dest.file}" basedir="${build.dir}"/>
	</target>
	
	<macrodef name="zip.module.res">
		<attribute name="name"/>
		<sequential>
			<zip destfile="${dist.dir}/titanium-@{name}.res.zip">
				<zipfileset dir="${modules.dir}/@{name}" includes="res/**"/>
			</zip>
		</sequential>
	</macrodef>


	<macrodef name="build.module.jar">
		<attribute name="name"/>

		<sequential>
			<build.module.project name="@{name}">
				<extra.javac.classpath>
					<classpath refid="dependencies"/>
				</extra.javac.classpath>
			</build.module.project>
			<jar destfile="${dist.dir}/titanium-@{name}.jar" basedir="${dist.classes.dir}/@{name}"/>
		</sequential>
	</macrodef>

	<target name="update.apis" depends="build.kroll.apt.jar">
		<apply executable="java" parallel="true" failonerror="true">
			<arg value="-classpath"/>
			<arg value="${toString:kroll.apt.path}"/>
			<arg value="org.appcelerator.kroll.annotations.generator.KrollAPIUpdater"/>
			<arg value="${dist.dir}"/>

			<fileset dir="${dist.json.dir}" includes="**/*.json"/>
		</apply>

		<jar update="true" destfile="${dist.dir}/titanium.jar">
			<fileset dir="${dist.json.dir}">
				<include name="org/appcelerator/titanium/bindings/titanium.json"/>
			</fileset>
		</jar>

		<ti.getModuleBuildOrder json="${dependency.json}" property="modules"/>

		<for list="${modules}" param="module" delimiter=" ">
		<sequential>
			<jar update="true" destfile="${dist.dir}/titanium-@{module}.jar">
				<fileset dir="${dist.json.dir}">
					<include name="org/appcelerator/titanium/bindings/@{module}.json"/>
				</fileset>
			</jar>
		</sequential>
		</for>
	</target>

	<target name="build.all">
		<build.ti.ant.tasks/>
		<define.ti.ant.tasks/>
		<antcall target="update.libv8"/>
		<antcall target="build.kroll.apt.jar"/>
		<antcall target="build.titanium.jar"/>
		<antcall target="build.all.modules"/>
		<antcall target="update.apis"/>

		<!-- the runtime libraries need to be last so we can build all the generated native bindings -->
		<antcall target="build.kroll.runtime.${kroll.runtime}"/>
	</target>
	
	<macrodef name="clean.project">
		<attribute name="name"/>
		<attribute name="prefix" default=""/>
		<attribute name="dir" default="${ti.android.root}/@{prefix}@{name}"/>
		<attribute name="build.dir" default="${dist.classes.dir}/@{prefix}@{name}"/>
		<sequential>
			<delete includeemptydirs="true" failonerror="false">
				<fileset dir="@{build.dir}" includes="**/*" defaultexcludes="false"/>
				<fileset file="${dist.dir}/@{name}.jar"/>
			</delete>
		</sequential>
	</macrodef>

	<target name="clean.all">
		<delete includeemptydirs="true" failonerror="false">
			<fileset dir="${dist.dir}" includes="**/*" excludes="libv8/**/*" defaultexcludes="false"/>
		</delete>

		<!-- V8 clean target requires we have libv8 for now -->
		<build.ti.ant.tasks/>
		<define.ti.ant.tasks/>
		<antcall target="update.libv8"/>

		<exec executable="${ndk.build}" dir="${kroll.v8.project.dir}" failonerror="true">
			<env key="ANDROID_NDK" file="${android.ndk}"/>
			<env key="ANDROID_PLATFORM" file="${android.platform}"/>
			<env key="NUM_CPUS" value="1"/>
			<arg value="clean"/>
		</exec>
	</target>

	<macrodef name="define.ti.ant.tasks">
		<sequential>
			<taskdef classname="org.appcelerator.titanium.ant.GetModuleBuildOrderTask" name="ti.getModuleBuildOrder" classpathref="ti.build.path"/>
			<taskdef classname="org.appcelerator.titanium.ant.ModulePathTask" name="ti.modulePath" classpathref="ti.build.path"/>
			<taskdef classname="org.appcelerator.titanium.ant.StringTask" name="ti.string" classpathref="ti.build.path"/>
			<taskdef classname="org.appcelerator.titanium.ant.UpdateModulesJSONTask" name="ti.updateModulesJSON" classpathref="ti.build.path"/>
			<taskdef classname="org.appcelerator.titanium.ant.JSONMap" name="ti.jsonMap" classpathref="ti.build.path"/>
		</sequential>
	</macrodef>

	<macrodef name="build.ti.ant.tasks">
		<sequential>
			<mkdir dir="${dist.classes.dir}/ant-tasks"/>
			<javac srcdir="${ti.build.dir}/src"
				destdir="${dist.classes.dir}/ant-tasks"
				includes="**/*.java"
				classpathref="ti.build.lib.path"
				includeantruntime="false"
				debug="true"
				target="1.6"
				source="1.6"/>
			<jar basedir="${dist.classes.dir}/ant-tasks" destfile="${dist.dir}/ant-tasks.jar"/>
		</sequential>
	</macrodef>

	<macrodef name="build.module">
		<attribute name="module"/>
		<sequential>
			<ti.modulePath json="${dependency.json}" module="@{module}" modulesdir="${dist.classes.dir}" pathid="dependencies"/>
			<build.module.jar name="@{module}"/>
			<available type="dir" file="${modules.dir}/@{module}/res" property="@{module}.res.avail"/>
			<if>
				<istrue value="${@{module}.res.avail}"/>
				<then>
					<fileset dir="${modules.dir}/@{module}/res" id="fileset"/>
  					<pathconvert refid="fileset" property="@{module}.res.empty" setonempty="false"/>
  					<if>
  					    <isset property="@{module}.res.empty"/>
  					    <then>
							<zip.module.res name="@{module}"/>
  					    </then>
  					</if>
				</then>
			</if>
		</sequential>
	</macrodef>

	<target name="build.all.modules">
		<ti.getModuleBuildOrder json="${dependency.json}" property="modules"/>

		<for list="${modules}" param="module" delimiter=" ">
		<sequential>
			<build.module module="@{module}"/>
		</sequential>
		</for>
	</target>

	<target name="clean.dist" if="distdir.available">
		<delete includeemptydirs="true">
			<fileset dir="${dist.dir}" includes="**/*" defaultexcludes="false"/>
		</delete>
	</target>

	<target name="update.libv8">
		<property file="${ti.build.dir}/libv8.properties"/>
		<property name="dist.libv8.dir" location="${dist.dir}/libv8/${libv8.version}/${libv8.mode}"/>
		<property name="libv8.archive" value="libv8-${libv8.version}-${libv8.mode}.tar.bz2"/>
		<mkdir dir="${dist.libv8.dir}"/>

		<ti.jsonMap file="${dist.libv8.dir}/libv8.json" prefix="libv8.current"/>

		<condition property="libv8.latest">
			<equals arg1="${libv8.current.version}" arg2="${libv8.version}"/>
		</condition>
		<antcall target="download.libv8"/>
	</target>

	<target name="download.libv8" unless="libv8.latest">
		<get src="http://timobile.appcelerator.com.s3.amazonaws.com/libv8/${libv8.archive}"
			dest="${dist.libv8.dir}" verbose="true" usetimestamp="true"/>
		<untar compression="bzip2" src="${dist.libv8.dir}/${libv8.archive}" dest="${dist.libv8.dir}"/>
	</target>

	<target name="dont.run.me">
		<echo>This script is intended for reuse by other ant scripts, and is not directly executable</echo>
	</target>
</project>
<commit_msg>[TIMOB-16023] Update titanium path for new structure<commit_after><!-- 
Appcelerator Titanium Mobile

Copyright (c) 2010-2013 by Appcelerator, Inc. All Rights Reserved.
Licensed under the terms of the Apache Public License
Please see the LICENSE included with this distribution for details.

Common ant tasks and macros for building Android-based Titanium modules and projects
-->
<project name="titanium-common" default="dont.run.me">
	<property file="build.properties"/>
	<property name="ti.android.root" location="${basedir}/.." />
	<property name="ti.build.dir" value="${ti.android.root}/build"/>
	<property file="${ti.build.dir}/build.properties"/>

	<taskdef resource="net/sf/antcontrib/antlib.xml">
		<classpath>
			<pathelement location="${ti.build.dir}/lib/ant-contrib-1.0b3.jar" />
		</classpath>
	</taskdef>

	<path id="serialver.path">
		<fileset file="${ti.build.dir}/lib/serialver.jar"/>
	</path>

	<taskdef name="serialver" classname="net.sourceforge.serialver.SerialVer">
		<classpath refid="serialver.path"/>
	</taskdef>

	<path id="ti.build.lib.path">
		<fileset dir="${ti.build.dir}/lib" includes="**/*.jar"/>
	</path>
	
	<property name="v7appcompat.project.dir" location="${ti.android.root}/modules/appcompat"/>
	<property name="titanium.project.dir" location="${ti.android.root}/titanium"/>
	<property name="kroll.apt.project.dir" location="${ti.android.root}/kroll-apt"/>
	<property name="kroll.common.project.dir" location="${ti.android.root}/runtime/common"/>
	<property name="kroll.v8.project.dir" location="${ti.android.root}/runtime/v8"/>
	<property name="kroll.runtime" value="all"/>

	<condition property="ndk.build" value="${kroll.v8.project.dir}/ndk-build.cmd" else="${kroll.v8.project.dir}/ndk-build.sh">
		<os family="windows"/>
	</condition>

	<property name="modules.dir" location="${ti.android.root}/modules"/>
	<property name="ui.module.dir" location="${modules.dir}/ui"/>
	
	<property name="dist.dir" location="${ti.android.root}/../dist/android"/>
	<available property="dist.dir.available" file="${dist.dir}"/>

	<property name="dist.json.dir" location="${dist.dir}/json"/>
	<property name="dist.classes.dir" location="${dist.dir}/classes"/>
	<property name="gen.src.dir" location="${dist.dir}/generated"/>
	<property name="build.version" value="1.0.0"/>
	<property name="dependency.json" location="${ti.android.root}/dependency.json"/>
	<property environment="env"/>

	<path id="ti.build.path">
		<path refid="ti.build.lib.path"/>
		<path path="${dist.classes.dir}/ant-tasks"/>
	</path>

	<property name="android.ndk" value="${env.ANDROID_NDK}"/>

	<if>
		<isset property="env.TI_DEBUG"/>
		<then>
			<property name="ti.debug" value="${env.TI_DEBUG}"/>
		</then>
		<else>
			<property name="ti.debug" value="0"/>
		</else>
	</if>

	<if>
		<isset property="env.ANDROID_PLATFORM"/>
		<then>
			<property name="android.sdk" location="${env.ANDROID_PLATFORM}/../.."/>
			<property name="android.platform" location="${env.ANDROID_PLATFORM}"/>
			<property name="google.apis" location="${env.GOOGLE_APIS}"/>
		</then>
		<else>
			<if>
				<isset property="env.ANDROID_SDK"/>
				<then>
					<property name="android.sdk" location="${env.ANDROID_SDK}"/>
				</then>
				<else>
					<if>
						<not><isset property="android.sdk"/></not>
						<then>
							<echo level="warning">Android SDK not found, using default /opt/android-sdk</echo>
						</then>
					</if>
					<property name="android.sdk" location="/opt/android-sdk"/>
				</else>
			</if>
			<if>
				<isset property="env.ANDROID_PLATFORM"/>
				<then>
					<property name="android.platform" location="${env.ANDROID_PLATFORM}"/>
				</then>
				<else>
					<property name="android.platform" location="${android.sdk}/platforms/android-14"/>
				</else>
			</if>
			<if>
				<isset property="env.GOOGLE_APIS"/>
				<then>
					<property name="google.apis" location="${env.GOOGLE_APIS}"/>
				</then>
				<else>
					<if>
						<not><isset property="google.apis"/></not>
						<then>
							<property name="google.apis" location="${android.sdk}/add-ons/addon-google_apis-google_inc_-8"/>
						</then>
					</if>
				</else>
			</if>
		</else>
	</if>

	<property name="android.jar" location="${android.platform}/android.jar"/>

	<path id="android">
		<pathelement path="${android.jar}"/>
		<pathelement path="${google.apis}/libs/maps.jar"/>
	</path>

	<path id="kroll.apt.path">
		<pathelement path="${dist.classes.dir}/kroll-apt"/>
		<fileset dir="${kroll.apt.project.dir}/lib" includes="**/*.jar"/>
	</path>

	<path id="kroll.common.path">
		<pathelement path="${dist.dir}/kroll-common.jar"/>
	</path>

	<path id="kroll.v8.path">
		<pathelement path="${dist.classes.dir}/kroll-v8"/>
	</path>

	<path id="titanium.path">
		<pathelement path="${dist.classes.dir}/titanium"/>
		<fileset dir="${titanium.project.dir}/lib" includes="**/*.jar"/>
		<fileset dir="${v7appcompat.project.dir}/lib" includes="**/*.jar"/>
	</path>

	<macrodef name="build.project">
		<attribute name="name"/>
		<attribute name="dir" default="${ti.android.root}/@{name}"/>
		<attribute name="build.dir" default="${dist.classes.dir}/@{name}"/>
		<attribute name="src.dir" default="@{dir}/src/java"/>
		<attribute name="includes" default="**/*.java"/>
		<attribute name="excludes" default=""/>
		<attribute name="debug" default="true"/>
		<attribute name="compiler.args" default=""/>

		<element name="javac.args" optional="true"/>
		<element name="javac.classpath" optional="true"/>
		<element name="copy.to.build" optional="true"/>

		<sequential>
			<mkdir dir="@{build.dir}"/>
			<javac destdir="@{build.dir}"
				includes="@{includes}"
				excludes="@{excludes}"
				target="1.6"
				source="1.6"
				debug="@{debug}"
				includeantruntime="false">

				<compilerarg line="@{compiler.args}"/>
				<src path="@{src.dir}"/>
				<classpath>
					<fileset dir="@{dir}">
						<include name="lib/**/*.jar"/>
					</fileset>
				</classpath>
				<javac.classpath/>
				<javac.args/>
			</javac>
			<copy todir="@{build.dir}">
				<fileset dir="@{src.dir}">
					<include name="**/*"/>
					<exclude name="**/*.java"/>
				</fileset>
				<copy.to.build/>
			</copy>
		</sequential>
	</macrodef>

	<macrodef name="build.project.annotations">
		<attribute name="name"/>
		<attribute name="prefix" default=""/>
		<attribute name="dir" default="${ti.android.root}/@{prefix}@{name}"/>
		<attribute name="build.dir" default="${dist.classes.dir}/@{name}"/>
		<attribute name="src.dir" default="@{dir}/src/java"/>
		<attribute name="apt.src.dir" default="${dist.json.dir}"/>
		<attribute name="kroll.jsonFile" default="@{name}.json"/>
		<attribute name="kroll.jsonPackage" default="org.appcelerator.titanium.bindings"/>
		<attribute name="includes" default="**/*.java"/>
		<attribute name="excludes" default=""/>
		<attribute name="debug" default="true"/>
		<attribute name="clean" default="false"/>
		<attribute name="compiler.args" default=""/>
		
		<element name="extra.args" implicit="true" optional="true"/>
		<sequential>
			<if>
				<istrue value="@{clean}"/>
				<then>
					<clean.project name="@{name}" prefix="@{prefix}" dir="@{dir}" apt.src.dir="@{apt.src.dir}" build.dir="@{build.dir}"/>
				</then>
			</if>
			<mkdir dir="@{apt.src.dir}"/>
			<build.project
				name="@{name}"
				dir="@{dir}"
				build.dir="@{build.dir}"
				src.dir="@{src.dir}"
				includes="@{includes}"
				excludes="@{excludes}"
				debug="@{debug}"
				compiler.args="@{compiler.args}">

				<javac.args>
					<compilerarg line="-s &quot;@{apt.src.dir}&quot; -Akroll.jsonFile=@{kroll.jsonFile} -Akroll.jsonPackage=@{kroll.jsonPackage} -proc:only"/>
					<extra.args/>
				</javac.args>
				<javac.classpath>
					<classpath refid="android"/>
					<classpath refid="kroll.apt.path"/>
				</javac.classpath>
				<copy.to.build>
					<fileset dir="@{apt.src.dir}">
						<include name="**/*"/>
						<exclude name="org/appcelerator/titanium/bindings/*.json"/>
						<exclude name="**/*.java"/>
					</fileset>
					<fileset dir="@{apt.src.dir}">
						<include name="**/@{name}.json"/>
					</fileset>
				</copy.to.build>
			</build.project>
		</sequential>
	</macrodef>

	<!-- 
	We do a two-phase module build:
	- Build all classes, and generate code from the annotation processor
	- Build annotation processor code and don't run any further processing
	-->
	<macrodef name="build.module.project">
		<attribute name="name"/>
		<attribute name="dir" default="${ti.android.root}/modules/@{name}"/>
		<attribute name="build.dir" default="${dist.classes.dir}/@{name}"/>
		<attribute name="src.dir" default="@{dir}/src/java"/>
		<attribute name="apt.src.dir" default="${dist.json.dir}"/>
		<attribute name="kroll.jsonFile" default="@{name}.json"/>
		<attribute name="kroll.jsonPackage" default="org.appcelerator.titanium.bindings"/>
		<attribute name="includes" default="**/*.java"/>
		<attribute name="excludes" default=""/>
		<attribute name="debug" default="true"/>
		<attribute name="compiler.args" default=""/>

		<element name="extra.javac.args" optional="true"/>
		<element name="extra.javac.classpath" optional="true"/>
		<element name="extra.copy.to.build" optional="true"/>

		<sequential>
			<build.project.annotations
				name="@{name}"
				dir="@{dir}"
				build.dir="@{build.dir}"
				src.dir="@{src.dir}"
				apt.src.dir="@{apt.src.dir}"
				kroll.jsonFile="@{kroll.jsonFile}"
				kroll.jsonPackage="@{kroll.jsonPackage}"
				includes="@{includes}"
				excludes="@{excludes}"
				debug="@{debug}"
				compiler.args="@{compiler.args}">

				<extra.javac.args/>
				<extra.javac.classpath/>
				<classpath refid="kroll.apt.path"/>
				<classpath refid="titanium.path"/>
				<classpath refid="kroll.common.path"/>
			</build.project.annotations>
			<build.project
				name="@{name}"
				dir="@{dir}"
				build.dir="@{build.dir}"
				includes="@{includes}"
				excludes="@{excludes}"
				debug="@{debug}"
				compiler.args="@{compiler.args}">

				<javac.args>
					<extra.javac.args/>
					<src path="@{apt.src.dir}"/>
					<src path="@{src.dir}"/>
					<compilerarg line="-proc:none"/>
				</javac.args>
				<javac.classpath>
					<extra.javac.classpath/>
					<classpath refid="android"/>
					<classpath refid="kroll.apt.path"/>
					<classpath refid="titanium.path"/>
					<classpath refid="kroll.common.path"/>
					<classpath>
						<pathelement path="@{build.dir}"/>
					</classpath>
				</javac.classpath>
				<copy.to.build>
					<extra.copy.to.build/>
				</copy.to.build>
			</build.project>
		</sequential>
	</macrodef>

	<!-- build targets are designed to be called with <antcall> so multiple projects can be built in the same file -->

	<target name="build.kroll.apt">
		<property name="build.dir" value="${dist.classes.dir}/kroll-apt"/>

		<build.project
			name="kroll-apt"
			build.dir="${build.dir}"
			excludes="org/appcelerator/kroll/apt/Activator.java">
			<copy.to.build>
				<fileset dir="${kroll.apt.project.dir}" includes="META-INF/**/*"/>
			</copy.to.build>
		</build.project>
	</target>

	<target name="build.kroll.apt.jar" depends="build.kroll.apt">
		<property name="dest.file" value="${dist.dir}/kroll-apt.jar"/>
		<jar destfile="${dest.file}" basedir="${build.dir}" manifest="${kroll.apt.project.dir}/META-INF/MANIFEST.MF"/>
	</target>

	<macrodef name="generate.build.properties">
		<attribute name="dir" default="${dist.classes.dir}/titanium"/>
		<sequential>
			<mkdir dir="@{dir}/org/appcelerator/titanium"/>
			<propertyfile file="@{dir}/org/appcelerator/titanium/build.properties"
				comment="Generated by Titanium">
				<entry key="build.version" value="${build.version}"/>
				<entry key="build.timestamp" type="date" value="now"/>
				<entry key="build.githash" value="${build.githash}"/>
			</propertyfile>
		</sequential>
	</macrodef>

	<macrodef name="generate.bindings">
		<attribute name="dest"/>
		<sequential>
			<apply executable="java" parallel="true" failonerror="true">
				<arg value="-classpath"/>
				<arg value="${toString:kroll.apt.path}"/>
				<arg value="org.appcelerator.kroll.annotations.generator.KrollBindingGenerator"/>
				<arg file="@{dest}"/>
				<!-- isModule -->
				<arg value="false"/>
				<!-- moduleId (Titanium for platform) -->
				<arg value="titanium"/>
				<fileset dir="${dist.json.dir}" includes="**/*.json"/>
			</apply>
		</sequential>
	</macrodef>

	<target name="generate.kroll.v8.bindings" depends="build.kroll.apt">
		<generate.bindings dest="${kroll.v8.project.dir}/generated"/>
	</target>

	<target name="build.kroll.v8.so" depends="generate.kroll.v8.bindings">
		<property name="ndk.build.args" value=""/>
		<property name="kroll.v8.build.x86" value=""/>
		<exec executable="${ndk.build}" dir="${kroll.v8.project.dir}" failonerror="true">
			<env key="ANDROID_NDK" file="${android.ndk}"/>
			<env key="ANDROID_PLATFORM" file="${android.platform}"/>
			<env key="BUILD_X86" value="${kroll.v8.build.x86}"/>
			<arg value="TI_DEBUG=${ti.debug}"/>
			<arg line="${ndk.build.args}"/>
		</exec>
		<copy todir="${dist.dir}">
			<fileset dir="${kroll.v8.project.dir}" includes="libs/**/lib*.so"/>
		</copy>
	</target>

	<target name="build.kroll.common.jar">
		<property name="kroll.common.classes.dir" location="${dist.classes.dir}/kroll-common"/>
		<mkdir dir="${kroll.common.classes.dir}"/>
		<javac srcdir="${kroll.common.project.dir}/src/java"
			destdir="${kroll.common.classes.dir}" debug="true"
			source="1.6" target="1.6"
			includeantruntime="false">
			<classpath refid="android"/>
		</javac>

		<property name="kroll.common.dest" value="${dist.dir}/kroll-common.jar"/>
		<jar destfile="${kroll.common.dest}" basedir="${kroll.common.classes.dir}"/>
	</target>

	<target name="build.kroll.v8.jar" depends="build.kroll.common.jar">
		<property name="kroll.v8.classes.dir" location="${dist.classes.dir}/kroll-v8"/>
		<mkdir dir="${kroll.v8.classes.dir}"/>
		<javac srcdir="${kroll.v8.project.dir}/src/java" destdir="${kroll.v8.classes.dir}" debug="true"
			target="1.6" source="1.6" includeantruntime="false">
			<classpath refid="android"/>
			<classpath>
				<fileset file="${dist.dir}/kroll-common.jar"/>
			</classpath>
		</javac>

		<property name="kroll.v8.dest" value="${dist.dir}/kroll-v8.jar"/>
		<jar destfile="${kroll.v8.dest}" basedir="${kroll.v8.classes.dir}"/>
	</target>

	<target name="build.kroll.runtime.v8" depends="build.kroll.v8.jar,build.kroll.v8.so"/>

	<target name="build.kroll.runtime.all"
		depends="build.kroll.runtime.v8"/>

	<target name="build.titanium" depends="build.kroll.common.jar">
		<property name="build.dir" value="${dist.classes.dir}/titanium"/>

		<build.module.project name="titanium" dir="${ti.android.root}/titanium" build.dir="${build.dir}"/>
	</target>

	<target name="build.titanium.javadoc">
		<path id="published.doclet.path">
			<fileset file="${ti.build.dir}/lib/publishedApiDoclet1.5-0.4.jar"/>
		</path>
		<mkdir dir="${dist.dir}/javadoc"/>
		<property file="${ti.build.dir}/javadoc.properties" prefix="javadoc" prefixValues="true"/>

		<property name="kroll.package" value="org/appcelerator/kroll"/>
		<property name="ti.package" value="org/appcelerator/titanium"/>

		<javadoc
			destdir="${dist.dir}/javadoc"
			version="true"
			use="true"
			windowtitle="${javadoc.windowTitle}">

			<doclet name="de.kruis.padoclet.PublishedApiDoclet">
				<path refid="published.doclet.path"/>
				<param name="-padIncludeTag" value="module.api"/>
				<param name="-padDefaultIsExclude"/>
			</doclet>

			<link href="http://java.sun.com/javase/6/docs/api/"/>
			<link href="http://developer.android.com/reference/" offline="true"
				packagelistLoc="${ti.build.dir}/android-reference/"/>

			<sourcefiles>
				<fileset dir="${titanium.project.dir}/src/java" defaultexcludes="yes">
					<include name="**/*.java"/>
					<!-- These don't work in external properties for some reason -->
					<exclude name="${kroll.package}/KrollConvertable.java"/>
					<exclude name="${kroll.package}/KrollModuleInfo.java"/>
					<exclude name="${kroll.package}/KrollNativeConverter.java"/>
					<exclude name="${kroll.package}/KrollProperty.java"/>
					<exclude name="${kroll.package}/util/KrollReflectionUtils.java"/>
					<exclude name="${ti.package}/ContextSpecific.java"/>
					<exclude name="${ti.package}/TiContext.java"/>
					<exclude name="${ti.package}/TiModalActivity.java"/>
					<exclude name="${ti.package}/TiStylesheet.java"/>
					<exclude name="${ti.package}/TiTranslucentActivity.java"/>
					<exclude name="${ti.package}/analytics/**"/>
					<exclude name="${ti.package}/bridge/**"/>
					<exclude name="${ti.package}/kroll/**"/>
					<exclude name="${ti.package}/proxy/DecorViewProxy.java"/>
					<exclude name="${ti.package}/proxy/RProxy.java"/>
					<exclude name="${ti.package}/util/Log.java"/>
					<exclude name="${ti.package}/util/TiAnimationBuilder.java"/>
					<exclude name="${ti.package}/util/TiAnimationPair.java"/>
					<exclude name="${ti.package}/util/TiBindingHelper.java"/>
					<exclude name="${ti.package}/util/TiConfig.java"/>
					<exclude name="${ti.package}/util/TiIntentWrapper.java"/>
					<exclude name="${ti.package}/util/TiResponseCache.java"/>
					<exclude name="${ti.package}/view/ITiWindowHandler.java"/>
					<exclude name="${ti.package}/view/TiUIDecorView.java"/>
				</fileset>

				<fileset dir="${kroll.apt.project.dir}/src/java" defaultexcludes="yes">
					<include name="${kroll.package}/annotations/*"/>
				</fileset>

				<fileset dir="${kroll.common.project.dir}/src/java" defaultexcludes="yes">
					<include name="**/*.java"/>
					<exclude name="${kroll.package}/KrollEvaluator.java"/>
					<exclude name="${kroll.package}/KrollExternalModule.java"/>
					<exclude name="${kroll.package}/KrollLogging.java"/>
					<exclude name="${kroll.package}/common/TiDeployData.java"/>
					<exclude name="${kroll.package}/common/TiFastDev.java"/>
					<exclude name="${kroll.package}/common/TiJSErrorDialog.java"/>
				</fileset>
			</sourcefiles>

			<classpath refid="android"/>
			<classpath refid="titanium.path"/>
			<classpath refid="kroll.apt.path"/>
			<classpath refid="kroll.common.path"/>
			
			<doctitle>${javadoc.docTitle}</doctitle>
			<bottom>${javadoc.bottom}</bottom>
			<tag name="default" description="${javadoc.defaultValueDescription}"/>
		</javadoc>
	</target>

	<target name="build.titanium.jar" depends="build.titanium">
		<!-- TODO: retrieve git hash / value from titanium_version.py -->
		<property name="build.githash" value="HEAD"/>
		<property name="dest.file" value="${dist.dir}/titanium.jar"/>

		<generate.build.properties/>

		<jar destfile="${dest.file}" basedir="${build.dir}"/>
	</target>
	
	<macrodef name="zip.module.res">
		<attribute name="name"/>
		<sequential>
			<zip destfile="${dist.dir}/titanium-@{name}.res.zip">
				<zipfileset dir="${modules.dir}/@{name}" includes="res/**"/>
			</zip>
		</sequential>
	</macrodef>


	<macrodef name="build.module.jar">
		<attribute name="name"/>

		<sequential>
			<build.module.project name="@{name}">
				<extra.javac.classpath>
					<classpath refid="dependencies"/>
				</extra.javac.classpath>
			</build.module.project>
			<jar destfile="${dist.dir}/titanium-@{name}.jar" basedir="${dist.classes.dir}/@{name}"/>
		</sequential>
	</macrodef>

	<target name="update.apis" depends="build.kroll.apt.jar">
		<apply executable="java" parallel="true" failonerror="true">
			<arg value="-classpath"/>
			<arg value="${toString:kroll.apt.path}"/>
			<arg value="org.appcelerator.kroll.annotations.generator.KrollAPIUpdater"/>
			<arg value="${dist.dir}"/>

			<fileset dir="${dist.json.dir}" includes="**/*.json"/>
		</apply>

		<jar update="true" destfile="${dist.dir}/titanium.jar">
			<fileset dir="${dist.json.dir}">
				<include name="org/appcelerator/titanium/bindings/titanium.json"/>
			</fileset>
		</jar>

		<ti.getModuleBuildOrder json="${dependency.json}" property="modules"/>

		<for list="${modules}" param="module" delimiter=" ">
		<sequential>
			<jar update="true" destfile="${dist.dir}/titanium-@{module}.jar">
				<fileset dir="${dist.json.dir}">
					<include name="org/appcelerator/titanium/bindings/@{module}.json"/>
				</fileset>
			</jar>
		</sequential>
		</for>
	</target>

	<target name="build.all">
		<build.ti.ant.tasks/>
		<define.ti.ant.tasks/>
		<antcall target="update.libv8"/>
		<antcall target="build.kroll.apt.jar"/>
		<antcall target="build.titanium.jar"/>
		<antcall target="build.all.modules"/>
		<antcall target="update.apis"/>

		<!-- the runtime libraries need to be last so we can build all the generated native bindings -->
		<antcall target="build.kroll.runtime.${kroll.runtime}"/>
	</target>
	
	<macrodef name="clean.project">
		<attribute name="name"/>
		<attribute name="prefix" default=""/>
		<attribute name="dir" default="${ti.android.root}/@{prefix}@{name}"/>
		<attribute name="build.dir" default="${dist.classes.dir}/@{prefix}@{name}"/>
		<sequential>
			<delete includeemptydirs="true" failonerror="false">
				<fileset dir="@{build.dir}" includes="**/*" defaultexcludes="false"/>
				<fileset file="${dist.dir}/@{name}.jar"/>
			</delete>
		</sequential>
	</macrodef>

	<target name="clean.all">
		<delete includeemptydirs="true" failonerror="false">
			<fileset dir="${dist.dir}" includes="**/*" excludes="libv8/**/*" defaultexcludes="false"/>
		</delete>

		<!-- V8 clean target requires we have libv8 for now -->
		<build.ti.ant.tasks/>
		<define.ti.ant.tasks/>
		<antcall target="update.libv8"/>

		<exec executable="${ndk.build}" dir="${kroll.v8.project.dir}" failonerror="true">
			<env key="ANDROID_NDK" file="${android.ndk}"/>
			<env key="ANDROID_PLATFORM" file="${android.platform}"/>
			<env key="NUM_CPUS" value="1"/>
			<arg value="clean"/>
		</exec>
	</target>

	<macrodef name="define.ti.ant.tasks">
		<sequential>
			<taskdef classname="org.appcelerator.titanium.ant.GetModuleBuildOrderTask" name="ti.getModuleBuildOrder" classpathref="ti.build.path"/>
			<taskdef classname="org.appcelerator.titanium.ant.ModulePathTask" name="ti.modulePath" classpathref="ti.build.path"/>
			<taskdef classname="org.appcelerator.titanium.ant.StringTask" name="ti.string" classpathref="ti.build.path"/>
			<taskdef classname="org.appcelerator.titanium.ant.UpdateModulesJSONTask" name="ti.updateModulesJSON" classpathref="ti.build.path"/>
			<taskdef classname="org.appcelerator.titanium.ant.JSONMap" name="ti.jsonMap" classpathref="ti.build.path"/>
		</sequential>
	</macrodef>

	<macrodef name="build.ti.ant.tasks">
		<sequential>
			<mkdir dir="${dist.classes.dir}/ant-tasks"/>
			<javac srcdir="${ti.build.dir}/src"
				destdir="${dist.classes.dir}/ant-tasks"
				includes="**/*.java"
				classpathref="ti.build.lib.path"
				includeantruntime="false"
				debug="true"
				target="1.6"
				source="1.6"/>
			<jar basedir="${dist.classes.dir}/ant-tasks" destfile="${dist.dir}/ant-tasks.jar"/>
		</sequential>
	</macrodef>

	<macrodef name="build.module">
		<attribute name="module"/>
		<sequential>
			<ti.modulePath json="${dependency.json}" module="@{module}" modulesdir="${dist.classes.dir}" pathid="dependencies"/>
			<build.module.jar name="@{module}"/>
			<available type="dir" file="${modules.dir}/@{module}/res" property="@{module}.res.avail"/>
			<if>
				<istrue value="${@{module}.res.avail}"/>
				<then>
					<fileset dir="${modules.dir}/@{module}/res" id="fileset"/>
  					<pathconvert refid="fileset" property="@{module}.res.empty" setonempty="false"/>
  					<if>
  					    <isset property="@{module}.res.empty"/>
  					    <then>
							<zip.module.res name="@{module}"/>
  					    </then>
  					</if>
				</then>
			</if>
		</sequential>
	</macrodef>

	<target name="build.all.modules">
		<ti.getModuleBuildOrder json="${dependency.json}" property="modules"/>

		<for list="${modules}" param="module" delimiter=" ">
		<sequential>
			<build.module module="@{module}"/>
		</sequential>
		</for>
	</target>

	<target name="clean.dist" if="distdir.available">
		<delete includeemptydirs="true">
			<fileset dir="${dist.dir}" includes="**/*" defaultexcludes="false"/>
		</delete>
	</target>

	<target name="update.libv8">
		<property file="${ti.build.dir}/libv8.properties"/>
		<property name="dist.libv8.dir" location="${dist.dir}/libv8/${libv8.version}/${libv8.mode}"/>
		<property name="libv8.archive" value="libv8-${libv8.version}-${libv8.mode}.tar.bz2"/>
		<mkdir dir="${dist.libv8.dir}"/>

		<ti.jsonMap file="${dist.libv8.dir}/libv8.json" prefix="libv8.current"/>

		<condition property="libv8.latest">
			<equals arg1="${libv8.current.version}" arg2="${libv8.version}"/>
		</condition>
		<antcall target="download.libv8"/>
	</target>

	<target name="download.libv8" unless="libv8.latest">
		<get src="http://timobile.appcelerator.com.s3.amazonaws.com/libv8/${libv8.archive}"
			dest="${dist.libv8.dir}" verbose="true" usetimestamp="true"/>
		<untar compression="bzip2" src="${dist.libv8.dir}/${libv8.archive}" dest="${dist.libv8.dir}"/>
	</target>

	<target name="dont.run.me">
		<echo>This script is intended for reuse by other ant scripts, and is not directly executable</echo>
	</target>
</project>

{'fraction_non_alphanumeric': 0.21901157435219673, 'fraction_numerical': 0.004625735912531539, 'mean_word_length': 4.196566077003122, 'pattern_counts': {'":': 0, '<': 1131, '<?xml version=': 0, '>': 1131, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6239828', 'n_tokens_mistral': 19874, 'n_tokens_neox': 17079, 'n_words': 2610}