-
Notifications
You must be signed in to change notification settings - Fork 5
/
build.xml
209 lines (186 loc) · 8.27 KB
/
build.xml
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
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- This is the default Apache Ant build file for javafpe. It contains all the targets required to clean, build, test and package javafpe, with
all it's publishable artifacts (including javadoc and source distributions). -->
<project basedir="." default="all" name="javafpe" xmlns:ivy="antlib:org.apache.ivy.ant">
<property environment="env" />
<path id="ivy.lib.path">
<fileset dir="${env.IVY_HOME}" includes="*.jar" />
</path>
<taskdef resource="org/apache/ivy/ant/antlib.xml" uri="antlib:org.apache.ivy.ant" classpathref="ivy.lib.path" />
<property name="junit.output.dir" value="junit" />
<property name="debuglevel" value="source,lines,vars" />
<!-- Target is Java 8 as HMAC(SHA-256) impleemntation only ships with Java 8, you can relax this
if you want to use BouncyCastle or another provider. -->
<property name="target" value="1.8" />
<property name="source" value="1.8" />
<property name="lib" value="lib" />
<property name="dist" value="dist" />
<path id="JUnit 4.libraryclasspath">
<fileset dir="${lib}">
<include name="junit-4.11.jar" />
<include name="hamcrest-core-1.3.jar" />
</fileset>
</path>
<!-- The classpath to build javafpe against -->
<path id="javafpe.build.classpath">
<fileset dir="${lib}">
<include name="slf4j-api-1.7.14.jar" />
</fileset>
<path refid="JUnit 4.libraryclasspath" />
</path>
<!-- The classpath required to execute javafpe -->
<path id="javafpe.execute.classpath">
<!-- Make sure that you include ALL jar files, otherwise we're taking responsibility for knowing
all the transitive dependendies of Jars we depend on. -->
<fileset dir="${lib}">
<include name="**/*.jar" />
</fileset>
<!-- Don't forget to include our own bin directory -->
<pathelement location="bin" />
</path>
<target name="resolve" description="Retrieve dependencies with ivy">
<ivy:retrieve sync="true" />
</target>
<!-- Cleaning targets -->
<target name="clean" description="Deletes all the built artifacts">
<delete dir="bin" />
<delete dir="testbin" />
<delete dir="javadoc" />
<delete dir="${dist}" />
<delete dir="${lib}" />
</target>
<target name="clean-ivy" description="Deletes the dependencies downloaded by Ivy">
<delete dir="${lib}" />
</target>
<target name="clean-junit" description="Deletes all JUnit outputs">
<delete dir="${junit.output.dir}" />
</target>
<target name="clean-jar" description="Deletes all built jar artifacts">
<delete file="${dist}/javafpe.jar" />
</target>
<target depends="clean, clean-ivy, clean-junit,clean-jar" name="clean-all" description="Deletes all built artifacts and downloaded dependencies" />
<target depends="resolve" name="build" description="Compile all the sources that make up javafpe (not tests)">
<echo message="${ant.project.name}: ${ant.file}" />
<mkdir dir="bin" />
<!-- Copy all the non-compiled resources from the source directory to bin -->
<copy includeemptydirs="false" todir="bin">
<fileset dir="src">
<exclude name="**/*.java" />
</fileset>
</copy>
<javac debug="true" debuglevel="${debuglevel}" destdir="bin" includeantruntime="false" source="${source}" target="${target}">
<src path="src" />
<classpath refid="javafpe.build.classpath" />
</javac>
</target>
<target depends="resolve" name="build-tests" description="Compile all the test sources">
<echo message="${ant.project.name}: ${ant.file}" />
<mkdir dir="testbin" />
<!-- Copy all the non-compiled resources from the source directory to bin -->
<copy includeemptydirs="false" todir="testbin">
<fileset dir="testsrc">
<exclude name="**/*.java" />
</fileset>
</copy>
<javac debug="true" debuglevel="${debuglevel}" destdir="testbin" includeantruntime="false" source="${source}" target="${target}">
<src path="testsrc" />
<classpath>
<path refid="javafpe.build.classpath" />
<pathelement location="bin" />
</classpath>
</javac>
</target>
<target name="test" depends="build, build-tests" description="Run all the unit tests">
<mkdir dir="${junit.output.dir}" />
<junit fork="yes" printsummary="withOutAndErr">
<formatter type="xml" />
<batchtest todir="${junit.output.dir}">
<fileset dir="testbin">
<include name="**/*Test.class" />
</fileset>
</batchtest>
<jvmarg value="-Dlogback.configurationFile="src/logback.xml"" />
<classpath>
<path refid="javafpe.execute.classpath" />
<pathelement location="bin" />
<pathelement location="testbin" />
</classpath>
</junit>
</target>
<target name="junit-report" depends="test" description="Creates a pretty Junit execution report">
<junitreport todir="${junit.output.dir}">
<fileset dir="${junit.output.dir}">
<include name="TEST-*.xml" />
</fileset>
<report format="frames" todir="${junit.output.dir}" />
</junitreport>
</target>
<target name="build-jar" description="Create runnable jar which requires external dependencies in a lib subdirectory" depends="build, update-build.properties">
<!-- convert classpath to a flat list/string for use in manifest task -->
<pathconvert property="mf.classpath" pathsep=" ">
<path refid="javafpe.execute.classpath" />
<mapper>
<chainedmapper>
<flattenmapper />
<globmapper from="*" to="lib/*" />
</chainedmapper>
</mapper>
</pathconvert>
<tstamp />
<jar destfile="${dist}/javafpe-${version}.jar">
<manifest>
<attribute name="Class-Path" value="${mf.classpath}" />
</manifest>
<fileset dir="bin" excludes="**/logback-test.xml" />
</jar>
</target>
<target name="build-javadoc" depends="resolve, create-properties" description="Build javadoc for all the source code except tests">
<javadoc sourcepath="src" access="private" destdir="javadoc" packagenames="javafpe.*" author="true" version="true" use="true" overview="src/overview.html" windowtitle="javafpe ${version}">
<classpath refid="javafpe.execute.classpath" />
<bottom>
<i>Copyright © 2016 Worldpay Ltd. All Rights Reserved.
</bottom>
</javadoc>
<jar destfile="${dist}/javafpe-${version}-javadoc.jar" basedir="javadoc" />
</target>
<target name="create-properties" description="Sets the values up for properties used in the build (current timestamp and Git information (latest tag is version number and latest commit hash)">
<!-- Determine how to run Git, Windows is git.exe, non-Windows is git. -->
<condition property="gitExecutable" value="git.exe">
<os family="windows"/>
</condition>
<property name="gitExecutable" value="git"/>
<!-- Get the short commit hash from Git -->
<exec executable="${gitExecutable}" outputproperty="commitHash">
<arg value="log" />
<arg value="-1" />
<arg value="--pretty=format:%h" />
</exec>
<echo message="Latest commit hash: ${commitHash}" />
<!-- Get the latest tag name, which is used as the version number of the build product -->
<exec executable="${gitExecutable}" outputproperty="version">
<arg value="describe" />
<arg value="--abbrev=0" />
<arg value="--tags" />
</exec>
<echo message="Version: ${version}" />
<!-- Get the current date and time as the build timestamp -->
<tstamp>
<format property="buildTimeStamp" pattern="yyyy-MM-dd HH:mm:ss" />
</tstamp>
<echo message="Build Timestamp ${buildTimeStamp}" />
</target>
<target name="update-build.properties" description="Updates or creates the file src/META-INF/build.properties which contains information used by the packaged program to track version." depends="create-properties">
<mkdir dir="src/META-INF"/>
<property name="propsFile" value="src/META-INF/build.properties" />
<propertyfile file="${propsFile}" comment="Created dynamically by Ant in build.xml update-version-properties task">
<entry key="CommitHash" value="${commitHash}" />
<entry key="Version" value="${version}" />
<entry key="BuildTimeStamp" value="${buildTimeStamp}" />
</propertyfile>
</target>
<target name="build-src-jar" depends="update-build.properties" description="Builds main code and test code source jars">
<jar destfile="${dist}/javafpe-${version}-sources.jar" basedir="src" />
<jar destfile="${dist}/javafpe-${version}-test-sources.jar" basedir="src" />
</target>
<target name="all" depends="build-jar, build-javadoc, build-src-jar, test, junit-report" description="Build, package everything and run unit tests" />
</project>