blob: ddf5df82d688562ea39b11bc682d88a004d26147 [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
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:ivy="antlib:org.apache.ivy.ant"
Roger Meierda6e6ae2011-03-15 09:55:33 +000021 xmlns:artifact="antlib:org.apache.maven.artifact.ant"
22 xmlns:jsl="antlib:com.googlecode.jslint4java">
Roger Meier37b5bf82010-10-24 21:41:24 +000023
24 <description>Java Script Test based on Thrift Java Library</description>
25
26 <property name="src" location="src" />
27 <property name="genjava" location="gen-java" />
28 <property name="genjs" location="gen-js" />
29 <property name="build" location="build" />
30 <property name="jar.file" location="${basedir}/jstest.jar" />
31
32 <!-- the root directory, where you unpack thrift distibution (e.g. thrift-0.x.x.tar.gz) -->
33 <property name="thrift.dir" location="../../../" />
34 <property name="thrift.java.dir" location="${thrift.dir}/lib/java" />
35
36 <property name="thrift.compiler" location="${thrift.dir}/compiler/cpp/thrift" />
37
38 <!-- take ivy from java, test depends anyway on java! -->
39 <property name="ivy.dir" location="${thrift.java.dir}/build/ivy" />
40 <property name="ivy.lib.dir" location="${ivy.dir}/lib" />
41
42 <path id="libs.classpath">
43 <pathelement path="${thrift.java.dir}/libthrift.jar" />
44 <pathelement path="${thrift.java.dir}/libthrift-test.jar" />
45 <fileset dir="${thrift.java.dir}/build/ivy/lib">
46 <include name="*.jar" />
47 </fileset>
48 </path>
49
50 <path id="test.classpath">
51 <path refid="libs.classpath" />
52 <pathelement location="${jar.file}" />
53 </path>
54
Roger Meierda6e6ae2011-03-15 09:55:33 +000055 <taskdef uri="antlib:com.googlecode.jslint4java" resource="com/googlecode/jslint4java/antlib.xml" classpathref="libs.classpath" />
56
Roger Meier37b5bf82010-10-24 21:41:24 +000057 <target name="dependencies">
58 <fail>
59 <condition>
60 <not>
61 <resourcecount count="1">
62 <fileset id="fs" dir="${thrift.java.dir}" includes="libthrift.jar"/>
63 </resourcecount>
64 </not>
65 </condition>
66 You need libthrift.jar located at
67 ${thrift.java.dir}
68 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">
74 <fileset id="fs" dir="${ivy.dir}" includes="ivy-2*.jar"/>
75 </resourcecount>
76 </not>
77 </condition>
78 ivy is missing at ${ivy.dir}
79 </fail>
80 <fail>
81 <condition>
82 <not>
83 <resourcecount count="1">
84 <fileset id="fs" dir="${thrift.dir}" includes="compiler/cpp/thrift"/>
85 </resourcecount>
86 </not>
87 </condition>
88 Thrift compiler is missing !
89 </fail>
90 </target>
91
92 <target name="init" depends="dependencies">
93 <tstamp />
94 <mkdir dir="${build}"/>
95 </target>
96
97 <target name="compile" description="compile the test suite" depends="init, generate, resolve">
98 <javac srcdir="${genjava}" destdir="${build}" classpathref="libs.classpath" />
99 <javac srcdir="${src}" destdir="${build}" classpathref="libs.classpath" />
100 </target>
101
102 <target name="jstest" description="" depends="compile">
103 <jar jarfile="${jar.file}" basedir="${build}"/>
104 </target>
105
Roger Meierf2495762011-03-17 19:13:36 +0000106 <target name="testserver" description="run the test server" depends="jstest">
Roger Meier37b5bf82010-10-24 21:41:24 +0000107 <java classname="test.Httpd" fork="true"
108 classpathref="test.classpath" failonerror="true">
109 <arg value="../" />
110 </java>
111 </target>
112
113 <target name="generate">
114 <exec executable="${thrift.compiler}" failonerror="true">
115 <arg line="--gen java ${thrift.dir}/test/ThriftTest.thrift" />
116 </exec>
117 <exec executable="${thrift.compiler}" failonerror="true">
118 <arg line="--gen js ${thrift.dir}/test/ThriftTest.thrift" />
119 </exec>
120 </target>
121
Roger Meierf2495762011-03-17 19:13:36 +0000122 <!-- @TODO QUnit tests as part of the testsuite-->
123 <target name="test" description="run test suite" depends="init, generate, resolve, lint"/>
124
125 <target name="lint" description="code quality checks" depends="gjslint, jslint, generate"/>
Roger Meierda6e6ae2011-03-15 09:55:33 +0000126
127 <target name="jslint">
128 <!--
129 the following options would probably make sense in the future:
130 browser,undef,eqeqeq,plusplus,bitwise,regexp,strict,newcap,immed
131 -->
132 <jsl:jslint options="evil,forin,browser,bitwise,regexp,newcap,immed">
133 <formatter type="plain" />
134 <fileset dir="${genjs}" includes="**/*.js" />
135 <fileset dir=".." includes="thrift.js" />
136 </jsl:jslint>
137 </target>
138
139 <target name="check-gjslint">
140 <echo>check if gjslint is available:</echo>
141 <exec executable="gjslint" failifexecutionfails="no" resultproperty="gjslint.present" failonerror="false">
142 <arg line="--helpshort"/>
143 </exec>
144 </target>
145
146 <target name="gjslint" depends="check-gjslint" if="gjslint.present">
147 <exec executable="gjslint" failifexecutionfails="no">
148 <arg line="--nojsdoc"/>
149 <arg line="${genjs}/*.js"/>
150 <arg line="../thrift.js"/>
151 </exec>
152 </target>
153
Roger Meier37b5bf82010-10-24 21:41:24 +0000154 <target name="clean">
155 <delete dir="${build}" />
156 <delete dir="${genjava}" />
157 <delete dir="${genjs}" />
158 <delete file="${jar.file}" />
159 </target>
160
161 <!-- ivy tasks from java build.xml ... don't know how to import them instead of copying -->
162 <target name="resolve" depends="ivy-init-antlib" description="retrieve dependencies with ivy" unless="noivy">
163 <ivy:retrieve />
164 </target>
165
166 <target name="ivy-probe-antlib">
167 <condition property="ivy.found">
168 <typefound uri="antlib:org.apache.ivy.ant" name="cleancache"/>
169 </condition>
170 </target>
171
172 <target name="ivy-init-antlib" depends="ivy-probe-antlib" unless="ivy.found">
173 <typedef uri="antlib:org.apache.ivy.ant" onerror="fail"
174 loaderRef="ivyLoader">
175 <classpath>
176 <fileset dir="${ivy.dir}">
177 <include name="ivy-2.*.jar" />
178 </fileset>
179 </classpath>
180 </typedef>
181 <fail>
182 <condition >
183 <not>
184 <typefound uri="antlib:org.apache.ivy.ant" name="cleancache"/>
185 </not>
186 </condition>
187 You need Apache Ivy 2.0 or later from http://ant.apache.org/
188 It could not be loaded from ${ivy_repo_url}
189 </fail>
190 </target>
191
192</project>