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" /> |
Alex Volanis | 7004a61 | 2018-01-24 10:30:13 -0500 | [diff] [blame] | 34 | <property name="build.tools.dir" location="${thrift.java.dir}/build/tools/"/> |
| 35 | <property file="${basedir}/build.properties"/> |
Roger Meier | 37b5bf8 | 2010-10-24 21:41:24 +0000 | [diff] [blame] | 36 | |
Jake Farrell | ad6426c | 2011-04-20 16:35:20 +0000 | [diff] [blame] | 37 | <!-- Include the base java properties file --> |
Alex Volanis | 7004a61 | 2018-01-24 10:30:13 -0500 | [diff] [blame] | 38 | <property file="${thrift.java.dir}/gradle.properties" /> |
Roger Meier | 37b5bf8 | 2010-10-24 21:41:24 +0000 | [diff] [blame] | 39 | |
Jake Farrell | ad6426c | 2011-04-20 16:35:20 +0000 | [diff] [blame] | 40 | <property name="thrift.compiler" location="${thrift.dir}/compiler/cpp/thrift" /> |
Roger Meier | 37b5bf8 | 2010-10-24 21:41:24 +0000 | [diff] [blame] | 41 | |
| 42 | <path id="libs.classpath"> |
Alex Volanis | 7004a61 | 2018-01-24 10:30:13 -0500 | [diff] [blame] | 43 | <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 Meier | 2fdf05c | 2011-03-25 11:37:16 +0000 | [diff] [blame] | 47 | </fileset> |
Alex Volanis | 7004a61 | 2018-01-24 10:30:13 -0500 | [diff] [blame] | 48 | <fileset dir="${thrift.java.dir}/build/deps"> |
Roger Meier | 2fdf05c | 2011-03-25 11:37:16 +0000 | [diff] [blame] | 49 | <include name="*.jar" /> |
| 50 | </fileset> |
Jake Farrell | ad6426c | 2011-04-20 16:35:20 +0000 | [diff] [blame] | 51 | <fileset dir="${build}/lib"> |
Roger Meier | 37b5bf8 | 2010-10-24 21:41:24 +0000 | [diff] [blame] | 52 | <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 Meier | 2fdf05c | 2011-03-25 11:37:16 +0000 | [diff] [blame] | 65 | <resourcecount count="2"> |
Alex Volanis | 7004a61 | 2018-01-24 10:30:13 -0500 | [diff] [blame] | 66 | <fileset id="fs" dir="${thrift.java.dir}/build/libs"> |
Roger Meier | a35944b | 2011-07-15 20:16:43 +0000 | [diff] [blame] | 67 | <include name="libthrift*.jar" /> |
| 68 | <exclude name="libthrift*javadoc.jar" /> |
Alex Volanis | 7004a61 | 2018-01-24 10:30:13 -0500 | [diff] [blame] | 69 | <exclude name="libthrift*sources.jar" /> |
Roger Meier | a35944b | 2011-07-15 20:16:43 +0000 | [diff] [blame] | 70 | </fileset> |
Roger Meier | 37b5bf8 | 2010-10-24 21:41:24 +0000 | [diff] [blame] | 71 | </resourcecount> |
| 72 | </not> |
| 73 | </condition> |
Roger Meier | 2fdf05c | 2011-03-25 11:37:16 +0000 | [diff] [blame] | 74 | You need libthrift*.jar and libthrift*test.jar located at |
Roger Meier | 08b3099 | 2011-04-06 21:30:53 +0000 | [diff] [blame] | 75 | ${thrift.java.dir}/build |
Roger Meier | 37b5bf8 | 2010-10-24 21:41:24 +0000 | [diff] [blame] | 76 | 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 Meier | 37b5bf8 | 2010-10-24 21:41:24 +0000 | [diff] [blame] | 82 | <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 Volanis | 7004a61 | 2018-01-24 10:30:13 -0500 | [diff] [blame] | 92 | <mkdir dir="${build.tools.dir}"/> |
Roger Meier | 37b5bf8 | 2010-10-24 21:41:24 +0000 | [diff] [blame] | 93 | <mkdir dir="${build}"/> |
Roger Meier | edf0d1d | 2011-08-03 21:21:43 +0000 | [diff] [blame] | 94 | <mkdir dir="${build}/js/lib"/> |
Jake Farrell | ad6426c | 2011-04-20 16:35:20 +0000 | [diff] [blame] | 95 | <mkdir dir="${build}/lib"/> |
Roger Meier | 0b26725 | 2011-07-29 21:08:04 +0000 | [diff] [blame] | 96 | <mkdir dir="${build}/log"/> |
Roger Meier | edf0d1d | 2011-08-03 21:21:43 +0000 | [diff] [blame] | 97 | <mkdir dir="${build}/test"/> |
| 98 | <mkdir dir="${build}/test/log"/> |
| 99 | </target> |
| 100 | |
| 101 | <target name="jslibs" depends="init, proxy"> |
Nobuaki Sukegawa | 63b5120 | 2015-05-10 23:35:07 +0900 | [diff] [blame] | 102 | <get src="http://code.jquery.com/jquery-1.11.3.min.js" dest="${build}/js/lib/jquery.js" usetimestamp="true"/> |
Nobuaki Sukegawa | 63b5120 | 2015-05-10 23:35:07 +0900 | [diff] [blame] | 103 | <get src="http://code.jquery.com/qunit/qunit-1.18.0.js" dest="${build}/js/lib/qunit.js" usetimestamp="true"/> |
| 104 | <get src="http://code.jquery.com/qunit/qunit-1.18.0.css" dest="${build}/js/lib/qunit.css" usetimestamp="true"/> |
Philip Frank | 8fdd610 | 2017-12-06 12:38:05 +0100 | [diff] [blame] | 105 | <get src="https://cdn.jsdelivr.net/npm/es6-promise@4/dist/es6-promise.auto.js" dest="${build}/js/lib/es6-promise.js" usetimestamp="true"/> |
Roger Meier | 37b5bf8 | 2010-10-24 21:41:24 +0000 | [diff] [blame] | 106 | </target> |
| 107 | |
| 108 | <target name="compile" description="compile the test suite" depends="init, generate, resolve"> |
Roger Meier | edf0d1d | 2011-08-03 21:21:43 +0000 | [diff] [blame] | 109 | <!-- //TODO enable <compilerarg value="-Xlint"/>--> |
James E. King, III | cf25489 | 2017-01-25 20:34:04 -0500 | [diff] [blame] | 110 | <javac compiler="modern" includeantruntime="false" srcdir="${genjava}" destdir="${build}/test" classpathref="libs.classpath"/> |
| 111 | <javac compiler="modern" includeantruntime="false" srcdir="${src}" destdir="${build}/test" classpathref="libs.classpath"/> |
Roger Meier | 37b5bf8 | 2010-10-24 21:41:24 +0000 | [diff] [blame] | 112 | </target> |
| 113 | |
Roger Meier | 0b26725 | 2011-07-29 21:08:04 +0000 | [diff] [blame] | 114 | <target name="jstest" description="create the test suite jar file" depends="compile"> |
Roger Meier | edf0d1d | 2011-08-03 21:21:43 +0000 | [diff] [blame] | 115 | <jar jarfile="${jar.file}" basedir="${build}/test"/> |
Roger Meier | 37b5bf8 | 2010-10-24 21:41:24 +0000 | [diff] [blame] | 116 | </target> |
| 117 | |
Roger Meier | edf0d1d | 2011-08-03 21:21:43 +0000 | [diff] [blame] | 118 | <target name="testserver" description="run the test server" depends="jstest, jslibs"> |
Roger Meier | 37b5bf8 | 2010-10-24 21:41:24 +0000 | [diff] [blame] | 119 | <java classname="test.Httpd" fork="true" |
| 120 | classpathref="test.classpath" failonerror="true"> |
| 121 | <arg value="../" /> |
| 122 | </java> |
| 123 | </target> |
| 124 | |
Roger Meier | edf0d1d | 2011-08-03 21:21:43 +0000 | [diff] [blame] | 125 | <target name="proxy" if="proxy.enabled"> |
| 126 | <setproxy proxyhost="${proxy.host}" proxyport="${proxy.port}" |
| 127 | proxyuser="${proxy.user}" proxypassword="${proxy.pass}"/> |
| 128 | </target> |
| 129 | |
Roger Meier | 0b26725 | 2011-07-29 21:08:04 +0000 | [diff] [blame] | 130 | <target name="xvfb"> |
| 131 | <echo>check if Xvfb is available:</echo> |
| 132 | <exec executable="Xvfb" failifexecutionfails="no" resultproperty="xvfb.present" failonerror="false" output="${build}/log/xvfb.log"> |
| 133 | <arg line="--version"/> |
| 134 | </exec> |
| 135 | </target> |
| 136 | |
| 137 | <target name="phantomjs" depends="xvfb" if="xvfb.present"> |
| 138 | <echo>check if phantomjs is available:</echo> |
| 139 | <exec executable="phantomjs" failifexecutionfails="no" resultproperty="phantomjs.present" failonerror="false" output="${build}/log/phantomjs.log"> |
| 140 | <arg line="--version"/> |
| 141 | </exec> |
| 142 | </target> |
| 143 | |
Roger Meier | edf0d1d | 2011-08-03 21:21:43 +0000 | [diff] [blame] | 144 | <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] | 145 | <parallel> |
| 146 | <exec executable="Xvfb" spawn="true" failonerror="false"> |
| 147 | <arg line=":99" /> |
| 148 | </exec> |
Roger Meier | 4f8a523 | 2011-09-09 08:17:02 +0000 | [diff] [blame] | 149 | <java classname="test.Httpd" fork="true" timeout="10000" |
Roger Meier | 0b26725 | 2011-07-29 21:08:04 +0000 | [diff] [blame] | 150 | classpathref="test.classpath" failonerror="false" output="${build}/log/unittest.log"> |
| 151 | <arg value="../" /> |
| 152 | </java> |
| 153 | <sequential> |
| 154 | <sleep seconds="2"/> |
| 155 | <echo>Running Unit Tests with headless browser!</echo> |
| 156 | <exec executable="phantomjs" failonerror="true"> |
| 157 | <env key="DISPLAY" value=":99"/> |
| 158 | <arg line="phantomjs-qunit.js http://localhost:8088/test/test.html" /> |
| 159 | </exec> |
| 160 | </sequential> |
| 161 | </parallel> |
| 162 | </target> |
| 163 | |
Roger Meier | 37b5bf8 | 2010-10-24 21:41:24 +0000 | [diff] [blame] | 164 | <target name="generate"> |
| 165 | <exec executable="${thrift.compiler}" failonerror="true"> |
| 166 | <arg line="--gen java ${thrift.dir}/test/ThriftTest.thrift" /> |
| 167 | </exec> |
| 168 | <exec executable="${thrift.compiler}" failonerror="true"> |
Roger Meier | 08b3099 | 2011-04-06 21:30:53 +0000 | [diff] [blame] | 169 | <arg line="--gen js:jquery ${thrift.dir}/test/ThriftTest.thrift" /> |
Roger Meier | 37b5bf8 | 2010-10-24 21:41:24 +0000 | [diff] [blame] | 170 | </exec> |
| 171 | </target> |
| 172 | |
Roger Meier | edf0d1d | 2011-08-03 21:21:43 +0000 | [diff] [blame] | 173 | <target name="test" description="run test suite (lint, unittest)" depends="lint, unittest"/> |
Roger Meier | f249576 | 2011-03-17 19:13:36 +0000 | [diff] [blame] | 174 | |
Roger Meier | edf0d1d | 2011-08-03 21:21:43 +0000 | [diff] [blame] | 175 | <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] | 176 | |
Roger Meier | edf0d1d | 2011-08-03 21:21:43 +0000 | [diff] [blame] | 177 | <target name="jslint" depends="resolve"> |
Roger Meier | 42a6fa4 | 2011-03-21 21:26:35 +0000 | [diff] [blame] | 178 | <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] | 179 | <!-- |
| 180 | the following options would probably make sense in the future: |
| 181 | browser,undef,eqeqeq,plusplus,bitwise,regexp,strict,newcap,immed |
| 182 | --> |
Roger Meier | edf0d1d | 2011-08-03 21:21:43 +0000 | [diff] [blame] | 183 | <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] | 184 | <formatter type="plain" /> |
| 185 | <fileset dir="${genjs}" includes="**/*.js" /> |
Henrique Mendonça | 095ddb7 | 2013-09-20 19:38:03 +0200 | [diff] [blame] | 186 | <fileset dir="../src" includes="thrift.js" /> |
Roger Meier | edf0d1d | 2011-08-03 21:21:43 +0000 | [diff] [blame] | 187 | |
| 188 | <!-- issues with unsafe character --> |
| 189 | <!-- fileset dir="." includes="*test*.js" /> --> |
Roger Meier | da6e6ae | 2011-03-15 09:55:33 +0000 | [diff] [blame] | 190 | </jsl:jslint> |
| 191 | </target> |
| 192 | |
| 193 | <target name="check-gjslint"> |
| 194 | <echo>check if gjslint is available:</echo> |
| 195 | <exec executable="gjslint" failifexecutionfails="no" resultproperty="gjslint.present" failonerror="false"> |
| 196 | <arg line="--helpshort"/> |
| 197 | </exec> |
| 198 | </target> |
Jake Farrell | ad6426c | 2011-04-20 16:35:20 +0000 | [diff] [blame] | 199 | |
Roger Meier | da6e6ae | 2011-03-15 09:55:33 +0000 | [diff] [blame] | 200 | <target name="gjslint" depends="check-gjslint" if="gjslint.present"> |
| 201 | <exec executable="gjslint" failifexecutionfails="no"> |
| 202 | <arg line="--nojsdoc"/> |
| 203 | <arg line="${genjs}/*.js"/> |
Henrique Mendonça | 095ddb7 | 2013-09-20 19:38:03 +0200 | [diff] [blame] | 204 | <arg line="../src/thrift.js"/> |
Roger Meier | edf0d1d | 2011-08-03 21:21:43 +0000 | [diff] [blame] | 205 | |
| 206 | <!-- issues with unsafe character, etc. --> |
| 207 | <!-- <arg line="*test*.js"/> --> |
Roger Meier | da6e6ae | 2011-03-15 09:55:33 +0000 | [diff] [blame] | 208 | </exec> |
| 209 | </target> |
| 210 | |
Roger Meier | 37b5bf8 | 2010-10-24 21:41:24 +0000 | [diff] [blame] | 211 | <target name="clean"> |
| 212 | <delete dir="${build}" /> |
| 213 | <delete dir="${genjava}" /> |
| 214 | <delete dir="${genjs}" /> |
Roger Meier | 37b5bf8 | 2010-10-24 21:41:24 +0000 | [diff] [blame] | 215 | </target> |
| 216 | |
Alex Volanis | 7004a61 | 2018-01-24 10:30:13 -0500 | [diff] [blame] | 217 | <target name="mvn.ant.tasks.download" depends="init,mvn.ant.tasks.check" unless="mvn.ant.tasks.found"> |
| 218 | <get src="${mvn.ant.task.url}/${mvn.ant.task.jar}" dest="${build.tools.dir}/${mvn.ant.task.jar}" usetimestamp="true"/> |
| 219 | </target> |
| 220 | |
| 221 | <target name="mvn.ant.tasks.check"> |
| 222 | <condition property="mvn.ant.tasks.found"> |
| 223 | <typefound uri="antlib:org.apache.maven.artifact.ant" name="artifact"/> |
| 224 | </condition> |
| 225 | </target> |
| 226 | |
| 227 | <target name="resolve" depends="mvn.ant.tasks.download" unless="mvn.finished"> |
Jake Farrell | ad6426c | 2011-04-20 16:35:20 +0000 | [diff] [blame] | 228 | <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] | 229 | |
Jake Farrell | ad6426c | 2011-04-20 16:35:20 +0000 | [diff] [blame] | 230 | <artifact:dependencies filesetId="js.test.dependency.jars"> |
| 231 | <dependency groupId="org.apache.httpcomponents" artifactId="httpclient" version="4.0.1"/> |
| 232 | <dependency groupId="com.googlecode.jslint4java" artifactId="jslint4java-ant" version="1.4.6"/> |
Roger Meier | c8d5d4d | 2012-01-07 20:32:24 +0000 | [diff] [blame] | 233 | <dependency groupId="eu.medsea.mimeutil" artifactId="mime-util" version="2.1.3"/> |
Jake Farrell | ad6426c | 2011-04-20 16:35:20 +0000 | [diff] [blame] | 234 | </artifact:dependencies> |
Roger Meier | 37b5bf8 | 2010-10-24 21:41:24 +0000 | [diff] [blame] | 235 | |
Jake Farrell | ad6426c | 2011-04-20 16:35:20 +0000 | [diff] [blame] | 236 | <!-- Copy the dependencies to the build/lib dir --> |
| 237 | <copy todir="${build}/lib"> |
| 238 | <fileset refid="js.test.dependency.jars"/> |
| 239 | <mapper type="flatten"/> |
| 240 | </copy> |
Roger Meier | 0856273 | 2015-06-14 22:30:22 +0200 | [diff] [blame] | 241 | |
Jake Farrell | ad6426c | 2011-04-20 16:35:20 +0000 | [diff] [blame] | 242 | <property name="mvn.finished" value="true"/> |
Roger Meier | 37b5bf8 | 2010-10-24 21:41:24 +0000 | [diff] [blame] | 243 | </target> |
Roger Meier | 37b5bf8 | 2010-10-24 21:41:24 +0000 | [diff] [blame] | 244 | </project> |