summaryrefslogtreecommitdiffstats
path: root/java/project/build.xml
blob: 9e73341d4ce38ce71386f516df75d4c91aafa717 (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
187
188
189
190
191
192
193
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:ivy="antlib:org.apache.ivy.ant"
         name="AntIvyJUnit"
         basedir="."
         default="test">

    <target name="configure">
        <property file="${basedir}/src/main/resources/Application.properties"/>
        <property name="build.dir"      value="${basedir}/build"/>
        <property name="dist.dir"       value="${basedir}/dist"/>
        <property name="doc.dir"        value="${basedir}/doc"/>

        <property name="main.dir"       value="${basedir}/src/main" />
        <property name="test.dir"       value="${basedir}/src/test" />
        <property name="src.dir"        value="${main.dir}/java" />
        <property name="resources.dir"  value="${main.dir}/resources"/>
        <property name="classes.dir"    value="${build.dir}/classes"/>

        <property name="class.main"     value="ch.asynk.Main"/>
        <property name="jar.name"       value="${dist.dir}/myjar-${app.version}"/>

        <property name="compile.debug"          value="true"/>
        <property name="compile.deprecation"    value="false"/>
        <property name="compile.optimize"       value="true"/>
        <property name="signatures.remove"      value="true"/>

        <path id="cp.build">
            <dirset dir="${classes.dir}" />
        </path>
        <path id="cp.resources">
            <dirset dir="${resources.dir}" />
        </path>
        <condition property="filter.sign.out">
            <istrue value="${signatures.remove}"/>
        </condition>

    </target>

    <target name="resolve" description="retrieve dependencies with Ivy">
        <ivy:resolve file="ivy.xml" log="download-only"/>
        <ivy:cachepath pathid="ivy.deps.compile" conf="compile" />
        <ivy:cachepath pathid="ivy.deps.runtime" conf="runtime" />
        <ivy:cachepath pathid="ivy.deps.test" conf="test" />
        <ivy:cachefileset setid="ivy.deps.runtime.fileset" conf="runtime"/>
    </target>

    <target name="ivy-report" depends="configure,resolve">
        <ivy:report conf="compile" organisation="ch.asynk" module="${app.name}"/>
        <ivy:report conf="runtime" organisation="ch.asynk" module="${app.name}"/>
        <ivy:report conf="test" organisation="ch.asynk" module="${app.name}"/>
    </target>

    <target name="clean" depends="configure" description="clean project">
        <delete dir="${build.dir}" />
        <delete dir="${dist.dir}" />
        <delete file="${app.logfile}" />
        <delete file="build.log" />
        <delete file="test.log" />
        <delete file="ivy-report.css" />
        <delete>
            <fileset dir="${basedir}" includes="ch.asynk-${app.name}-*"/>
        </delete>
    </target>

    <target name="ctags" depends="configure">
        <exec executable="ctags" failonerror="false">
            <arg value="-R"/>
            <arg value="--language-force=java"/>
            <arg value="-f.tags"/>
            <arg value="${src.dir}"/>
        </exec>
    </target>

    <target name="compile.main" depends="configure,resolve,ctags">
        <record name="build.log" loglevel="verbose" action="start" />
        <mkdir dir="${classes.dir}/main" />
        <javac srcdir="${src.dir}"
            destdir="${classes.dir}/main"
            debug="${compile.debug}"
            deprecation="${compile.deprecation}"
            optimize="${compile.optimize}"
            includeantruntime="false">
            <classpath refid="ivy.deps.compile"/>
            <compilerarg value="-Xlint:all"/>
            <compilerarg value="-Xlint:-path"/>
            <compilerarg value="-Xlint:-processing"/>
            <compilerarg value="-Xmaxerrs"/>
            <compilerarg value="10"/>
        </javac>
    </target>

    <target name="compile.test" depends="configure,resolve">
        <mkdir dir="${classes.dir}/test" />
        <javac srcdir="${test.dir}"
            destdir="${classes.dir}/test"
            debug="${compile.debug}"
            deprecation="${compile.deprecation}"
            optimize="${compile.optimize}"
            includeantruntime="false">
            <classpath refid="cp.build"/>
            <classpath refid="ivy.deps.compile"/>
            <compilerarg value="-Xlint:all"/>
            <compilerarg value="-Xlint:-path"/>
            <compilerarg value="-Xlint:-processing"/>
            <compilerarg value="-Xmaxerrs"/>
            <compilerarg value="10"/>
        </javac>
    </target>

    <target name="compile.all" depends="compile.main,compile.test"/>

    <target name="test" description="run JUnit tests" depends="compile.all">
        <junit fork="true" dir="${basedir}" failureProperty="test.failed" printsummary="yes" haltonfailure="no">
            <jvmarg value="-Xmx600M"/>
            <classpath refid="cp.build"/>
            <classpath refid="ivy.deps.test"/>
            <formatter type="plain" usefile="true" extension=".log"/>
            <test name = "ch.asynk.TestSuite" todir="." outfile="test"/>
        </junit>
        <fail message="-- FAILED --" if="test.failed" />
    </target>

    <target name="-jar.static" depends="compile.all">
        <manifestclasspath property="cp.manifest" jarfile="${jar.name}-static-cp.jar" maxParentLevels="10">
            <classpath refid="ivy.deps.runtime"/>
        </manifestclasspath>
        <jar jarfile="${jar.name}-static-cp.jar" basedir="${classes.dir}/main">
            <manifest>
                <attribute name="Main-Class" value="${class.main}"/>
                <attribute name="Class-Path" value="${cp.manifest}"/>
            </manifest>
            <fileset dir="${resources.dir}"/>
        </jar>
    </target>

    <target name="-jar.deps.check" unless="-jar.deps.exists">
        <available property="-jar.deps.exists" file="${jar.name}-deps.jar"/>
    </target>

    <target name="-jar.deps" unless="-jar.deps.exists">
        <jar jarfile="${jar.name}-deps.jar">
            <zipgroupfileset refid="ivy.deps.runtime.fileset"/>
        </jar>
    </target>

    <target name="-jar.fat.0" if="filter.sign.out" depends="compile.all,-jar.deps.check,-jar.deps">
        <jar jarfile="${jar.name}-fat.jar" basedir="${classes.dir}/main">
            <manifest>
                <attribute name="Main-Class" value="${class.main}"/>
                <attribute name="Class-Path" value="."/>
            </manifest>
            <fileset dir="${resources.dir}"/>
            <zipfileset src="${jar.name}-deps.jar" excludes="META-INF/*.SF" />
        </jar>
    </target>

    <target name="-jar.fat.1" unless="filter.sign.out" depends="compile.all">
        <jar jarfile="${jar.name}-fat.jar" basedir="${classes.dir}/main">
            <manifest>
                <attribute name="Main-Class" value="${class.main}"/>
                <attribute name="Class-Path" value="."/>
            </manifest>
            <fileset dir="${resources.dir}"/>
            <zipgroupfileset refid="ivy.deps.runtime.fileset"/>
        </jar>
    </target>

    <target name="-jar.fat" depends="-jar.fat.0,-jar.fat.1"/>

    <target name="-jar.src" depends="compile.all">
        <jar jarfile="${jar.name}-src.jar" basedir="${basedir}" excludes="build/** dist/** *.log .tags" />
    </target>

    <target name="-jar.dir" depends="configure">
        <mkdir dir="${dist.dir}" />
    </target>

    <target name="dist" description="generate the distribution" depends="-jar.dir,-jar.static,-jar.fat,-jar.src"/>

    <target name="run" description="execute built main Class" depends="compile.all">
        <java classname="${class.main}" fork="true">
            <classpath refid="cp.build"/>
            <classpath refid="cp.resources"/>
            <classpath refid="ivy.deps.runtime"/>
        </java>
    </target>

    <target name="run.jar" description="execute built jars" depends="dist">
        <java jar="${jar.name}-static-cp.jar" fork="true"/>
        <java jar="${jar.name}-fat.jar" fork="true"/>
    </target>

</project>