summaryrefslogtreecommitdiffstats
path: root/src/jaegertracing/thrift/lib/json/test/build.xml
blob: 956a2382b7439ca3cc7893a3b7cf2cdcffd1d27e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<!--
 Licensed to the Apache Software Foundation (ASF) under one
 or more contributor license agreements. See the NOTICE file
 distributed with this work for additional information
 regarding copyright ownership. The ASF licenses this file
 to you under the Apache License, Version 2.0 (the
 "License"); you may not use this file except in compliance
 with the License. You may obtain a copy of the License at

 http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing,
 software distributed under the License is distributed on an
 "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 KIND, either express or implied. See the License for the
 specific language governing permissions and limitations
 under the License.
-->
<project name="JSON Schema Test" default="test" basedir="."
  xmlns:artifact="antlib:org.apache.maven.artifact.ant">

  <description>JSON Schema Validation Test</description>

  <property name="build.dir" location="${basedir}/build" />
  <property name="json.dir" location="${basedir}/.." />
  <property name="gen.json.dir" location="${build.dir}/gen-json" />
  <property name="json.schema" location="${json.dir}/schema.json" />
  <property name="build.tools.dir" location="${build.dir}/tools"/>
  <property name="build.lib.dir" location="${build.dir}/lib"/>

  <!-- the root directory, where you unpack thrift distibution (e.g. thrift-0.x.x.tar.gz) -->
  <property name="thrift.dir" location="../../../" />
  <property name="thrift.test.dir" location="${thrift.dir}/test" />
  <property name="thrift.compiler" location="${thrift.dir}/compiler/cpp/thrift" />

  <!-- Get maven dependency versions from here -->
  <property file="${basedir}/build.properties" />

  <path id="test.classpath">
    <fileset dir="${build.lib.dir}">
      <include name="*.jar" />
    </fileset>
  </path>

  <target name="compiler.check">
    <fail>
      <condition>
        <not>
          <resourcecount count="1">
            <fileset id="fs" file="${thrift.compiler}"/>
          </resourcecount>
        </not>
      </condition>
      Thrift compiler is missing !
    </fail>
  </target>

  <target name="init" depends="compiler.check, mkdirs, mvn.init">
    <tstamp />
  </target>

  <target name="mkdirs">
    <mkdir dir="${build.dir}"/>
    <mkdir dir="${build.lib.dir}"/>
    <mkdir dir="${build.tools.dir}"/>
    <mkdir dir="${gen.json.dir}"/>
  </target>

  <target name="generate" depends="init">
    <exec executable="${thrift.compiler}" failonerror="true">
      <arg line="--gen json"/>
      <arg line="-out ${gen.json.dir}"/>
      <arg line="${thrift.test.dir}/ThriftTest.thrift"/>
    </exec>
    <exec executable="${thrift.compiler}" failonerror="true">
      <arg line="--gen json:merge"/>
      <arg line="-out ${gen.json.dir}"/>
      <arg line="${thrift.test.dir}/Include.thrift"/>
    </exec>
  </target>

  <target name="test" description="run schema validation"
          depends="validate-schema, validate-generated-json"/>

  <target name="validate-schema" depends="init">
    <java classname="com.github.fge.jsonschema.main.cli.Main"
          classpathref="test.classpath" failonerror="true">
      <arg value="--syntax"/>
      <arg value="${json.schema}"/>
    </java>
  </target>

  <target name="validate-generated-json" depends="init, generate">
    <validate-json file="${gen.json.dir}/ThriftTest.json"/>
    <validate-json file="${gen.json.dir}/Include.json"/>
  </target>

  <target name="clean">
    <delete dir="${build.dir}" />
    <delete dir="${gen.json.dir}" />
  </target>

  <target name="mvn.ant.tasks.download" depends="mkdirs,mvn.ant.tasks.check" unless="mvn.ant.tasks.found">
    <get src="${mvn.ant.task.url}/${mvn.ant.task.jar}" dest="${build.tools.dir}/${mvn.ant.task.jar}" usetimestamp="true"/>
  </target>

  <target name="mvn.ant.tasks.check">
    <condition property="mvn.ant.tasks.found">
      <typefound uri="antlib:org.apache.maven.artifact.ant" name="artifact"/>
    </condition>
  </target>

  <target name="mvn.init" depends="mvn.ant.tasks.download" unless="mvn.finished">
    <typedef uri="antlib:org.apache.maven.artifact.ant" classpath="${build.tools.dir}/${mvn.ant.task.jar}"/>

    <artifact:dependencies filesetId="test.dependency.jars">
      <dependency groupId="com.github.fge" artifactId="json-schema-validator" version="${json-schema-validator.version}"/>
    </artifact:dependencies>

    <!-- Copy the dependencies to the build/lib dir -->
    <copy todir="${build.lib.dir}">
      <fileset refid="test.dependency.jars"/>
      <mapper type="flatten"/>
    </copy>

    <property name="mvn.finished" value="true"/>
  </target>

  <macrodef name="validate-json">
    <attribute name="file" default=""/>
    <sequential>
      <java failonerror="true"
            fork="true"
            dir="${json.dir}"
            classname="com.github.fge.jsonschema.main.cli.Main"
            classpathref="test.classpath">
        <arg line="--fakeroot http://thrift.apache.org/"/>
        <arg value="${json.schema}"/>
        <arg value="@{file}"/>
      </java>
    </sequential>
  </macrodef>

</project>