|
| 1 | +<project name="SpockExample" |
| 2 | + default="test" |
| 3 | + xmlns:groovy="antlib:org.codehaus.groovy.ant" |
| 4 | + xmlns:ivy="antlib:org.apache.ivy.ant"> |
| 5 | + <!-- Various Paths --> |
| 6 | + <property name="test.src.dir" |
| 7 | + location="src/test/groovy"/> |
| 8 | + <property name="test.resource.dir" |
| 9 | + location="src/test/resources"/> |
| 10 | + <property name="build.dir" |
| 11 | + location="ant/build"/> |
| 12 | + <property name="lib.dir" |
| 13 | + location="ant/lib"/> |
| 14 | + <property name="classes.dir" |
| 15 | + location="${build.dir}/classes"/> |
| 16 | + |
| 17 | + <!-- Ivy Properties --> |
| 18 | + <property name="config.ivy.version" |
| 19 | + value="2.5.3"/> |
| 20 | + <property name="ivy.jar.dir" |
| 21 | + location="${lib.dir}/ivy"/> |
| 22 | + <property name="ivy.jar.filename" |
| 23 | + value="ivy-${config.ivy.version}.jar"/> |
| 24 | + <property name="ivy.jar.file" |
| 25 | + location="${ivy.jar.dir}/${ivy.jar.filename}"/> |
| 26 | + |
| 27 | + <target name="init"> |
| 28 | + <echo message="Buildfile for ${ant.project.name} (${ant.file})" |
| 29 | + level="info"/> |
| 30 | + <fail message="Ant 1.10.6 or newer is needed for ${ant.project.name} to build, please install it and rerun (found Ant version: '${ant.version}')"> |
| 31 | + <condition> |
| 32 | + <not> |
| 33 | + <antversion atleast="1.10.6"/> |
| 34 | + </not> |
| 35 | + </condition> |
| 36 | + </fail> |
| 37 | + <fail message="Java 8 or newer is needed for ${ant.project.name} to build, please install it and rerun (found Java version: '${ant.java.version}')"> |
| 38 | + <condition> |
| 39 | + <not> |
| 40 | + <javaversion atleast="8"/> |
| 41 | + </not> |
| 42 | + </condition> |
| 43 | + </fail> |
| 44 | + <fail message="The ant-optional package is needed for ${ant.project.name} to build, please install it and rerun"> |
| 45 | + <condition> |
| 46 | + <not> |
| 47 | + <and> |
| 48 | + <available classname="org.apache.tools.ant.taskdefs.optional.depend.Depend"/> |
| 49 | + <available classname="org.apache.tools.ant.taskdefs.optional.TraXLiaison"/> |
| 50 | + </and> |
| 51 | + </not> |
| 52 | + </condition> |
| 53 | + </fail> |
| 54 | + </target> |
| 55 | + |
| 56 | + <target name="check-ivy" |
| 57 | + depends="init"> |
| 58 | + <available property="ivy.jar.present" |
| 59 | + file="${ivy.jar.file}" |
| 60 | + type="file"/> |
| 61 | + </target> |
| 62 | + |
| 63 | + <target name="download-ivy" |
| 64 | + depends="init,check-ivy" |
| 65 | + unless="ivy.jar.present"> |
| 66 | + <mkdir dir="${ivy.jar.dir}"/> |
| 67 | + <get src="https://repo.maven.apache.org/maven2/org/apache/ivy/ivy/${config.ivy.version}/ivy-${config.ivy.version}.jar" |
| 68 | + dest="${ivy.jar.file}" |
| 69 | + usetimestamp="true"/> |
| 70 | + </target> |
| 71 | + |
| 72 | + <target name="init-ivy" |
| 73 | + depends="init,download-ivy"> |
| 74 | + <property name="ivy.retrieve.pattern" |
| 75 | + value="${lib.dir}/[conf]/[artifact](-[classifier]).[ext]"/> |
| 76 | + <taskdef resource="org/apache/ivy/ant/antlib.xml" |
| 77 | + classpath="${ivy.jar.file}" |
| 78 | + loaderref="ivy.loader" |
| 79 | + uri="antlib:org.apache.ivy.ant"/> |
| 80 | + </target> |
| 81 | + |
| 82 | + <target name="retrieve" |
| 83 | + description="retrieve the dependencies" |
| 84 | + depends="init,init-ivy"> |
| 85 | + <ivy:retrieve sync="true"/> |
| 86 | + <ivy:retrieve pattern="${lib.dir}/ivy/[artifact]-[revision].[ext]" |
| 87 | + organisation="org.apache.ivy" |
| 88 | + module="ivy" |
| 89 | + revision="${config.ivy.version}" |
| 90 | + conf="default" |
| 91 | + inline="true"/> |
| 92 | + </target> |
| 93 | + |
| 94 | + <target name="clean" |
| 95 | + depends="init" |
| 96 | + description="clean up intermediate files"> |
| 97 | + <delete includeemptydirs="true" |
| 98 | + failonerror="false"> |
| 99 | + <fileset dir="${classes.dir}" |
| 100 | + defaultexcludes="false"/> |
| 101 | + </delete> |
| 102 | + </target> |
| 103 | + |
| 104 | + <target name="clean-all" |
| 105 | + depends="init" |
| 106 | + description="clean up lib.dir, classes.dir, and build.dir completely"> |
| 107 | + <delete includeemptydirs="true" |
| 108 | + failonerror="false"> |
| 109 | + <fileset dir="${lib.dir}" |
| 110 | + defaultexcludes="false"/> |
| 111 | + <fileset dir="${classes.dir}" |
| 112 | + defaultexcludes="false"/> |
| 113 | + <fileset dir="${build.dir}" |
| 114 | + defaultexcludes="false"/> |
| 115 | + </delete> |
| 116 | + </target> |
| 117 | + |
| 118 | + <target name="compile-test" |
| 119 | + depends="init,retrieve"> |
| 120 | + <mkdir dir="${classes.dir}/test"/> |
| 121 | + <depend srcDir="${test.src.dir}" |
| 122 | + destDir="${classes.dir}/test" |
| 123 | + cache="${classes.dir}"/> |
| 124 | + <dependset> |
| 125 | + <srcfilelist files="build.xml"/> |
| 126 | + <srcfilelist files="ivy.xml"/> |
| 127 | + <srcfilelist files="ivysettings.xml"/> |
| 128 | + <targetfileset dir="${classes.dir}/test"/> |
| 129 | + </dependset> |
| 130 | + <taskdef resource="org/codehaus/groovy/antlib.xml" |
| 131 | + uri="antlib:org.codehaus.groovy.ant"> |
| 132 | + <classpath> |
| 133 | + <fileset dir="${lib.dir}/groovy-ant" |
| 134 | + includes="*.jar"/> |
| 135 | + </classpath> |
| 136 | + </taskdef> |
| 137 | + <groovy:groovyc srcdir="${test.src.dir}" |
| 138 | + destdir="${classes.dir}/test" |
| 139 | + encoding="UTF-8" |
| 140 | + includeAntRuntime="false" |
| 141 | + fork="true"> |
| 142 | + <groovy:classpath id="classpath.test"> |
| 143 | + <fileset dir="${lib.dir}/test" |
| 144 | + includes="*.jar"/> |
| 145 | + </groovy:classpath> |
| 146 | + </groovy:groovyc> |
| 147 | + </target> |
| 148 | + |
| 149 | + <target name="test" |
| 150 | + depends="init,retrieve,compile-test" |
| 151 | + description="run unit tests"> |
| 152 | + <delete dir="${build.dir}/test/raw-reports"/> |
| 153 | + <mkdir dir="${build.dir}/test/raw-reports"/> |
| 154 | + <junitlauncher printsummary="true" |
| 155 | + failureproperty="tests.failed"> |
| 156 | + <classpath refid="classpath.test"/> |
| 157 | + <classpath location="§{test.resource.dir}"/> |
| 158 | + <classpath location="${classes.dir}/test"/> |
| 159 | + <classpath location="${ant.library.dir}/ant.jar"/> |
| 160 | + <classpath location="${ant.library.dir}/ant-junitlauncher.jar"/> |
| 161 | + <listener type="legacy-xml" |
| 162 | + outputDir="${build.dir}/test/raw-reports"/> |
| 163 | + <testclasses> |
| 164 | + <fork includeJUnitPlatformLibraries="false" |
| 165 | + includeAntRuntimeLibraries="false"/> |
| 166 | + <fileset dir="${classes.dir}/test"> |
| 167 | + <scriptselector language="groovy"> |
| 168 | + <classpath> |
| 169 | + <fileset dir="${lib.dir}/groovy-script" |
| 170 | + includes="*.jar"/> |
| 171 | + </classpath> |
| 172 | + <![CDATA[ |
| 173 | + import org.spockframework.buildsupport.SpecClassFileFinder |
| 174 | + self.selected = new SpecClassFileFinder().isRunnableSpec(file) |
| 175 | + ]]> |
| 176 | + </scriptselector> |
| 177 | + </fileset> |
| 178 | + </testclasses> |
| 179 | + </junitlauncher> |
| 180 | + <mkdir dir="${build.dir}/test/merged-reports"/> |
| 181 | + <junitreport todir="${build.dir}/test/merged-reports"> |
| 182 | + <fileset dir="${build.dir}/test/raw-reports"/> |
| 183 | + <report todir="${build.dir}/test/reports"/> |
| 184 | + </junitreport> |
| 185 | + <fail message="Unit test(s) failed! See reports at ${build.dir}/test/reports/index.html" |
| 186 | + if="tests.failed"/> |
| 187 | + </target> |
| 188 | +</project> |
0 commit comments