blob: bd2faf25afdbaa5fd0d3d9a4abc04fd49bae2ade [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 Farrell209d6dc2011-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="."
Jake Farrell209d6dc2011-04-20 16:35:20 +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 Farrell209d6dc2011-04-20 16:35:20 +000035 <!-- Include the base java properties file -->
36 <property file="${thrift.java.dir}/build.properties" />
37
Roger Meier37b5bf82010-10-24 21:41:24 +000038 <property name="thrift.compiler" location="${thrift.dir}/compiler/cpp/thrift" />
39
Roger Meier37b5bf82010-10-24 21:41:24 +000040 <path id="libs.classpath">
Jake Farrell209d6dc2011-04-20 16:35:20 +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>
47 <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>
Jake Farrell209d6dc2011-04-20 16:35:20 +000061 <resourcecount count="2">
62 <fileset id="fs" dir="${thrift.java.dir}/build" includes="libthrift*.jar"/>
Roger Meier37b5bf82010-10-24 21:41:24 +000063 </resourcecount>
64 </not>
65 </condition>
Jake Farrell209d6dc2011-04-20 16:35:20 +000066 You need libthrift*.jar and libthrift*test.jar located at
67 ${thrift.java.dir}/build
Roger Meier37b5bf82010-10-24 21:41:24 +000068 Did you compile Thrift Java library and its test suite by "ant compile-test"?
69 </fail>
70 <fail>
71 <condition>
72 <not>
73 <resourcecount count="1">
Roger Meier37b5bf82010-10-24 21:41:24 +000074 <fileset id="fs" dir="${thrift.dir}" includes="compiler/cpp/thrift"/>
75 </resourcecount>
76 </not>
77 </condition>
78 Thrift compiler is missing !
79 </fail>
80 </target>
81
82 <target name="init" depends="dependencies">
83 <tstamp />
84 <mkdir dir="${build}"/>
Jake Farrell209d6dc2011-04-20 16:35:20 +000085 <mkdir dir="${build}/lib"/>
Roger Meier37b5bf82010-10-24 21:41:24 +000086 </target>
87
88 <target name="compile" description="compile the test suite" depends="init, generate, resolve">
89 <javac srcdir="${genjava}" destdir="${build}" classpathref="libs.classpath" />
90 <javac srcdir="${src}" destdir="${build}" classpathref="libs.classpath" />
91 </target>
92
Jake Farrell209d6dc2011-04-20 16:35:20 +000093 <target name="jstest" description="" depends="compile, lint">
Roger Meier37b5bf82010-10-24 21:41:24 +000094 <jar jarfile="${jar.file}" basedir="${build}"/>
95 </target>
96
Jake Farrell209d6dc2011-04-20 16:35:20 +000097 <target name="testserver" description="run the test server" depends="jstest">
Roger Meier37b5bf82010-10-24 21:41:24 +000098 <java classname="test.Httpd" fork="true"
99 classpathref="test.classpath" failonerror="true">
100 <arg value="../" />
101 </java>
102 </target>
103
104 <target name="generate">
105 <exec executable="${thrift.compiler}" failonerror="true">
106 <arg line="--gen java ${thrift.dir}/test/ThriftTest.thrift" />
107 </exec>
108 <exec executable="${thrift.compiler}" failonerror="true">
Jake Farrell209d6dc2011-04-20 16:35:20 +0000109 <arg line="--gen js:jquery ${thrift.dir}/test/ThriftTest.thrift" />
110 </exec>
111 </target>
112
113 <!-- @TODO QUnit tests as part of the testsuite-->
114 <target name="test" description="run test suite" depends="init, generate, resolve, lint"/>
115
116 <target name="lint" description="code quality checks" depends="generate, gjslint, jslint"/>
117
118 <target name="jslint">
119 <taskdef uri="antlib:com.googlecode.jslint4java" resource="com/googlecode/jslint4java/antlib.xml" classpathref="libs.classpath" />
120 <!--
121 the following options would probably make sense in the future:
122 browser,undef,eqeqeq,plusplus,bitwise,regexp,strict,newcap,immed
123 -->
124 <jsl:jslint options="evil,forin,browser,bitwise,regexp,newcap,immed">
125 <formatter type="plain" />
126 <fileset dir="${genjs}" includes="**/*.js" />
127 <fileset dir=".." includes="thrift.js" />
128 </jsl:jslint>
129 </target>
130
131 <target name="check-gjslint">
132 <echo>check if gjslint is available:</echo>
133 <exec executable="gjslint" failifexecutionfails="no" resultproperty="gjslint.present" failonerror="false">
134 <arg line="--helpshort"/>
135 </exec>
136 </target>
137
138 <target name="gjslint" depends="check-gjslint" if="gjslint.present">
139 <exec executable="gjslint" failifexecutionfails="no">
140 <arg line="--nojsdoc"/>
141 <arg line="${genjs}/*.js"/>
142 <arg line="../thrift.js"/>
Roger Meier37b5bf82010-10-24 21:41:24 +0000143 </exec>
144 </target>
145
146 <target name="clean">
147 <delete dir="${build}" />
148 <delete dir="${genjava}" />
149 <delete dir="${genjs}" />
150 <delete file="${jar.file}" />
151 </target>
152
Jake Farrell209d6dc2011-04-20 16:35:20 +0000153 <target name="resolve" unless="mvn.finished">
154 <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 +0000155
Jake Farrell209d6dc2011-04-20 16:35:20 +0000156 <artifact:dependencies filesetId="js.test.dependency.jars">
157 <dependency groupId="org.apache.httpcomponents" artifactId="httpclient" version="4.0.1"/>
158 <dependency groupId="com.googlecode.jslint4java" artifactId="jslint4java-ant" version="1.4.6"/>
159 </artifact:dependencies>
Roger Meier37b5bf82010-10-24 21:41:24 +0000160
Jake Farrell209d6dc2011-04-20 16:35:20 +0000161 <!-- Copy the dependencies to the build/lib dir -->
162 <copy todir="${build}/lib">
163 <fileset refid="js.test.dependency.jars"/>
164 <mapper type="flatten"/>
165 </copy>
166
167 <property name="mvn.finished" value="true"/>
Roger Meier37b5bf82010-10-24 21:41:24 +0000168 </target>
Roger Meier37b5bf82010-10-24 21:41:24 +0000169</project>
Jake Farrell209d6dc2011-04-20 16:35:20 +0000170