<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project basedir="." name="boppi">
	<property environment="env" />
	<property name="junit.output.dir" value="doc/junit" />
	<property name="g4.iloc" value="src/pp/iloc/parse" />
	<property name="g4.boppi" value="src/pp/s1184725/boppi/antlr" />
	<property name="debuglevel" value="source,lines,vars" />
	<property name="target" value="1.8" />
	<property name="source" value="1.8" />
	<path id="boppi.classpath">
		<pathelement location="bin" />
		<pathelement location="lib/antlr-4.7-complete.jar" />
		<pathelement location="lib/hamcrest-all-1.3.jar" />
		<pathelement location="lib/junit-4.12.jar" />
		<pathelement location="lib/commons-lang3-3.5.jar" />
		<pathelement location="lib/commons-cli-1.4.jar" />
	</path>
	<path id="libraries.path">
		<fileset dir="lib">
			<include name="*.jar" />
		</fileset>
	</path>


	<target name="build-all" depends="build,build-jar,javadoc,junit" description="Build all targets." />
	<target name="build" depends="do-init,do-build-antlr,do-build" description="Build the ANTLR parser code and compile all Java code." />
	<target name="build-jar" depends="build,do-build-jar" description="Build a runnable JAR to compile and run programs." />
	<target name="javadoc" depends="do-build-antlr,do-javadoc" description="Generate Javadoc." />
	<target name="junit" depends="build,do-junit,do-junit-report" description="Run JUnit tests and generate a report." />
	<target name="clean" depends="do-clean" description="Clear all generated files." />


	<target name="do-init">
		<mkdir dir="bin" />
		<mkdir dir="bin/lib" />
		<mkdir dir="${junit.output.dir}" />
		<mkdir dir="dist" />
		<copy includeemptydirs="false" todir="bin">
			<fileset dir="src">
				<exclude name="**/*.launch" />
				<exclude name="**/*.xtend" />
				<exclude name="**/*.java" />
				<exclude name="**/*.g4" />
			</fileset>
		</copy>
	</target>

	<target name="do-build">
		<echo message="${ant.project.name}: ${ant.file}" />
		<javac debug="true" debuglevel="${debuglevel}" destdir="bin" includeantruntime="false" source="${source}" target="${target}">
			<src path="src" />
			<classpath refid="boppi.classpath" />
		</javac>
	</target>

	<target name="do-clean">
		<delete dir="bin" />
		<delete dir="doc/javadoc" />
		<delete dir="dist" />
		<delete dir="${junit.output.dir}" />
		<delete>
			<fileset dir="${g4.iloc}" casesensitive="yes">
				<include name="ILOC*.java" />
				<include name="*.tokens" />
			</fileset>
			<fileset dir="${g4.boppi}" casesensitive="yes">
				<include name="Boppi*.java" />
				<include name="*.tokens" />
			</fileset>
		</delete>
	</target>

	<target name="do-junit">
		<junit fork="yes" dir="src" showoutput="false" printsummary="withOutAndErr">
			<formatter type="xml" />
			<batchtest todir="${junit.output.dir}">
				<fileset dir="src">
					<include name="pp/iloc/**/*Test.java" />
					<include name="pp/s1184725/**/*Test.java" />
				</fileset>
			</batchtest>
			<jvmarg line="-ea" />
			<classpath refid="boppi.classpath" />
		</junit>
	</target>

	<target name="do-junit-report">
		<junitreport todir="${junit.output.dir}">
			<fileset dir="${junit.output.dir}">
				<include name="TEST-*.xml" />
			</fileset>
			<report format="frames" todir="${junit.output.dir}">
				<param name="TITLE" expression="Boppi test report. See 'System.out' per test case for source listings, ILOC listings and compiler messages."/>
			</report>
		</junitreport>
	</target>

	<target name="do-build-antlr">
		<java classname="org.antlr.v4.Tool">
			<classpath>
				<pathelement location="lib/antlr-4.7-complete.jar" />
			</classpath>
			<arg value="${g4.boppi}/Boppi.g4" />
			<!-- <arg value="-o" />
			<arg value="${g4.boppi}" /> -->
			<arg value="-package" />
			<arg value="pp.s1184725.boppi.antlr" />
			<arg value="-no-listener" />
			<arg value="-visitor" />
		</java>
		<java classname="org.antlr.v4.Tool">
			<classpath>
				<pathelement location="lib/antlr-4.7-complete.jar" />
			</classpath>
			<arg value="${g4.iloc}/ILOC.g4" />
			<!-- <arg value="-o" />
			<arg value="${g4.iloc}" /> -->
			<arg value="-listener" />
			<arg value="-no-visitor" />
		</java>
	</target>

	<target name="do-javadoc">
		<javadoc access="public" author="true" classpath="lib/commons-lang3-3.5.jar;lib/commons-cli-1.4.jar;lib/antlr-4.7-complete.jar;lib/junit-4.12.jar;lib/hamcrest-all-1.3.jar" destdir="doc/javadoc" nodeprecated="false" nodeprecatedlist="false" noindex="false" nonavbar="false" notree="false" packagenames="pp.*" source="1.8" sourcepath="src" splitindex="false" use="true" version="true">
			<link href="https://www.antlr.org/api/Java/" />
			<link href="http://hamcrest.org/JavaHamcrest/javadoc/1.3/" />
			<link href="https://docs.oracle.com/javase/8/docs/api/" />
			<link href="https://junit.org/junit4/javadoc/4.12/" />
			<link href="https://commons.apache.org/proper/commons-lang/javadocs/api-3.5/" />
			<link href="https://commons.apache.org/proper/commons-cli/javadocs/api-release/" />
			<arg value="-Xdoclint:none" /> <!-- may disable tons of warnings in ILOC docs -->
			<arg value="-html5" />
		</javadoc>
	</target>

	<target name="do-build-jar">
		<copy todir="dist">
			<fileset dir="util" includes="boppi.*" />
		</copy>
		<copy todir="dist/lib" flatten="true">
			<path refid="libraries.path" />
		</copy>

		<manifestclasspath property="manifest.classpath" jarfile="${ant.project.name}.jar">
			<classpath refid="libraries.path" />
		</manifestclasspath>

		<jar destfile="dist/${ant.project.name}.jar" basedir="bin">
			<manifest>
				<attribute name="Main-Class" value="pp.s1184725.boppi.util.CommandLineInterface" />
				<attribute name="Class-Path" value="${manifest.classpath}" />
			</manifest>
		</jar>
	</target>
</project>
