-
Notifications
You must be signed in to change notification settings - Fork 5
/
build.xml
186 lines (158 loc) · 6.88 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
<?xml version="1.0" encoding="UTF-8"?>
<!-- A valid XML document requires a declaration as the first line. -->
<!-- The @encoding attribute is optional, but if specified it should be correct. -->
<!-- The root element of an Ant build file.
Valid attributes are @name, @default, and @basedir.
@name = This sets the ant.project.name property. (Optional)
We are skipping it here to set it later in the properties file.
@default = The default target. The name of the target to run if none are specified
on the command-line. (Optional)
We are using the meta-target 'all' for configurability.
@basedir = The base directory for all relative paths. (Optional)
-->
<project default="all" basedir=".">
<!-- Load the properties file containing the project-specific configuration. -->
<loadproperties srcFile="build.properties"/>
<property name="x-jarfile" location="${dist}/${ant.project.name}.jar"/>
<!-- Initialization target. -->
<target name="init">
<!-- Initialize the timestamp properties. -->
<tstamp/>
<!-- Make sure the src and lib directories exist. -->
<mkdir dir="${src}"/>
<mkdir dir="${test}"/>
<mkdir dir="${lib}"/>
<!-- Create the build directory. -->
<mkdir dir="${build}"/>
</target>
<!-- Meta-target. Just specifies the default target(s) when none is specified on the command-line. -->
<target name="all" depends="make-jar, test"/>
<!-- Distribute target. Here we prepare for distribution to a customer. -->
<target name="dist" depends="clean, make-jar, javadoc" />
<!-- Compile target. Here we compile the .java files to .class files. -->
<target name="compile" depends="init">
<!-- Call javac.
Compile the files in @srcdir and place the classes in @destdir.
@includeantruntime = Don't want Ant run-time libraries in the classpath.
@debug = Include debugging information in the .class files.
@debuglevel = Include line numbers, variable names, and lines of source.
-->
<javac srcdir="${src}"
destdir="${build}"
includeantruntime="false"
debug="${debug}"
debuglevel="${debuglevel}">
<!-- Include these libraries in the classpath. -->
<classpath>
<pathelement path="${libs}"/>
<fileset dir="${lib}">
<include name="**/*.jar"/>
</fileset>
</classpath>
</javac>
</target>
<!-- Compile the unit tests. -->
<target name="compile-tests" depends="compile">
<javac srcdir="${test}"
destdir="${build}"
includeantruntime="false"
debug="${debug}"
debuglevel="${debuglevel}">
<classpath>
<pathelement path="${build}"/>
<pathelement path="${junit.path}"/>
<pathelement path="${libs}"/>
<fileset dir="${lib}">
<include name="**/*.jar"/>
</fileset>
</classpath>
</javac>
</target>
<!-- Test target. Make sure all the unit tests pass. -->
<target name="test" depends="compile, compile-tests">
<junit fork="yes" haltonfailure="yes">
<classpath>
<pathelement path="${build}"/>
<pathelement path="${junit.path}"/>
<pathelement path="${libs}"/>
<fileset dir="${lib}">
<include name="**/*.jar"/>
</fileset>
</classpath>
<!-- Format and report the test results to the console. -->
<formatter type="plain" usefile="no"/>
<!-- Consider all classes named Test* to be unit tests and run them. -->
<batchtest>
<fileset dir="${test}">
<include name="**/Test*.java"/>
</fileset>
</batchtest>
</junit>
</target>
<!-- Make-jar target. Here we make the Jar file that will be distributed. -->
<target name="make-jar" depends="compile">
<!-- Create the distributable directory. -->
<mkdir dir="${dist}"/>
<!-- Create the lib sub directory for the third-party libraries we depend on. -->
<mkdir dir="${dist}/lib"/> <!-- this should be conditional on whether or not we have any libs -->
<!-- Copy the dependent libs to the lib folder.
@overwrite = Overwrite exiting (potentially older) versions.
@flatten = Don't create subdirectories in the @todir.
-->
<copy todir="${dist}/lib" overwrite="true" flatten="true">
<fileset dir="${lib}"/>
</copy>
<!-- Create a normalized Classpath to point to our libs -->
<pathconvert pathsep=" " property="x.classpath">
<fileset dir="${lib}"/>
<chainedmapper>
<flattenmapper/>
<globmapper from="*" to="lib/*"/>
</chainedmapper>
</pathconvert>
<!-- Create the Jar file for our project in the distributable directory. -->
<jar jarfile="${x-jarfile}">
<!-- Include compiled classes -->
<fileset dir="${build}"/>
<!-- Include source code, but exclude temporary editor files -->
<fileset dir="${src}" excludes="**/.*.swp **/*~"/>
<manifest>
<!-- Set's the Main class.
This is the class who's main() method will be called by default.
-->
<attribute name="Main-Class" value="${main}"/>
<!-- Set the Classpath to use when the Main-Class is executed. -->
<attribute name="Class-Path" value="${x.classpath} ${classpath}"/>
</manifest>
</jar>
</target>
<!-- Javadoc target. Generate the Javadoc for the project. -->
<target name="javadoc" depends="init">
<!-- Create the directory for the project's documentation. -->
<mkdir dir="${javadoc}"/>
<!-- Generate the Javadoc -->
<javadoc destdir="${javadoc}">
<fileset dir="${src}" excludes="**/.*.swp **/*~"/>
<classpath>
<pathelement path="${libs}"/>
<fileset dir="${lib}">
<include name="**/*.jar"/>
</fileset>
</classpath>
</javadoc>
</target>
<!-- Run target. Run the finished product. -->
<target name="run" depends="make-jar">
<!-- Run the compiled Jar file using the arguments and directory specified in the properties. -->
<java jar="${x-jarfile}"
args="${run.args}"
fork="true"
dir="${run.dir}"/>
</target>
<!-- Clean target. Clean up all the generated files and directories. -->
<target name="clean">
<delete dir="${javadoc}"/>
<delete dir="${dist}"/>
<delete dir="${build}"/>
</target>
</project>