<?xml version="1.0" encoding="ISO-8859-1"?>
<project name="Liquibase-DSL" basedir="." default="help" xmlns:ivy="antlib:org.apache.ivy.ant">
<property environment="env"/><!-- pulls in environment variables -->
<!-- allows custom values for all properties -->
<property name="build.properties" value="${basedir}/build.properties"/>
<property file="${build.properties}"/>
<!-- "public" properties -->
<property name="tmp.dir" value="${basedir}/buildtmp"/><!-- temp dir for build artifacts-->
<property name="src.dir" value="${basedir}/src"/><!-- groovy and java sources -->
<property name="tests.dir" value="${basedir}/test"/><!-- groovy and java tests -->
<property name="ivy.dep.file" value="${basedir}/dependencies.xml"/><!-- ivy dependencies file -->
<property name="ivy.dep.conf" value="default"/>
<property name="lib.groovy.dir" value="${env.GROOVY_HOME}/lib"/><!-- lib dir of Groovy installation -->
<property name="lib.custom.dir" value="${basedir}/lib"/><!-- directory for custom libs -->
<property name="jar.file" value="${basedir}/lbdsl.jar"/><!-- location of resulting jar file -->
<!-- "private" or internal properties -->
<property name="-ivy.basedir" value="${tmp.dir}/ivy"/>
<property name="-ivy.dest.file" value="${-ivy.basedir}/ivy.jar"/>
<property name="-ivy.cachedir" value="${-ivy.basedir}/cache"/>
<property name="-ivy.repourl" value="http://repo1.maven.org/maven2/"/>
<property name="-ivy.version" value="2.0.0-rc2"/>
<property name="-ivy.jarurl" value="${-ivy.repourl}/org/apache/ivy/ivy/${-ivy.version}/ivy-${-ivy.version}.jar"/>
<available property="-ivy.available" file="${-ivy.dest.file}"/>
<condition property="-use.ivy">
<or>
<istrue value="${use.ivy}"/>
<not><available file="${lib.groovy.dir}" type="dir"/></not>
<not><available file="${lib.custom.dir}" type="dir"/></not>
</or>
</condition>
<!-- "public" targets -->
<target name="build" depends="-prepare, test, jar"/>
<target name="jar"
depends="-prepare, -compile"
description="creates the liquibase-dsl jar">
<jar jarfile="${jar.file}" index="true">
<manifest>
<attribute name="Built-By" value="${user.name}"/>
<attribute name="Implementation-Vendor" value="http://github.com/Argelbargel/"/>
<attribute name="Implementation-URL" value="http://github.com/Argelbargel/liquibase-dsl/"/>
<attribute name="Implementation-Title" value="${ant.project.name}"/>
</manifest>
<fileset dir="${tmp.dir}/classes"/>
</jar>
</target>
<target name="test"
depends="-prepare, -compile, -compile.tests"
description="compiles and tests the liquibase-dsl">
<mkdir dir="${tmp.dir}/test-results"/>
<echo message="running tests from ${tests.dir}"/>
<junit showoutput="true" fork="true"
dir="${basedir}" forkmode="once"
failureproperty="tests.failed"
errorproperty="tests.failed">
<batchtest todir="${tmp.dir}/test-results">
<fileset dir="${tmp.dir}/tests" includes="**/*Test.class"/>
</batchtest>
<classpath>
<path refid="-classpath"/>
<path location="${tmp.dir}/classes"/>
<path location="${tmp.dir}/tests"/>
</classpath>
<formatter usefile="false" type="brief"/>
<formatter type="xml"/>
</junit>
<fail message="Some tests failed or had errors" if="${tests.failed}"/>
</target>
<target name="clean"
depends="-ivy.clean"
description="removes all artifacts created by the build">
<delete file="${jar.file}"/>
<delete dir="${tmp.dir}"
includeemptydirs="true"
quiet="true"/>
</target>
<target name="help" description="shows the help from BUILD.txt">
<loadfile property="-help.txt" srcfile="BUILD.txt"/>
<echo>${-help.txt}</echo>
</target>
<!-- internal targets -->
<target name="-compile.tests"
depends="-prepare, -compile, -taskdef.groovyc"
description="compiles the tests of the liquibase-dsl">
<delete dir="${tmp.dir}/tests"/><!-- delete dest dir to ensure java-files get recompiled -->
<mkdir dir="${tmp.dir}/tests"/>
<!--
IMPORTANT: MUST fork <groovyc> and <javac> MUST NOT have target-
attributes or build fails. Whatever. It works ;-)
-->
<groovyc srcdir="${tests.dir}" destdir="${tmp.dir}/tests" fork="true">
<classpath>
<path refid="-classpath"/>
<path location="${tmp.dir}/classes"/>
</classpath>
<javac/>
</groovyc>
</target>
<target name="-compile"
depends="-prepare, -taskdef.groovyc"
description="compiles the sources of the liquibase-dsl">
<delete dir="${tmp.dir}/classes"/><!-- delete dest dir to ensure java-files get recompiled -->
<mkdir dir="${tmp.dir}/classes"/>
<echo message="Compiling sources from ${src.dir}..."/>
<!--
IMPORTANT: MUST fork <groovyc> and <javac> MUST NOT have target-
attributes or build fails. Whatever. It works ;-)
-->
<groovyc srcdir="${src.dir}" destdir="${tmp.dir}/classes" fork="true">
<classpath refid="-classpath"/>
<javac/>
</groovyc>
</target>
<target name="-prepare"
depends="-banner, -classpath.local, -classpath.ivy"
description="prepares the build"/>
<target name="-banner">
<echo>
====================================================================
Building ${ant.project.name} with following settings:
----------------------------------------------------------------
build properties: ${build.properties}
use ivy: ${-use.ivy}
ivy dependencies: ${ivy.dep.conf} in ${ivy.dep.file}
groovy libraries: ${lib.groovy.dir}
additional libs: ${lib.custom.dir}
lbdsl file path: ${jar.file}
------------------------------------------------------------
source directory ${src.dir}
tests directory ${tests.dir}
====================================================================
</echo>
</target>
<target name="-classpath.local"
unless="-use.ivy"
description="sets the classpath to the libraries in groovy-installation and custom lib dir">
<echo message="setting classpath for existing groovy-installation and custom lib dir..."/>
<path id="-classpath">
<fileset dir="${lib.groovy.dir}">
<include name="**/*.jar"/>
</fileset>
<fileset dir="${lib.custom.dir}">
<include name="**/*.jar"/>
</fileset>
</path>
<property name="-classpath.debug" refid="-classpath"/>
<echo level="verbose" message="classpath set to ${-classpath.debug}"/>
</target>
<target name="-classpath.ivy"
depends="-ivy.taskdef"
if="-use.ivy"
description="retrieves dependencies with ivy and sets classpath accordingly">
<echo message="setting classpath to dependencies retrieved via ivy..."/>
<mkdir dir="${-ivy.cachedir}"/>
<ivy:retrieve file="${ivy.dep.file}"
conf="${ivy.dep.conf}"
pattern="${-ivy.cachedir}/[artifact](-[classifier]).[ext]"/>
<path id="-classpath">
<fileset dir="${-ivy.cachedir}">
<include name="**/*.jar"/>
</fileset>
</path>
<property name="-classpath.debug" refid="-classpath"/>
<echo level="verbose" message="classpath set to ${-classpath.debug}"/>
</target>
<target name="-taskdef.groovyc" depends="-prepare">
<taskdef name="groovyc"
classname="org.codehaus.groovy.ant.Groovyc"
classpathref="-classpath" onerror="failall"/>
</target>
<!-- internal targets for dependency-handling via ivy -->
<target name="-ivy.taskdef"
depends="-ivy.download"
if="-use.ivy"
description="enables ivy's ant-tasks">
<taskdef resource="org/apache/ivy/ant/antlib.xml" uri="antlib:org.apache.ivy.ant" classpath="${-ivy.dest.file}" onerror="failall"/>
</target>
<target name="-ivy.download"
if="-use.ivy"
unless="-ivy.available"
description="downloads the jar file with the ivy binary distribution">
<mkdir dir="${-ivy.basedir}"/>
<echo message="downloading ivy from ${-ivy.jarurl}..."/>
<get src="${-ivy.jarurl}" dest="${-ivy.dest.file}" usetimestamp="true"/>
</target>
<target name="-ivy.clean"
if="-use.ivy"
description="cleans the ivy cache and deletes ivy's cache-dir">
<delete file="${-ivy.dest.file}" quiet="false"/>
<delete dir="${-ivy.cachedir}}"
includeemptydirs="true"
quiet="false"/>
</target>
</project>