<?xml version="1.0" encoding="UTF-8" ?>

<project name="Mekanism" default="build">

	<property file="build.properties" />
	<property environment="env" />
	<property name="file.core" value="Mekanism-v${version.mod.major}.${version.mod.minor}.${version.mod.revis}.${env.BUILD_NUMBER}.jar"/>
	<property name="file.generators" value="MekanismGenerators-v${version.mod.major}.${version.mod.minor}.${version.mod.revis}.${env.BUILD_NUMBER}.jar"/>
	<property name="file.tools" value="MekanismTools-v${version.mod.major}.${version.mod.minor}.${version.mod.revis}.${env.BUILD_NUMBER}.jar"/>
	<property name="file.mdk" value="MDK-v${version.mod.major}.${version.mod.minor}.${version.mod.revis}.${env.BUILD_NUMBER}.zip"/>

	<target name="build">

		<delete dir="coreContents"/>
		<delete dir="generatorsContents"/>
		<delete dir="toolsContents"/>
		<delete dir="mdkContents"/>
		<delete dir="${dir.development}/forge"/>

		<copy todir="${dir.development}">
			<fileset dir="../Minecraft Forge Latest/"/>
		</copy>

		<get src="https://www.dropbox.com/s/0txj0orswr2ru5z/CodeChickenCore-dev-latest.jar?dl=1"
			dest = "${dir.mcp}/lib/CCC-dev.jar"/>

		<get src="https://www.dropbox.com/s/6lsq0qk00h38ktm/NotEnoughItems-dev-latest.jar?dl=1"
			dest="${dir.mcp}/lib/NEI-dev.jar"/>
		
		<get src="https://www.dropbox.com/s/qedjhg8gf1fuk8t/CodeChickenLib-dev-latest.jar?dl=1"
			dest="${dir.mcp}/lib/CCLib-dev.jar"/>
			
		<get src="http://files.minecraftforge.net/ForgeMultipart/ForgeMultipart-dev-1.6.4-1.0.0.212.jar"
			dest="${dir.mcp}/lib/ForgeMultipart-dev.jar"/>

		<copy todir="${dir.mcp}/src/minecraft">

			<fileset dir="${dir.development}common">
				<exclude name=".git/**"/>
				<exclude name="**/*.xml"/>
			</fileset>
		</copy>

		<mkdir dir="coreContents"/>
		<mkdir dir="generatorsContents"/>
		<mkdir dir="toolsContents"/>
		<mkdir dir="mdkContents"/>

		<replace dir="${dir.mcp}/src/minecraft" token="@MAJOR@" value="${version.mod.major}"/>
		<replace dir="${dir.mcp}/src/minecraft" token="@MINOR@" value="${version.mod.minor}"/>
		<replace dir="${dir.mcp}/src/minecraft" token="@REVIS@" value="${version.mod.revis}"/>
		<replace dir="${dir.mcp}/src/minecraft" token="@BUILD@" value="${env.BUILD_NUMBER}"/>

		<exec dir="${dir.mcp}" executable="cmd" osfamily="windows">
			<arg line="recompile.bat"/>
		</exec>
		<exec dir="${dir.mcp}" executable="cmd" osfamily="windows">
			<arg line="reobfuscate_srg.bat"/>
		</exec>

		<exec dir="${dir.mcp}" executable="bash" osfamily="unix">
			<arg line="recompile.sh"/>
		</exec>
		<exec dir="${dir.mcp}" executable="bash" osfamily="unix">
			<arg line="reobfuscate_srg.sh"/>
		</exec>

		<copy todir="coreContents">
			<fileset dir="${dir.mcp}/reobf/minecraft">
				<exclude name="**/mekanism/generators/**"/>
				<exclude name="**/mekanism/tools/**"/>
			</fileset>

			<fileset dir="${dir.development}resources"/>

			<fileset dir="${dir.development}etc/core"/>
		</copy>

		<copy todir="generatorsContents">
			<fileset dir="${dir.mcp}/reobf/minecraft">
				<include name = "**/mekanism/generators/**"/>
			</fileset>

			<fileset dir="${dir.development}etc/generators"/>
		</copy>

		<copy todir="toolsContents">
			<fileset dir="${dir.mcp}/reobf/minecraft">
				<include name = "**/mekanism/tools/**"/>
			</fileset>

			<fileset dir="${dir.development}etc/tools"/>
		</copy>

		<copy todir="mdkContents">
			<fileset dir="${dir.development}common">
				<include name = "**/mekanism/api/**"/>
			</fileset>
		</copy>

		<!-- Artifacts -->
		<jar destfile="output/${file.core}">
			<fileset dir="coreContents"/>
		</jar>

		<jar destfile="output/${file.generators}">
			<fileset dir="generatorsContents"/>
		</jar>

		<jar destfile="output/${file.tools}">
			<fileset dir="toolsContents"/>
		</jar>

		<zip destfile="output/${file.mdk}">
			<fileset dir="mdkContents"/>
		</zip>
		
		<!-- Latest Artifacts -->
		<jar destfile="Mekanism.jar">
			<fileset dir="coreContents"/>
		</jar>

		<jar destfile="Mekanism_Generators.jar">
			<fileset dir="generatorsContents"/>
		</jar>

		<jar destfile="Mekanism_Tools.jar">
			<fileset dir="toolsContents"/>
		</jar>

		<zip destfile="MDK.zip">
			<fileset dir="mdkContents"/>
		</zip>
		
		<copy todir="output" file="build.properties" />
	</target>
</project>