-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-lib.xml
218 lines (194 loc) · 6.84 KB
/
build-lib.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
210
211
212
213
214
215
216
217
218
<!-- build lib for web apps -->
<project name="build-lib" basedir=".">
<!-- generic build properties -->
<property file="build.properties"/>
<property name="version.props" value="version.properties"/>
<property file="${version.props}"/>
<!-- some properties are built from environment variables -->
<property environment="myenv"/>
<property name="java.build.root" value="${myenv.JAVA_BUILD_ROOT}"/>
<!-- build to different directory depending on env -->
<condition property="build.root" value="${java.build.root}/${webapp.name}" else=".">
<and>
<istrue value="${build.useextdir}"/>
<available file="${java.build.root}" type="dir"/>
</and>
</condition>
<!-- Set the uncustomizable properties -->
<property name="src.dir" value="src/main/java"/>
<property name="src.test.dir" value="src/test/java"/>
<property name="lib.dir" value="lib/main"/>
<property name="lib.provided.dir" value="lib/provided"/>
<property name="lib.build.dir" value="lib/build"/>
<property name="lib.test.dir" value="lib/test"/>
<property name="etc.dir" value="etc"/>
<property name="build.dir" value="${build.root}/build"/>
<property name="classes.dir" value="${build.dir}/classes"/>
<property name="classes.test.dir" value="${build.dir}/test-classes"/>
<property name="cobertura.dir" value="${build.dir}/cobertura"/>
<property name="instrumented.dir" value="${cobertura.dir}/instrumented"/>
<property name="cover.data.file" value="${cobertura.dir}/cobertura.ser"/>
<property name="cover.html.dir" value="${cobertura.dir}/html"/>
<property name="dist.dir" value="${build.root}/dist"/>
<property name="doc.dir" value="doc"/>
<property name="doc.dist.dir" value="${dist.dir}/doc"/>
<property name="javadoc.dir" value="${doc.dist.dir}/javadoc"/>
<property name="doc.pdf.dir" value="${doc.dist.dir}/pdf"/>
<!-- webapp properties -->
<property name="war.name" value="${webapp.name}.war"/>
<property name="webapp.dir" value="src/main/webapp"/>
<!-- The classpaths to be used to compile, test, etc -->
<path id="compile.classpath">
<fileset dir="${lib.dir}">
<include name="**/*.jar"/>
</fileset>
<fileset dir="${lib.provided.dir}">
<include name="**/*.jar"/>
</fileset>
</path>
<path id="app.classpath">
<path refid="compile.classpath"/>
<pathelement location="${classes.dir}"/>
</path>
<path id="test.classpath">
<path refid="app.classpath"/>
<fileset dir="${lib.test.dir}">
<include name="**/*.jar"/>
</fileset>
</path>
<path id="cobertura.classpath">
<path refid="compile.classpath"/>
<fileset dir="${lib.test.dir}/cobertura">
<include name="**/*.jar"/>
</fileset>
</path>
<taskdef classpathref="cobertura.classpath" resource="tasks.properties"/>
<path id="instrumented.classpath">
<pathelement location="${instrumented.dir}"/>
</path>
<!-- version: generate .X from .X.template -->
<macrodef name="versiongen">
<attribute name="basedir"/>
<attribute name="versionfile"/>
<sequential>
<dependset>
<srcfileset dir="@{basedir}">
<include name="@{versionfile}.template"/>
<include name="${version.props}"/>
</srcfileset>
<targetfileset dir="@{basedir}">
<include name="@{versionfile}"/>
</targetfileset>
</dependset>
<copy file="@{versionfile}.template" tofile="@{versionfile}">
<filterset>
<filtersfile file="${version.props}"/>
</filterset>
</copy>
</sequential>
</macrodef>
<!-- Default build target -->
<target name="init">
<mkdir dir="${classes.dir}"/>
<mkdir dir="${classes.test.dir}"/>
<mkdir dir="${dist.dir}"/>
<mkdir dir="${cover.html.dir}"/>
</target>
<target name="clean" description="Deletes all generated files">
<delete dir="${classes.dir}"/>
<delete dir="${build.dir}"/>
<delete dir="${dist.dir}"/>
</target>
<target name="webapp-version">
<versiongen basedir="." versionfile="${src.dir}/${webapp.versionfile}"/>
</target>
<target name="compile" depends="init, webapp-version">
<copy todir="${classes.dir}">
<fileset dir="${src.dir}">
<include name="**/*.properties"/>
</fileset>
</copy>
<javac srcdir="${src.dir}" destdir="${classes.dir}"
source="${javac.source}" target="${javac.target}"
debug="${javac.debug}" optimize="${javac.optimize}">
<classpath>
<path refid="compile.classpath"/>
</classpath>
</javac>
</target>
<target name="webapp" depends="compile">
<jar destfile="${dist.dir}/${war.name}">
<fileset dir="${webapp.dir}">
<include name="**/*"/>
</fileset>
<zipfileset dir="${lib.dir}" prefix="WEB-INF/lib"/>
<zipfileset dir="${classes.dir}" prefix="WEB-INF/classes"/>
<zipfileset dir="${src.dir}" prefix="WEB-INF/classes">
<include name="**/*.properties"/>
</zipfileset>
</jar>
</target>
<!-- Targets for testing -->
<target name="compile-test" description="Compiles the unittests" depends="init, compile">
<copy todir="${classes.test.dir}">
<fileset dir="${src.test.dir}">
<include name="**/*.xml"/>
</fileset>
</copy>
<javac srcdir="${src.test.dir}" destdir="${classes.test.dir}"
debug="${javac.debug}"
source="${javac.source}" target="${javac.target}">
<classpath>
<path refid="test.classpath"/>
</classpath>
</javac>
</target>
<target name="instrument" depends="init, compile">
<delete file="${cover.data.file}"/>
<delete dir="${instrumented.dir}" />
<cobertura-instrument datafile="${cover.data.file}" todir="${instrumented.dir}">
<!--
<ignore regex="org.apache.log4j.*" />
-->
<fileset dir="${classes.dir}">
<include name="**/*.class" />
</fileset>
</cobertura-instrument>
</target>
<target name="test" depends="compile-test">
<junit fork="on" forkmode="perBatch" haltonerror="true">
<sysproperty key="net.sourceforge.cobertura.datafile" file="${cover.data.file}"/>
<classpath>
<path refid="instrumented.classpath"/>
<path refid="test.classpath"/>
<pathelement location="${classes.test.dir}"/>
<path refid="cobertura.classpath"/>
</classpath>
<batchtest>
<fileset dir="${classes.test.dir}" includes="**/*Test.class"/>
<formatter type="brief" usefile="false"/>
</batchtest>
</junit>
</target>
<target name="coverage" depends="instrument, test">
<cobertura-report datafile="${cover.data.file}" destdir="${cover.html.dir}">
<fileset dir="${src.dir}">
<include name="**/*.java"/>
</fileset>
</cobertura-report>
</target>
<!-- Doc targets -->
<target name="javadoc">
<javadoc destdir="${javadoc.dir}"
access="public" author="true" nodeprecated="false"
nodeprecatedlist="false" noindex="false" nonavbar="false"
notree="false" splitindex="true" use="true" version="true">
<classpath>
<path refid="app.classpath"/>
</classpath>
<fileset dir="${src.dir}" defaultexcludes="yes">
<include name="**/*.java"/>
</fileset>
</javadoc>
</target>
</project>