Stig Bakken | ae3775a | 2014-12-02 09:21:24 +0100 | [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="JSON Schema Test" default="test" basedir="." |
| 20 | xmlns:artifact="antlib:org.apache.maven.artifact.ant"> |
| 21 | |
| 22 | <description>JSON Schema Validation Test</description> |
| 23 | |
| 24 | <property name="build.dir" location="${basedir}/build" /> |
| 25 | <property name="json.dir" location="${basedir}/.." /> |
| 26 | <property name="gen.json.dir" location="${build.dir}/gen-json" /> |
| 27 | <property name="json.schema" location="${json.dir}/schema.json" /> |
| 28 | <property name="build.tools.dir" location="${build.dir}/tools"/> |
| 29 | <property name="build.lib.dir" location="${build.dir}/lib"/> |
| 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.test.dir" location="${thrift.dir}/test" /> |
| 34 | <property name="thrift.compiler" location="${thrift.dir}/compiler/cpp/thrift" /> |
| 35 | |
| 36 | <!-- Get maven dependency versions from here --> |
| 37 | <property file="${basedir}/build.properties" /> |
| 38 | |
| 39 | <path id="test.classpath"> |
| 40 | <fileset dir="${build.lib.dir}"> |
| 41 | <include name="*.jar" /> |
| 42 | </fileset> |
| 43 | </path> |
| 44 | |
| 45 | <target name="compiler.check"> |
| 46 | <fail> |
| 47 | <condition> |
| 48 | <not> |
| 49 | <resourcecount count="1"> |
| 50 | <fileset id="fs" file="${thrift.compiler}"/> |
| 51 | </resourcecount> |
| 52 | </not> |
| 53 | </condition> |
| 54 | Thrift compiler is missing ! |
| 55 | </fail> |
| 56 | </target> |
| 57 | |
| 58 | <target name="init" depends="compiler.check, mkdirs, mvn.init"> |
| 59 | <tstamp /> |
| 60 | </target> |
| 61 | |
| 62 | <target name="mkdirs"> |
| 63 | <mkdir dir="${build.dir}"/> |
| 64 | <mkdir dir="${build.lib.dir}"/> |
| 65 | <mkdir dir="${build.tools.dir}"/> |
| 66 | <mkdir dir="${gen.json.dir}"/> |
| 67 | </target> |
| 68 | |
| 69 | <target name="generate" depends="init"> |
| 70 | <exec executable="${thrift.compiler}" failonerror="true"> |
| 71 | <arg line="--gen json"/> |
| 72 | <arg line="-out ${gen.json.dir}"/> |
| 73 | <arg line="${thrift.test.dir}/ThriftTest.thrift"/> |
| 74 | </exec> |
| 75 | <exec executable="${thrift.compiler}" failonerror="true"> |
| 76 | <arg line="--gen json:merge"/> |
| 77 | <arg line="-out ${gen.json.dir}"/> |
| 78 | <arg line="${thrift.test.dir}/Include.thrift"/> |
| 79 | </exec> |
| 80 | </target> |
| 81 | |
| 82 | <target name="test" description="run schema validation" |
| 83 | depends="validate-schema, validate-generated-json"/> |
| 84 | |
| 85 | <target name="validate-schema" depends="init"> |
| 86 | <java classname="com.github.fge.jsonschema.main.cli.Main" |
| 87 | classpathref="test.classpath" failonerror="true"> |
| 88 | <arg value="--syntax"/> |
| 89 | <arg value="${json.schema}"/> |
| 90 | </java> |
| 91 | </target> |
| 92 | |
| 93 | <target name="validate-generated-json" depends="init, generate"> |
| 94 | <validate-json file="${gen.json.dir}/ThriftTest.json"/> |
| 95 | <validate-json file="${gen.json.dir}/Include.json"/> |
| 96 | </target> |
| 97 | |
| 98 | <target name="clean"> |
| 99 | <delete dir="${build.dir}" /> |
| 100 | <delete dir="${gen.json.dir}" /> |
| 101 | </target> |
| 102 | |
| 103 | <target name="mvn.ant.tasks.download" depends="mkdirs,mvn.ant.tasks.check" unless="mvn.ant.tasks.found"> |
| 104 | <get src="${mvn.ant.task.url}/${mvn.ant.task.jar}" dest="${build.tools.dir}/${mvn.ant.task.jar}" usetimestamp="true"/> |
| 105 | </target> |
| 106 | |
| 107 | <target name="mvn.ant.tasks.check"> |
| 108 | <condition property="mvn.ant.tasks.found"> |
| 109 | <typefound uri="antlib:org.apache.maven.artifact.ant" name="artifact"/> |
| 110 | </condition> |
| 111 | </target> |
| 112 | |
| 113 | <target name="mvn.init" depends="mvn.ant.tasks.download" unless="mvn.finished"> |
| 114 | <typedef uri="antlib:org.apache.maven.artifact.ant" classpath="${build.tools.dir}/${mvn.ant.task.jar}"/> |
| 115 | |
| 116 | <artifact:dependencies filesetId="test.dependency.jars"> |
| 117 | <dependency groupId="com.github.fge" artifactId="json-schema-validator" version="${json-schema-validator.version}"/> |
Kengo Seki | d5a9bf2 | 2020-04-24 05:58:00 +0900 | [diff] [blame^] | 118 | <remoteRepository url="${mvn.repo}"/> |
Stig Bakken | ae3775a | 2014-12-02 09:21:24 +0100 | [diff] [blame] | 119 | </artifact:dependencies> |
| 120 | |
| 121 | <!-- Copy the dependencies to the build/lib dir --> |
| 122 | <copy todir="${build.lib.dir}"> |
| 123 | <fileset refid="test.dependency.jars"/> |
| 124 | <mapper type="flatten"/> |
| 125 | </copy> |
| 126 | |
| 127 | <property name="mvn.finished" value="true"/> |
| 128 | </target> |
| 129 | |
| 130 | <macrodef name="validate-json"> |
| 131 | <attribute name="file" default=""/> |
| 132 | <sequential> |
| 133 | <java failonerror="true" |
| 134 | fork="true" |
| 135 | dir="${json.dir}" |
| 136 | classname="com.github.fge.jsonschema.main.cli.Main" |
| 137 | classpathref="test.classpath"> |
| 138 | <arg line="--fakeroot http://thrift.apache.org/"/> |
| 139 | <arg value="${json.schema}"/> |
| 140 | <arg value="@{file}"/> |
| 141 | </java> |
| 142 | </sequential> |
| 143 | </macrodef> |
| 144 | |
| 145 | </project> |