blob: b3a6b3e0d21a1038df170b71dace8a2beca8c729 [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" />
34
Jake Farrellad6426c2011-04-20 16:35:20 +000035 <!-- Include the base java properties file -->
36 <property file="${thrift.java.dir}/build.properties" />
Roger Meier37b5bf82010-10-24 21:41:24 +000037
Jake Farrellad6426c2011-04-20 16:35:20 +000038 <property name="thrift.compiler" location="${thrift.dir}/compiler/cpp/thrift" />
Roger Meier37b5bf82010-10-24 21:41:24 +000039
40 <path id="libs.classpath">
Roger Meier2fdf05c2011-03-25 11:37:16 +000041 <fileset dir="${thrift.java.dir}/build/">
42 <include name="*.jar" />
43 </fileset>
44 <fileset dir="${thrift.java.dir}/build/lib">
45 <include name="*.jar" />
46 </fileset>
Jake Farrellad6426c2011-04-20 16:35:20 +000047 <fileset dir="${build}/lib">
Roger Meier37b5bf82010-10-24 21:41:24 +000048 <include name="*.jar" />
49 </fileset>
50 </path>
51
52 <path id="test.classpath">
53 <path refid="libs.classpath" />
54 <pathelement location="${jar.file}" />
55 </path>
56
57 <target name="dependencies">
58 <fail>
59 <condition>
60 <not>
Roger Meier2fdf05c2011-03-25 11:37:16 +000061 <resourcecount count="2">
Roger Meiera35944b2011-07-15 20:16:43 +000062 <fileset id="fs" dir="${thrift.java.dir}/build">
63 <include name="libthrift*.jar" />
64 <exclude name="libthrift*javadoc.jar" />
65 </fileset>
Roger Meier37b5bf82010-10-24 21:41:24 +000066 </resourcecount>
67 </not>
68 </condition>
Roger Meier2fdf05c2011-03-25 11:37:16 +000069 You need libthrift*.jar and libthrift*test.jar located at
Roger Meier08b30992011-04-06 21:30:53 +000070 ${thrift.java.dir}/build
Roger Meier37b5bf82010-10-24 21:41:24 +000071 Did you compile Thrift Java library and its test suite by "ant compile-test"?
72 </fail>
73 <fail>
74 <condition>
75 <not>
76 <resourcecount count="1">
Roger Meier37b5bf82010-10-24 21:41:24 +000077 <fileset id="fs" dir="${thrift.dir}" includes="compiler/cpp/thrift"/>
78 </resourcecount>
79 </not>
80 </condition>
81 Thrift compiler is missing !
82 </fail>
83 </target>
84
85 <target name="init" depends="dependencies">
86 <tstamp />
87 <mkdir dir="${build}"/>
Roger Meieredf0d1d2011-08-03 21:21:43 +000088 <mkdir dir="${build}/js/lib"/>
Jake Farrellad6426c2011-04-20 16:35:20 +000089 <mkdir dir="${build}/lib"/>
Roger Meier0b267252011-07-29 21:08:04 +000090 <mkdir dir="${build}/log"/>
Roger Meieredf0d1d2011-08-03 21:21:43 +000091 <mkdir dir="${build}/test"/>
92 <mkdir dir="${build}/test/log"/>
93 </target>
94
95 <target name="jslibs" depends="init, proxy">
Nobuaki Sukegawa63b51202015-05-10 23:35:07 +090096 <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 +090097 <get src="http://code.jquery.com/qunit/qunit-1.18.0.js" dest="${build}/js/lib/qunit.js" usetimestamp="true"/>
98 <get src="http://code.jquery.com/qunit/qunit-1.18.0.css" dest="${build}/js/lib/qunit.css" usetimestamp="true"/>
Roger Meier37b5bf82010-10-24 21:41:24 +000099 </target>
100
101 <target name="compile" description="compile the test suite" depends="init, generate, resolve">
Roger Meieredf0d1d2011-08-03 21:21:43 +0000102 <!-- //TODO enable <compilerarg value="-Xlint"/>-->
103 <javac includeantruntime="false" srcdir="${genjava}" destdir="${build}/test" classpathref="libs.classpath"/>
104 <javac includeantruntime="false" srcdir="${src}" destdir="${build}/test" classpathref="libs.classpath"/>
Roger Meier37b5bf82010-10-24 21:41:24 +0000105 </target>
106
Roger Meier0b267252011-07-29 21:08:04 +0000107 <target name="jstest" description="create the test suite jar file" depends="compile">
Roger Meieredf0d1d2011-08-03 21:21:43 +0000108 <jar jarfile="${jar.file}" basedir="${build}/test"/>
Roger Meier37b5bf82010-10-24 21:41:24 +0000109 </target>
110
Roger Meieredf0d1d2011-08-03 21:21:43 +0000111 <target name="testserver" description="run the test server" depends="jstest, jslibs">
Roger Meier37b5bf82010-10-24 21:41:24 +0000112 <java classname="test.Httpd" fork="true"
113 classpathref="test.classpath" failonerror="true">
114 <arg value="../" />
115 </java>
116 </target>
117
Roger Meieredf0d1d2011-08-03 21:21:43 +0000118 <target name="proxy" if="proxy.enabled">
119 <setproxy proxyhost="${proxy.host}" proxyport="${proxy.port}"
120 proxyuser="${proxy.user}" proxypassword="${proxy.pass}"/>
121 </target>
122
Roger Meier0b267252011-07-29 21:08:04 +0000123 <target name="xvfb">
124 <echo>check if Xvfb is available:</echo>
125 <exec executable="Xvfb" failifexecutionfails="no" resultproperty="xvfb.present" failonerror="false" output="${build}/log/xvfb.log">
126 <arg line="--version"/>
127 </exec>
128 </target>
129
130 <target name="phantomjs" depends="xvfb" if="xvfb.present">
131 <echo>check if phantomjs is available:</echo>
132 <exec executable="phantomjs" failifexecutionfails="no" resultproperty="phantomjs.present" failonerror="false" output="${build}/log/phantomjs.log">
133 <arg line="--version"/>
134 </exec>
135 </target>
136
Roger Meieredf0d1d2011-08-03 21:21:43 +0000137 <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 +0000138 <parallel>
139 <exec executable="Xvfb" spawn="true" failonerror="false">
140 <arg line=":99" />
141 </exec>
Roger Meier4f8a5232011-09-09 08:17:02 +0000142 <java classname="test.Httpd" fork="true" timeout="10000"
Roger Meier0b267252011-07-29 21:08:04 +0000143 classpathref="test.classpath" failonerror="false" output="${build}/log/unittest.log">
144 <arg value="../" />
145 </java>
146 <sequential>
147 <sleep seconds="2"/>
148 <echo>Running Unit Tests with headless browser!</echo>
149 <exec executable="phantomjs" failonerror="true">
150 <env key="DISPLAY" value=":99"/>
151 <arg line="phantomjs-qunit.js http://localhost:8088/test/test.html" />
152 </exec>
153 </sequential>
154 </parallel>
155 </target>
156
Roger Meier37b5bf82010-10-24 21:41:24 +0000157 <target name="generate">
158 <exec executable="${thrift.compiler}" failonerror="true">
159 <arg line="--gen java ${thrift.dir}/test/ThriftTest.thrift" />
160 </exec>
161 <exec executable="${thrift.compiler}" failonerror="true">
Roger Meier08b30992011-04-06 21:30:53 +0000162 <arg line="--gen js:jquery ${thrift.dir}/test/ThriftTest.thrift" />
Roger Meier37b5bf82010-10-24 21:41:24 +0000163 </exec>
164 </target>
165
Roger Meieredf0d1d2011-08-03 21:21:43 +0000166 <target name="test" description="run test suite (lint, unittest)" depends="lint, unittest"/>
Roger Meierf2495762011-03-17 19:13:36 +0000167
Roger Meieredf0d1d2011-08-03 21:21:43 +0000168 <target name="lint" description="code quality checks (jslint and gjslint if available)" depends="generate, gjslint, jslint"/>
Roger Meierda6e6ae2011-03-15 09:55:33 +0000169
Roger Meieredf0d1d2011-08-03 21:21:43 +0000170 <target name="jslint" depends="resolve">
Roger Meier42a6fa42011-03-21 21:26:35 +0000171 <taskdef uri="antlib:com.googlecode.jslint4java" resource="com/googlecode/jslint4java/antlib.xml" classpathref="libs.classpath" />
Roger Meierda6e6ae2011-03-15 09:55:33 +0000172 <!--
173 the following options would probably make sense in the future:
174 browser,undef,eqeqeq,plusplus,bitwise,regexp,strict,newcap,immed
175 -->
Roger Meieredf0d1d2011-08-03 21:21:43 +0000176 <jsl:jslint options="evil,forin,browser,bitwise,regexp,newcap,immed" encoding="UTF-8">
Roger Meierda6e6ae2011-03-15 09:55:33 +0000177 <formatter type="plain" />
178 <fileset dir="${genjs}" includes="**/*.js" />
Henrique Mendonça095ddb72013-09-20 19:38:03 +0200179 <fileset dir="../src" includes="thrift.js" />
Roger Meieredf0d1d2011-08-03 21:21:43 +0000180
181 <!-- issues with unsafe character -->
182 <!-- fileset dir="." includes="*test*.js" /> -->
Roger Meierda6e6ae2011-03-15 09:55:33 +0000183 </jsl:jslint>
184 </target>
185
186 <target name="check-gjslint">
187 <echo>check if gjslint is available:</echo>
188 <exec executable="gjslint" failifexecutionfails="no" resultproperty="gjslint.present" failonerror="false">
189 <arg line="--helpshort"/>
190 </exec>
191 </target>
Jake Farrellad6426c2011-04-20 16:35:20 +0000192
Roger Meierda6e6ae2011-03-15 09:55:33 +0000193 <target name="gjslint" depends="check-gjslint" if="gjslint.present">
194 <exec executable="gjslint" failifexecutionfails="no">
195 <arg line="--nojsdoc"/>
196 <arg line="${genjs}/*.js"/>
Henrique Mendonça095ddb72013-09-20 19:38:03 +0200197 <arg line="../src/thrift.js"/>
Roger Meieredf0d1d2011-08-03 21:21:43 +0000198
199 <!-- issues with unsafe character, etc. -->
200 <!-- <arg line="*test*.js"/> -->
Roger Meierda6e6ae2011-03-15 09:55:33 +0000201 </exec>
202 </target>
203
Roger Meier37b5bf82010-10-24 21:41:24 +0000204 <target name="clean">
205 <delete dir="${build}" />
206 <delete dir="${genjava}" />
207 <delete dir="${genjs}" />
Roger Meier37b5bf82010-10-24 21:41:24 +0000208 </target>
209
Jake Farrellad6426c2011-04-20 16:35:20 +0000210 <target name="resolve" unless="mvn.finished">
211 <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 +0000212
Jake Farrellad6426c2011-04-20 16:35:20 +0000213 <artifact:dependencies filesetId="js.test.dependency.jars">
214 <dependency groupId="org.apache.httpcomponents" artifactId="httpclient" version="4.0.1"/>
215 <dependency groupId="com.googlecode.jslint4java" artifactId="jslint4java-ant" version="1.4.6"/>
Roger Meierc8d5d4d2012-01-07 20:32:24 +0000216 <dependency groupId="eu.medsea.mimeutil" artifactId="mime-util" version="2.1.3"/>
Jake Farrellad6426c2011-04-20 16:35:20 +0000217 </artifact:dependencies>
Roger Meier37b5bf82010-10-24 21:41:24 +0000218
Jake Farrellad6426c2011-04-20 16:35:20 +0000219 <!-- Copy the dependencies to the build/lib dir -->
220 <copy todir="${build}/lib">
221 <fileset refid="js.test.dependency.jars"/>
222 <mapper type="flatten"/>
223 </copy>
Roger Meier08562732015-06-14 22:30:22 +0200224
Jake Farrellad6426c2011-04-20 16:35:20 +0000225 <property name="mvn.finished" value="true"/>
Roger Meier37b5bf82010-10-24 21:41:24 +0000226 </target>
Roger Meier37b5bf82010-10-24 21:41:24 +0000227</project>