Roger Meier | 37b5bf8 | 2010-10-24 21:41:24 +0000 | [diff] [blame] | 1 | <!-- |
| 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 Farrell | ad6426c | 2011-04-20 16:35:20 +0000 | [diff] [blame] | 10 | http://www.apache.org/licenses/LICENSE-2.0 |
Roger Meier | 37b5bf8 | 2010-10-24 21:41:24 +0000 | [diff] [blame] | 11 | |
| 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 Meier | da6e6ae | 2011-03-15 09:55:33 +0000 | [diff] [blame] | 20 | xmlns:artifact="antlib:org.apache.maven.artifact.ant" |
| 21 | xmlns:jsl="antlib:com.googlecode.jslint4java"> |
Roger Meier | 37b5bf8 | 2010-10-24 21:41:24 +0000 | [diff] [blame] | 22 | |
| 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 Meier | edf0d1d | 2011-08-03 21:21:43 +0000 | [diff] [blame] | 29 | <property name="jar.file" location="${build}/jstest.jar" /> |
Roger Meier | 37b5bf8 | 2010-10-24 21:41:24 +0000 | [diff] [blame] | 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 Farrell | ad6426c | 2011-04-20 16:35:20 +0000 | [diff] [blame] | 35 | <!-- Include the base java properties file --> |
| 36 | <property file="${thrift.java.dir}/build.properties" /> |
Roger Meier | 37b5bf8 | 2010-10-24 21:41:24 +0000 | [diff] [blame] | 37 | |
Jake Farrell | ad6426c | 2011-04-20 16:35:20 +0000 | [diff] [blame] | 38 | <property name="thrift.compiler" location="${thrift.dir}/compiler/cpp/thrift" /> |
Roger Meier | 37b5bf8 | 2010-10-24 21:41:24 +0000 | [diff] [blame] | 39 | |
| 40 | <path id="libs.classpath"> |
Roger Meier | 2fdf05c | 2011-03-25 11:37:16 +0000 | [diff] [blame] | 41 | <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 Farrell | ad6426c | 2011-04-20 16:35:20 +0000 | [diff] [blame] | 47 | <fileset dir="${build}/lib"> |
Roger Meier | 37b5bf8 | 2010-10-24 21:41:24 +0000 | [diff] [blame] | 48 | <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 Meier | 2fdf05c | 2011-03-25 11:37:16 +0000 | [diff] [blame] | 61 | <resourcecount count="2"> |
Roger Meier | a35944b | 2011-07-15 20:16:43 +0000 | [diff] [blame] | 62 | <fileset id="fs" dir="${thrift.java.dir}/build"> |
| 63 | <include name="libthrift*.jar" /> |
| 64 | <exclude name="libthrift*javadoc.jar" /> |
| 65 | </fileset> |
Roger Meier | 37b5bf8 | 2010-10-24 21:41:24 +0000 | [diff] [blame] | 66 | </resourcecount> |
| 67 | </not> |
| 68 | </condition> |
Roger Meier | 2fdf05c | 2011-03-25 11:37:16 +0000 | [diff] [blame] | 69 | You need libthrift*.jar and libthrift*test.jar located at |
Roger Meier | 08b3099 | 2011-04-06 21:30:53 +0000 | [diff] [blame] | 70 | ${thrift.java.dir}/build |
Roger Meier | 37b5bf8 | 2010-10-24 21:41:24 +0000 | [diff] [blame] | 71 | 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 Meier | 37b5bf8 | 2010-10-24 21:41:24 +0000 | [diff] [blame] | 77 | <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 Meier | edf0d1d | 2011-08-03 21:21:43 +0000 | [diff] [blame] | 88 | <mkdir dir="${build}/js/lib"/> |
Jake Farrell | ad6426c | 2011-04-20 16:35:20 +0000 | [diff] [blame] | 89 | <mkdir dir="${build}/lib"/> |
Roger Meier | 0b26725 | 2011-07-29 21:08:04 +0000 | [diff] [blame] | 90 | <mkdir dir="${build}/log"/> |
Roger Meier | edf0d1d | 2011-08-03 21:21:43 +0000 | [diff] [blame] | 91 | <mkdir dir="${build}/test"/> |
| 92 | <mkdir dir="${build}/test/log"/> |
| 93 | </target> |
| 94 | |
| 95 | <target name="jslibs" depends="init, proxy"> |
Randy Abernethy | 5057b4c | 2014-09-30 17:34:44 -0700 | [diff] [blame] | 96 | <get src="http://code.jquery.com/jquery-1.7.2.js" dest="${build}/js/lib/jquery-1.7.2.js" usetimestamp="true"/> |
| 97 | <get src="http://js-test-driver.googlecode.com/svn/trunk/JsTestDriver/contrib/qunit/src/equiv.js" dest="${build}/js/lib/equiv.js" usetimestamp="true"/> |
| 98 | <get src="http://js-test-driver.googlecode.com/svn/trunk/JsTestDriver/contrib/qunit/src/QUnitAdapter.js" dest="${build}/js/lib/QUnitAdapter.js" usetimestamp="true"/> |
Roger Meier | edf0d1d | 2011-08-03 21:21:43 +0000 | [diff] [blame] | 99 | |
Roger Meier | e924874 | 2013-08-15 00:23:02 +0200 | [diff] [blame] | 100 | <get src="http://code.jquery.com/qunit/qunit-1.5.0.js" dest="${build}/js/lib/qunit.js" usetimestamp="true"/> |
| 101 | <get src="http://code.jquery.com/qunit/qunit-1.5.0.css" dest="${build}/js/lib/qunit.css" usetimestamp="true"/> |
Roger Meier | edf0d1d | 2011-08-03 21:21:43 +0000 | [diff] [blame] | 102 | <!-- js-test-driver has issues with relative path...so we need a copy --> |
Randy Abernethy | 5057b4c | 2014-09-30 17:34:44 -0700 | [diff] [blame] | 103 | <copy file="../src/thrift.js" todir="${build}/js/thrift.js"/> |
Roger Meier | 37b5bf8 | 2010-10-24 21:41:24 +0000 | [diff] [blame] | 104 | </target> |
| 105 | |
| 106 | <target name="compile" description="compile the test suite" depends="init, generate, resolve"> |
Roger Meier | edf0d1d | 2011-08-03 21:21:43 +0000 | [diff] [blame] | 107 | <!-- //TODO enable <compilerarg value="-Xlint"/>--> |
| 108 | <javac includeantruntime="false" srcdir="${genjava}" destdir="${build}/test" classpathref="libs.classpath"/> |
| 109 | <javac includeantruntime="false" srcdir="${src}" destdir="${build}/test" classpathref="libs.classpath"/> |
Roger Meier | 37b5bf8 | 2010-10-24 21:41:24 +0000 | [diff] [blame] | 110 | </target> |
| 111 | |
Roger Meier | 0b26725 | 2011-07-29 21:08:04 +0000 | [diff] [blame] | 112 | <target name="jstest" description="create the test suite jar file" depends="compile"> |
Roger Meier | edf0d1d | 2011-08-03 21:21:43 +0000 | [diff] [blame] | 113 | <jar jarfile="${jar.file}" basedir="${build}/test"/> |
Roger Meier | 37b5bf8 | 2010-10-24 21:41:24 +0000 | [diff] [blame] | 114 | </target> |
| 115 | |
Roger Meier | edf0d1d | 2011-08-03 21:21:43 +0000 | [diff] [blame] | 116 | <target name="testserver" description="run the test server" depends="jstest, jslibs"> |
Roger Meier | 37b5bf8 | 2010-10-24 21:41:24 +0000 | [diff] [blame] | 117 | <java classname="test.Httpd" fork="true" |
| 118 | classpathref="test.classpath" failonerror="true"> |
| 119 | <arg value="../" /> |
| 120 | </java> |
| 121 | </target> |
| 122 | |
Roger Meier | edf0d1d | 2011-08-03 21:21:43 +0000 | [diff] [blame] | 123 | <target name="proxy" if="proxy.enabled"> |
| 124 | <setproxy proxyhost="${proxy.host}" proxyport="${proxy.port}" |
| 125 | proxyuser="${proxy.user}" proxypassword="${proxy.pass}"/> |
| 126 | </target> |
| 127 | |
Roger Meier | 0b26725 | 2011-07-29 21:08:04 +0000 | [diff] [blame] | 128 | <target name="xvfb"> |
| 129 | <echo>check if Xvfb is available:</echo> |
| 130 | <exec executable="Xvfb" failifexecutionfails="no" resultproperty="xvfb.present" failonerror="false" output="${build}/log/xvfb.log"> |
| 131 | <arg line="--version"/> |
| 132 | </exec> |
| 133 | </target> |
| 134 | |
| 135 | <target name="phantomjs" depends="xvfb" if="xvfb.present"> |
| 136 | <echo>check if phantomjs is available:</echo> |
| 137 | <exec executable="phantomjs" failifexecutionfails="no" resultproperty="phantomjs.present" failonerror="false" output="${build}/log/phantomjs.log"> |
| 138 | <arg line="--version"/> |
| 139 | </exec> |
| 140 | </target> |
| 141 | |
Roger Meier | edf0d1d | 2011-08-03 21:21:43 +0000 | [diff] [blame] | 142 | <target name="unittest" description="do unit tests with headless browser phantomjs" depends="init, phantomjs, jstest, jslibs" if="phantomjs.present"> |
Roger Meier | 0b26725 | 2011-07-29 21:08:04 +0000 | [diff] [blame] | 143 | <parallel> |
| 144 | <exec executable="Xvfb" spawn="true" failonerror="false"> |
| 145 | <arg line=":99" /> |
| 146 | </exec> |
Roger Meier | 4f8a523 | 2011-09-09 08:17:02 +0000 | [diff] [blame] | 147 | <java classname="test.Httpd" fork="true" timeout="10000" |
Roger Meier | 0b26725 | 2011-07-29 21:08:04 +0000 | [diff] [blame] | 148 | classpathref="test.classpath" failonerror="false" output="${build}/log/unittest.log"> |
| 149 | <arg value="../" /> |
| 150 | </java> |
| 151 | <sequential> |
| 152 | <sleep seconds="2"/> |
| 153 | <echo>Running Unit Tests with headless browser!</echo> |
| 154 | <exec executable="phantomjs" failonerror="true"> |
| 155 | <env key="DISPLAY" value=":99"/> |
| 156 | <arg line="phantomjs-qunit.js http://localhost:8088/test/test.html" /> |
| 157 | </exec> |
| 158 | </sequential> |
| 159 | </parallel> |
| 160 | </target> |
| 161 | |
Roger Meier | edf0d1d | 2011-08-03 21:21:43 +0000 | [diff] [blame] | 162 | <target name="jstestdriver-server" description="start the js-test-driver server" depends="init, resolve"> |
| 163 | <echo>Starting js-test-driver Server...</echo> |
| 164 | <java jar="${build}/lib/jstestdriver-1.3.2.jar" dir="." fork="true" |
| 165 | failonerror="true" output="${build}/log/jstestdriver-server.log"> |
| 166 | <arg line="--port 9876"/> |
| 167 | </java> |
| 168 | </target> |
| 169 | |
| 170 | <target name="jstestdriver" description="do unit tests with js-test-driver" depends="init, jstest, jslibs"> |
| 171 | <parallel> |
| 172 | <java classname="test.Httpd" fork="true" timeout="10000" |
| 173 | classpathref="test.classpath" failonerror="false" output="${build}/log/unittest.log"> |
| 174 | <arg value="../" /> |
| 175 | </java> |
| 176 | <sequential> |
| 177 | <sleep seconds="2"/> |
| 178 | <echo>Running Unit Tests with js-test-driver</echo> |
| 179 | <java jar="${build}/lib/jstestdriver-1.3.2.jar" dir="." fork="true" |
| 180 | failonerror="true" output="${build}/log/jstestdriver.log"> |
| 181 | <arg value="--config" /> |
| 182 | <arg value="jsTestDriver.conf" /> |
| 183 | |
| 184 | <arg value="--reset" /> |
| 185 | <arg value="--verbose" /> |
| 186 | |
| 187 | <arg value="--tests" /> |
| 188 | <arg value="all" /> |
| 189 | |
| 190 | <arg value="--testOutput" /> |
| 191 | <arg value="${build}/test/log/" /> |
| 192 | </java> |
| 193 | </sequential> |
| 194 | </parallel> |
| 195 | </target> |
| 196 | |
Roger Meier | 37b5bf8 | 2010-10-24 21:41:24 +0000 | [diff] [blame] | 197 | <target name="generate"> |
| 198 | <exec executable="${thrift.compiler}" failonerror="true"> |
| 199 | <arg line="--gen java ${thrift.dir}/test/ThriftTest.thrift" /> |
| 200 | </exec> |
| 201 | <exec executable="${thrift.compiler}" failonerror="true"> |
Roger Meier | 08b3099 | 2011-04-06 21:30:53 +0000 | [diff] [blame] | 202 | <arg line="--gen js:jquery ${thrift.dir}/test/ThriftTest.thrift" /> |
Roger Meier | 37b5bf8 | 2010-10-24 21:41:24 +0000 | [diff] [blame] | 203 | </exec> |
| 204 | </target> |
| 205 | |
Roger Meier | edf0d1d | 2011-08-03 21:21:43 +0000 | [diff] [blame] | 206 | <target name="test" description="run test suite (lint, unittest)" depends="lint, unittest"/> |
Roger Meier | f249576 | 2011-03-17 19:13:36 +0000 | [diff] [blame] | 207 | |
Roger Meier | edf0d1d | 2011-08-03 21:21:43 +0000 | [diff] [blame] | 208 | <target name="lint" description="code quality checks (jslint and gjslint if available)" depends="generate, gjslint, jslint"/> |
Roger Meier | da6e6ae | 2011-03-15 09:55:33 +0000 | [diff] [blame] | 209 | |
Roger Meier | edf0d1d | 2011-08-03 21:21:43 +0000 | [diff] [blame] | 210 | <target name="jslint" depends="resolve"> |
Roger Meier | 42a6fa4 | 2011-03-21 21:26:35 +0000 | [diff] [blame] | 211 | <taskdef uri="antlib:com.googlecode.jslint4java" resource="com/googlecode/jslint4java/antlib.xml" classpathref="libs.classpath" /> |
Roger Meier | da6e6ae | 2011-03-15 09:55:33 +0000 | [diff] [blame] | 212 | <!-- |
| 213 | the following options would probably make sense in the future: |
| 214 | browser,undef,eqeqeq,plusplus,bitwise,regexp,strict,newcap,immed |
| 215 | --> |
Roger Meier | edf0d1d | 2011-08-03 21:21:43 +0000 | [diff] [blame] | 216 | <jsl:jslint options="evil,forin,browser,bitwise,regexp,newcap,immed" encoding="UTF-8"> |
Roger Meier | da6e6ae | 2011-03-15 09:55:33 +0000 | [diff] [blame] | 217 | <formatter type="plain" /> |
| 218 | <fileset dir="${genjs}" includes="**/*.js" /> |
Henrique Mendonça | 095ddb7 | 2013-09-20 19:38:03 +0200 | [diff] [blame] | 219 | <fileset dir="../src" includes="thrift.js" /> |
Roger Meier | edf0d1d | 2011-08-03 21:21:43 +0000 | [diff] [blame] | 220 | |
| 221 | <!-- issues with unsafe character --> |
| 222 | <!-- fileset dir="." includes="*test*.js" /> --> |
Roger Meier | da6e6ae | 2011-03-15 09:55:33 +0000 | [diff] [blame] | 223 | </jsl:jslint> |
| 224 | </target> |
| 225 | |
| 226 | <target name="check-gjslint"> |
| 227 | <echo>check if gjslint is available:</echo> |
| 228 | <exec executable="gjslint" failifexecutionfails="no" resultproperty="gjslint.present" failonerror="false"> |
| 229 | <arg line="--helpshort"/> |
| 230 | </exec> |
| 231 | </target> |
Jake Farrell | ad6426c | 2011-04-20 16:35:20 +0000 | [diff] [blame] | 232 | |
Roger Meier | da6e6ae | 2011-03-15 09:55:33 +0000 | [diff] [blame] | 233 | <target name="gjslint" depends="check-gjslint" if="gjslint.present"> |
| 234 | <exec executable="gjslint" failifexecutionfails="no"> |
| 235 | <arg line="--nojsdoc"/> |
| 236 | <arg line="${genjs}/*.js"/> |
Henrique Mendonça | 095ddb7 | 2013-09-20 19:38:03 +0200 | [diff] [blame] | 237 | <arg line="../src/thrift.js"/> |
Roger Meier | edf0d1d | 2011-08-03 21:21:43 +0000 | [diff] [blame] | 238 | |
| 239 | <!-- issues with unsafe character, etc. --> |
| 240 | <!-- <arg line="*test*.js"/> --> |
Roger Meier | da6e6ae | 2011-03-15 09:55:33 +0000 | [diff] [blame] | 241 | </exec> |
| 242 | </target> |
| 243 | |
Roger Meier | 37b5bf8 | 2010-10-24 21:41:24 +0000 | [diff] [blame] | 244 | <target name="clean"> |
| 245 | <delete dir="${build}" /> |
| 246 | <delete dir="${genjava}" /> |
| 247 | <delete dir="${genjs}" /> |
Roger Meier | 37b5bf8 | 2010-10-24 21:41:24 +0000 | [diff] [blame] | 248 | </target> |
| 249 | |
Jake Farrell | ad6426c | 2011-04-20 16:35:20 +0000 | [diff] [blame] | 250 | <target name="resolve" unless="mvn.finished"> |
| 251 | <typedef uri="antlib:org.apache.maven.artifact.ant" classpath="${thrift.java.dir}/build/tools/${mvn.ant.task.jar}"/> |
Roger Meier | 37b5bf8 | 2010-10-24 21:41:24 +0000 | [diff] [blame] | 252 | |
Jake Farrell | ad6426c | 2011-04-20 16:35:20 +0000 | [diff] [blame] | 253 | <artifact:dependencies filesetId="js.test.dependency.jars"> |
| 254 | <dependency groupId="org.apache.httpcomponents" artifactId="httpclient" version="4.0.1"/> |
| 255 | <dependency groupId="com.googlecode.jslint4java" artifactId="jslint4java-ant" version="1.4.6"/> |
Roger Meier | c8d5d4d | 2012-01-07 20:32:24 +0000 | [diff] [blame] | 256 | <dependency groupId="eu.medsea.mimeutil" artifactId="mime-util" version="2.1.3"/> |
Roger Meier | edf0d1d | 2011-08-03 21:21:43 +0000 | [diff] [blame] | 257 | <!-- get jstestdriver.jar via maven--> |
| 258 | <remoteRepository id="jstd-maven-plugin google code repo" url="http://jstd-maven-plugin.googlecode.com/svn/maven2"/> |
| 259 | <dependency groupId="com.google.jstestdriver" artifactId="maven-jstestdriver-plugin" version="1.3.2.3"/> |
Jake Farrell | ad6426c | 2011-04-20 16:35:20 +0000 | [diff] [blame] | 260 | </artifact:dependencies> |
Roger Meier | 37b5bf8 | 2010-10-24 21:41:24 +0000 | [diff] [blame] | 261 | |
Jake Farrell | ad6426c | 2011-04-20 16:35:20 +0000 | [diff] [blame] | 262 | <!-- Copy the dependencies to the build/lib dir --> |
| 263 | <copy todir="${build}/lib"> |
| 264 | <fileset refid="js.test.dependency.jars"/> |
| 265 | <mapper type="flatten"/> |
| 266 | </copy> |
| 267 | |
| 268 | <property name="mvn.finished" value="true"/> |
Roger Meier | 37b5bf8 | 2010-10-24 21:41:24 +0000 | [diff] [blame] | 269 | </target> |
Roger Meier | 37b5bf8 | 2010-10-24 21:41:24 +0000 | [diff] [blame] | 270 | </project> |
Jake Farrell | ad6426c | 2011-04-20 16:35:20 +0000 | [diff] [blame] | 271 | |