forked from clafonta/Mockey
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.xml
299 lines (267 loc) · 11.9 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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
<?xml version="1.0" encoding="UTF-8"?>
<project name="Mockey" default="compile" basedir="." xmlns:dn="antlib:org.apache.ant.dotnet">
<!-- =================================================================== -->
<!-- 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"/>
<property name="version.num" value="1.3"/>
<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"/>
</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" />
<mkdir dir="${webapp.dir}/WEB-INF/classes"/>
<!-- 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"/>
</fileset>
</copy>
</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 a .war and executable .jar file, e.g. 'java -jar Mockey.jar'">
<zip destfile="${dist.dir}/${ant.project.name}-${version.num}_with_dependencies.zip">
<fileset dir="${dist.dir}" includes="${ant.project.name}.war"/>
</zip>
<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="webapp" depends="compile, jspc" description="Builds a WAR file 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"/>
</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}"/>
<!-- Putting these jars in WEB-INF/lib (instead of 'etc') breaks Eclipse Tomcat debug plugin, -->
<!-- but are needed for compiled JSPs for a .war file. -->
<lib dir="${etc.dir}">
<include name="jsp-api-2.1-glassfish-9.1.1.B60.25.p2.jar"/>
<include name="jsp-2.1-glassfish-9.1.1.B60.25.p2.jar"/>
</lib>
</war>
</target>
<!-- =================================================================== -->
<!-- Deploys to Tomcat -->
<!-- =================================================================== -->
<target name="tomcat" depends="webapp" description="Deploys to Tomcat's webapp directory. Be sure to set env home for Tomcat as CATALINA_HOME.">
<copy file="${dist.dir}/${ant.project.name}.war" todir="${env.CATALINA_HOME}/webapps"/>
</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="tomcat-update" depends="compile">
<javac srcdir="src"
destdir="webapp/WEB-INF/classes" deprecation="on"
classpathref="standard.classpath" debug="on"
/>
<copy todir="webapp/WEB-INF/classes">
<fileset dir="src">
<include name="**/*.properties"/>
<include name="**/*.xml"/>
</fileset>
</copy>
<antcall target="_tomcat-reload" inheritall="true"/>
</target>
<!-- Based on \apache-tomcat-6.0.20 -->
<target name="_tomcat-reload">
<taskdef name="tomcatreload" classname="org.apache.catalina.ant.ReloadTask">
<classpath>
<fileset dir="${env.CATALINA_HOME}/lib">
<include name="*.jar"/>
</fileset>
</classpath>
</taskdef>
<tomcatreload url="http://localhost:8080/manager" path="/rulesengine"
username="tomcat" password="tomcat"/>
</target>
<target name="_tomcat-check">
<available file="${env.CATALINA_HOME}" property="tomcat-dir-avail"/>
<fail unless="tomcat-dir-avail"
message="Missing tomcat 5 directory or 'CATALINA_HOME' is not set correctly!"/>
</target>
<target name="windows-deps" depends="dist">
<mkdir dir="${dist.dir}\win32service" />
<copy file="${etc.dir}/one-jar/jetty-runner.jar"
todir="${basedir}\windows\MockeyWin32Service\MockeyWin32Runner\resources\"/>
<copy file="${etc.dir}/one-jar/jsp-api.jar"
todir="${basedir}\windows\MockeyWin32Service\MockeyWin32Runner\resources\"/>
<copy file="${etc.dir}/one-jar/servlet-api.jar"
todir="${basedir}\windows\MockeyWin32Service\MockeyWin32Runner\resources\"/>
<copy file="${dist.dir}\${ant.project.name}.war"
todir="${basedir}\windows\MockeyWin32Service\MockeyWin32Runner\resources\"/>
<jar destfile="${basedir}\windows\MockeyWin32Service\MockeyWin32Runner\resources\MockeyBooter.jar">
<fileset dir="${build.dir}/WEB-INF/classes" includes="**/runner/**" />
</jar>
</target>
<target name="windows-service" depends="">
<taskdef resource="org/apache/ant/dotnet/antlib.xml">
<classpath>
<pathelement location="etc/ant-dotnet-1.0.jar"/>
</classpath>
</taskdef>
<msbuild>
<build>
<MSBuild Projects="${basedir}\windows\MockeyWin32Service\MockeyWin32Service.sln"
xmlns="http://schemas.microsoft.com/developer/msbuild/2003"/>
</build>
</msbuild>
</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>
<jar destfile="dist/Mockey.jar">
<manifest>
<attribute name="Main-Class" value="com.mockey.runner.JettyRunner"/>
</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>