-
Notifications
You must be signed in to change notification settings - Fork 40
/
build.xml
246 lines (226 loc) · 9.52 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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
<?xml version="1.0" encoding="UTF-8"?>
<project name="Mockey" default="compile" basedir=".">
<!-- =================================================================== -->
<!-- Base global properties for this build -->
<!-- =================================================================== -->
<property environment="env"/>
<property name="src.dir" location="src/java"/>
<property name="test.src.dir" value="src/test" />
<property name="webapp.dir" value="web"/>
<property name="lib.dir" value="${webapp.dir}/WEB-INF/lib"/>
<property name="build.dir" location="build"/>
<property name="etc.dir" location="etc"/>
<property name="one-jar-lib.dir" location="${etc.dir}/one-jar"/>
<property name="dist.dir" location="dist"/>
<!-- VERSION NUMBER should follow Semantic Versioning. http://semver.org/ -->
<property name="version.num" value="2.0"/>
<property name="classes.dir" location="${build.dir}/WEB-INF/classes"/>
<property name="test.classes.dir" value="${build.dir}/test/classes" />
<property name="test.report.dir" value="${build.dir}/report"/>
<path id="standard.classpath">
<fileset dir="${lib.dir}">
<include name="**/*.jar"/>
</fileset>
<fileset dir="${etc.dir}">
<include name="**/*.jar" />
</fileset>
<pathelement location="${classes.dir}"/>
</path>
<!-- Creates the build directories. -->
<target name="prepare">
<mkdir dir="${build.dir}"/>
<mkdir dir="${dist.dir}"/>
<mkdir dir="${classes.dir}"/>
<mkdir dir="${build.dir}/WEB-INF/lib"/>
<!-- This is a workaround to support Log4J management in Tomcat and Jetty implementations.-->
<copy todir="${webapp.dir}/WEB-INF/classes">
<fileset dir="${webapp.dir}/WEB-INF">
<include name="**/*.properties"/>
<include name="**/*.json"/>
</fileset>
</copy>
</target>
<!-- =================================================================== -->
<!-- Basic compile. -->
<!-- =================================================================== -->
<target name="compile" depends="prepare" description="Compiles all Java code">
<javac srcdir="${src.dir}" destdir="${classes.dir}" deprecation="on" classpathref="standard.classpath" debug="on"/>
<copy todir="${classes.dir}">
<fileset dir="${src.dir}">
<include name="**/*.properties"/>
<include name="**/*.xml"/>
</fileset>
</copy>
</target>
<!-- Remove all files created by the compile and tomcat-deploy target-->
<target name="clean">
<delete dir="bin"/>
<delete dir="${build.dir}"/>
<delete dir="${dist.dir}"/>
<delete dir="${env.CATALINA_HOME}/webapps/${ant.project.name}"/>
<delete file="${env.CATALINA_HOME}/webapps/${ant.project.name}.war"/>
<delete dir="${env.CATALINA_HOME}/work"/>
<delete dir="${webapp.dir}/WEB-INF/classes" />
</target>
<target name="one-jar" depends="webapp" description="Generates an executable jar file with the war file embedded">
<taskdef name="one-jar" classname="com.simontuffs.onejar.ant.OneJarTask" classpathref="standard.classpath" onerror="report"/>
<one-jar destfile="${dist.dir}/${ant.project.name}.jar" manifest="src/manifest.mf">
<main>
<!-- Construct main.jar from classes and source code -->
<fileset dir="${classes.dir}">
<include name="**/runner/*.class" />
<include name="**/centerkey/**/*.class" />
</fileset>
</main>
<lib>
<fileset dir="${one-jar-lib.dir}" >
<include name="*.jar" />
</fileset>
</lib>
<fileset dir="${dist.dir}">
<include name="*.war" />
</fileset>
</one-jar>
</target>
<!-- =================================================================== -->
<!-- Jars up file for distribution -->
<!-- =================================================================== -->
<target name="dist" depends="clean, build, webapp, create-jar" description="Builds an executable .jar file, e.g. 'java -jar Mockey.jar'">
<!-- Removing this WAR file; it was created for JETTY, not Tomcat useful. -->
<delete file="${dist.dir}/${ant.project.name}.war"/>
<echo message="Success! Now try this:"/>
<echo message=" >cd dist"/>
<echo message=" >java -jar Mockey.jar --help"/>
</target>
<!-- =================================================================== -->
<!-- Jars up a war file for application server -->
<!-- =================================================================== -->
<target name="webapptomcat" depends="compile" description="Builds a WAR file specific for Tomcat, non-precompiled JSPs, and places in a dist directory. ">
<property name="WEBINF" value="${webapp.dir}/WEB-INF"/>
<copy todir="${build.dir}">
<fileset dir="${webapp.dir}" />
</copy>
<copy todir="${build.dir}/WEB-INF">
<fileset dir="${webapp.dir}/WEB-INF">
<include name="**/*.properties"/>
<include name="**/*.xml"/>
</fileset>
</copy>
<copy todir="${build.dir}/WEB-INF/classes">
<fileset dir="${webapp.dir}/WEB-INF">
<include name="**/*.properties"/>
<include name="**/*.json"/>
</fileset>
</copy>
<war destfile="${dist.dir}/${ant.project.name}.war" webxml="${build.dir}/WEB-INF/web.xml">
<fileset dir="${webapp.dir}">
<exclude name="**/web.xml" />
</fileset>
<classes dir="${classes.dir}"/>
<lib dir="${lib.dir}"/>
</war>
</target>
<target name="webapp" depends="compile, jspc" description="Builds a WAR file with pre-compiled JSP pages for JETTY usage, and places in a dist directory. ">
<property name="WEBINF" value="${webapp.dir}/WEB-INF"/>
<copy todir="${build.dir}/WEB-INF">
<fileset dir="${webapp.dir}/WEB-INF">
<include name="**/*.properties"/>
<include name="**/*.xml"/>
</fileset>
</copy>
<copy todir="${build.dir}/WEB-INF/classes">
<fileset dir="${webapp.dir}/WEB-INF">
<include name="**/*.properties"/>
<include name="**/*.json"/>
</fileset>
</copy>
<war destfile="${dist.dir}/${ant.project.name}.war" webxml="${build.dir}/WEB-INF/web.xml">
<fileset dir="${webapp.dir}">
<exclude name="**/web.xml" />
<exclude name="**/*.jsp" />
</fileset>
<classes dir="${classes.dir}"/>
<lib dir="${lib.dir}"/>
</war>
</target>
<!-- =================================================================== -->
<!-- Runs TestNG tests -->
<!-- =================================================================== -->
<target name="compile-test" depends="compile" description="Compile Test Classes">
<mkdir dir="${test.classes.dir}" />
<javac srcdir="${test.src.dir}" destdir="${test.classes.dir}" deprecation="on" classpathref="standard.classpath" debug="on"/>
<copy todir="${classes.dir}">
<fileset dir="${src.dir}">
<include name="**/*.properties"/>
<include name="**/*.xml"/>
</fileset>
</copy>
</target>
<target name="test" depends="compile-test" description="Run TestNG">
<taskdef resource="testngtasks" classpath="etc/testng.jar" />
<testng outputdir="${test.report.dir}" haltonfailure="true">
<classpath >
<pathelement location="${test.classes.dir}" />
<pathelement location="${classes.dir}" />
<path refid="standard.classpath" />
</classpath>
<classfileset dir="${test.classes.dir}" includes="**/*.class" />
</testng>
</target>
<target name="build" depends="compile, jspc, test" description="Build the whole app and test it" />
<target name="build-in-place" depends="compile" description="Build app into the webapp src dir">
<copy todir="${webapp.dir}/WEB-INF/classes">
<fileset dir="${classes.dir}" />
</copy>
</target>
<target name="jspc" depends="compile">
<taskdef classname="org.apache.jasper.JspC" name="jasper">
<classpath>
<pathelement location="${java.home}/../lib/tools.jar" />
<path refid="standard.classpath" />
</classpath>
</taskdef>
<!-- this is lame, but i can't find any way to not get jasper to modify the web.xml in place -->
<property name="tmp.webapp.dir" value="${build.dir}/tmp.web" />
<copy todir="${tmp.webapp.dir}">
<fileset dir="${webapp.dir}" />
</copy>
<jasper
validateXml="false"
addwebxmlmappings="true"
uriroot="${tmp.webapp.dir}"
webXmlFragment="${build.dir}/WEB-INF/generated_web.xml"
outputDir="${build.dir}/jsp"
package="com.mockey.jsp"
/>
<javac srcdir="${build.dir}/jsp" destdir="${classes.dir}" deprecation="on" classpathref="standard.classpath" debug="on"/>
<copy todir="${build.dir}/WEB-INF" file="${tmp.webapp.dir}/WEB-INF/web.xml" />
</target>
<target name="create-jar">
<!-- Will clean up the hard-coded paths, just want to see what needs to be included -->
<mkdir dir="build/jar" />
<unzip dest="build/jar" overwrite="false">
<fileset dir="etc/one-jar" />
<fileset dir="web/WEB-INF/lib" />
</unzip>
<buildnumber file="build.num"/>
<jar destfile="dist/Mockey.jar">
<manifest>
<attribute name="Main-Class" value="com.mockey.runner.JettyRunner"/>
<attribute name="Implementation-Version" value="${version.num}.${build.number}"/>
</manifest>
<fileset dir="build/jar">
<exclude name="MANIFEST.MF" />
<exclude name="**/*.SF" />
</fileset>
<fileset dir="build/WEB-INF/classes" />
<fileset dir="build">
<include name="WEB-INF/*" />
</fileset>
<fileset dir="web">
<exclude name="WEB-INF/**" />
<exclude name="**/*.jsp" />
</fileset>
</jar>
</target>
</project>