blob: db8501229bd3dd50f002b73c57574c6647807f33 [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>
Jake Farrellad6426c2011-04-20 16:35:20 +000048 <fileset dir="${build}/lib">
Roger Meier37b5bf82010-10-24 21:41:24 +000049 <include name="*.jar" />
50 </fileset>
51 </path>
52
53 <path id="test.classpath">
54 <path refid="libs.classpath" />
55 <pathelement location="${jar.file}" />
56 </path>
57
58 <target name="dependencies">
59 <fail>
60 <condition>
61 <not>
Roger Meier2fdf05c2011-03-25 11:37:16 +000062 <resourcecount count="2">
Alex Volanis7004a612018-01-24 10:30:13 -050063 <fileset id="fs" dir="${thrift.java.dir}/build/libs">
Roger Meiera35944b2011-07-15 20:16:43 +000064 <include name="libthrift*.jar" />
65 <exclude name="libthrift*javadoc.jar" />
Alex Volanis7004a612018-01-24 10:30:13 -050066 <exclude name="libthrift*sources.jar" />
Roger Meiera35944b2011-07-15 20:16:43 +000067 </fileset>
Roger Meier37b5bf82010-10-24 21:41:24 +000068 </resourcecount>
69 </not>
70 </condition>
Roger Meier2fdf05c2011-03-25 11:37:16 +000071 You need libthrift*.jar and libthrift*test.jar located at
James E. King III2b09dfe2018-03-13 10:11:25 -040072 ${thrift.java.dir}/build/libs
James E. King IIIb96c4382019-01-24 17:45:07 -050073 Did you compile Thrift Java library and its test suite by "make check"?
Roger Meier37b5bf82010-10-24 21:41:24 +000074 </fail>
75 <fail>
76 <condition>
77 <not>
78 <resourcecount count="1">
Roger Meier37b5bf82010-10-24 21:41:24 +000079 <fileset id="fs" dir="${thrift.dir}" includes="compiler/cpp/thrift"/>
80 </resourcecount>
81 </not>
82 </condition>
83 Thrift compiler is missing !
84 </fail>
85 </target>
86
87 <target name="init" depends="dependencies">
88 <tstamp />
Alex Volanis7004a612018-01-24 10:30:13 -050089 <mkdir dir="${build.tools.dir}"/>
Roger Meier37b5bf82010-10-24 21:41:24 +000090 <mkdir dir="${build}"/>
Roger Meieredf0d1d2011-08-03 21:21:43 +000091 <mkdir dir="${build}/js/lib"/>
Jake Farrellad6426c2011-04-20 16:35:20 +000092 <mkdir dir="${build}/lib"/>
Roger Meier0b267252011-07-29 21:08:04 +000093 <mkdir dir="${build}/log"/>
Roger Meieredf0d1d2011-08-03 21:21:43 +000094 <mkdir dir="${build}/test"/>
95 <mkdir dir="${build}/test/log"/>
96 </target>
97
Philip Frank5066eb42018-03-07 20:49:25 +010098 <target name="download_jslibs">
Nobuaki Sukegawa63b51202015-05-10 23:35:07 +090099 <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 -0400100 <get src="http://code.jquery.com/qunit/qunit-2.6.2.js" dest="${build}/js/lib/qunit.js" usetimestamp="true"/>
101 <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 +0000102 </target>
103
Philip Frank5066eb42018-03-07 20:49:25 +0100104 <target name="jslibs" depends="init, proxy, download_jslibs">
105 </target>
106
Roger Meier37b5bf82010-10-24 21:41:24 +0000107 <target name="compile" description="compile the test suite" depends="init, generate, resolve">
Roger Meieredf0d1d2011-08-03 21:21:43 +0000108 <!-- //TODO enable <compilerarg value="-Xlint"/>-->
James E. King, IIIcf254892017-01-25 20:34:04 -0500109 <javac compiler="modern" includeantruntime="false" srcdir="${genjava}" destdir="${build}/test" classpathref="libs.classpath"/>
110 <javac compiler="modern" includeantruntime="false" srcdir="${src}" destdir="${build}/test" classpathref="libs.classpath"/>
Roger Meier37b5bf82010-10-24 21:41:24 +0000111 </target>
112
Roger Meier0b267252011-07-29 21:08:04 +0000113 <target name="jstest" description="create the test suite jar file" depends="compile">
Roger Meieredf0d1d2011-08-03 21:21:43 +0000114 <jar jarfile="${jar.file}" basedir="${build}/test"/>
Roger Meier37b5bf82010-10-24 21:41:24 +0000115 </target>
116
Roger Meieredf0d1d2011-08-03 21:21:43 +0000117 <target name="testserver" description="run the test server" depends="jstest, jslibs">
Roger Meier37b5bf82010-10-24 21:41:24 +0000118 <java classname="test.Httpd" fork="true"
119 classpathref="test.classpath" failonerror="true">
120 <arg value="../" />
121 </java>
122 </target>
123
Roger Meieredf0d1d2011-08-03 21:21:43 +0000124 <target name="proxy" if="proxy.enabled">
125 <setproxy proxyhost="${proxy.host}" proxyport="${proxy.port}"
126 proxyuser="${proxy.user}" proxypassword="${proxy.pass}"/>
127 </target>
128
Roger Meier0b267252011-07-29 21:08:04 +0000129 <target name="xvfb">
130 <echo>check if Xvfb is available:</echo>
131 <exec executable="Xvfb" failifexecutionfails="no" resultproperty="xvfb.present" failonerror="false" output="${build}/log/xvfb.log">
132 <arg line="--version"/>
133 </exec>
134 </target>
135
136 <target name="phantomjs" depends="xvfb" if="xvfb.present">
137 <echo>check if phantomjs is available:</echo>
138 <exec executable="phantomjs" failifexecutionfails="no" resultproperty="phantomjs.present" failonerror="false" output="${build}/log/phantomjs.log">
139 <arg line="--version"/>
140 </exec>
141 </target>
142
Roger Meieredf0d1d2011-08-03 21:21:43 +0000143 <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 +0000144 <parallel>
145 <exec executable="Xvfb" spawn="true" failonerror="false">
146 <arg line=":99" />
147 </exec>
Roger Meier4f8a5232011-09-09 08:17:02 +0000148 <java classname="test.Httpd" fork="true" timeout="10000"
Roger Meier0b267252011-07-29 21:08:04 +0000149 classpathref="test.classpath" failonerror="false" output="${build}/log/unittest.log">
150 <arg value="../" />
151 </java>
152 <sequential>
153 <sleep seconds="2"/>
154 <echo>Running Unit Tests with headless browser!</echo>
155 <exec executable="phantomjs" failonerror="true">
156 <env key="DISPLAY" value=":99"/>
157 <arg line="phantomjs-qunit.js http://localhost:8088/test/test.html" />
158 </exec>
159 </sequential>
160 </parallel>
161 </target>
162
Roger Meier37b5bf82010-10-24 21:41:24 +0000163 <target name="generate">
164 <exec executable="${thrift.compiler}" failonerror="true">
165 <arg line="--gen java ${thrift.dir}/test/ThriftTest.thrift" />
166 </exec>
167 <exec executable="${thrift.compiler}" failonerror="true">
Roger Meier08b30992011-04-06 21:30:53 +0000168 <arg line="--gen js:jquery ${thrift.dir}/test/ThriftTest.thrift" />
Roger Meier37b5bf82010-10-24 21:41:24 +0000169 </exec>
Ozan Can Altioke46419b2018-03-20 15:02:28 +0300170 <exec executable="${thrift.compiler}" failonerror="true">
171 <arg line="--gen js:jquery ${thrift.dir}/test/DoubleConstantsTest.thrift" />
172 </exec>
Roger Meier37b5bf82010-10-24 21:41:24 +0000173 </target>
174
Roger Meieredf0d1d2011-08-03 21:21:43 +0000175 <target name="test" description="run test suite (lint, unittest)" depends="lint, unittest"/>
Roger Meierf2495762011-03-17 19:13:36 +0000176
Roger Meieredf0d1d2011-08-03 21:21:43 +0000177 <target name="lint" description="code quality checks (jslint and gjslint if available)" depends="generate, gjslint, jslint"/>
Roger Meierda6e6ae2011-03-15 09:55:33 +0000178
Roger Meieredf0d1d2011-08-03 21:21:43 +0000179 <target name="jslint" depends="resolve">
Roger Meier42a6fa42011-03-21 21:26:35 +0000180 <taskdef uri="antlib:com.googlecode.jslint4java" resource="com/googlecode/jslint4java/antlib.xml" classpathref="libs.classpath" />
Roger Meierda6e6ae2011-03-15 09:55:33 +0000181 <!--
182 the following options would probably make sense in the future:
183 browser,undef,eqeqeq,plusplus,bitwise,regexp,strict,newcap,immed
184 -->
Roger Meieredf0d1d2011-08-03 21:21:43 +0000185 <jsl:jslint options="evil,forin,browser,bitwise,regexp,newcap,immed" encoding="UTF-8">
Roger Meierda6e6ae2011-03-15 09:55:33 +0000186 <formatter type="plain" />
Henrique Mendonça095ddb72013-09-20 19:38:03 +0200187 <fileset dir="../src" includes="thrift.js" />
Roger Meieredf0d1d2011-08-03 21:21:43 +0000188
189 <!-- issues with unsafe character -->
190 <!-- fileset dir="." includes="*test*.js" /> -->
Roger Meierda6e6ae2011-03-15 09:55:33 +0000191 </jsl:jslint>
192 </target>
193
194 <target name="check-gjslint">
195 <echo>check if gjslint is available:</echo>
196 <exec executable="gjslint" failifexecutionfails="no" resultproperty="gjslint.present" failonerror="false">
197 <arg line="--helpshort"/>
198 </exec>
199 </target>
Jake Farrellad6426c2011-04-20 16:35:20 +0000200
Roger Meierda6e6ae2011-03-15 09:55:33 +0000201 <target name="gjslint" depends="check-gjslint" if="gjslint.present">
202 <exec executable="gjslint" failifexecutionfails="no">
203 <arg line="--nojsdoc"/>
204 <arg line="${genjs}/*.js"/>
Henrique Mendonça095ddb72013-09-20 19:38:03 +0200205 <arg line="../src/thrift.js"/>
Roger Meieredf0d1d2011-08-03 21:21:43 +0000206
207 <!-- issues with unsafe character, etc. -->
208 <!-- <arg line="*test*.js"/> -->
Roger Meierda6e6ae2011-03-15 09:55:33 +0000209 </exec>
210 </target>
211
Roger Meier37b5bf82010-10-24 21:41:24 +0000212 <target name="clean">
213 <delete dir="${build}" />
214 <delete dir="${genjava}" />
215 <delete dir="${genjs}" />
Roger Meier37b5bf82010-10-24 21:41:24 +0000216 </target>
217
Alex Volanis7004a612018-01-24 10:30:13 -0500218 <target name="mvn.ant.tasks.download" depends="init,mvn.ant.tasks.check" unless="mvn.ant.tasks.found">
219 <get src="${mvn.ant.task.url}/${mvn.ant.task.jar}" dest="${build.tools.dir}/${mvn.ant.task.jar}" usetimestamp="true"/>
220 </target>
221
222 <target name="mvn.ant.tasks.check">
223 <condition property="mvn.ant.tasks.found">
224 <typefound uri="antlib:org.apache.maven.artifact.ant" name="artifact"/>
225 </condition>
226 </target>
227
228 <target name="resolve" depends="mvn.ant.tasks.download" unless="mvn.finished">
Jake Farrellad6426c2011-04-20 16:35:20 +0000229 <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 +0000230
Jake Farrellad6426c2011-04-20 16:35:20 +0000231 <artifact:dependencies filesetId="js.test.dependency.jars">
232 <dependency groupId="org.apache.httpcomponents" artifactId="httpclient" version="4.0.1"/>
233 <dependency groupId="com.googlecode.jslint4java" artifactId="jslint4java-ant" version="1.4.6"/>
Roger Meierc8d5d4d2012-01-07 20:32:24 +0000234 <dependency groupId="eu.medsea.mimeutil" artifactId="mime-util" version="2.1.3"/>
Jiayu Liueb62fa82022-05-08 13:01:41 +0800235 <dependency groupId="javax.annotation" artifactId="javax.annotation-api" version="1.3.2"/>
Kengo Sekid5a9bf22020-04-24 05:58:00 +0900236 <remoteRepository url="${mvn.repo}"/>
Jake Farrellad6426c2011-04-20 16:35:20 +0000237 </artifact:dependencies>
Roger Meier37b5bf82010-10-24 21:41:24 +0000238
Jake Farrellad6426c2011-04-20 16:35:20 +0000239 <!-- Copy the dependencies to the build/lib dir -->
240 <copy todir="${build}/lib">
241 <fileset refid="js.test.dependency.jars"/>
242 <mapper type="flatten"/>
243 </copy>
Roger Meier08562732015-06-14 22:30:22 +0200244
Jake Farrellad6426c2011-04-20 16:35:20 +0000245 <property name="mvn.finished" value="true"/>
Roger Meier37b5bf82010-10-24 21:41:24 +0000246 </target>
Roger Meier37b5bf82010-10-24 21:41:24 +0000247</project>