blob: 109c62fcccf779c14bc30b3d53a14303515bbe57 [file] [log] [blame]
Roger Meier37b5bf82010-10-24 21:41:24 +00001<!--
2 Licensed to the Apache Software Foundation (ASF) under one
3 or more contributor license agreements. See the NOTICE file
4 distributed with this work for additional information
5 regarding copyright ownership. The ASF licenses this file
6 to you under the Apache License, Version 2.0 (the
7 "License"); you may not use this file except in compliance
8 with the License. You may obtain a copy of the License at
9
Jake Farrellad6426c2011-04-20 16:35:20 +000010 http://www.apache.org/licenses/LICENSE-2.0
Roger Meier37b5bf82010-10-24 21:41:24 +000011
12 Unless required by applicable law or agreed to in writing,
13 software distributed under the License is distributed on an
14 "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 KIND, either express or implied. See the License for the
16 specific language governing permissions and limitations
17 under the License.
18-->
19<project name="Java Script Test" default="test" basedir="."
Roger Meierda6e6ae2011-03-15 09:55:33 +000020 xmlns:artifact="antlib:org.apache.maven.artifact.ant"
21 xmlns:jsl="antlib:com.googlecode.jslint4java">
Roger Meier37b5bf82010-10-24 21:41:24 +000022
23 <description>Java Script Test based on Thrift Java Library</description>
24
25 <property name="src" location="src" />
26 <property name="genjava" location="gen-java" />
27 <property name="genjs" location="gen-js" />
28 <property name="build" location="build" />
Roger Meieredf0d1d2011-08-03 21:21:43 +000029 <property name="jar.file" location="${build}/jstest.jar" />
Roger Meier37b5bf82010-10-24 21:41:24 +000030
31 <!-- the root directory, where you unpack thrift distibution (e.g. thrift-0.x.x.tar.gz) -->
32 <property name="thrift.dir" location="../../../" />
33 <property name="thrift.java.dir" location="${thrift.dir}/lib/java" />
Alex Volanis7004a612018-01-24 10:30:13 -050034 <property name="build.tools.dir" location="${thrift.java.dir}/build/tools/"/>
35 <property file="${basedir}/build.properties"/>
Roger Meier37b5bf82010-10-24 21:41:24 +000036
Jake Farrellad6426c2011-04-20 16:35:20 +000037 <!-- Include the base java properties file -->
Alex Volanis7004a612018-01-24 10:30:13 -050038 <property file="${thrift.java.dir}/gradle.properties" />
Roger Meier37b5bf82010-10-24 21:41:24 +000039
Jake Farrellad6426c2011-04-20 16:35:20 +000040 <property name="thrift.compiler" location="${thrift.dir}/compiler/cpp/thrift" />
Roger Meier37b5bf82010-10-24 21:41:24 +000041
42 <path id="libs.classpath">
Alex Volanis7004a612018-01-24 10:30:13 -050043 <fileset dir="${thrift.java.dir}/build/libs">
44 <include name="libthrift*.jar" />
45 <exclude name="libthrift*javadoc.jar" />
46 <exclude name="libthrift*sources.jar" />
Roger Meier2fdf05c2011-03-25 11:37:16 +000047 </fileset>
Alex Volanis7004a612018-01-24 10:30:13 -050048 <fileset dir="${thrift.java.dir}/build/deps">
Roger Meier2fdf05c2011-03-25 11:37:16 +000049 <include name="*.jar" />
50 </fileset>
Jake Farrellad6426c2011-04-20 16:35:20 +000051 <fileset dir="${build}/lib">
Roger Meier37b5bf82010-10-24 21:41:24 +000052 <include name="*.jar" />
53 </fileset>
54 </path>
55
56 <path id="test.classpath">
57 <path refid="libs.classpath" />
58 <pathelement location="${jar.file}" />
59 </path>
60
61 <target name="dependencies">
62 <fail>
63 <condition>
64 <not>
Roger Meier2fdf05c2011-03-25 11:37:16 +000065 <resourcecount count="2">
Alex Volanis7004a612018-01-24 10:30:13 -050066 <fileset id="fs" dir="${thrift.java.dir}/build/libs">
Roger Meiera35944b2011-07-15 20:16:43 +000067 <include name="libthrift*.jar" />
68 <exclude name="libthrift*javadoc.jar" />
Alex Volanis7004a612018-01-24 10:30:13 -050069 <exclude name="libthrift*sources.jar" />
Roger Meiera35944b2011-07-15 20:16:43 +000070 </fileset>
Roger Meier37b5bf82010-10-24 21:41:24 +000071 </resourcecount>
72 </not>
73 </condition>
Roger Meier2fdf05c2011-03-25 11:37:16 +000074 You need libthrift*.jar and libthrift*test.jar located at
Roger Meier08b30992011-04-06 21:30:53 +000075 ${thrift.java.dir}/build
Roger Meier37b5bf82010-10-24 21:41:24 +000076 Did you compile Thrift Java library and its test suite by "ant compile-test"?
77 </fail>
78 <fail>
79 <condition>
80 <not>
81 <resourcecount count="1">
Roger Meier37b5bf82010-10-24 21:41:24 +000082 <fileset id="fs" dir="${thrift.dir}" includes="compiler/cpp/thrift"/>
83 </resourcecount>
84 </not>
85 </condition>
86 Thrift compiler is missing !
87 </fail>
88 </target>
89
90 <target name="init" depends="dependencies">
91 <tstamp />
Alex Volanis7004a612018-01-24 10:30:13 -050092 <mkdir dir="${build.tools.dir}"/>
Roger Meier37b5bf82010-10-24 21:41:24 +000093 <mkdir dir="${build}"/>
Roger Meieredf0d1d2011-08-03 21:21:43 +000094 <mkdir dir="${build}/js/lib"/>
Jake Farrellad6426c2011-04-20 16:35:20 +000095 <mkdir dir="${build}/lib"/>
Roger Meier0b267252011-07-29 21:08:04 +000096 <mkdir dir="${build}/log"/>
Roger Meieredf0d1d2011-08-03 21:21:43 +000097 <mkdir dir="${build}/test"/>
98 <mkdir dir="${build}/test/log"/>
99 </target>
100
101 <target name="jslibs" depends="init, proxy">
Nobuaki Sukegawa63b51202015-05-10 23:35:07 +0900102 <get src="http://code.jquery.com/jquery-1.11.3.min.js" dest="${build}/js/lib/jquery.js" usetimestamp="true"/>
Nobuaki Sukegawa63b51202015-05-10 23:35:07 +0900103 <get src="http://code.jquery.com/qunit/qunit-1.18.0.js" dest="${build}/js/lib/qunit.js" usetimestamp="true"/>
104 <get src="http://code.jquery.com/qunit/qunit-1.18.0.css" dest="${build}/js/lib/qunit.css" usetimestamp="true"/>
Philip Frank8fdd6102017-12-06 12:38:05 +0100105 <get src="https://cdn.jsdelivr.net/npm/es6-promise@4/dist/es6-promise.auto.js" dest="${build}/js/lib/es6-promise.js" usetimestamp="true"/>
Roger Meier37b5bf82010-10-24 21:41:24 +0000106 </target>
107
108 <target name="compile" description="compile the test suite" depends="init, generate, resolve">
Roger Meieredf0d1d2011-08-03 21:21:43 +0000109 <!-- //TODO enable <compilerarg value="-Xlint"/>-->
James E. King, IIIcf254892017-01-25 20:34:04 -0500110 <javac compiler="modern" includeantruntime="false" srcdir="${genjava}" destdir="${build}/test" classpathref="libs.classpath"/>
111 <javac compiler="modern" includeantruntime="false" srcdir="${src}" destdir="${build}/test" classpathref="libs.classpath"/>
Roger Meier37b5bf82010-10-24 21:41:24 +0000112 </target>
113
Roger Meier0b267252011-07-29 21:08:04 +0000114 <target name="jstest" description="create the test suite jar file" depends="compile">
Roger Meieredf0d1d2011-08-03 21:21:43 +0000115 <jar jarfile="${jar.file}" basedir="${build}/test"/>
Roger Meier37b5bf82010-10-24 21:41:24 +0000116 </target>
117
Roger Meieredf0d1d2011-08-03 21:21:43 +0000118 <target name="testserver" description="run the test server" depends="jstest, jslibs">
Roger Meier37b5bf82010-10-24 21:41:24 +0000119 <java classname="test.Httpd" fork="true"
120 classpathref="test.classpath" failonerror="true">
121 <arg value="../" />
122 </java>
123 </target>
124
Roger Meieredf0d1d2011-08-03 21:21:43 +0000125 <target name="proxy" if="proxy.enabled">
126 <setproxy proxyhost="${proxy.host}" proxyport="${proxy.port}"
127 proxyuser="${proxy.user}" proxypassword="${proxy.pass}"/>
128 </target>
129
Roger Meier0b267252011-07-29 21:08:04 +0000130 <target name="xvfb">
131 <echo>check if Xvfb is available:</echo>
132 <exec executable="Xvfb" failifexecutionfails="no" resultproperty="xvfb.present" failonerror="false" output="${build}/log/xvfb.log">
133 <arg line="--version"/>
134 </exec>
135 </target>
136
137 <target name="phantomjs" depends="xvfb" if="xvfb.present">
138 <echo>check if phantomjs is available:</echo>
139 <exec executable="phantomjs" failifexecutionfails="no" resultproperty="phantomjs.present" failonerror="false" output="${build}/log/phantomjs.log">
140 <arg line="--version"/>
141 </exec>
142 </target>
143
Roger Meieredf0d1d2011-08-03 21:21:43 +0000144 <target name="unittest" description="do unit tests with headless browser phantomjs" depends="init, phantomjs, jstest, jslibs" if="phantomjs.present">
Roger Meier0b267252011-07-29 21:08:04 +0000145 <parallel>
146 <exec executable="Xvfb" spawn="true" failonerror="false">
147 <arg line=":99" />
148 </exec>
Roger Meier4f8a5232011-09-09 08:17:02 +0000149 <java classname="test.Httpd" fork="true" timeout="10000"
Roger Meier0b267252011-07-29 21:08:04 +0000150 classpathref="test.classpath" failonerror="false" output="${build}/log/unittest.log">
151 <arg value="../" />
152 </java>
153 <sequential>
154 <sleep seconds="2"/>
155 <echo>Running Unit Tests with headless browser!</echo>
156 <exec executable="phantomjs" failonerror="true">
157 <env key="DISPLAY" value=":99"/>
158 <arg line="phantomjs-qunit.js http://localhost:8088/test/test.html" />
159 </exec>
160 </sequential>
161 </parallel>
162 </target>
163
Roger Meier37b5bf82010-10-24 21:41:24 +0000164 <target name="generate">
165 <exec executable="${thrift.compiler}" failonerror="true">
166 <arg line="--gen java ${thrift.dir}/test/ThriftTest.thrift" />
167 </exec>
168 <exec executable="${thrift.compiler}" failonerror="true">
Roger Meier08b30992011-04-06 21:30:53 +0000169 <arg line="--gen js:jquery ${thrift.dir}/test/ThriftTest.thrift" />
Roger Meier37b5bf82010-10-24 21:41:24 +0000170 </exec>
171 </target>
172
Roger Meieredf0d1d2011-08-03 21:21:43 +0000173 <target name="test" description="run test suite (lint, unittest)" depends="lint, unittest"/>
Roger Meierf2495762011-03-17 19:13:36 +0000174
Roger Meieredf0d1d2011-08-03 21:21:43 +0000175 <target name="lint" description="code quality checks (jslint and gjslint if available)" depends="generate, gjslint, jslint"/>
Roger Meierda6e6ae2011-03-15 09:55:33 +0000176
Roger Meieredf0d1d2011-08-03 21:21:43 +0000177 <target name="jslint" depends="resolve">
Roger Meier42a6fa42011-03-21 21:26:35 +0000178 <taskdef uri="antlib:com.googlecode.jslint4java" resource="com/googlecode/jslint4java/antlib.xml" classpathref="libs.classpath" />
Roger Meierda6e6ae2011-03-15 09:55:33 +0000179 <!--
180 the following options would probably make sense in the future:
181 browser,undef,eqeqeq,plusplus,bitwise,regexp,strict,newcap,immed
182 -->
Roger Meieredf0d1d2011-08-03 21:21:43 +0000183 <jsl:jslint options="evil,forin,browser,bitwise,regexp,newcap,immed" encoding="UTF-8">
Roger Meierda6e6ae2011-03-15 09:55:33 +0000184 <formatter type="plain" />
185 <fileset dir="${genjs}" includes="**/*.js" />
Henrique Mendonça095ddb72013-09-20 19:38:03 +0200186 <fileset dir="../src" includes="thrift.js" />
Roger Meieredf0d1d2011-08-03 21:21:43 +0000187
188 <!-- issues with unsafe character -->
189 <!-- fileset dir="." includes="*test*.js" /> -->
Roger Meierda6e6ae2011-03-15 09:55:33 +0000190 </jsl:jslint>
191 </target>
192
193 <target name="check-gjslint">
194 <echo>check if gjslint is available:</echo>
195 <exec executable="gjslint" failifexecutionfails="no" resultproperty="gjslint.present" failonerror="false">
196 <arg line="--helpshort"/>
197 </exec>
198 </target>
Jake Farrellad6426c2011-04-20 16:35:20 +0000199
Roger Meierda6e6ae2011-03-15 09:55:33 +0000200 <target name="gjslint" depends="check-gjslint" if="gjslint.present">
201 <exec executable="gjslint" failifexecutionfails="no">
202 <arg line="--nojsdoc"/>
203 <arg line="${genjs}/*.js"/>
Henrique Mendonça095ddb72013-09-20 19:38:03 +0200204 <arg line="../src/thrift.js"/>
Roger Meieredf0d1d2011-08-03 21:21:43 +0000205
206 <!-- issues with unsafe character, etc. -->
207 <!-- <arg line="*test*.js"/> -->
Roger Meierda6e6ae2011-03-15 09:55:33 +0000208 </exec>
209 </target>
210
Roger Meier37b5bf82010-10-24 21:41:24 +0000211 <target name="clean">
212 <delete dir="${build}" />
213 <delete dir="${genjava}" />
214 <delete dir="${genjs}" />
Roger Meier37b5bf82010-10-24 21:41:24 +0000215 </target>
216
Alex Volanis7004a612018-01-24 10:30:13 -0500217 <target name="mvn.ant.tasks.download" depends="init,mvn.ant.tasks.check" unless="mvn.ant.tasks.found">
218 <get src="${mvn.ant.task.url}/${mvn.ant.task.jar}" dest="${build.tools.dir}/${mvn.ant.task.jar}" usetimestamp="true"/>
219 </target>
220
221 <target name="mvn.ant.tasks.check">
222 <condition property="mvn.ant.tasks.found">
223 <typefound uri="antlib:org.apache.maven.artifact.ant" name="artifact"/>
224 </condition>
225 </target>
226
227 <target name="resolve" depends="mvn.ant.tasks.download" unless="mvn.finished">
Jake Farrellad6426c2011-04-20 16:35:20 +0000228 <typedef uri="antlib:org.apache.maven.artifact.ant" classpath="${thrift.java.dir}/build/tools/${mvn.ant.task.jar}"/>
Roger Meier37b5bf82010-10-24 21:41:24 +0000229
Jake Farrellad6426c2011-04-20 16:35:20 +0000230 <artifact:dependencies filesetId="js.test.dependency.jars">
231 <dependency groupId="org.apache.httpcomponents" artifactId="httpclient" version="4.0.1"/>
232 <dependency groupId="com.googlecode.jslint4java" artifactId="jslint4java-ant" version="1.4.6"/>
Roger Meierc8d5d4d2012-01-07 20:32:24 +0000233 <dependency groupId="eu.medsea.mimeutil" artifactId="mime-util" version="2.1.3"/>
Jake Farrellad6426c2011-04-20 16:35:20 +0000234 </artifact:dependencies>
Roger Meier37b5bf82010-10-24 21:41:24 +0000235
Jake Farrellad6426c2011-04-20 16:35:20 +0000236 <!-- Copy the dependencies to the build/lib dir -->
237 <copy todir="${build}/lib">
238 <fileset refid="js.test.dependency.jars"/>
239 <mapper type="flatten"/>
240 </copy>
Roger Meier08562732015-06-14 22:30:22 +0200241
Jake Farrellad6426c2011-04-20 16:35:20 +0000242 <property name="mvn.finished" value="true"/>
Roger Meier37b5bf82010-10-24 21:41:24 +0000243 </target>
Roger Meier37b5bf82010-10-24 21:41:24 +0000244</project>