<?xml version="1.0" encoding="utf-8"?>
<project name="exports" basedir="." default="build-env">
	<property name="sourcedir" value="${ws}/source" />
	<property name="reportdir" value="${ws}/reports" />
	<property name="docdir" value="${ws}/build-docs" />
	<property name="docsrcdir" value="${ws}/docsrc" />
	<property name="env" value="production" />
	<!--   fileset pro nas kod bez lib -->
	<fileset dir="${sourcedir}" id="ownphpcode">
		<include name="**/*.php" />
		<exclude name="lib/Livingsk/**" />
		<exclude name="lib/Prazskereality/**" />
		<exclude name="lib/RealHit/**" />
		<exclude name="lib/RealitySk/**" />
		<exclude name="lib/Sreality/**" />
        <exclude name="lib/Viareality/**" />
        <exclude name="lib/Livingsk.php" />
		<exclude name="lib/Prazskereality.php" />
		<exclude name="lib/RealHit.php" />
		<exclude name="lib/RealitySk.php" />
		<exclude name="lib/Sreality.php" />
        <exclude name="lib/Viareality.php" />
		<exclude name="tests/**" />
	</fileset>
	<!--   Clear workspace -->
	<target name="clear" description="Clears workspace and previous reports">
		<delete dir="${builddir}" />
		<delete dir="${appdir}" />
		<delete dir="${docdir}" />
		<delete dir="${reportdir}" />
		<delete dir="${docsrcdir}" />
	</target>
	<!--   Prepare workspace -->
	<target name="prepare" depends="clear" description="Creates directories and files required for build to start">
		<mkdir dir="${reportdir}" />
		<mkdir dir="${reportdir}/coverage" />
		<mkdir dir="${reportdir}/phpunit" />
		<mkdir dir="${docdir}" />
		<mkdir dir="${docsrcdir}" />
		<copy todir="${docsrcdir}">
			<fileset dir="${sourcedir}">
				<include name="lib/Dalten/**/*.php" />
				<include name="lib/Serenity/**/*.php" />
			</fileset>
		</copy>
		<reflexive>
			<fileset dir="${docsrcdir}">
				<include name="lib/Dalten/**/*.php" />
				<include name="lib/Irest/**/*.php" />
			</fileset>
			<filterchain>
				<replaceregexp>
					<!--  Misto categories a packages pouzijeme samotne namespaces (vic urovni zanoreni) -->
					<regexp pattern="@(?:sub)?package.*" replace="" />
					<regexp pattern="@category.*" replace="" />
				</replaceregexp>
			</filterchain>
		</reflexive>
	</target>
	<!-- PHP API Documentation -->
	<target name="phpdoc" description="Generates documentation using PHP_UML">
		<exec command='phpuml ${docsrcdir} -f htmlnew -o ${docdir} -e utf8 -n "iRest2 API Documentation"' escape="false" />
		<copy file="${docdir}/index.htm" tofile="${docdir}/index.html" />
	</target>
	<!-- PHP copy/paste analysis -->
	<target name="phpcpd" description="Generates copy-paste detection report">
		<phpcpd>
			<fileset refid="ownphpcode" />
			<formatter type="pmd" outfile="${reportdir}/pmd-cpd.xml" />
		</phpcpd>
	</target>
	<!-- PHP mess detector -->
	<target name="phpmd" description="Generates PHPMD (like PMD) report">
		<exec command="phpmd ${sourcedir}/lib/Serenity/ xml codesize,unusedcode,naming,design &gt; ${reportdir}/phpmd-dalten.xml" escape="false" />
		<exec command="phpmd ${sourcedir}/lib/Dalten/ xml codesize,unusedcode,naming,design &gt; ${reportdir}/phpmd-serenity.xml" escape="false" />
	</target>
	<!-- PHP CodeSniffer -->
	<target name="phpcs" description="Generates code standards report using PHP_CodeSniffer">
		<exec command="phpcs --extensions=php,css --standard=/usr/local/share/pear/PHP/CodeSniffer/Standards/Dalten --tab-width=4 --report-checkstyle=${reportdir}/checkstyle.xml lib/Serenity lib/Dalten" />
	</target>
	<target name="phpunit" description="Runs unit-tests and generates reports">
		<exec command="phpunit --log-junit ${reportdir}/phpunit.xml --coverage-clover ${reportdir}/coverage/clover.xml --coverage-html=${reportdir}/coverage" dir="${sourcedir}/tests" escape="false" passthru="true" checkreturn="true" />
	</target>
	<target name="publish" description="Publishes application to passed-in application.dir">
		<echo msg="Publishing to ${export.dir}" />
		<copy todir="${export.dir}">
			<fileset dir="${sourcedir}">
				<include name="**/*" />
				<exclude name=".gitignore" />
			</fileset>
		</copy>

		<delete dir="${export.dir}/.git" />
	</target>
</project>
