Skip to content

Instantly share code, notes, and snippets.

@DanielBoerlage
Created June 7, 2014 03:36
Show Gist options
  • Save DanielBoerlage/b5bb003e10ed93dcb8f4 to your computer and use it in GitHub Desktop.
Save DanielBoerlage/b5bb003e10ed93dcb8f4 to your computer and use it in GitHub Desktop.
build file for Implicit Plot
# Example build.properties file for the generic ant build file by Daniel Boerlage 2014 - version 0.1.0
# Most imortant to change this
backup.dir=C:/Users/Daniel/Desktop/code-backups/${ant.project.name}
# Change this if you dont want the automatic backup to compress your project files
backup.compress=true
src.dir=src
bin.dir=bin
res.dir=res
classes.dir=${bin.dir}/classes
jar.dir=${bin.dir}/jar
javadoc.dir=javadoc
main-class=implicitplot.Main
<project name="Implicit-Plotter" default="main" basedir=".">
<description>
A generic apache ant java build system by Daniel Boerlage 2014 - version 0.1.0
################
HOW TO USE:
################
[ant] > the main build tool; runs [clean] then [run]
[ant clean] > purges the binary directory
[ant compile] > compiles the .java files in the source directory and puts the .class files in the classes
directory, while maintaing the original source package structure
[ant jar] > runs [compile] then creates a java archive inside the jar directory that contains all of
the compiled .class files and the resource directory
[ant run] > runs [jar] then starts the java runtime environment with the jar file
[ant javadoc] > creates a javadoc inside the javadoc directory that uses all of the source code in the
source directory
[ant backup-clean] > purges the backup directory, with a warning
[ant backup] > creates a new directory inside the backup directory with all the project files except the
LICENSE. The name of the new directory is the current date and the daily revision number.
If the backup compress option is set to true, then it will make a tar.gz file rather than a
directory.
</description>
<property file="build.properties"/>
<target name="main" depends="clean,run" description="removes the binary directory, re-compiles and runs"/>
<target name="clean" description="removes the binary directory">
<delete dir="${bin.dir}"/>
</target>
<target name="compile" description="compiles the source code">
<mkdir dir="${classes.dir}"/>
<javac srcdir="${src.dir}" destdir="${classes.dir}" includeantruntime="false"/>
</target>
<target name="jar" depends="compile" description="creates a java archive of the binaries and the resource file">
<mkdir dir="${jar.dir}"/>
<jar destfile="${jar.dir}/${ant.project.name}.jar" basedir="${classes.dir}">
<manifest>
<attribute name="Main-Class" value="${main-class}"/>
</manifest>
<fileset dir="${res.dir}"/>
</jar>
</target>
<target name="run" depends="jar" description="runs the jar binary">
<java jar="${jar.dir}/${ant.project.name}.jar" fork="true"/>
</target>
<target name="javadoc" description="generates a javadoc">
<mkdir dir="${javadoc.dir}"/>
<javadoc sourcepath="${src.dir}" destdir="${javadoc.dir}"/>
</target>
<target name="backup-clean" depends ="confirm-purge" if="${confirmed}">
<delete dir="${backup.dir}"/>
</target>
<target name="confirm-purge">
<input message="Are you sure you would like to purge all the contents of the backup directory? (yes/no)" addproperty="answer"/>
<condition property="confirmed">
<equals arg1="${answer}" arg2="yes"/>
</condition>
</target>
<target name="backup" description="copies the project directory into a specified backup directory">
<tstamp>
<format property="date" pattern="yyyy.MM.dd"/>
</tstamp>
<mkdir dir="${backup.dir}"/>
<attrib file="${backup.dir}/revision.number" hidden="false" readonly="false"/>
<propertyfile file="${backup.dir}/revision.number" jdkproperties="true" comment=" Auto-generated ant file for ${ant.project.name}">
<entry key="last.date" type="string" default="never"/>
<entry key="revision.number" type="int" default="0"/>
</propertyfile>
<property file="${backup.dir}/revision.number"/>
<antcall target="update-revision"/>
<antcall target="copy-files" inheritAll="false"/>
<attrib file="${backup.dir}/revision.number" hidden="true" readonly="true"/>
</target>
<target name="copy-files" depends="normal-copy-files,compress-copy-files"/>
<target name="normal-copy-files" unless="${backup.compress}">
<property file="${backup.dir}/revision.number"/>
<mkdir dir="${backup.dir}/${last.date}-r${revision.number}"/>
<copy todir="${backup.dir}/${last.date}-r${revision.number}">
<fileset dir=".">
<exclude name="LICENSE"/>
</fileset>
</copy>
</target>
<target name="compress-copy-files" if="${backup.compress}">
<property file="${backup.dir}/revision.number"/>
<!--
<zip basedir="." destfile="${backup.dir}/${last.date}-r${revision.number}.zip" excludes="LICENSE" level="9"/>
-->
<tar basedir="." destfile="${backup.dir}/${last.date}-r${revision.number}.tar.gz" excludes="LICENSE" compression="gzip"/>
</target>
<target name="update-revision" depends="reset-revision,increment-revision"/>
<target name="reset-revision" depends="-check-for-same-date" unless="${same.date}">
<propertyfile file="${backup.dir}/revision.number" jdkproperties="true" comment=" Auto-generated ant file for ${ant.project.name}">
<entry key="last.date" type="string" value="${date}"/>
<entry key="revision.number" type="int" value="0"/>
</propertyfile>
</target>
<target name="increment-revision" depends="-check-for-same-date" if="${same.date}">
<propertyfile file="${backup.dir}/revision.number" jdkproperties="true" comment=" Auto-generated ant file for ${ant.project.name}">
<entry key="revision.number" type="int" default="0" operation="+"/>
</propertyfile>
</target>
<target name="-check-for-same-date">
<condition property="same.date">
<equals arg1="${date}" arg2="${last.date}"/>
</condition>
</target>
</project>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment