Mustafa Senol Cosar | f86845e | 2018-12-05 17:50:18 +0300 | [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 | |
| 10 | http://www.apache.org/licenses/LICENSE-2.0 |
| 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="." |
| 20 | xmlns:artifact="antlib:org.apache.maven.artifact.ant" |
| 21 | xmlns:jsl="antlib:com.googlecode.jslint4java"> |
| 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" /> |
| 29 | <property name="jar.file" location="${build}/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 | <property name="build.tools.dir" location="${thrift.java.dir}/build/tools/"/> |
| 35 | <property file="${basedir}/build.properties"/> |
| 36 | |
| 37 | <!-- Include the base Java properties file --> |
| 38 | <property file="${thrift.java.dir}/gradle.properties" /> |
| 39 | |
| 40 | <property name="thrift.compiler" location="${thrift.dir}/compiler/cpp/thrift" /> |
| 41 | |
| 42 | <path id="libs.classpath"> |
| 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" /> |
| 47 | </fileset> |
| 48 | <fileset dir="${thrift.java.dir}/build/deps"> |
| 49 | <include name="*.jar" /> |
| 50 | </fileset> |
| 51 | <fileset dir="${build}/lib"> |
| 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> |
| 65 | <resourcecount count="2"> |
| 66 | <fileset id="fs" dir="${thrift.java.dir}/build/libs"> |
| 67 | <include name="libthrift*.jar" /> |
| 68 | <exclude name="libthrift*javadoc.jar" /> |
| 69 | <exclude name="libthrift*sources.jar" /> |
| 70 | </fileset> |
| 71 | </resourcecount> |
| 72 | </not> |
| 73 | </condition> |
| 74 | You need libthrift*.jar and libthrift*test.jar located at |
| 75 | ${thrift.java.dir}/build/libs |
| 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"> |
| 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 /> |
| 92 | <mkdir dir="${build.tools.dir}"/> |
| 93 | <mkdir dir="${build}"/> |
| 94 | <mkdir dir="${build}/js/lib"/> |
| 95 | <mkdir dir="${build}/lib"/> |
| 96 | <mkdir dir="${build}/log"/> |
| 97 | <mkdir dir="${build}/test"/> |
| 98 | <mkdir dir="${build}/test/log"/> |
| 99 | </target> |
| 100 | |
| 101 | <target name="download_jslibs"> |
| 102 | <get src="http://code.jquery.com/jquery-1.11.3.min.js" dest="${build}/js/lib/jquery.js" usetimestamp="true"/> |
| 103 | <get src="http://code.jquery.com/qunit/qunit-2.6.2.js" dest="${build}/js/lib/qunit.js" usetimestamp="true"/> |
| 104 | <get src="http://code.jquery.com/qunit/qunit-2.6.2.css" dest="${build}/js/lib/qunit.css" usetimestamp="true"/> |
| 105 | <get src="http://code.jquery.com/qunit/qunit-2.6.2.js" dest="${build}/ts/qunit.js" usetimestamp="true"/> |
| 106 | <get src="http://code.jquery.com/qunit/qunit-2.6.2.css" dest="${build}/ts/qunit.css" usetimestamp="true"/> |
| 107 | </target> |
| 108 | |
| 109 | <target name="jslibs" depends="init, proxy, download_jslibs"> |
| 110 | </target> |
| 111 | |
| 112 | <target name="compile" description="compile the test suite" depends="init, generate, resolve"> |
| 113 | <!-- //TODO enable <compilerarg value="-Xlint"/>--> |
| 114 | <javac compiler="modern" includeantruntime="false" srcdir="${genjava}" destdir="${build}/test" classpathref="libs.classpath"/> |
| 115 | <javac compiler="modern" includeantruntime="false" srcdir="${src}" destdir="${build}/test" classpathref="libs.classpath"/> |
| 116 | </target> |
| 117 | |
| 118 | <target name="jstest" description="create the test suite jar file" depends="compile"> |
| 119 | <jar jarfile="${jar.file}" basedir="${build}/test"/> |
| 120 | </target> |
| 121 | |
| 122 | <target name="testserver" description="run the test server" depends="jstest, jslibs"> |
| 123 | <java classname="test.Httpd" fork="true" |
| 124 | classpathref="test.classpath" failonerror="true"> |
| 125 | <arg value="../" /> |
| 126 | </java> |
| 127 | </target> |
| 128 | |
| 129 | <target name="proxy" if="proxy.enabled"> |
| 130 | <setproxy proxyhost="${proxy.host}" proxyport="${proxy.port}" |
| 131 | proxyuser="${proxy.user}" proxypassword="${proxy.pass}"/> |
| 132 | </target> |
| 133 | |
| 134 | <target name="xvfb"> |
| 135 | <echo>check if Xvfb is available:</echo> |
| 136 | <exec executable="Xvfb" failifexecutionfails="no" resultproperty="xvfb.present" failonerror="false" output="${build}/log/xvfb.log"> |
| 137 | <arg line="--version"/> |
| 138 | </exec> |
| 139 | </target> |
| 140 | |
| 141 | <target name="phantomjs" depends="xvfb" if="xvfb.present"> |
| 142 | <echo>check if phantomjs is available:</echo> |
| 143 | <exec executable="phantomjs" failifexecutionfails="no" resultproperty="phantomjs.present" failonerror="false" output="${build}/log/phantomjs.log"> |
| 144 | <arg line="--version"/> |
| 145 | </exec> |
| 146 | </target> |
| 147 | |
| 148 | <target name="unittest" description="do unit tests with headless browser phantomjs" depends="init, phantomjs, jstest, jslibs" if="phantomjs.present"> |
| 149 | <parallel> |
| 150 | <exec executable="Xvfb" spawn="true" failonerror="false"> |
| 151 | <arg line=":99" /> |
| 152 | </exec> |
| 153 | <java classname="test.Httpd" fork="true" timeout="10000" |
| 154 | classpathref="test.classpath" failonerror="false" output="${build}/log/unittest.log"> |
| 155 | <arg value="../" /> |
| 156 | </java> |
| 157 | <sequential> |
| 158 | <sleep seconds="2"/> |
| 159 | <echo>Running Unit Tests with headless browser!</echo> |
| 160 | <exec executable="phantomjs" failonerror="true"> |
| 161 | <env key="DISPLAY" value=":99"/> |
| 162 | <arg line="phantomjs-qunit.js http://localhost:8088/test/test.html" /> |
| 163 | </exec> |
| 164 | </sequential> |
| 165 | </parallel> |
| 166 | </target> |
| 167 | |
| 168 | <target name="generate"> |
| 169 | <exec executable="${thrift.compiler}" failonerror="true"> |
| 170 | <arg line="--gen java ${thrift.dir}/test/ThriftTest.thrift" /> |
| 171 | </exec> |
| 172 | <exec executable="${thrift.compiler}" failonerror="true"> |
| 173 | <arg line="--gen js:jquery ${thrift.dir}/test/ThriftTest.thrift" /> |
| 174 | </exec> |
| 175 | <exec executable="${thrift.compiler}" failonerror="true"> |
| 176 | <arg line="--gen js:jquery ${thrift.dir}/test/DoubleConstantsTest.thrift" /> |
| 177 | </exec> |
| 178 | </target> |
| 179 | |
| 180 | <target name="test" description="run test suite (lint, unittest)" depends="lint, unittest"/> |
| 181 | |
| 182 | <target name="lint" description="code quality checks (jslint and gjslint if available)" depends="generate, gjslint, jslint"/> |
| 183 | |
| 184 | <target name="jslint" depends="resolve"> |
| 185 | <taskdef uri="antlib:com.googlecode.jslint4java" resource="com/googlecode/jslint4java/antlib.xml" classpathref="libs.classpath" /> |
| 186 | <!-- |
| 187 | the following options would probably make sense in the future: |
| 188 | browser,undef,eqeqeq,plusplus,bitwise,regexp,strict,newcap,immed |
| 189 | --> |
| 190 | <jsl:jslint options="evil,forin,browser,bitwise,regexp,newcap,immed" encoding="UTF-8"> |
| 191 | <formatter type="plain" /> |
| 192 | <fileset dir="../src" includes="thrift.js" /> |
| 193 | |
| 194 | <!-- issues with unsafe character --> |
| 195 | <!-- fileset dir="." includes="*test*.js" /> --> |
| 196 | </jsl:jslint> |
| 197 | </target> |
| 198 | |
| 199 | <target name="check-gjslint"> |
| 200 | <echo>check if gjslint is available:</echo> |
| 201 | <exec executable="gjslint" failifexecutionfails="no" resultproperty="gjslint.present" failonerror="false"> |
| 202 | <arg line="--helpshort"/> |
| 203 | </exec> |
| 204 | </target> |
| 205 | |
| 206 | <target name="gjslint" depends="check-gjslint" if="gjslint.present"> |
| 207 | <exec executable="gjslint" failifexecutionfails="no"> |
| 208 | <arg line="--nojsdoc"/> |
| 209 | <arg line="${genjs}/*.js"/> |
| 210 | <arg line="../src/thrift.js"/> |
| 211 | |
| 212 | <!-- issues with unsafe character, etc. --> |
| 213 | <!-- <arg line="*test*.js"/> --> |
| 214 | </exec> |
| 215 | </target> |
| 216 | |
| 217 | <target name="clean"> |
| 218 | <delete dir="${build}" /> |
| 219 | <delete dir="${genjava}" /> |
| 220 | <delete dir="${genjs}" /> |
| 221 | </target> |
| 222 | |
| 223 | <target name="mvn.ant.tasks.download" depends="init,mvn.ant.tasks.check" unless="mvn.ant.tasks.found"> |
| 224 | <get src="${mvn.ant.task.url}/${mvn.ant.task.jar}" dest="${build.tools.dir}/${mvn.ant.task.jar}" usetimestamp="true"/> |
| 225 | </target> |
| 226 | |
| 227 | <target name="mvn.ant.tasks.check"> |
| 228 | <condition property="mvn.ant.tasks.found"> |
| 229 | <typefound uri="antlib:org.apache.maven.artifact.ant" name="artifact"/> |
| 230 | </condition> |
| 231 | </target> |
| 232 | |
| 233 | <target name="resolve" depends="mvn.ant.tasks.download" unless="mvn.finished"> |
| 234 | <typedef uri="antlib:org.apache.maven.artifact.ant" classpath="${thrift.java.dir}/build/tools/${mvn.ant.task.jar}"/> |
| 235 | |
| 236 | <artifact:dependencies filesetId="js.test.dependency.jars"> |
| 237 | <dependency groupId="org.apache.httpcomponents" artifactId="httpclient" version="4.0.1"/> |
| 238 | <dependency groupId="com.googlecode.jslint4java" artifactId="jslint4java-ant" version="1.4.6"/> |
| 239 | <dependency groupId="eu.medsea.mimeutil" artifactId="mime-util" version="2.1.3"/> |
| 240 | </artifact:dependencies> |
| 241 | |
| 242 | <!-- Copy the dependencies to the build/lib dir --> |
| 243 | <copy todir="${build}/lib"> |
| 244 | <fileset refid="js.test.dependency.jars"/> |
| 245 | <mapper type="flatten"/> |
| 246 | </copy> |
| 247 | |
| 248 | <property name="mvn.finished" value="true"/> |
| 249 | </target> |
| 250 | </project> |