Difference between revisions of "User:Nat/Ant Build File"
(my ant build file I'm using now) |
m |
||
(One intermediate revision by the same user not shown) | |||
Line 36: | Line 36: | ||
== XML File == | == XML File == | ||
− | + | Because color make you memorization better by 72%, so... (but I can't disabled the auto line break TT) | |
− | < | + | <!-- Don't edit below unless you know what you are doing, I have no backup of that code with formatting! --> |
− | < | + | <span style='font-family:"Courier New", courier, monospace;display:block;line-height: 1em; border: 1px dashed rgb(47, 111, 171); padding: 1em;'> <span style="color: #c60"><span style="color: #f00"><?xml <span style="color: #606">version</span><span style="color: #000">=</span><span style="color: #00f">"1.0"</span> <span style="color: #606">encoding</span><span style="color: #000">=</span><span style="color: #00f">"utf-8"</span> ?></span></span><br /> <span style="color: #090"><!-- ======================================================<br /> <br /> ANT build file<br /> Nat Pavasant<br /> <br /> ======================================================<br /> <br /> Directory structure:<br /> - /bin - this will store all of classes files<br /> - /src - this will store all of source files<br /> - /resource - contain all the resources you want to include <br /> in .jar in the same structure<br /> - /backups - contain each and every build of your code.<br /> <br /> Dependancies:<br /> - Pack task (http://sadun-util.sourceforge.net/pack.html)<br /> - yGuard Obfuscator (http://www.yworks.com/en/products_yguard_about.htm)<br /> - CodeSize version 1.0 (version 1.1 come with robocode now doesn't have valid entry point)<br /> <br /> Configuration:<br /> - basedir - in <span style="color: #c60"><project></span> tag - must set to your working directory that<br /> contains the structure<br /> - In task 'init'<br /> - robot.name - robot classname<br /> - robot.package - robot package name<br /> - robot.propertiesfile - path to property file to created<br /> - ...<br /> <br /> Credit:<br /> - David Alves<br /> - Hexkid<br /> <br /> ======================================================= --></span><br /> <span style="color: #c60"><project <span style="color: #606">name</span><span style="color: #000">=</span><span style="color: #00f">"Robot"</span> <span style="color: #606">default</span><span style="color: #000">=</span><span style="color: #00f">"build"</span> <span style="color: #606">basedir</span><span style="color: #000">=</span><span style="color: #00f">"."</span>></span><br /> <span style="color: #c60"><description></span><br /> <span style="color: #00f">Build File</span><br /> <span style="color: #c60"></description></span><br /> <br /> <span style="color: #090"><!-- define a task use in this build file --></span><br /> <span style="color: #c60"><taskdef <span style="color: #606">name</span><span style="color: #000">=</span><span style="color: #00f">"yguard"</span> <span style="color: #606">classname</span><span style="color: #000">=</span><span style="color: #00f">"com.yworks.yguard.YGuardTask"</span> <span style="color: #606">classpath</span><span style="color: #000">=</span><span style="color: #00f">"./yguard.jar"</span> /></span><br /> <span style="color: #c60"><taskdef <span style="color: #606">name</span><span style="color: #000">=</span><span style="color: #00f">"pack"</span> <span style="color: #606">classname</span><span style="color: #000">=</span><span style="color: #00f">"org.sadun.util.ant.Pack"</span> <span style="color: #606">classpath</span><span style="color: #000">=</span><span style="color: #00f">"./pack.jar"</span> /></span><br /> <br /> <span style="color: #090"><!-- Initialize the config, all properties must be here --></span><br /> <span style="color: #c60"><target <span style="color: #606">name</span><span style="color: #000">=</span><span style="color: #00f">"init"</span> <span style="color: #606">description</span><span style="color: #000">=</span><span style="color: #00f">"Initialize properties to build"</span>></span><br /> <span style="color: #c60"><tstamp></span><br /> <span style="color: #090"><!-- configure time string use for backup version --></span><br /> <span style="color: #c60"><format <span style="color: #606">property</span><span style="color: #000">=</span><span style="color: #00f">"timestamp"</span> <span style="color: #606">pattern</span><span style="color: #000">=</span><span style="color: #00f">"yyyyMMdHHmmss"</span> <span style="color: #606">locale</span><span style="color: #000">=</span><span style="color: #00f">"en,US"</span> <span style="color: #606">timezone</span><span style="color: #000">=</span><span style="color: #00f">"UTC"</span> /></span><br /> <span style="color: #c60"></tstamp></span><br /> <br /> <span style="color: #090"><!-- Start configuration setting --></span><br /> <span style="color: #c60"><property <span style="color: #606">name</span><span style="color: #000">=</span><span style="color: #00f">"robot.name"</span> <span style="color: #606">value</span><span style="color: #000">=</span><span style="color: #00f">"Your Robot Name"</span> /></span><br /> <span style="color: #c60"><property <span style="color: #606">name</span><span style="color: #000">=</span><span style="color: #00f">"robot.package"</span> <span style="color: #606">value</span><span style="color: #000">=</span><span style="color: #00f">"Your Package Name"</span> /></span><br /> <br /> <span style="color: #090"><!-- Set the path to your properties file inside .jar, please make sure <br /> that the specific directory is available under ./resource/ directory --></span><br /> <span style="color: #c60"><property <span style="color: #606">name</span><span style="color: #000">=</span><span style="color: #00f">"robot.propertiesfile"</span> <span style="color: #606">value</span><span style="color: #000">=</span><span style="color: #00f">"Your package name/${robot.name}.properties"</span> /></span><br /> <br /> <span style="color: #090"><!-- Create the property file that describes this robot --></span><br /> <span style="color: #c60"><propertyfile <span style="color: #606">file</span><span style="color: #000">=</span><span style="color: #00f">"resource/${robot.propertiesfile}"</span>></span><br /> <span style="color: #c60"><entry <span style="color: #606">key</span><span style="color: #000">=</span><span style="color: #00f">"robot.description"</span> <span style="color: #606">value</span><span style="color: #000">=</span><span style="color: #00f">""</span> /></span><br /> <span style="color: #c60"><entry <span style="color: #606">key</span><span style="color: #000">=</span><span style="color: #00f">"robot.java.source.included"</span> <span style="color: #606">value</span><span style="color: #000">=</span><span style="color: #00f">"false"</span> /></span><br /> <span style="color: #c60"><entry <span style="color: #606">key</span><span style="color: #000">=</span><span style="color: #00f">"robocode.version"</span> <span style="color: #606">value</span><span style="color: #000">=</span><span style="color: #00f">"1.7.1.2"</span> /></span><br /> <span style="color: #c60"><entry <span style="color: #606">key</span><span style="color: #000">=</span><span style="color: #00f">"robot.version"</span> <span style="color: #606">value</span><span style="color: #000">=</span><span style="color: #00f">"0.1"</span> /></span><br /> <span style="color: #c60"><entry <span style="color: #606">key</span><span style="color: #000">=</span><span style="color: #00f">"robot.author.name"</span> <span style="color: #606">value</span><span style="color: #000">=</span><span style="color: #00f">"Your Name"</span> /></span><br /> <span style="color: #c60"><entry <span style="color: #606">key</span><span style="color: #000">=</span><span style="color: #00f">"robot.classname"</span> <span style="color: #606">value</span><span style="color: #000">=</span><span style="color: #00f">"${robot.package}.${robot.name}"</span> /></span><br /> <span style="color: #c60"></propertyfile></span><br /> <br /> <span style="color: #c60"><property <span style="color: #606">file</span><span style="color: #000">=</span><span style="color: #00f">"resource/${robot.propertiesfile}"</span> <span style="color: #606">description</span><span style="color: #000">=</span><span style="color: #00f">"Use the entries from the properties file within this script."</span> /></span><br /> <span style="color: #c60"><property <span style="color: #606">name</span><span style="color: #000">=</span><span style="color: #00f">"robocode.home"</span> <span style="color: #606">value</span><span style="color: #000">=</span><span style="color: #00f">"C:\robocode"</span> /></span><br /> <span style="color: #c60"><property <span style="color: #606">name</span><span style="color: #000">=</span><span style="color: #00f">"robocode.jar"</span> <span style="color: #606">location</span><span style="color: #000">=</span><span style="color: #00f">"${robocode.home}/libs/robocode.jar"</span> /></span><br /> <span style="color: #c60"><property <span style="color: #606">name</span><span style="color: #000">=</span><span style="color: #00f">"codesize.jar"</span> <span style="color: #606">location</span><span style="color: #000">=</span><span style="color: #00f">"./codesize.jar"</span> /></span><br /> <span style="color: #c60"><property <span style="color: #606">name</span><span style="color: #000">=</span><span style="color: #00f">"class.path"</span> <span style="color: #606">value</span><span style="color: #000">=</span><span style="color: #00f">"./bin;${robocode.jar}"</span> /></span><br /> <br /> <span style="color: #c60"><property <span style="color: #606">name</span><span style="color: #000">=</span><span style="color: #00f">"COMPILECLASSNAME"</span> <span style="color: #606">value</span><span style="color: #000">=</span><span style="color: #00f">""</span> /></span><br /> <span style="color: #c60"><property <span style="color: #606">name</span><span style="color: #000">=</span><span style="color: #00f">"COMPILE_WITH_DEBUG"</span> <span style="color: #606">value</span><span style="color: #000">=</span><span style="color: #00f">"off"</span> /></span><br /> <span style="color: #c60"><property <span style="color: #606">name</span><span style="color: #000">=</span><span style="color: #00f">"VERBOSE_LEVEL"</span> <span style="color: #606">value</span><span style="color: #000">=</span><span style="color: #00f">"1"</span> /></span><br /> <br /> <span style="color: #c60"><property <span style="color: #606">name</span><span style="color: #000">=</span><span style="color: #00f">"backup.file"</span> <span style="color: #606">location</span><span style="color: #000">=</span><span style="color: #00f">"target/${robot.name}_${robot.version}_${timestamp}.jar"</span> /></span><br /> <span style="color: #c60"><property <span style="color: #606">name</span><span style="color: #000">=</span><span style="color: #00f">"release.file"</span> <span style="color: #606">location</span><span style="color: #000">=</span><span style="color: #00f">"target/${robot.classname}_${robot.version}.jar"</span> /></span><br /> <span style="color: #c60"><property <span style="color: #606">name</span><span style="color: #000">=</span><span style="color: #00f">"temp.file"</span> <span style="color: #606">location</span><span style="color: #000">=</span><span style="color: #00f">"target/${robot.name}_temp.jar"</span> /></span><br /> <span style="color: #c60"></target></span><br /> <br /> <span style="color: #090"><!-- Clean up the build --></span><br /> <span style="color: #c60"><target <span style="color: #606">name</span><span style="color: #000">=</span><span style="color: #00f">"clean"</span> <span style="color: #606">depends</span><span style="color: #000">=</span><span style="color: #00f">"init"</span> <span style="color: #606">description</span><span style="color: #000">=</span><span style="color: #00f">"Remove the directories containing the classes and the jar file"</span>></span><br /> <span style="color: #c60"><delete <span style="color: #606">dir</span><span style="color: #000">=</span><span style="color: #00f">"bin"</span> /></span><br /> <span style="color: #c60"><delete <span style="color: #606">dir</span><span style="color: #000">=</span><span style="color: #00f">"target"</span> /></span><br /> <span style="color: #c60"></target></span><br /> <br /> <span style="color: #c60"><target <span style="color: #606">name</span><span style="color: #000">=</span><span style="color: #00f">"prepare"</span> <span style="color: #606">depends</span><span style="color: #000">=</span><span style="color: #00f">"init"</span> <span style="color: #606">description</span><span style="color: #000">=</span><span style="color: #00f">"Create the generated directories"</span>></span><br /> <span style="color: #c60"><mkdir <span style="color: #606">dir</span><span style="color: #000">=</span><span style="color: #00f">"bin"</span> /></span><br /> <span style="color: #c60"><mkdir <span style="color: #606">dir</span><span style="color: #000">=</span><span style="color: #00f">"target"</span> /></span><br /> <span style="color: #c60"></target></span><br /> <br /> <span style="color: #c60"><target <span style="color: #606">name</span><span style="color: #000">=</span><span style="color: #00f">"compile"</span> <span style="color: #606">depends</span><span style="color: #000">=</span><span style="color: #00f">"prepare"</span> <span style="color: #606">description</span><span style="color: #000">=</span><span style="color: #00f">"Compile the Java classes"</span>></span><br /> <span style="color: #c60"><javac <span style="color: #606">srcdir</span><span style="color: #000">=</span><span style="color: #00f">"src"</span> <span style="color: #606">destdir</span><span style="color: #000">=</span><span style="color: #00f">"bin"</span> <span style="color: #606">classpath</span><span style="color: #000">=</span><span style="color: #00f">"${class.path}"</span> <span style="color: #606">debug</span><span style="color: #000">=</span><span style="color: #00f">"${COMPILE_WITH_DEBUG}"</span> <span style="color: #606">includes</span><span style="color: #000">=</span><span style="color: #00f">"**/*.java"</span> /></span><br /> <span style="color: #c60"></target></span><br /> <br /> <span style="color: #c60"><target <span style="color: #606">name</span><span style="color: #000">=</span><span style="color: #00f">"buildjar"</span> <span style="color: #606">depends</span><span style="color: #000">=</span><span style="color: #00f">"compile"</span> <span style="color: #606">description</span><span style="color: #000">=</span><span style="color: #00f">"Make .jar file"</span>></span><br /> <span style="color: #c60"><delete <span style="color: #606">file</span><span style="color: #000">=</span><span style="color: #00f">"${backup.file}"</span> <span style="color: #606">failonerror</span><span style="color: #000">=</span><span style="color: #00f">"false"</span> /></span><br /> <span style="color: #c60"><delete <span style="color: #606">file</span><span style="color: #000">=</span><span style="color: #00f">"${release.file}"</span> <span style="color: #606">failonerror</span><span style="color: #000">=</span><span style="color: #00f">"false"</span> /></span><br /> <span style="color: #c60"><delete <span style="color: #606">file</span><span style="color: #000">=</span><span style="color: #00f">"${temp.file}"</span> <span style="color: #606">failonerror</span><span style="color: #000">=</span><span style="color: #00f">"false"</span> /></span><br /> <br /> <span style="color: #c60"><jar <span style="color: #606">duplicate</span><span style="color: #000">=</span><span style="color: #00f">"add"</span> <span style="color: #606">destfile</span><span style="color: #000">=</span><span style="color: #00f">"${backup.file}"</span> <span style="color: #606">compress</span><span style="color: #000">=</span><span style="color: #00f">"true"</span>></span><br /> <span style="color: #c60"><fileset <span style="color: #606">dir</span><span style="color: #000">=</span><span style="color: #00f">"bin"</span> <span style="color: #606">includes</span><span style="color: #000">=</span><span style="color: #00f">"**/*.class"</span> /></span><br /> <span style="color: #c60"><fileset <span style="color: #606">dir</span><span style="color: #000">=</span><span style="color: #00f">"src"</span> <span style="color: #606">includes</span><span style="color: #000">=</span><span style="color: #00f">"**/*.java"</span> /></span><br /> <span style="color: #c60"><fileset <span style="color: #606">dir</span><span style="color: #000">=</span><span style="color: #00f">"resource"</span> <span style="color: #606">includes</span><span style="color: #000">=</span><span style="color: #00f">"**/*"</span> /></span><br /> <span style="color: #c60"></jar></span><br /> <br /> <span style="color: #c60"><pack <span style="color: #606">classes</span><span style="color: #000">=</span><span style="color: #00f">"${robot.classname}"</span> <span style="color: #606">targetjar</span><span style="color: #000">=</span><span style="color: #00f">"${temp.file}"</span> <span style="color: #606">excludepkg</span><span style="color: #000">=</span><span style="color: #00f">"java,javax,sun,robocode"</span>></span><br /> <span style="color: #c60"><classpath <span style="color: #606">path</span><span style="color: #000">=</span><span style="color: #00f">"./bin"</span> /></span><br /> <span style="color: #c60"><classpath <span style="color: #606">location</span><span style="color: #000">=</span><span style="color: #00f">"${robocode.jar}"</span> /></span><br /> <span style="color: #c60"><additionalfileset <span style="color: #606">dir</span><span style="color: #000">=</span><span style="color: #00f">"resource"</span> <span style="color: #606">includes</span><span style="color: #000">=</span><span style="color: #00f">"**/*"</span> /></span><br /> <span style="color: #c60"></pack></span><br /> <br /> <span style="color: #090"><!-- Print codesize--></span><br /> <span style="color: #c60"><java <span style="color: #606">fork</span><span style="color: #000">=</span><span style="color: #00f">"yes"</span> <span style="color: #606">jar</span><span style="color: #000">=</span><span style="color: #00f">"${codesize.jar}"</span>></span><br /> <span style="color: #c60"><arg <span style="color: #606">value</span><span style="color: #000">=</span><span style="color: #00f">"${temp.file}"</span> /></span><br /> <span style="color: #c60"></java></span><br /> <br /> <span style="color: #090"><!-- Obfuscate release jar --></span><br /> <span style="color: #c60"><yguard></span><br /> <span style="color: #c60"><inoutpair <span style="color: #606">in</span><span style="color: #000">=</span><span style="color: #00f">"${temp.file}"</span> <span style="color: #606">out</span><span style="color: #000">=</span><span style="color: #00f">"${release.file}"</span> /></span><br /> <br /> <span style="color: #c60"><externalclasses></span><br /> <span style="color: #c60"><pathelement <span style="color: #606">location</span><span style="color: #000">=</span><span style="color: #00f">"${robocode.jar}"</span> /></span><br /> <span style="color: #c60"></externalclasses></span><br /> <br /> <span style="color: #c60"><rename <span style="color: #606">logfile</span><span style="color: #000">=</span><span style="color: #00f">"obfuscate.log"</span> <span style="color: #606">replaceclassnamestrings</span><span style="color: #000">=</span><span style="color: #00f">"true"</span>></span><br /> <br /> <span style="color: #c60"><property <span style="color: #606">name</span><span style="color: #000">=</span><span style="color: #00f">"overload-enabled"</span> <span style="color: #606">value</span><span style="color: #000">=</span><span style="color: #00f">"false"</span> /></span><br /> <span style="color: #c60"><property <span style="color: #606">name</span><span style="color: #000">=</span><span style="color: #00f">"naming-scheme"</span> <span style="color: #606">value</span><span style="color: #000">=</span><span style="color: #00f">"mix"</span> /></span><br /> <span style="color: #090"><!-- You may set this to 'compatible' instead --></span><br /> <span style="color: #c60"><property <span style="color: #606">name</span><span style="color: #000">=</span><span style="color: #00f">"language-conformity"</span> <span style="color: #606">value</span><span style="color: #000">=</span><span style="color: #00f">"illegal"</span> /></span><br /> <br /> <span style="color: #c60"><keep></span><br /> <span style="color: #c60"><class <span style="color: #606">name</span><span style="color: #000">=</span><span style="color: #00f">"${robot.classname}"</span> <span style="color: #606">methods</span><span style="color: #000">=</span><span style="color: #00f">"public"</span> <span style="color: #606">fields</span><span style="color: #000">=</span><span style="color: #00f">"none"</span> /></span><br /> <span style="color: #c60"></keep></span><br /> <span style="color: #c60"></rename></span><br /> <span style="color: #c60"></yguard></span><br /> <span style="color: #c60"></target></span><br /> <br /> <span style="color: #c60"><target <span style="color: #606">name</span><span style="color: #000">=</span><span style="color: #00f">"deploy"</span> <span style="color: #606">description</span><span style="color: #000">=</span><span style="color: #00f">"Deploy .jar file to robocode directory and make a backup"</span> <span style="color: #606">depends</span><span style="color: #000">=</span><span style="color: #00f">"buildjar"</span>></span><br /> <span style="color: #c60"><copy <span style="color: #606">file</span><span style="color: #000">=</span><span style="color: #00f">"${release.file}"</span> <span style="color: #606">overwrite</span><span style="color: #000">=</span><span style="color: #00f">"true"</span> <span style="color: #606">todir</span><span style="color: #000">=</span><span style="color: #00f">"${robocode.home}/robots"</span> /></span><br /> <span style="color: #c60"><copy <span style="color: #606">file</span><span style="color: #000">=</span><span style="color: #00f">"${backup.file}"</span> <span style="color: #606">overwrite</span><span style="color: #000">=</span><span style="color: #00f">"true"</span> <span style="color: #606">todir</span><span style="color: #000">=</span><span style="color: #00f">"./backups"</span> /></span><br /> <span style="color: #c60"></target></span><br /> <br /> <span style="color: #c60"><target <span style="color: #606">name</span><span style="color: #000">=</span><span style="color: #00f">"cleanup"</span> <span style="color: #606">description</span><span style="color: #000">=</span><span style="color: #00f">"Cleanup .jar in target directory"</span>></span><br /> <span style="color: #c60"><delete <span style="color: #606">file</span><span style="color: #000">=</span><span style="color: #00f">"${backup.file}"</span> <span style="color: #606">failonerror</span><span style="color: #000">=</span><span style="color: #00f">"false"</span> /></span><br /> <span style="color: #c60"><delete <span style="color: #606">file</span><span style="color: #000">=</span><span style="color: #00f">"${release.file}"</span> <span style="color: #606">failonerror</span><span style="color: #000">=</span><span style="color: #00f">"false"</span> /></span><br /> <span style="color: #c60"><delete <span style="color: #606">file</span><span style="color: #000">=</span><span style="color: #00f">"${temp.file}"</span> <span style="color: #606">failonerror</span><span style="color: #000">=</span><span style="color: #00f">"false"</span> /></span><br /> <span style="color: #c60"></target></span><br /> <br /> <span style="color: #c60"><target <span style="color: #606">name</span><span style="color: #000">=</span><span style="color: #00f">"build"</span> <span style="color: #606">depends</span><span style="color: #000">=</span><span style="color: #00f">"clean,deploy"</span> <span style="color: #606">description</span><span style="color: #000">=</span><span style="color: #00f">"Automatically build file and cleanup"</span>></target></span><br /> <span style="color: #c60"></project></span></span> |
− | < | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | < | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | </ |
Latest revision as of 05:30, 17 May 2009
Just start using ant recently. I now come up with my own ant build file base on two example files on the old wiki. Have fun!
Documentation
- Directory structure
- /bin - this will store all of classes files
- /src - this will store all of source files
- /resource - contain all the resources you want to include in .jar in the same structure
- /backups - contain each and every build of your code.
- Dependancies
- Pack task (http://sadun-util.sourceforge.net/pack.html)
- yGuard Obfuscator (http://www.yworks.com/en/products_yguard_about.htm)
- CodeSize version 1.0 (version 1.1 come with Robocode 1.7 doesn't have valid entry point)
- Configuration
- basedir - in <project> tag - must set to your working directory thatcontains the structure
- In task "init"
- robot.name - robot classname
- robot.package - robot package name
- robot.propertiesfile - path to property file to created
- ...
- Credit
Features
- Automatically packed only required file
- Deploy to robots folder automatically
- Automatically backup every builds.
- Obfuscate the JAR file so no one can take your code by decompiler.
- Very easy configuration (I think)
- Automatically pack resources if any.
Note that this build file create the closed-source robot, if you are open sources, you may have to edit it a bit to use the backup files instead (the backup file will include everything in your project). But for someone want to publish their source code but want to obfuscate the jar file too like me, you can use this build file and publish the source code through other context.
XML File
Because color make you memorization better by 72%, so... (but I can't disabled the auto line break TT)
<?xml version="1.0" encoding="utf-8" ?>
<!-- ======================================================
ANT build file
Nat Pavasant
======================================================
Directory structure:
- /bin - this will store all of classes files
- /src - this will store all of source files
- /resource - contain all the resources you want to include
in .jar in the same structure
- /backups - contain each and every build of your code.
Dependancies:
- Pack task (http://sadun-util.sourceforge.net/pack.html)
- yGuard Obfuscator (http://www.yworks.com/en/products_yguard_about.htm)
- CodeSize version 1.0 (version 1.1 come with robocode now doesn't have valid entry point)
Configuration:
- basedir - in <project> tag - must set to your working directory that
contains the structure
- In task 'init'
- robot.name - robot classname
- robot.package - robot package name
- robot.propertiesfile - path to property file to created
- ...
Credit:
- David Alves
- Hexkid
======================================================= -->
<project name="Robot" default="build" basedir=".">
<description>
Build File
</description>
<!-- define a task use in this build file -->
<taskdef name="yguard" classname="com.yworks.yguard.YGuardTask" classpath="./yguard.jar" />
<taskdef name="pack" classname="org.sadun.util.ant.Pack" classpath="./pack.jar" />
<!-- Initialize the config, all properties must be here -->
<target name="init" description="Initialize properties to build">
<tstamp>
<!-- configure time string use for backup version -->
<format property="timestamp" pattern="yyyyMMdHHmmss" locale="en,US" timezone="UTC" />
</tstamp>
<!-- Start configuration setting -->
<property name="robot.name" value="Your Robot Name" />
<property name="robot.package" value="Your Package Name" />
<!-- Set the path to your properties file inside .jar, please make sure
that the specific directory is available under ./resource/ directory -->
<property name="robot.propertiesfile" value="Your package name/${robot.name}.properties" />
<!-- Create the property file that describes this robot -->
<propertyfile file="resource/${robot.propertiesfile}">
<entry key="robot.description" value="" />
<entry key="robot.java.source.included" value="false" />
<entry key="robocode.version" value="1.7.1.2" />
<entry key="robot.version" value="0.1" />
<entry key="robot.author.name" value="Your Name" />
<entry key="robot.classname" value="${robot.package}.${robot.name}" />
</propertyfile>
<property file="resource/${robot.propertiesfile}" description="Use the entries from the properties file within this script." />
<property name="robocode.home" value="C:\robocode" />
<property name="robocode.jar" location="${robocode.home}/libs/robocode.jar" />
<property name="codesize.jar" location="./codesize.jar" />
<property name="class.path" value="./bin;${robocode.jar}" />
<property name="COMPILECLASSNAME" value="" />
<property name="COMPILE_WITH_DEBUG" value="off" />
<property name="VERBOSE_LEVEL" value="1" />
<property name="backup.file" location="target/${robot.name}_${robot.version}_${timestamp}.jar" />
<property name="release.file" location="target/${robot.classname}_${robot.version}.jar" />
<property name="temp.file" location="target/${robot.name}_temp.jar" />
</target>
<!-- Clean up the build -->
<target name="clean" depends="init" description="Remove the directories containing the classes and the jar file">
<delete dir="bin" />
<delete dir="target" />
</target>
<target name="prepare" depends="init" description="Create the generated directories">
<mkdir dir="bin" />
<mkdir dir="target" />
</target>
<target name="compile" depends="prepare" description="Compile the Java classes">
<javac srcdir="src" destdir="bin" classpath="${class.path}" debug="${COMPILE_WITH_DEBUG}" includes="**/*.java" />
</target>
<target name="buildjar" depends="compile" description="Make .jar file">
<delete file="${backup.file}" failonerror="false" />
<delete file="${release.file}" failonerror="false" />
<delete file="${temp.file}" failonerror="false" />
<jar duplicate="add" destfile="${backup.file}" compress="true">
<fileset dir="bin" includes="**/*.class" />
<fileset dir="src" includes="**/*.java" />
<fileset dir="resource" includes="**/*" />
</jar>
<pack classes="${robot.classname}" targetjar="${temp.file}" excludepkg="java,javax,sun,robocode">
<classpath path="./bin" />
<classpath location="${robocode.jar}" />
<additionalfileset dir="resource" includes="**/*" />
</pack>
<!-- Print codesize-->
<java fork="yes" jar="${codesize.jar}">
<arg value="${temp.file}" />
</java>
<!-- Obfuscate release jar -->
<yguard>
<inoutpair in="${temp.file}" out="${release.file}" />
<externalclasses>
<pathelement location="${robocode.jar}" />
</externalclasses>
<rename logfile="obfuscate.log" replaceclassnamestrings="true">
<property name="overload-enabled" value="false" />
<property name="naming-scheme" value="mix" />
<!-- You may set this to 'compatible' instead -->
<property name="language-conformity" value="illegal" />
<keep>
<class name="${robot.classname}" methods="public" fields="none" />
</keep>
</rename>
</yguard>
</target>
<target name="deploy" description="Deploy .jar file to robocode directory and make a backup" depends="buildjar">
<copy file="${release.file}" overwrite="true" todir="${robocode.home}/robots" />
<copy file="${backup.file}" overwrite="true" todir="./backups" />
</target>
<target name="cleanup" description="Cleanup .jar in target directory">
<delete file="${backup.file}" failonerror="false" />
<delete file="${release.file}" failonerror="false" />
<delete file="${temp.file}" failonerror="false" />
</target>
<target name="build" depends="clean,deploy" description="Automatically build file and cleanup"></target>
</project>