Difference between revisions of "Ant (tool)"
Jump to navigation
Jump to search
m (moved Ant to Ant (tool): There is an Ant robot, too.) |
(Robocodes packing has gotten pretty slow lately, so needed to update this (must more robust/optionful now too)) |
||
Line 19: | Line 19: | ||
<taskdef name="yguard" classname="com.yworks.yguard.YGuardTask" /> | <taskdef name="yguard" classname="com.yworks.yguard.YGuardTask" /> | ||
− | |||
<!-- Your settings, all you need to change is here --> | <!-- Your settings, all you need to change is here --> | ||
<description>SkunkWorks Ant Build Script</description> | <description>SkunkWorks Ant Build Script</description> | ||
− | <property name="robot.classpath" value=" | + | <property name="robot.classpath" value="cs" /> |
− | <property name="robot.name" value=" | + | <property name="robot.name" value="Nene" /> |
− | <property name=" | + | <property name="obfuscate" value="false" /> |
− | + | <property name="build.version" value="1.5" /> | |
− | <!-- Comment this out if you don't want to | + | |
− | <property name="build.compiler" value="org.eclipse.jdt.core.JDTCompilerAdapter"/> | + | <property name="jardir" value="." /> |
− | + | <property name="srcdir" value="." /> | |
− | + | <property name="bindir" value="." /> | |
+ | |||
+ | <!-- Comment this out if you don't want to use the Eclipse Compiler for Java --> | ||
+ | <!-- <property name="build.compiler" value="org.eclipse.jdt.core.JDTCompilerAdapter"/> --> | ||
<!-- Load version number from robot properties file --> | <!-- Load version number from robot properties file --> | ||
<property file="${robot.classpath}/${robot.name}.properties" /> | <property file="${robot.classpath}/${robot.name}.properties" /> | ||
+ | <property name="robocode.jar" location="C:/robocode/libs/robocode.jar" /> | ||
+ | |||
+ | <!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! --> | ||
+ | <!-- !!!!!!!!!!!!!!! NO CONFIGURATION BEYOND THIS POINT !!!!!!!!!!!!!!!!!!!! --> | ||
+ | <!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! --> | ||
<!-- Compile the source java to class files --> | <!-- Compile the source java to class files --> | ||
Line 38: | Line 45: | ||
<!-- Delete all the current files so we can recompile with our compiler. --> | <!-- Delete all the current files so we can recompile with our compiler. --> | ||
<delete> | <delete> | ||
− | <fileset dir="${ | + | <fileset dir="${basedir}" includes="**/*.class"/> |
</delete> | </delete> | ||
<!-- Compile with no debugging info --> | <!-- Compile with no debugging info --> | ||
− | <javac srcdir=" | + | <javac srcdir="${srcdir}" destdir="${bindir}" includeAntRuntime="no" encoding="UTF-8" |
− | + | target="${build.version}" source="${build.version}" debug="off"> | |
<classpath> | <classpath> | ||
<pathelement path="${basedir}"/> | <pathelement path="${basedir}"/> | ||
Line 57: | Line 64: | ||
</tstamp> | </tstamp> | ||
− | <property name="backup.file" location="${robot.classname}_${robot.version} | + | <!-- Setup directories and filenames --> |
− | <property name="release.file" location="${robot.classname}_${robot.version}.jar" /> | + | <mkdir dir="${jardir}"/> |
− | <property name="tmp.file" location="~${robot.version}.jar" /> | + | <property name="backup.file" location="${jardir}/${robot.classname}_${robot.version}_${LONGSTAMP}.jar" /> |
+ | <property name="release.file" location="${jardir}/${robot.classname}_${robot.version}.jar" /> | ||
+ | <property name="tmp.file" location="${jardir}/~${robot.version}.jar" /> | ||
<!-- delete older copies of your files --> | <!-- delete older copies of your files --> | ||
Line 66: | Line 75: | ||
<!-- jar takes all your java and class files and packs them togeather --> | <!-- jar takes all your java and class files and packs them togeather --> | ||
− | <jar duplicate="add" basedir=" | + | <jar duplicate="add" basedir="${srcdir}" destfile="${backup.file}" compress="true"> |
− | <include name=" | + | <include name="**/*.java" /> |
− | <include name=" | + | <include name="**/*.properties" /> |
− | + | </jar> | |
+ | <jar duplicate="add" basedir="${bindir}" destfile="${backup.file}" update="true" compress="true"> | ||
+ | <include name="**/*.class" /> | ||
</jar> | </jar> | ||
Line 76: | Line 87: | ||
<!-- http://sadun-util.sourceforge.net/pack.html --> | <!-- http://sadun-util.sourceforge.net/pack.html --> | ||
<pack classes="${robot.classname}" targetjar="${tmp.file}" excludepkg="java,javax,sun,robocode"> | <pack classes="${robot.classname}" targetjar="${tmp.file}" excludepkg="java,javax,sun,robocode"> | ||
− | <classpath path=" | + | <classpath path="${bindir}" /> |
<classpath location="${robocode.jar}" /> | <classpath location="${robocode.jar}" /> | ||
<!-- A bit of magic so we don't have to type out our property files. | <!-- A bit of magic so we don't have to type out our property files. | ||
Bonus, it includes those in the data folder aswell. --> | Bonus, it includes those in the data folder aswell. --> | ||
− | <additionalfileset dir=" | + | <additionalfileset dir="${srcdir}"> |
<filename name="**/*.properties" /> | <filename name="**/*.properties" /> | ||
</additionalfileset> | </additionalfileset> | ||
</pack> | </pack> | ||
− | <!-- | + | <antcall target="doObfuscate" /> |
− | < | + | <antcall target="dontObfuscate" /> |
− | + | ||
− | <!-- | + | <!-- Cleanup your unneeded tmp jar --> |
− | + | <delete file="${tmp.file}" failonerror="false" /> | |
− | + | </target> | |
− | + | ||
− | + | <!-- Skip Obfuscation of release jar. --> | |
− | + | <target name="dontObfuscate" unless="${obfuscate}"> | |
− | + | <echo>Skipping Obfuscation</echo> | |
− | + | <move file="${tmp.file}" tofile="${release.file}" /> | |
+ | </target> | ||
+ | |||
+ | <!-- Obfuscate release jar. --> | ||
+ | <!-- http://www.yworks.com/products/yguard/yguard_ant_howto.html --> | ||
+ | <target name="doObfuscate" if="${obfuscate}"> | ||
+ | <echo>Obfuscating Jar</echo> | ||
<yguard> | <yguard> | ||
<inoutpair in="${tmp.file}" out="${release.file}" /> | <inoutpair in="${tmp.file}" out="${release.file}" /> | ||
Line 111: | Line 128: | ||
<class> | <class> | ||
<patternset> | <patternset> | ||
+ | <include name="ags.*" /> | ||
<include name="ags.utils.*" /> | <include name="ags.utils.*" /> | ||
− | |||
<include name="wiki.*" /> | <include name="wiki.*" /> | ||
</patternset> | </patternset> | ||
Line 119: | Line 136: | ||
</rename> | </rename> | ||
</yguard> | </yguard> | ||
− | |||
− | |||
− | |||
</target> | </target> | ||
</project> | </project> | ||
</syntaxhighlight> | </syntaxhighlight> |
Revision as of 00:45, 30 August 2011
Apache Ant is a Java-based build tool, similar to a make file. It allows you to automate the procedure of compiling and packaging your Java code. It is an open source tool and is available at Ant Home Page and is produced by Apache Software Foundation who develop a whole collection of top-class open-source projects.
Example Script
Example ant script for robocode: If you are Ant saavy enough you can change the other settings to your liking.
<?xml version="1.0" encoding="utf-8" ?>
<project name="SkunkWorks" default="package" basedir="." >
<!--
Find it here: http://sourceforge.net/projects/sadun-util/
put it in your ANT_HOME/lib
-->
<taskdef name="pack" classname="org.sadun.util.ant.Pack" />
<!--
Find it here: http://www.yworks.com/en/products_yguard_about.html
put it in your ANT_HOME/lib
-->
<taskdef name="yguard" classname="com.yworks.yguard.YGuardTask" />
<!-- Your settings, all you need to change is here -->
<description>SkunkWorks Ant Build Script</description>
<property name="robot.classpath" value="cs" />
<property name="robot.name" value="Nene" />
<property name="obfuscate" value="false" />
<property name="build.version" value="1.5" />
<property name="jardir" value="." />
<property name="srcdir" value="." />
<property name="bindir" value="." />
<!-- Comment this out if you don't want to use the Eclipse Compiler for Java -->
<!-- <property name="build.compiler" value="org.eclipse.jdt.core.JDTCompilerAdapter"/> -->
<!-- Load version number from robot properties file -->
<property file="${robot.classpath}/${robot.name}.properties" />
<property name="robocode.jar" location="C:/robocode/libs/robocode.jar" />
<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<!-- !!!!!!!!!!!!!!! NO CONFIGURATION BEYOND THIS POINT !!!!!!!!!!!!!!!!!!!! -->
<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<!-- Compile the source java to class files -->
<target name="compile">
<!-- Delete all the current files so we can recompile with our compiler. -->
<delete>
<fileset dir="${basedir}" includes="**/*.class"/>
</delete>
<!-- Compile with no debugging info -->
<javac srcdir="${srcdir}" destdir="${bindir}" includeAntRuntime="no" encoding="UTF-8"
target="${build.version}" source="${build.version}" debug="off">
<classpath>
<pathelement path="${basedir}"/>
<pathelement location="${robocode.jar}"/>
</classpath>
</javac>
</target>
<!-- Package the robot for upload. -->
<target name="package" depends="compile">
<tstamp>
<format property="LONGSTAMP" pattern="yyyyMMdd-HHmm" locale="en"/>
</tstamp>
<!-- Setup directories and filenames -->
<mkdir dir="${jardir}"/>
<property name="backup.file" location="${jardir}/${robot.classname}_${robot.version}_${LONGSTAMP}.jar" />
<property name="release.file" location="${jardir}/${robot.classname}_${robot.version}.jar" />
<property name="tmp.file" location="${jardir}/~${robot.version}.jar" />
<!-- delete older copies of your files -->
<delete file="${backup.file}" failonerror="false" />
<delete file="${release.file}" failonerror="false" />
<!-- jar takes all your java and class files and packs them togeather -->
<jar duplicate="add" basedir="${srcdir}" destfile="${backup.file}" compress="true">
<include name="**/*.java" />
<include name="**/*.properties" />
</jar>
<jar duplicate="add" basedir="${bindir}" destfile="${backup.file}" update="true" compress="true">
<include name="**/*.class" />
</jar>
<!-- "pack" task selects only the minimal set of classes needed to run the bot.
This can also be done with the "classfileset" task from ant-contrib -->
<!-- http://sadun-util.sourceforge.net/pack.html -->
<pack classes="${robot.classname}" targetjar="${tmp.file}" excludepkg="java,javax,sun,robocode">
<classpath path="${bindir}" />
<classpath location="${robocode.jar}" />
<!-- A bit of magic so we don't have to type out our property files.
Bonus, it includes those in the data folder aswell. -->
<additionalfileset dir="${srcdir}">
<filename name="**/*.properties" />
</additionalfileset>
</pack>
<antcall target="doObfuscate" />
<antcall target="dontObfuscate" />
<!-- Cleanup your unneeded tmp jar -->
<delete file="${tmp.file}" failonerror="false" />
</target>
<!-- Skip Obfuscation of release jar. -->
<target name="dontObfuscate" unless="${obfuscate}">
<echo>Skipping Obfuscation</echo>
<move file="${tmp.file}" tofile="${release.file}" />
</target>
<!-- Obfuscate release jar. -->
<!-- http://www.yworks.com/products/yguard/yguard_ant_howto.html -->
<target name="doObfuscate" if="${obfuscate}">
<echo>Obfuscating Jar</echo>
<yguard>
<inoutpair in="${tmp.file}" out="${release.file}" />
<externalclasses>
<pathelement location="${robocode.jar}"/>
</externalclasses>
<rename>
<property name="naming-scheme" value="small" />
<property name="language-conformity" value="illegal" />
<property name="overload-enabled" value="true" />
<keep>
<class name="${robot.classname}" methods="public" />
<!-- Put here the classes you don't want to obfuscate -->
<class>
<patternset>
<include name="ags.*" />
<include name="ags.utils.*" />
<include name="wiki.*" />
</patternset>
</class>
</keep>
</rename>
</yguard>
</target>
</project>