RobertFischer / liquibase-dsl

A Groovy-based DSL for Liquibase (with a Perl driver)

This URL has Read+Write access

liquibase-dsl / build.xml
100644 228 lines (193 sloc) 9.475 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
<?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>