blob: bfb9e271e3a957e7c6c1d80cba57f09c047bfa5d [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
55 <target name="dependencies">
56 <fail>
57 <condition>
58 <not>
59 <resourcecount count="1">
60 <fileset id="fs" dir="${thrift.java.dir}" includes="libthrift.jar"/>
61 </resourcecount>
62 </not>
63 </condition>
64 You need libthrift.jar located at
65 ${thrift.java.dir}
66 Did you compile Thrift Java library and its test suite by "ant compile-test"?
67 </fail>
68 <fail>
69 <condition>
70 <not>
71 <resourcecount count="1">
72 <fileset id="fs" dir="${ivy.dir}" includes="ivy-2*.jar"/>
73 </resourcecount>
74 </not>
75 </condition>
76 ivy is missing at ${ivy.dir}
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}"/>
93 </target>
94
95 <target name="compile" description="compile the test suite" depends="init, generate, resolve">
96 <javac srcdir="${genjava}" destdir="${build}" classpathref="libs.classpath" />
97 <javac srcdir="${src}" destdir="${build}" classpathref="libs.classpath" />
98 </target>
99
100 <target name="jstest" description="" depends="compile">
101 <jar jarfile="${jar.file}" basedir="${build}"/>
102 </target>
103
Roger Meierf2495762011-03-17 19:13:36 +0000104 <target name="testserver" description="run the test server" depends="jstest">
Roger Meier37b5bf82010-10-24 21:41:24 +0000105 <java classname="test.Httpd" fork="true"
106 classpathref="test.classpath" failonerror="true">
107 <arg value="../" />
108 </java>
109 </target>
110
111 <target name="generate">
112 <exec executable="${thrift.compiler}" failonerror="true">
113 <arg line="--gen java ${thrift.dir}/test/ThriftTest.thrift" />
114 </exec>
115 <exec executable="${thrift.compiler}" failonerror="true">
116 <arg line="--gen js ${thrift.dir}/test/ThriftTest.thrift" />
117 </exec>
118 </target>
119
Roger Meierf2495762011-03-17 19:13:36 +0000120 <!-- @TODO QUnit tests as part of the testsuite-->
121 <target name="test" description="run test suite" depends="init, generate, resolve, lint"/>
122
123 <target name="lint" description="code quality checks" depends="gjslint, jslint, generate"/>
Roger Meierda6e6ae2011-03-15 09:55:33 +0000124
125 <target name="jslint">
Roger Meier42a6fa42011-03-21 21:26:35 +0000126 <taskdef uri="antlib:com.googlecode.jslint4java" resource="com/googlecode/jslint4java/antlib.xml" classpathref="libs.classpath" />
Roger Meierda6e6ae2011-03-15 09:55:33 +0000127 <!--
128 the following options would probably make sense in the future:
129 browser,undef,eqeqeq,plusplus,bitwise,regexp,strict,newcap,immed
130 -->
131 <jsl:jslint options="evil,forin,browser,bitwise,regexp,newcap,immed">
132 <formatter type="plain" />
133 <fileset dir="${genjs}" includes="**/*.js" />
134 <fileset dir=".." includes="thrift.js" />
135 </jsl:jslint>
136 </target>
137
138 <target name="check-gjslint">
139 <echo>check if gjslint is available:</echo>
140 <exec executable="gjslint" failifexecutionfails="no" resultproperty="gjslint.present" failonerror="false">
141 <arg line="--helpshort"/>
142 </exec>
143 </target>
144
145 <target name="gjslint" depends="check-gjslint" if="gjslint.present">
146 <exec executable="gjslint" failifexecutionfails="no">
147 <arg line="--nojsdoc"/>
148 <arg line="${genjs}/*.js"/>
149 <arg line="../thrift.js"/>
150 </exec>
151 </target>
152
Roger Meier37b5bf82010-10-24 21:41:24 +0000153 <target name="clean">
154 <delete dir="${build}" />
155 <delete dir="${genjava}" />
156 <delete dir="${genjs}" />
157 <delete file="${jar.file}" />
158 </target>
159
160 <!-- ivy tasks from java build.xml ... don't know how to import them instead of copying -->
161 <target name="resolve" depends="ivy-init-antlib" description="retrieve dependencies with ivy" unless="noivy">
162 <ivy:retrieve />
163 </target>
164
165 <target name="ivy-probe-antlib">
166 <condition property="ivy.found">
167 <typefound uri="antlib:org.apache.ivy.ant" name="cleancache"/>
168 </condition>
169 </target>
170
171 <target name="ivy-init-antlib" depends="ivy-probe-antlib" unless="ivy.found">
172 <typedef uri="antlib:org.apache.ivy.ant" onerror="fail"
173 loaderRef="ivyLoader">
174 <classpath>
175 <fileset dir="${ivy.dir}">
176 <include name="ivy-2.*.jar" />
177 </fileset>
178 </classpath>
179 </typedef>
180 <fail>
181 <condition >
182 <not>
183 <typefound uri="antlib:org.apache.ivy.ant" name="cleancache"/>
184 </not>
185 </condition>
186 You need Apache Ivy 2.0 or later from http://ant.apache.org/
187 It could not be loaded from ${ivy_repo_url}
188 </fail>
189 </target>
190
191</project>