blob: 4795fd26751e5615cade75fe4b18a20e4d601c18 [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
Mustafa Senol Cosarf86845e2018-12-05 17:50:18 +030031 <!-- the root directory, where you unpack thrift distibution (e.g.: thrift-0.x.x.tar.gz) -->
Roger Meier37b5bf82010-10-24 21:41:24 +000032 <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
Mustafa Senol Cosarf86845e2018-12-05 17:50:18 +030037 <!-- 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
James E. King III2b09dfe2018-03-13 10:11:25 -040075 ${thrift.java.dir}/build/libs
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
Philip Frank5066eb42018-03-07 20:49:25 +0100101 <target name="download_jslibs">
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"/>
Brian Forbisb5d6ea32018-08-25 23:39:29 -0400103 <get src="http://code.jquery.com/qunit/qunit-2.6.2.js" dest="${build}/js/lib/qunit.js" usetimestamp="true"/>
104 <get src="http://code.jquery.com/qunit/qunit-2.6.2.css" dest="${build}/js/lib/qunit.css" usetimestamp="true"/>
Roger Meier37b5bf82010-10-24 21:41:24 +0000105 </target>
106
Philip Frank5066eb42018-03-07 20:49:25 +0100107 <target name="jslibs" depends="init, proxy, download_jslibs">
108 </target>
109
Roger Meier37b5bf82010-10-24 21:41:24 +0000110 <target name="compile" description="compile the test suite" depends="init, generate, resolve">
Roger Meieredf0d1d2011-08-03 21:21:43 +0000111 <!-- //TODO enable <compilerarg value="-Xlint"/>-->
James E. King, IIIcf254892017-01-25 20:34:04 -0500112 <javac compiler="modern" includeantruntime="false" srcdir="${genjava}" destdir="${build}/test" classpathref="libs.classpath"/>
113 <javac compiler="modern" includeantruntime="false" srcdir="${src}" destdir="${build}/test" classpathref="libs.classpath"/>
Roger Meier37b5bf82010-10-24 21:41:24 +0000114 </target>
115
Roger Meier0b267252011-07-29 21:08:04 +0000116 <target name="jstest" description="create the test suite jar file" depends="compile">
Roger Meieredf0d1d2011-08-03 21:21:43 +0000117 <jar jarfile="${jar.file}" basedir="${build}/test"/>
Roger Meier37b5bf82010-10-24 21:41:24 +0000118 </target>
119
Roger Meieredf0d1d2011-08-03 21:21:43 +0000120 <target name="testserver" description="run the test server" depends="jstest, jslibs">
Roger Meier37b5bf82010-10-24 21:41:24 +0000121 <java classname="test.Httpd" fork="true"
122 classpathref="test.classpath" failonerror="true">
123 <arg value="../" />
124 </java>
125 </target>
126
Roger Meieredf0d1d2011-08-03 21:21:43 +0000127 <target name="proxy" if="proxy.enabled">
128 <setproxy proxyhost="${proxy.host}" proxyport="${proxy.port}"
129 proxyuser="${proxy.user}" proxypassword="${proxy.pass}"/>
130 </target>
131
Roger Meier0b267252011-07-29 21:08:04 +0000132 <target name="xvfb">
133 <echo>check if Xvfb is available:</echo>
134 <exec executable="Xvfb" failifexecutionfails="no" resultproperty="xvfb.present" failonerror="false" output="${build}/log/xvfb.log">
135 <arg line="--version"/>
136 </exec>
137 </target>
138
139 <target name="phantomjs" depends="xvfb" if="xvfb.present">
140 <echo>check if phantomjs is available:</echo>
141 <exec executable="phantomjs" failifexecutionfails="no" resultproperty="phantomjs.present" failonerror="false" output="${build}/log/phantomjs.log">
142 <arg line="--version"/>
143 </exec>
144 </target>
145
Roger Meieredf0d1d2011-08-03 21:21:43 +0000146 <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 +0000147 <parallel>
148 <exec executable="Xvfb" spawn="true" failonerror="false">
149 <arg line=":99" />
150 </exec>
Roger Meier4f8a5232011-09-09 08:17:02 +0000151 <java classname="test.Httpd" fork="true" timeout="10000"
Roger Meier0b267252011-07-29 21:08:04 +0000152 classpathref="test.classpath" failonerror="false" output="${build}/log/unittest.log">
153 <arg value="../" />
154 </java>
155 <sequential>
156 <sleep seconds="2"/>
157 <echo>Running Unit Tests with headless browser!</echo>
158 <exec executable="phantomjs" failonerror="true">
159 <env key="DISPLAY" value=":99"/>
160 <arg line="phantomjs-qunit.js http://localhost:8088/test/test.html" />
161 </exec>
162 </sequential>
163 </parallel>
164 </target>
165
Roger Meier37b5bf82010-10-24 21:41:24 +0000166 <target name="generate">
167 <exec executable="${thrift.compiler}" failonerror="true">
168 <arg line="--gen java ${thrift.dir}/test/ThriftTest.thrift" />
169 </exec>
170 <exec executable="${thrift.compiler}" failonerror="true">
Roger Meier08b30992011-04-06 21:30:53 +0000171 <arg line="--gen js:jquery ${thrift.dir}/test/ThriftTest.thrift" />
Roger Meier37b5bf82010-10-24 21:41:24 +0000172 </exec>
Ozan Can Altioke46419b2018-03-20 15:02:28 +0300173 <exec executable="${thrift.compiler}" failonerror="true">
174 <arg line="--gen js:jquery ${thrift.dir}/test/DoubleConstantsTest.thrift" />
175 </exec>
Roger Meier37b5bf82010-10-24 21:41:24 +0000176 </target>
177
Roger Meieredf0d1d2011-08-03 21:21:43 +0000178 <target name="test" description="run test suite (lint, unittest)" depends="lint, unittest"/>
Roger Meierf2495762011-03-17 19:13:36 +0000179
Roger Meieredf0d1d2011-08-03 21:21:43 +0000180 <target name="lint" description="code quality checks (jslint and gjslint if available)" depends="generate, gjslint, jslint"/>
Roger Meierda6e6ae2011-03-15 09:55:33 +0000181
Roger Meieredf0d1d2011-08-03 21:21:43 +0000182 <target name="jslint" depends="resolve">
Roger Meier42a6fa42011-03-21 21:26:35 +0000183 <taskdef uri="antlib:com.googlecode.jslint4java" resource="com/googlecode/jslint4java/antlib.xml" classpathref="libs.classpath" />
Roger Meierda6e6ae2011-03-15 09:55:33 +0000184 <!--
185 the following options would probably make sense in the future:
186 browser,undef,eqeqeq,plusplus,bitwise,regexp,strict,newcap,immed
187 -->
Roger Meieredf0d1d2011-08-03 21:21:43 +0000188 <jsl:jslint options="evil,forin,browser,bitwise,regexp,newcap,immed" encoding="UTF-8">
Roger Meierda6e6ae2011-03-15 09:55:33 +0000189 <formatter type="plain" />
Henrique Mendonça095ddb72013-09-20 19:38:03 +0200190 <fileset dir="../src" includes="thrift.js" />
Roger Meieredf0d1d2011-08-03 21:21:43 +0000191
192 <!-- issues with unsafe character -->
193 <!-- fileset dir="." includes="*test*.js" /> -->
Roger Meierda6e6ae2011-03-15 09:55:33 +0000194 </jsl:jslint>
195 </target>
196
197 <target name="check-gjslint">
198 <echo>check if gjslint is available:</echo>
199 <exec executable="gjslint" failifexecutionfails="no" resultproperty="gjslint.present" failonerror="false">
200 <arg line="--helpshort"/>
201 </exec>
202 </target>
Jake Farrellad6426c2011-04-20 16:35:20 +0000203
Roger Meierda6e6ae2011-03-15 09:55:33 +0000204 <target name="gjslint" depends="check-gjslint" if="gjslint.present">
205 <exec executable="gjslint" failifexecutionfails="no">
206 <arg line="--nojsdoc"/>
207 <arg line="${genjs}/*.js"/>
Henrique Mendonça095ddb72013-09-20 19:38:03 +0200208 <arg line="../src/thrift.js"/>
Roger Meieredf0d1d2011-08-03 21:21:43 +0000209
210 <!-- issues with unsafe character, etc. -->
211 <!-- <arg line="*test*.js"/> -->
Roger Meierda6e6ae2011-03-15 09:55:33 +0000212 </exec>
213 </target>
214
Roger Meier37b5bf82010-10-24 21:41:24 +0000215 <target name="clean">
216 <delete dir="${build}" />
217 <delete dir="${genjava}" />
218 <delete dir="${genjs}" />
Roger Meier37b5bf82010-10-24 21:41:24 +0000219 </target>
220
Alex Volanis7004a612018-01-24 10:30:13 -0500221 <target name="mvn.ant.tasks.download" depends="init,mvn.ant.tasks.check" unless="mvn.ant.tasks.found">
222 <get src="${mvn.ant.task.url}/${mvn.ant.task.jar}" dest="${build.tools.dir}/${mvn.ant.task.jar}" usetimestamp="true"/>
223 </target>
224
225 <target name="mvn.ant.tasks.check">
226 <condition property="mvn.ant.tasks.found">
227 <typefound uri="antlib:org.apache.maven.artifact.ant" name="artifact"/>
228 </condition>
229 </target>
230
231 <target name="resolve" depends="mvn.ant.tasks.download" unless="mvn.finished">
Jake Farrellad6426c2011-04-20 16:35:20 +0000232 <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 +0000233
Jake Farrellad6426c2011-04-20 16:35:20 +0000234 <artifact:dependencies filesetId="js.test.dependency.jars">
235 <dependency groupId="org.apache.httpcomponents" artifactId="httpclient" version="4.0.1"/>
236 <dependency groupId="com.googlecode.jslint4java" artifactId="jslint4java-ant" version="1.4.6"/>
Roger Meierc8d5d4d2012-01-07 20:32:24 +0000237 <dependency groupId="eu.medsea.mimeutil" artifactId="mime-util" version="2.1.3"/>
Jake Farrellad6426c2011-04-20 16:35:20 +0000238 </artifact:dependencies>
Roger Meier37b5bf82010-10-24 21:41:24 +0000239
Jake Farrellad6426c2011-04-20 16:35:20 +0000240 <!-- Copy the dependencies to the build/lib dir -->
241 <copy todir="${build}/lib">
242 <fileset refid="js.test.dependency.jars"/>
243 <mapper type="flatten"/>
244 </copy>
Roger Meier08562732015-06-14 22:30:22 +0200245
Jake Farrellad6426c2011-04-20 16:35:20 +0000246 <property name="mvn.finished" value="true"/>
Roger Meier37b5bf82010-10-24 21:41:24 +0000247 </target>
Roger Meier37b5bf82010-10-24 21:41:24 +0000248</project>