<?xml version="1.0" encoding="UTF-8"?>
<project name="custom_rules">
	<target name="-pre-build" >
		<!-- Replace OC server URL if set in environment -->
		<if>
			<condition>
				<isset property="env.OCTEST_SERVER_BASE_URL" />
			</condition>
			<then>
				<replaceregexp
					file="res/values/setup.xml"
					match='("server_base_url"&gt;)\s*(&lt;)'
					replace="\1${env.OCTEST_SERVER_BASE_URL}\2"
					byline="true" />
			</then>
		</if>
		
		<!-- Replace OC server URL 2 if set in environment -->
		<if>
			<condition>
				<isset property="env.OCTEST_SERVER_BASE_URL_2" />
			</condition>
			<then>
				<replaceregexp
					file="res/values/setup.xml"
					match='("server_base_url_2"&gt;)\s*(&lt;)'
					replace="\1${env.OCTEST_SERVER_BASE_URL_2}\2"
					byline="true" />
			</then>
		</if>
		
		<!-- Replace test username if set in environment -->
		<if>
			<condition>
				<isset property="env.OCTEST_USERNAME" />
			</condition>
			<then>
				<echo>Setting username ${env.OCTEST_USERNAME}</echo>
				<replaceregexp
					file="res/values/setup.xml"
					match='("username"&gt;)\s*(&lt;)'
					replace="\1${env.OCTEST_USERNAME}\2"
					byline="true" />
			</then>
		</if>
				
		<!-- Replace test username if set in environment -->
		<if>
			<condition>
				<isset property="env.OCTEST_PASSWORD" />
			</condition>
			<then>
				<replaceregexp
				file="res/values/setup.xml"
				match='("password"&gt;)\s*(&lt;)'
				replace="\1${env.OCTEST_PASSWORD}\2"
				byline="true" />
			</then>
		</if>
		
		<!-- Make Travis build number available to the test app in the emulator -->
		<if>
			<condition>
				<isset property="env.TRAVIS_BUILD_NUMBER" />
			</condition>
			<then>
				<replaceregexp
				file="res/values/setup.xml"
				match='("build_number"&gt;)\s*(&lt;)'
				replace="\1${env.TRAVIS_BUILD_NUMBER}\2"
				byline="true" />
			</then>
		</if>
	</target>
</project>