build_liteloader.xml 14.8 KB
<?xml version="1.0" encoding="UTF-8" ?>
<project name="liteloader" basedir="." default="development">

	<taskdef resource="net/sf/antcontrib/antcontrib.properties" classpath="tasks/ant-contrib.jar" />

	<!-- Versions !!IMPORTANT -->
	<property name="version" value="1.8.0_00" />
	<property name="mcversion" value="1.8" />
	<property name="author" value="Mumfrey" />

	<!-- Project definitions and dependencies -->
	<property name="upstream" value="" />
	<property name="project" value="LiteLoader" />
	<property name="displayname" value="LiteLoader" />
	<property name="md5set" value="mcp" />
	<property name="outmd5set" value="liteloader" />
	<property name="tweakclass" value="com.mumfrey.liteloader.launch.LiteLoaderTweaker" />

	<property name="mcp.dir" location="../../.." />
	<property name="build.dir" location="${mcp.dir}/build" />
	<property name="eclipse.dir" location="${mcp.dir}/eclipse" />
	<property name="temp.dir" location="${mcp.dir}/temp" />
	<property name="md5.dir" location="${mcp.dir}/md5" />
	<property name="libs.dir" location="${mcp.dir}/lib" />
	<property name="src.dir" location="${build.dir}/src"/>
	<property name="mc.src.dir" location="${mcp.dir}/src/minecraft" />
	<property name="mc.bin.dir" location="${mcp.dir}/bin/minecraft" />
	<property name="reobf.dir" location="${mcp.dir}/reobf/minecraft" />
	<property name="mc.libs.dir" location="${mcp.dir}/jars/libraries" />

	<property name="dist.dir" location="${build.dir}/dist" />
	<property name="filetype" value="jar" />

	<property name="python_windows" location="${mcp.dir}/runtime/bin/python/python_mcp.exe" />
	<property name="python_linux" location="/usr/bin/python" />

	<property environment="env" />
	
	<propertyregex property="gitcommit" input="${env.GIT_COMMIT}" regexp="^(.{7})" select="\1" casesensitive="false" />
	
	<target name="setup_client">
		<property name="clientjar" value="true" />
		<property name="suffix" value="" />
		<property name="javadocpath" value="docs" />
	</target>

	<target name="setup_core">
		<property name="suffix" value="-core" />
		<property name="javadocpath" value="coredocs" />
	</target>

	<target name="setup_development">
		<property name="skipremoval" value="DEV" />
		<property name="md5.outfile" value="${md5.dir}/client_${outmd5set}.md5" />
		<property name="artefact.name" value="${ant.project.name}${suffix}-${mcversion}" />
		<property name="stage.dir" location="${build.dir}/stage/${ant.project.name}/${version}" />
		<property name="meta.version" value="${version}" />
	</target>

	<target name="setup_production">
		<property name="skipremoval" value="" />
		<property name="md5.outfile" value="${md5.dir}/client_${outmd5set}_production.md5" />
		<property name="artefact.name" value="${ant.project.name}${suffix}-${mcversion}" />
		<property name="stage.dir" location="${build.dir}/stage/${ant.project.name}/${version}" />
		<property name="meta.version" value="${version}" />
	</target>

	<target name="setup_jenkins">
		<property name="skipremoval" value="" />
		<property name="md5.outfile" value="${md5.dir}/client_${outmd5set}_production.md5" />
		<property name="artefact.name" value="${ant.project.name}${suffix}-${mcversion}-SNAPSHOT" />
		<property name="stage.dir" location="${build.dir}/stage" />
		<property name="brand" value="${mcversion}-SNAPSHOT-r${gitcommit}-b${env.BUILD_NUMBER}-${env.BUILD_ID}" />
		<property name="meta.version" value="${version} [${brand}]" />
		<property name="jenkins" value="" />
	</target>

	<!-- Main target -->
	<target name="development" depends="setup_client, setup_development, build" description="Entry point for MCP and upstream builds" />

	<target name="production" depends="setup_client, setup_production, build, javadoc, mcpjar" description="Entry point for production builds" />

	<target name="jenkins" depends="setup_client, setup_jenkins, build, javadoc, mcpjar" description="Entry point for CI builds" />

	<target name="core" depends="setup_core, setup_jenkins, build, javadoc, mcpjar" description="Entry point for CI builds" />

	<target name="build" description="Perform all tasks for a client build" depends="init, recompile, reobfuscate, savemd5, stage, jar" >
	</target>
	
	<target name="clean">
		<echo level="info" message="Cleaning output directories" />
		
		<delete dir="${src.dir}" />
		<delete dir="${mcp.dir}/reobf" />
	</target>

	<target name="contributesource" description="Contribute an upstream project source code to the source path">
		<echo level="info" message="Contributing project ${lib}" />
		<copy todir="${src.dir}" verbose="false" overwrite="true" failonerror="false">
			<fileset dir="${eclipse.dir}/${lib}/java${sub}">
				<exclude name="**/debug" />
				<exclude name="**/debug/*.java" />
			</fileset>
			<fileset dir="${eclipse.dir}/${lib}/src${sub}" />
			<filterchain>
				<linecontains negate="true">
					<contains value="@MCPONLY${skipremoval}" />
				</linecontains>
			</filterchain>
		</copy>
	</target>
	
	<target name="contributeclientsource" description="Contribute client source if building a client jar" if="clientjar">
		<antcall target="contributesource">
			<param name="lib" value="${project}" />
			<param name="sub" value="/client" />
		</antcall>
	</target>

	<target name="contributeresources" description="Contribute resources to the staging path">
		<echo level="info" message="Contributing project resources for ${lib}" />
		<copy todir="${stage.dir}" verbose="false" failonerror="false">
			<fileset dir="${eclipse.dir}/${lib}/resources" excludes=".svn/**">
				<exclude name="**/Thumbs.db" />
				<exclude name="**/minecraft.key" />
			</fileset>
		</copy>
	</target>

	<target name="findmd5dir">
		<echo level="info" message="Searching for existing MD5 directory..." />
		<condition property="md5dir.exists">
			<available file="${md5.dir}" type="dir"/>
		</condition>
	</target>

	<target name="findmd5" depends="findmd5dir">
		<echo level="info" message="Searching for existing MD5 sets..." />
		<condition property="md5set.exists">
			<available file="${md5.dir}/client_${md5set}.md5" type="file"/>
		</condition>
	</target>

	<target name="seedmd5" depends="findmd5" unless="md5set.exists">
		<echo level="info" message="MD5 sets not found, seeding..." />
		<ant target="genmd5" antfile="seed_md5.xml" inheritall="true" />
	</target>

	<target name="notifymd5ok" depends="findmd5" if="md5set.exists">
		<echo level="info" message="MD5 sets already exist, skipping MD5 set seeding" />
	</target>

	<target name="preparemd5" description="Copy patched MD5 to the temp directory" depends="seedmd5, notifymd5ok, clean">
		<echo level="info" message="Prepare exclusion MD5s, using exclusion set &quot;${md5set}&quot;" />

		<copy tofile="${temp.dir}/client.md5" file="${md5.dir}/client_${md5set}.md5" failonerror="true" verbose="true" overwrite="true" />
	</target>

	<target name="prepare" description="Prepare source for MCP" depends="preparemd5">
		<echo level="info" message="Prepare sources for compile" />

		<echo level="info" message="Contributing libs" />
		<copy todir="${libs.dir}" verbose="true" overwrite="true">
			<fileset dir="${eclipse.dir}/${project}/lib">
				<exclude name="**/authlib*.jar" />
				<exclude name="**/log4j*.jar" />
			</fileset>
		</copy>

		<echo level="info" message="Contributing MC source" />
		<copy todir="${src.dir}" verbose="false" overwrite="true">
			<fileset dir="${mc.src.dir}" />
		</copy>

		<echo level="info" message="Contributing upstream projects" />
		<foreach list="${upstream}" param="lib" target="contributesource" />

		<antcall target="contributesource">
			<param name="lib" value="${project}" />
			<param name="sub" value="/common" />
		</antcall>
		
		<antcall target="contributeclientsource" />
	</target>

	<target name="init" description="Initialize build environment" depends="prepare">
		<echo append="false" file="${temp.dir}/build.cfg" message="[OUTPUT]&#x0A;SrcClient  = build/src" />

		<echo level="info" message="Cleaning old stage and dist, MCP reobf directories" />

		<delete dir="${stage.dir}" />

		<echo level="info" message="Creating stage and dist dirs" />
		<mkdir dir="${stage.dir}" />
		<mkdir dir="${dist.dir}" />
		<mkdir dir="${md5.dir}" />
	</target>

	<target name="recompile" description="MCP recompile">
		<echo level="info" message="Compiling projects" />

		<exec executable="${python_windows}" dir="${mcp.dir}" osfamily="windows">
			<arg value="runtime/recompile.py" />
			<arg value="--client" />
			<arg value="--config" />
			<arg value="${temp.dir}/build.cfg" />
			<arg value="%*" />
		</exec>

		<exec executable="${python_linux}" dir="${mcp.dir}" osfamily="unix">
			<arg value="runtime/recompile.py" />
			<arg value="--client" />
			<arg value="--config" />
			<arg value="${temp.dir}/build.cfg" />
			<arg value="%*" />
		</exec>
	</target>

	<target name="reobfuscate" description="MCP reobfuscate">
		<echo level="info" message="Obfuscating classes" />

		<exec executable="${python_windows}" dir="${mcp.dir}" osfamily="windows">
			<arg value="runtime/reobfuscate.py" />
			<arg value="--client" />
			<arg value="%*" />
		</exec>

		<exec executable="${python_linux}" dir="${mcp.dir}" osfamily="unix">
			<arg value="runtime/reobfuscate.py" />
			<arg value="--client" />
			<arg value="%*" />
		</exec>
	</target>

	<target name="savemd5" description="Put post-obfuscation MD5 to stored md5 set" if="outmd5set">
		<echo level="info" message="Storing obfuscated MD5s" />

		<copy file="${temp.dir}/client_reobf.md5" tofile="${md5.outfile}" overwrite="true" verbose="true" />
	</target>

	<target name="stage" description="Stage resources into staging directory">
		<echo level="info" message="Staging resources" />

		<copy todir="${stage.dir}" overwrite="true">
			<fileset dir="${reobf.dir}" excludes=".svn/**, *.txt">
				<exclude name="?.class" />
				<exclude name="??.class" />
				<exclude name="???.class" />
				<exclude name="/net/minecraft/**" />
			</fileset>
		</copy>

		<foreach list="${upstream}" param="lib" target="contributeresources" />

		<antcall target="contributeresources">
			<param name="lib" value="${project}" />
		</antcall>

		<antcall target="stamp">
		</antcall>
	</target>
	
	<target name="stamp" description="Stamp build information into staged resources" if="jenkins">
		<echo level="info" message="Writing branding information into artefact staging area" />
		<echo level="info" message="Brand: ${brand}" />

		<replaceregexp file="${stage.dir}/liteloader.properties" byline="true" match="^brand=.*$" replace="brand=${brand}" />
	</target>

	<target name="jar" description="Build the client jar">
		<echo level="info" message="Building final output" />

		<mkdir dir="${dist.dir}" />

		<jar destfile="${dist.dir}/${artefact.name}.${filetype}" duplicate="preserve" index="true" manifestencoding="UTF-8">
			<manifest>
				<attribute name="Built-By" value="MCP (http://mcp.ocean-labs.de)" />
				<attribute name="Implementation-Vendor" value="${author}" />
				<attribute name="Implementation-Title" value="${ant.project.name}" />
				<attribute name="Implementation-Version" value="${meta.version}" />
				<attribute name="TweakClass" value="${tweakclass}" />
				<attribute name="TweakName" value="${displayname}" />
				<attribute name="TweakVersion" value="${version}" />
				<attribute name="TweakAuthor" value="${author}" />
			</manifest>
			<fileset dir="${stage.dir}" />
		</jar>
	</target>
	
	<target name="compiledebug" description="Recompile with debug classes">
		<copy todir="${src.dir}" verbose="false" overwrite="true" failonerror="false">
			<fileset dir="${eclipse.dir}/${project}/debug" />
		</copy>
		
		<antcall target="recompile" />
	</target>

	<target name="mcpjar" description="Build the MCP-names jar" depends="compiledebug">
		<echo level="info" message="Building mcpnamesjars" />

		<mkdir dir="${dist.dir}" />
		
		<delete file="${dist.dir}/${artefact.name}-mcpnames.${filetype}" />
		<delete file="${dist.dir}/${artefact.name}-mcpnames-sources.${filetype}" />
		
		<jar destfile="${dist.dir}/${artefact.name}-mcpnames.${filetype}" duplicate="preserve" index="true" manifestencoding="UTF-8">
			<manifest>
				<attribute name="Built-By" value="MCP (http://mcp.ocean-labs.de)" />
				<attribute name="Implementation-Vendor" value="${author}" />
				<attribute name="Implementation-Title" value="${ant.project.name}" />
				<attribute name="Implementation-Version" value="${meta.version}" />
				<attribute name="TweakClass" value="${tweakclass}" />
				<attribute name="TweakName" value="${displayname}" />
				<attribute name="TweakVersion" value="${version}" />
				<attribute name="TweakAuthor" value="${author}" />
			</manifest>
			<fileset dir="${mc.bin.dir}">
				<include name="com/mumfrey/**" />
				<include name="net/eq2online/**" />
			</fileset>
			<fileset dir="${eclipse.dir}/${project}/resources" excludes=".svn/**" />
			<fileset dir="${eclipse.dir}/${project}/debug" excludes=".svn/**">
				<exclude name="**/*.java" />
			</fileset>
		</jar>
		<jar destfile="${dist.dir}/${artefact.name}-mcpnames-sources.${filetype}" duplicate="preserve" index="false" filesetmanifest="skip">
			<fileset dir="${eclipse.dir}/${project}/java/common" />
			<fileset dir="${eclipse.dir}/${project}/java/client" />
			<fileset dir="${eclipse.dir}/${project}/debug" />
			<fileset dir="${eclipse.dir}/${project}/resources" />
		</jar>
	</target>

	<target name="javadoc" description="Create the javadoc jar">
		<echo level="info" message="Generating javadoc" />

		<javadoc destdir="${stage.dir}/${javadocpath}" useexternalfile="true">
			<fileset dir="${eclipse.dir}/${project}/java">
				<exclude name="**/debug" />
				<exclude name="**/debug/*.java" />
			</fileset>
			<classpath>
				<fileset dir="${mc.libs.dir}">
					<include name="**/*.jar" />
				</fileset>
				<fileset dir="${libs.dir}">
					<include name="*.jar" />
				</fileset>
				<pathelement location="${mc.bin.dir}"/>
			</classpath>
			<arg value="-XDignore.symbol.file" />
		</javadoc>
		<jar destfile="${dist.dir}/${artefact.name}-javadoc.${filetype}" duplicate="preserve" index="true" manifestencoding="UTF-8">
			<manifest>
				<attribute name="Built-By" value="MCP (http://mcp.ocean-labs.de)" />
				<attribute name="Implementation-Vendor" value="${author}" />
				<attribute name="Implementation-Title" value="${ant.project.name}" />
				<attribute name="Implementation-Version" value="${version}" />
			</manifest>
			<fileset dir="${stage.dir}/${javadocpath}" />
		</jar>
		<copy file="${dist.dir}/${artefact.name}-javadoc.${filetype}" tofile="${dist.dir}/${artefact.name}-mcpnames-javadoc.${filetype}" />
	</target>
	
	<target name="deploy" depends="production" description="Deploy artifact to local minecraft installation in APPDATA">
		<mkdir dir="${env.APPDATA}/.minecraft/libraries/com/mumfrey/liteloader/${mcversion}"/>
		<copy todir="${env.APPDATA}/.minecraft/libraries/com/mumfrey/liteloader/${mcversion}" file="${dist.dir}/${artefact.name}.${filetype}" failonerror="false" overwrite="true" />
		<copy todir="${eclipse.dir}/LiteLoaderInstaller/src/main/resources" file="${dist.dir}/${artefact.name}.${filetype}" failonerror="false" overwrite="true" />
	</target>
</project>