Sign in to follow this  
AngleWyrm

Another Neat Tool (ANT): It's better than batch files :)

Recommended Posts

So there I was, just a hackin' and a codin' a mod for Minecraft in Eclipse. And at the end, there's a bunch of stuff to do: Run a couple special external tools, relocate a bunch of files into a new folder tree, and then zip them up, add comments to the zip file, and so on. And I had a pretty cool batch file to do all that. Then someone showed me ANT, and I'm sold.

 

Ant does all the stuff I was doing, but much more elegantly. The tool uses an xml file, usually called build.xml, and it looks like this:

<project>
   <target>
       <!-- do some stuff -->
   </target>
 
   <target>
      <!-- do some other stuff -->
   </target>
</project>

The build.xml that I made for my Minecraft modding endeavors looks like so:[spoiler]

<?xml version="1.0" encoding="UTF-8"?>
<!-- ======================================================================
     Master Build file designed to work for all my minecraft mod projects
    
     Variables passed in from Eclipse environment:
     {project_name}

     ====================================================================== -->

<project name="${project_name}" default="all" basedir="D:/docs/prog/minecraft">

<!-- Manager task, executes all other tasks -->
<target name="all" description="default master task"
   depends="initialize, clean, stage, recompile, reobfuscate, zip, cleanup">
   <echo message="Finished building ${distribution}"/>
</target>

<!-- Debugging task, skips recompile/reobfuscate -->
<target name="debug"
   depends="initialize, clean, stage, zip, cleanup">
   <echo message="Rebuilt ${distribution}"/>
</target>

<!-- Initialize task -->
<target name="initialize">
   <echo message="Building ${project_name}"/>
   <property name="version" value="Pre-Alpha"/>

   <!-- Files and Folders -->
   <property name="MOD"         location="${basedir}/mods/${project_name}"/>
   <property name="anglewyrm" location="${basedir}/../anglewyrm"/>
   <property name="MCP"         location="${basedir}/MCP152"/>
   <property name="staging_area" location="${MCP}/src/minecraft/mods/${project_name}"/>
   <property name="reobf"     location="${MCP}/reobf/minecraft"/>
   <property name="python"     location="${MCP}/runtime/bin/python/python_mcp.exe"/>
   <tstamp>
      <format property="dateStamp" pattern="dd-MMM-yyyy"/>
   </tstamp>
   <property name="distribution" location="${basedir}/distribution/${project_name}-${dateStamp}.zip"/>
</target>

<!-- Clean -->
<target name="clean">
   <echo message="Preparing empty staging area"/>
   <delete dir="${staging_area}"/>
   <delete file="${distribution}"/>
   <mkdir dir="${staging_area}"/>
</target>

<!-- Stage source -->
<target name="stage">
   <echo message="Staging source to ${staging_area}"/>
   <filter token="VERSION" value="${version}"/>
   <filter token="RELEASE_DATE" value="${dateStamp}"/>
   <copy todir="${staging_area}" filtering="true">
      <fileset dir="${MOD}" excludes="textures/**"/>
   </copy>
   <copy todir="${staging_area}/textures" filtering="false">
      <fileset dir="${MOD}/textures" />
   </copy>
   <copy todir="${staging_area}/../..">
      <fileset file="${staging_area}/mcmod.info"/>
   </copy>
   <delete file="${staging_area}/mcmod.info"/>
</target>

<!-- Run recompile -->
<target name="recompile" description="MCP recompile" >
   <exec executable="${python}" dir="${MCP}" >
      <arg value="runtime/recompile.py" />
      <arg value="%*" />
   </exec>
</target>

<!-- Run reobfuscate -->
<target name="reobfuscate" description="MCP reobfuscate" >
   <exec executable="${python}" dir="${MCP}" >
      <arg value="runtime/reobfuscate.py" />
      <arg value="%*" />
   </exec>
</target>

<!-- Zip -->
<target name="zip" description="Zip up the mod">
   <echo message="Creating ${distribution}" />
   <zip destfile="${distribution}">
      <zipfileset dir="${reobf}" />
      <zipfileset dir="${staging_area}/textures" prefix="mods/${project_name}/textures" />
      <zipfileset dir="${staging_area}/../.." includes="mcmod.info" />
   </zip>
</target>

<!-- Cleanup -->
<target name="cleanup">
   <echo message="Removing temporary files"/>
   <!-- <delete dir="${staging_area}"/> -->
</target>

</project>

[/spoiler]

 

It can do advanced stuff, like substituting a token string during a copy operation. Within my source files is @VERSION@, but when copied by the build.xml, that string gets replaced.

Edited by AngleWyrm

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this