blob: c052e640d8e0b20cf766fe4aa5bc0775729969f6 [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" />
29 <property name="jar.file" location="${basedir}/jstest.jar" />
30
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}"/>
Jake Farrellad6426c2011-04-20 16:35:20 +000088 <mkdir dir="${build}/lib"/>
Roger Meier0b267252011-07-29 21:08:04 +000089 <mkdir dir="${build}/log"/>
Roger Meier37b5bf82010-10-24 21:41:24 +000090 </target>
91
92 <target name="compile" description="compile the test suite" depends="init, generate, resolve">
93 <javac srcdir="${genjava}" destdir="${build}" classpathref="libs.classpath" />
94 <javac srcdir="${src}" destdir="${build}" classpathref="libs.classpath" />
95 </target>
96
Roger Meier0b267252011-07-29 21:08:04 +000097 <target name="jstest" description="create the test suite jar file" depends="compile">
Roger Meier37b5bf82010-10-24 21:41:24 +000098 <jar jarfile="${jar.file}" basedir="${build}"/>
99 </target>
100
Roger Meierf2495762011-03-17 19:13:36 +0000101 <target name="testserver" description="run the test server" depends="jstest">
Roger Meier37b5bf82010-10-24 21:41:24 +0000102 <java classname="test.Httpd" fork="true"
103 classpathref="test.classpath" failonerror="true">
104 <arg value="../" />
105 </java>
106 </target>
107
Roger Meier0b267252011-07-29 21:08:04 +0000108 <target name="xvfb">
109 <echo>check if Xvfb is available:</echo>
110 <exec executable="Xvfb" failifexecutionfails="no" resultproperty="xvfb.present" failonerror="false" output="${build}/log/xvfb.log">
111 <arg line="--version"/>
112 </exec>
113 </target>
114
115 <target name="phantomjs" depends="xvfb" if="xvfb.present">
116 <echo>check if phantomjs is available:</echo>
117 <exec executable="phantomjs" failifexecutionfails="no" resultproperty="phantomjs.present" failonerror="false" output="${build}/log/phantomjs.log">
118 <arg line="--version"/>
119 </exec>
120 </target>
121
122 <target name="unittest" description="do unit tests with headless browser phantomjs" depends="phantomjs, jstest" if="phantomjs.present">
123 <parallel>
124 <exec executable="Xvfb" spawn="true" failonerror="false">
125 <arg line=":99" />
126 </exec>
127 <java classname="test.Httpd" fork="true" timeout="5000"
128 classpathref="test.classpath" failonerror="false" output="${build}/log/unittest.log">
129 <arg value="../" />
130 </java>
131 <sequential>
132 <sleep seconds="2"/>
133 <echo>Running Unit Tests with headless browser!</echo>
134 <exec executable="phantomjs" failonerror="true">
135 <env key="DISPLAY" value=":99"/>
136 <arg line="phantomjs-qunit.js http://localhost:8088/test/test.html" />
137 </exec>
138 </sequential>
139 </parallel>
140 </target>
141
Roger Meier37b5bf82010-10-24 21:41:24 +0000142 <target name="generate">
143 <exec executable="${thrift.compiler}" failonerror="true">
144 <arg line="--gen java ${thrift.dir}/test/ThriftTest.thrift" />
145 </exec>
146 <exec executable="${thrift.compiler}" failonerror="true">
Roger Meier08b30992011-04-06 21:30:53 +0000147 <arg line="--gen js:jquery ${thrift.dir}/test/ThriftTest.thrift" />
Roger Meier37b5bf82010-10-24 21:41:24 +0000148 </exec>
149 </target>
150
Roger Meier0b267252011-07-29 21:08:04 +0000151 <target name="test" description="run test suite" depends="init, generate, resolve, lint, jstest, unittest"/>
Roger Meierf2495762011-03-17 19:13:36 +0000152
Roger Meier08b30992011-04-06 21:30:53 +0000153 <target name="lint" description="code quality checks" depends="generate, gjslint, jslint"/>
Roger Meierda6e6ae2011-03-15 09:55:33 +0000154
155 <target name="jslint">
Roger Meier42a6fa42011-03-21 21:26:35 +0000156 <taskdef uri="antlib:com.googlecode.jslint4java" resource="com/googlecode/jslint4java/antlib.xml" classpathref="libs.classpath" />
Roger Meierda6e6ae2011-03-15 09:55:33 +0000157 <!--
158 the following options would probably make sense in the future:
159 browser,undef,eqeqeq,plusplus,bitwise,regexp,strict,newcap,immed
160 -->
Jake Farrellad6426c2011-04-20 16:35:20 +0000161 <jsl:jslint options="evil,forin,browser,bitwise,regexp,newcap,immed">
Roger Meierda6e6ae2011-03-15 09:55:33 +0000162 <formatter type="plain" />
163 <fileset dir="${genjs}" includes="**/*.js" />
164 <fileset dir=".." includes="thrift.js" />
165 </jsl:jslint>
166 </target>
167
168 <target name="check-gjslint">
169 <echo>check if gjslint is available:</echo>
170 <exec executable="gjslint" failifexecutionfails="no" resultproperty="gjslint.present" failonerror="false">
171 <arg line="--helpshort"/>
172 </exec>
173 </target>
Jake Farrellad6426c2011-04-20 16:35:20 +0000174
Roger Meierda6e6ae2011-03-15 09:55:33 +0000175 <target name="gjslint" depends="check-gjslint" if="gjslint.present">
176 <exec executable="gjslint" failifexecutionfails="no">
177 <arg line="--nojsdoc"/>
178 <arg line="${genjs}/*.js"/>
179 <arg line="../thrift.js"/>
180 </exec>
181 </target>
182
Roger Meier37b5bf82010-10-24 21:41:24 +0000183 <target name="clean">
184 <delete dir="${build}" />
185 <delete dir="${genjava}" />
186 <delete dir="${genjs}" />
187 <delete file="${jar.file}" />
188 </target>
189
Jake Farrellad6426c2011-04-20 16:35:20 +0000190 <target name="resolve" unless="mvn.finished">
191 <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 +0000192
Jake Farrellad6426c2011-04-20 16:35:20 +0000193 <artifact:dependencies filesetId="js.test.dependency.jars">
194 <dependency groupId="org.apache.httpcomponents" artifactId="httpclient" version="4.0.1"/>
195 <dependency groupId="com.googlecode.jslint4java" artifactId="jslint4java-ant" version="1.4.6"/>
196 </artifact:dependencies>
Roger Meier37b5bf82010-10-24 21:41:24 +0000197
Jake Farrellad6426c2011-04-20 16:35:20 +0000198 <!-- Copy the dependencies to the build/lib dir -->
199 <copy todir="${build}/lib">
200 <fileset refid="js.test.dependency.jars"/>
201 <mapper type="flatten"/>
202 </copy>
203
204 <property name="mvn.finished" value="true"/>
Roger Meier37b5bf82010-10-24 21:41:24 +0000205 </target>
Roger Meier37b5bf82010-10-24 21:41:24 +0000206</project>
Jake Farrellad6426c2011-04-20 16:35:20 +0000207