summaryrefslogtreecommitdiff
path: root/ant/build-common.xml
blob: d3a96be1178e45349fe4710ced399a5b9ff31783 (plain)
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
<project name="build-common"
    xmlns:ivy="antlib:org.apache.ivy.ant"
    xmlns:artifact="antlib:org.apache.maven.artifact.ant">

    <property name="src.dir" value="src" />
    <property name="test.dir" value="tst" />

    <property name="output.dir" value="build" />
    <property name="build.dir" value="${output.dir}/root" />
    <property name="output.testreport" value="${output.dir}/testreport" />
    <property name="output.coveragereport" value="${output.dir}/coverage" />

    <property name="build.classes" value="classes" />
    <property name="build.tests" value="tests" />
    <property name="lib.dir"   value="lib" />

    <property name="java.target.version" value="1.7" />
    <property name="compile.debug"       value="true" />
    <property name="compile.deprecation" value="false" />
    <property name="compile.optimize"    value="true" />

    <!-- CLASSPATHs -->
    <path id="classpath.build">
        <fileset dir="${lib.dir}" />
    </path>
    <path id="classpath.run">
        <path refid="classpath.build" />
        <path location="${build.dir}/${build.classes}" />
    </path>
    <path id="classpath.test">
        <path refid="classpath.run" />
        <path location="${build.dir}/${build.tests}" />
    </path>

    <taskdef classpathref="classpath.test" resource="tasks.properties" />

    <!-- Building/Running Targets -->

    <!-- Create the build directories -->
    <target name="prepare">
        <mkdir dir="${output.dir}" />
        <mkdir dir="${build.dir}" />
        <mkdir dir="${output.testreport}" />
        <mkdir dir="${output.coveragereport}" />
        <mkdir dir="${lib.dir}" />
        <mkdir dir="${build.dir}/${build.classes}" />
        <mkdir dir="${build.dir}/${build.tests}" />
    </target>

    <target name="build" depends="resolve,compile,test" description="Compile Project"/>

    <target name="compile" depends="prepare">
        <javac srcdir="${src.dir}"
            destdir="${build.dir}/${build.classes}"
            debug="${compile.debug}"
            deprecation="${compile.deprecation}"
            optimize="${compile.optimize}"
            source="${java.target.version}"
            target="${java.target.version}"
            classpathref="classpath.build" />

        <copy todir="${build.dir}/${build.classes}">
            <fileset dir="${src.dir}" excludes="**/*.java,**/*.swp"/>
        </copy>
    </target>

    <target name="compile-tests" depends="compile">
        <javac srcdir="${test.dir}"
            destdir="${build.dir}/${build.tests}"
            debug="${compile.debug}"
            deprecation="${compile.deprecation}"
            optimize="${compile.optimize}"
            source="${java.target.version}"
            target="${java.target.version}"
            classpathref="classpath.test" />

        <copy todir="${build.dir}/${build.tests}">
            <fileset dir="${test.dir}" excludes="**/*.java,**/*.swp"/>
        </copy>
    </target>

    <target name="test" depends="compile-tests">
        <junit printsummary="on"
               fork="on"
               dir="${build.dir}"
               failureproperty="tests.failed"
               showoutput="true">

            <classpath>
                <path refid="classpath.test" />
            </classpath>

            <formatter type="xml"/>

            <batchtest todir="${output.testreport}">
                <fileset dir="${test.dir}">
                    <include name="**/*Test.java" />
                </fileset>
            </batchtest>
        </junit>

        <junitreport todir="${output.testreport}">
            <fileset dir="${output.testreport}" includes="*.xml" />
            <report todir="${output.testreport}" />
        </junitreport>

        <fail message="TEST FAILURE" if="tests.failed" />
    </target>

    <target name="coverage" depends="compile-tests">
        <cobertura-instrument todir="${output.coveragereport}"
                              datafile="${output.coveragereport}/cobertura.ser">
            <fileset dir="${build.dir}/${build.classes}">
                <include name="**/*.class" />
            </fileset>
        </cobertura-instrument>

        <junit printsummary="on"
               fork="on"
               dir="${build.dir}"
               haltonfailure="true">

            <jvmarg value="-XX:-UseSplitVerifier" />

            <sysproperty key="net.sourceforge.cobertura.datafile"
                         file="${output.coveragereport}/cobertura.ser" />

            <classpath>
                <path location="${output.coveragereport}" />
                <path refid="classpath.test" />
            </classpath>

            <formatter type="xml"/>

            <batchtest todir="${output.coveragereport}">
                <fileset dir="${test.dir}">
                    <include name="**/*Test.java" />
                </fileset>
            </batchtest>
        </junit>

        <cobertura-report format="html"
                          datafile="${output.coveragereport}/cobertura.ser"
                          destdir="${output.coveragereport}"
                          srcdir="${src.dir}" />
    </target>

    <target name="run" depends="build" description="Run ${main.class}">
        <java classpathref="classpath.run" classname="${main.class}" />
    </target>

    <target name="clean" description="Clean Project">
        <delete includeemptydirs="true">
            <fileset dir="${basedir}">
                <include name="build/**" />
            </fileset>
        </delete>
    </target>

    <target name="jar" depends="build" description="Generate JAR">
        <jar destfile="${build.dir}/jars/${ant.project.name}.jar" basedir="${build.dir}/${build.classes}">
            <manifest>
                <attribute name="Main-Class" value="${main.class}"/>
            </manifest>
        </jar>
    </target>

    <available file=".git" type="dir" property="git.present"/>

    <target name="gitrevision" description="Store git revision in ${repository.version}" if="git.present">
        <exec executable="git" outputproperty="git.revision" failifexecutionfails="false" errorproperty="">
            <arg value="describe"/>
            <arg value="--tags"/>
            <arg value="--always"/>
            <arg value="--dirty"/>
        </exec>
        <condition property="repository.version" value="${git.revision}" else="unknown">
            <and>
                <isset property="git.revision"/>
                <length string="${git.revision}" trim="yes" length="0" when="greater"/>
            </and>
        </condition>
    </target>

    <import file="${jesterpm.buildtools.root}/ant/ivy-common.xml" />
</project>