1<?xml version="1.0"?>
2<!--
3  Licensed to the Apache Software Foundation (ASF) under one or more
4  contributor license agreements.  See the NOTICE file distributed with
5  this work for additional information regarding copyright ownership.
6  The ASF licenses this file to You under the Apache License, Version 2.0
7  (the "License"); you may not use this file except in compliance with
8  the License.  You may obtain a copy of the License at
9
10      http://www.apache.org/licenses/LICENSE-2.0
11
12  Unless required by applicable law or agreed to in writing, software
13  distributed under the License is distributed on an "AS IS" BASIS,
14  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  See the License for the specific language governing permissions and
16  limitations under the License.
17-->
18<!-- Build file for Tomcat Native -->
19<project name="Tomcat Native" default="compile" basedir=".">
20    <!-- Give user a chance to override without editing this file
21        (and without typing -D each time it compiles it
22    -->
23    <property file="${user.home}/.ant.properties" />
24    <property file="${user.home}/build.properties" />
25    <property file=".ant.properties" />
26    <property file="build.properties" />
27    <property file="build.properties.default"/>
28
29    <!-- Initialization properties -->
30    <property name="project"               value="tomcat-native" />
31    <property name="name"                  value="Tomcat Native" />
32    <property name="title"                 value="Tomcat Native Library"/>
33    <property name="year"                  value="2020" />
34
35    <property name="test.runner"           value="junit.textui.TestRunner"/>
36
37    <property name="version"               value="${version.major}.${version.minor}.${version.build}${version.suffix}" />
38    <property name="version.number"        value="${version.major}.${version.minor}.${version.build}.${version.patch}" />
39    <property name="version.major.minor"   value="${version.major}.${version.minor}" />
40
41    <property name="final.name"            value="${project}-${version}" />
42
43    <property name="build.dir" value="./dist"/>
44    <property name="build.src" value="${build.dir}/src"/>
45    <property name="build.dest" value="${build.dir}/classes"/>
46    <property name="src.dir" value="."/>
47    <property name="dist.root" value="./dist"/>
48    <property name="ant.home" value="."/>
49
50    <property name="docs.src" value="./xdocs"/>
51    <property name="docs.dest" value="${dist.root}/doc"/>
52    <property name="docs.dest.print" value="${dist.root}/doc/printable"/>
53    <property name="test.dir" value="${build.dest}/test"/>
54    <property name="examples.dir" value="${build.dest}/examples"/>
55
56    <property name="tc.library.path" value="${basedir}/native/.libs"/>
57
58    <!-- The base directory for component sources -->
59    <property name="source.home"             value="java"/>
60
61    <!-- Tests To Run -->
62    <property name="test.name" value="**/Test*.java"/>
63
64    <!-- Build classpath -->
65    <path id="classpath">
66        <pathelement location="${build.dest}/java"/>
67    </path>
68
69    <!-- Test classpath -->
70    <path id="test.classpath">
71        <pathelement location="${build.dest}/java"/>
72        <pathelement location="${build.dest}/test"/>
73        <pathelement location="${junit.jar}"/>
74        <pathelement location="${hamcrest.jar}"/>
75    </path>
76
77    <!-- Examples classpath -->
78    <path id="examples.classpath">
79        <pathelement location="${build.dest}/java"/>
80        <pathelement location="${build.dest}/examples"/>
81    </path>
82
83    <!-- =================================================================== -->
84    <!-- prints the environment                                              -->
85    <!-- =================================================================== -->
86    <target name="env">
87        <echo message="java.home = ${java.home}"/>
88        <echo message="user.home = ${user.home}"/>
89        <!--
90        <echo message="java.class.path = ${java.class.path}"/>
91        -->
92        <echo message="tc.library.path = ${tc.library.path}"/>
93        <echo message=""/>
94    </target>
95
96    <target name="prepare" depends="env">
97        <mkdir dir="${build.dir}"/>
98        <mkdir dir="${basedir}/logs"/>
99    </target>
100
101    <!-- Download and dependency building -->
102    <target name="proxyflags">
103      <!-- check proxy parameters. -->
104      <condition property="useproxy">
105        <equals arg1="${proxy.use}" arg2="on" />
106      </condition>
107    </target>
108
109    <target name="setproxy" depends="proxyflags" if="useproxy">
110      <taskdef name="setproxy"
111              classname="org.apache.tools.ant.taskdefs.optional.net.SetProxy" />
112      <setproxy proxyhost="${proxy.host}" proxyport="${proxy.port}"
113                proxyuser="${proxy.user}" proxypassword="${proxy.password}" />
114      <echo message="Using ${proxy.host}:${proxy.port} to download ${sourcefile}"/>
115    </target>
116
117    <target name="testexist">
118      <echo message="Testing for ${destfile}"/>
119      <available file="${destfile}" property="exist"/>
120    </target>
121
122    <target name="downloadgz" unless="exist" depends="setproxy,testexist">
123      <!-- Download and extract the package -->
124      <get src="${sourcefile}" dest="${base.path}/file.tar.gz" />
125      <gunzip src="${base.path}/file.tar.gz" dest="${base.path}/file.tar"/>
126      <untar src="${base.path}/file.tar" dest="${base.path}"/>
127      <delete file="${base.path}/file.tar"/>
128      <delete file="${base.path}/file.tar.gz"/>
129    </target>
130
131    <target name="downloadzip" unless="exist" depends="setproxy,testexist">
132      <!-- Download and extract the package -->
133      <get src="${sourcefile}" dest="${base.path}/file.zip" />
134      <mkdir dir="${destdir}" />
135      <unzip src="${base.path}/file.zip" dest="${destdir}"/>
136      <delete file="${base.path}/file.zip"/>
137    </target>
138
139    <target name="downloadfile" unless="exist" depends="setproxy,testexist">
140      <!-- Download extract the file -->
141      <mkdir dir="${destdir}" />
142      <get src="${sourcefile}" dest="${destfile}" />
143    </target>
144
145    <target name="download" description="Download needed dependencies">
146
147      <mkdir dir="${base.path}"/>
148
149      <antcall target="downloadfile">
150        <param name="sourcefile" value="${junit.loc}"/>
151        <param name="destfile" value="${junit.jar}"/>
152        <param name="destdir" value="${junit.home}"/>
153      </antcall>
154
155      <antcall target="downloadfile">
156        <param name="sourcefile" value="${hamcrest.loc}"/>
157        <param name="destfile" value="${hamcrest.jar}"/>
158        <param name="destdir" value="${hamcrest.home}"/>
159      </antcall>
160
161    </target>
162
163    <!-- =================================================================== -->
164    <!-- Creates the API documentation                                       -->
165    <!-- =================================================================== -->
166    <target name="javadocs" description="Java documentation">
167        <mkdir dir="${docs.dest}"/>
168        <mkdir dir="${docs.dest}/api"/>
169        <javadoc sourcepath="${build.src}/java"
170            destdir="${docs.dest}/api"
171            author="true"
172            version="true"
173            overview="${src.dir}/java/overview.html"
174            packagenames="org.apache.tomcat.*"
175            windowtitle="${title} (Version ${version})"
176            doctitle="&lt;h1&gt;${title} (Version ${version})&lt;/h1&gt;"
177            bottom="Copyright 2002-2020 The Apache Software Foundation.&lt;!--
178
179Licensed under the Apache License, Version 2.0 (the 'License');
180you may not use this file except in compliance with the License.
181You may obtain a copy of the License at
182
183  http://www.apache.org/licenses/LICENSE-2.0
184
185Unless required by applicable law or agreed to in writing, software
186distributed under the License is distributed on an 'AS IS' BASIS,
187WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
188See the License for the specific language governing permissions and
189limitations under the License.--&gt;">
190            <classpath refid="classpath"/>
191        </javadoc>
192     </target>
193
194    <!-- =================================================================== -->
195    <!-- Cleans up the build directory                                       -->
196    <!-- =================================================================== -->
197    <target name="clean" description="Clean build directory">
198        <delete dir="${build.dir}"/>
199    </target>
200
201    <!-- =================================================================== -->
202    <!-- Compiles the source directory                                       -->
203    <!-- =================================================================== -->
204    <target name="compile" depends="prepare" description="Compile Java sources">
205        <mkdir dir="${build.dest}"/>
206        <mkdir dir="${build.dest}/java"/>
207        <mkdir dir="${build.src}"/>
208        <mkdir dir="${build.src}/java"/>
209        <tstamp>
210            <format property="TODAY" pattern="MMM d yyyy" locale="en"/>
211            <format property="TSTAMP" pattern="hh:mm:ss"/>
212        </tstamp>
213        <!-- Copy static resource files -->
214        <filter token="VERSION" value="${version}"/>
215        <filter token="VERSION_NUMBER" value="${version.number}"/>
216        <filter token="VERSION_BUILT" value="${TODAY} ${TSTAMP}"/>
217        <copy todir="${build.src}/java" filtering="yes" encoding="ISO-8859-1">
218            <fileset dir="${src.dir}/java">
219                <include name="**/*.java"/>
220                <include name="**/*.xml"/>
221                <include name="**/*.properties"/>
222            </fileset>
223        </copy>
224
225        <javac srcdir="${build.src}/java"
226            destdir="${build.dest}/java"
227            source="${compile.source}"
228            target="${compile.target}"
229            debug="${compile.debug}"
230            deprecation="${compile.deprecation}"
231            optimize="${compile.optimize}"
232            encoding="ISO-8859-1"
233            includeantruntime="false">
234            <classpath refid="classpath"/>
235        </javac>
236
237        <copy todir="${build.dest}/java" filtering="yes" encoding="ISO-8859-1">
238            <fileset dir="${build.src}/java">
239                <include name="**/*.xml"/>
240                <include name="**/*.properties"/>
241            </fileset>
242        </copy>
243    </target>
244
245    <!-- ================================================================== -->
246    <!-- Make Tomcat Native jar                                             -->
247    <!-- ================================================================== -->
248    <target name="jar" depends="compile" description="Generates the Jar file">
249        <jar
250            destfile="${build.dir}/${final.name}.jar"
251            basedir="${build.dir}/classes/java"
252            excludes="**/*.java">
253            <manifest>
254                <section name="org/apache/tomcat/jni">
255                    <attribute name="Specification-Title" value="Tomcat Native"/>
256                    <attribute name="Specification-Version" value="${version}"/>
257                    <attribute name="Specification-Vendor" value="Apache Software Foundation"/>
258                    <attribute name="Implementation-Title" value="org.apache.tomcat.jni"/>
259                    <attribute name="Implementation-Vendor" value="Apache Software Foundation"/>
260                    <attribute name="Implementation-Vendor-Id" value="org.apache"/>
261                    <attribute name="Implementation-Version" value="${version} (build ${DSTAMP} ${TSTAMP})"/>
262                </section>
263            </manifest>
264        </jar>
265    </target>
266
267    <!-- =================================================================== -->
268    <!-- Compiles the test directory                                         -->
269    <!-- =================================================================== -->
270    <target name="compile-tests" depends="compile" description="Compile Java test classes">
271        <mkdir dir="${build.dest}"/>
272        <mkdir dir="${build.dest}/test"/>
273        <mkdir dir="${build.src}"/>
274        <mkdir dir="${build.src}/test"/>
275        <tstamp>
276            <format property="TODAY" pattern="MMM d yyyy" locale="en"/>
277            <format property="TSTAMP" pattern="hh:mm:ss"/>
278        </tstamp>
279        <!-- Copy static resource files -->
280        <filter token="VERSION" value="${version}"/>
281        <filter token="VERSION_NUMBER" value="${version.number}"/>
282        <filter token="VERSION_BUILT" value="${TODAY} ${TSTAMP}"/>
283        <copy todir="${build.src}/test" filtering="yes" encoding="ISO-8859-1">
284            <fileset dir="${src.dir}/test">
285                <include name="**/*.java"/>
286                <include name="**/*.xml"/>
287                <include name="**/*.properties"/>
288            </fileset>
289        </copy>
290        <javac srcdir="${build.src}/test"
291            destdir="${build.dest}/test"
292            source="${compile.source}"
293            target="${compile.target}"
294            debug="on"
295            deprecation="${compile.deprecation}"
296            optimize="${compile.optimize}"
297            encoding="ISO-8859-1"
298            includeantruntime="false">
299            <classpath refid="test.classpath"/>
300        </javac>
301        <copy todir="${build.dest}/test" filtering="yes" encoding="ISO-8859-1">
302            <fileset dir="${build.src}/test">
303                <include name="**/*.xml"/>
304                <include name="**/*.properties"/>
305            </fileset>
306        </copy>
307    </target>
308
309    <!-- =================================================================== -->
310    <!-- Junit tests                                                         -->
311    <!-- =================================================================== -->
312    <target name="test" depends="compile-tests" description="Run the tests">
313        <echo message="Running Tomcat Native package tests ..."/>
314        <junit printsummary="yes" fork="yes" dir="." showoutput="yes"
315            haltonfailure="${test.failonerror}" >
316
317            <formatter type="plain"/>
318
319            <jvmarg value="-Djava.library.path=${tc.library.path}"/>
320
321            <classpath refid="test.classpath" />
322
323            <batchtest todir="${basedir}/logs">
324                <!-- Include all by default -->
325                <fileset dir="test" includes="${test.name}">
326                  <!-- Exclude helper classes -->
327                  <exclude name="**/Tester*.java" />
328                </fileset>
329            </batchtest>
330        </junit>
331    </target>
332
333    <!-- =================================================================== -->
334    <!-- Compiles the examples directory                                     -->
335    <!-- =================================================================== -->
336    <target name="compile-examples" depends="compile" description="Compile example Java classes">
337        <mkdir dir="${build.dest}"/>
338        <mkdir dir="${build.dest}/examples"/>
339        <mkdir dir="${build.src}"/>
340        <mkdir dir="${build.src}/examples"/>
341        <tstamp>
342            <format property="TODAY" pattern="MMM d yyyy" locale="en"/>
343            <format property="TSTAMP" pattern="hh:mm:ss"/>
344        </tstamp>
345        <!-- Copy static resource files -->
346        <filter token="VERSION" value="${version}"/>
347        <filter token="VERSION_NUMBER" value="${version.number}"/>
348        <filter token="VERSION_BUILT" value="${TODAY} ${TSTAMP}"/>
349        <copy todir="${build.src}/examples" filtering="yes" encoding="ISO-8859-1">
350            <fileset dir="${src.dir}/examples">
351                <include name="**/*.java"/>
352                <include name="**/*.xml"/>
353                <include name="**/*.properties"/>
354            </fileset>
355        </copy>
356        <javac srcdir="${build.src}/examples"
357            destdir="${build.dest}/examples"
358            source="${compile.source}"
359            target="${compile.target}"
360            debug="${compile.debug}"
361            deprecation="${compile.deprecation}"
362            optimize="${compile.optimize}"
363            encoding="ISO-8859-1">
364            <classpath refid="examples.classpath"/>
365        </javac>
366        <copy todir="${build.dest}/examples" filtering="yes" encoding="ISO-8859-1">
367            <fileset dir="${build.src}/examples">
368                <include name="**/*.xml"/>
369                <include name="**/*.properties"/>
370            </fileset>
371        </copy>
372    </target>
373
374    <!-- =================================================================== -->
375    <!-- executes the examples                                                -->
376    <!-- =================================================================== -->
377    <target name="run-echo" depends="compile-examples" description="Run the Echo example">
378        <echo message="Running Tomcat Native Echo example ..."/>
379        <java dir="${examples.dir}" classname="org.apache.tomcat.jni.Echo"
380             fork="yes" failonerror="${test.failonerror}">
381            <classpath refid="examples.classpath"/>
382            <env key="PATH" path="${tc.library.path}:${java.library.path}"/>
383            <env key="Path" path="${tc.library.path}:${java.library.path}"/>
384            <jvmarg value="-Djava.library.path=${tc.library.path}"/>
385        </java>
386    </target>
387    <target name="run-ssl-server" depends="compile-examples" description="Run the SSL Server example">
388        <echo message="Running Tomcat Native SSL Server example ..."/>
389        <java dir="${examples.dir}" classname="org.apache.tomcat.jni.SSLServer"
390             fork="yes" failonerror="${test.failonerror}">
391            <env key="PATH" path="${tc.library.path}:${java.library.path}"/>
392            <env key="Path" path="${tc.library.path}:${java.library.path}"/>
393            <classpath refid="examples.classpath"/>
394            <jvmarg value="-Djava.library.path=${tc.library.path}"/>
395        </java>
396    </target>
397    <target name="run-local-server" depends="compile-examples" description="Run the Local Server example">
398        <echo message="Running Tomcat Native Local Server example ..."/>
399        <java dir="${examples.dir}" classname="org.apache.tomcat.jni.LocalServer"
400             fork="yes" failonerror="${test.failonerror}">
401            <classpath refid="examples.classpath"/>
402            <env key="PATH" path="${tc.library.path}:${java.library.path}"/>
403            <env key="Path" path="${tc.library.path}:${java.library.path}"/>
404            <jvmarg value="-Djava.library.path=${tc.library.path}"/>
405        </java>
406    </target>
407</project>
408