build.xml 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <project name="ieat2" basedir="." default="war"
  3. xmlns:ivy="antlib:org.apache.ivy.ant">
  4. <property name="lib.dir" value="lib/"/>
  5. <property name="web.dir" value="web/"/>
  6. <property name="test.dir" value="tests/"/>
  7. <property name="conf.dir" value="conf/dev/"/>
  8. <property name="script.dir" value="scripts/"/>
  9. <property name="ant.lib" value="${user.home}/.ant/lib"/>
  10. <property name="ant.conf.dir" value="${conf.dir}/ant/"/>
  11. <property prefix="app" file="${ant.conf.dir}/app.properties"/>
  12. <property name="app.conf.dir" value="${conf.dir}/app/"/>
  13. <property prefix="tomcat" file="${ant.conf.dir}/tomcat.properties"/>
  14. <property prefix="build" file="${ant.conf.dir}/build.properties"/>
  15. <property name="build.lib" value="${lib.dir}/war/"/>
  16. <property name="build.warfile"
  17. value="${build.dir}/${app.name}-${build.version}.war"/>
  18. <tstamp>
  19. <format property="build.time" pattern="MM/dd/yyyy hh:mm aa z" />
  20. </tstamp>
  21. <property prefix="test" file="${ant.conf.dir}/test.properties"/>
  22. <property name="test.lib" value="${lib.dir}/test/"/>
  23. <property name="test.target.dir" value="${build.dir}/tests"/>
  24. <property name="source.dir" value="src/"/>
  25. <property name="source.dir.java" value="${source.dir}/java"/>
  26. <property name="target.dir.server"
  27. value="${build.dir}/${app.name}/WEB-INF/classes"/>
  28. <property name="target.dir.client" value="${build.dir}/${app.name}/js"/>
  29. <property prefix="compile" file="${ant.conf.dir}/compile.properties"/>
  30. <property name="compile.lib" value="${lib.dir}/compile"/>
  31. <path id="compile.classpath">
  32. <pathelement location="${target.dir.server}"/>
  33. <fileset dir="${compile.lib}" includes="*.jar"/>
  34. </path>
  35. <property name="ivy.jar" value="${ant.lib}/ivy.jar"/>
  36. <property name="ivy.dep.file" value="${ant.conf.dir}/ivy.xml" />
  37. <available property="ivy.installed" file="${ivy.jar}"/>
  38. <property name="kotlin.lib" value="/opt/kotlinc/lib" />
  39. <typedef resource="org/jetbrains/kotlin/ant/antlib.xml"
  40. classpath="${kotlin.lib}/kotlin-ant.jar"/>
  41. <target name="help" description="Display build help">
  42. <echo>iEat v${build.version}</echo>
  43. <echo>To see list of targets, use ant -p</echo>
  44. </target>
  45. <target name="skip.ivy"
  46. description="Do not check dependencies. (Saves laptop battery)">
  47. <property name="ivy.skip" value="true"/>
  48. </target>
  49. <target name="ivy.install" unless="ivy.installed">
  50. <mkdir dir="${ant.lib}"/>
  51. <get dest="${ivy.jar}"
  52. src="http://search.maven.org/remotecontent?filepath=org/apache/ivy/ivy/2.3.0/ivy-2.3.0.jar"/>
  53. <taskdef resource="org/apache/ivy/ant/antlib.xml"
  54. uri="antlib:org.apache.ivy.ant"
  55. classpath="${ivy.jar}"/>
  56. <property name="ivy.installed" value="true"/>
  57. </target>
  58. <target name="ivy.tree" depends="ivy.install"
  59. description="Show the dependency tree.">
  60. <ivy:dependencytree />
  61. </target>
  62. <target name="ivy.resolve.compile" unless="ivy.skip" depends="ivy.install">
  63. <ivy:retrieve pattern="${lib.dir}/[conf]/[artifact].[ext]" conf="compile"/>
  64. </target>
  65. <target name="ivy.resolve.war" unless="ivy.skip" depends="ivy.install">
  66. <ivy:retrieve pattern="${lib.dir}/[conf]/[artifact].[ext]" conf="war"/>
  67. </target>
  68. <target name="ivy.resolve.test" unless="ivy.skip" depends="ivy.install">
  69. <ivy:retrieve pattern="${lib.dir}/[conf]/[artifact].[ext]" conf="test"/>
  70. </target>
  71. <target name="ivy.resolve.ant" unless="ivy.skip" depends="ivy.install">
  72. <ivy:retrieve pattern="${ant.lib}/[artifact].[ext]" conf="ant"/>
  73. </target>
  74. <target name="test.load" depends="ivy.resolve.ant">
  75. <taskdef name="junit"
  76. classname="org.apache.tools.ant.taskdefs.optional.junit.JUnitTask" />
  77. </target>
  78. <target name="init.db"
  79. description="Pre-populate database with seed from USDA. (Unix Only)">
  80. <!-- TODO: Port Unix scripts to batch -->
  81. <exec executable="${script.dir}/import_weights.sh" />
  82. </target>
  83. <target name="deploy.load" depends="ivy.resolve.ant">
  84. <path id="ant.lib.path">
  85. <fileset dir="${ant.lib}" includes="*.jar"/>
  86. </path>
  87. <taskdef resource="org/apache/catalina/ant/antlib.xml"
  88. uri="antlib:org.apache.catalina.ant">
  89. <classpath refid="ant.lib.path"/>
  90. </taskdef>
  91. <taskdef name="deploy"
  92. classname="org.apache.catalina.ant.DeployTask">
  93. <classpath refid="ant.lib.path"/>
  94. </taskdef>
  95. <taskdef name="undeploy"
  96. classname="org.apache.catalina.ant.UndeployTask">
  97. <classpath refid="ant.lib.path"/>
  98. </taskdef>
  99. </target>
  100. <target name="ivy.resolve"
  101. depends="ivy.resolve.compile,ivy.resolve.war,ivy.resolve.ant"
  102. description="Use ivy to resolve compilation dependencies"/>
  103. <target name="compile.server" depends="ivy.resolve.compile"
  104. description="Compile server source files">
  105. <mkdir dir="${target.dir.server}"/>
  106. <javac srcdir="${source.dir.java}"
  107. excludes="name/tflucke/ieat2/client/**"
  108. verbose="${compile.verbose}"
  109. destdir="${target.dir.server}"
  110. debug="${compile.debug}"
  111. deprecation="${compile.deprecation}"
  112. optimize="${compile.optimize}"
  113. nowarn="${compile.nowarn}"
  114. includeantruntime="${compile.include.ant}"
  115. bootclasspath="${build.bootstrap.path}"
  116. target="${build.java.version}"
  117. source="${build.java.version}">
  118. <classpath refid="compile.classpath" />
  119. <withKotlin/>
  120. </javac>
  121. <!--
  122. TF 2019-09-09: May not be nessisary because of withKotlin
  123. <kotlinc src="${source.dir.kotlin}"
  124. output="${target.dir.server}"
  125. nowarn="${compile.nowarn}"
  126. classpath="${compile.classpath}">
  127. <compilerarg value="-verbose"/>
  128. <compilerarg line="-jvm-target ${build.java.version}"/>
  129. verbose="${compile.verbose}" -verbose
  130. deprecation="${compile.deprecation}" -progressive
  131. optimize="${compile.optimize}" -Xno-optimize
  132. </kotlinc>
  133. -->
  134. </target>
  135. <target name="compile.client" depends="ivy.resolve.compile"
  136. description="Compile client source files">
  137. <mkdir dir="${target.dir.client}"/>
  138. <kotlin2js src="${source.dir.java}"
  139. output="${target.dir.client}/generated.js"
  140. nowarn="${compile.nowarn}">
  141. </kotlin2js>
  142. </target>
  143. <target name="compile.tests" depends="ivy.resolve.test,compile.server"
  144. description="Compile test files">
  145. <mkdir dir="${test.target.dir}"/>
  146. <javac srcdir="${test.dir}"
  147. verbose="${compile.verbose}"
  148. destdir="${test.target.dir}"
  149. debug="${compile.debug}"
  150. deprecation="${compile.deprecation}"
  151. optimize="false"
  152. nowarn="${compile.nowarn}"
  153. includeantruntime="${compile.include.ant}"
  154. bootclasspath="${build.bootstrap.path}"
  155. target="${build.java.version}"
  156. source="${build.java.version}">
  157. <classpath>
  158. <path refid="compile.classpath"/>
  159. <fileset dir="${test.lib}" includes="*.jar"/>
  160. </classpath>
  161. </javac>
  162. </target>
  163. <target name="war" depends="compile.server,compile.client,ivy.resolve.war"
  164. description="Create application WAR">
  165. <mkdir dir="${build.dir}"/>
  166. <war warfile="${build.warfile}" webxml="${app.conf.dir}/web.xml">
  167. <lib dir="${build.lib}"/>
  168. <fileset dir="web"/>
  169. <fileset dir="${build.dir}/${app.name}">
  170. <include name="js/**/*.js"/>
  171. </fileset>
  172. <classes dir="${target.dir.server}"/>
  173. <classes dir="${app.conf.dir}">
  174. <exclude name="web.xml"/>
  175. </classes>
  176. </war>
  177. </target>
  178. <target name="test.server"
  179. description="Run all unit tests on server"
  180. depends="compile.server,compile.tests,test.load">
  181. <junit printsummary="yes"
  182. haltonfailure="${test.halt.failure}"
  183. haltonerror="${test.halt.error}">
  184. <classpath>
  185. <path refid="compile.classpath"/>
  186. <fileset dir="${test.lib}" includes="*.jar"/>
  187. <fileset dir="${lib.dir" includes="*.jar"/>
  188. <pathelement location="${test.target.dir}"/>
  189. <pathelement location="conf/test/app/"/>
  190. </classpath>
  191. <batchtest fork="yes">
  192. <fileset dir="${test.dir}">
  193. <include name="**/*.java"/>
  194. </fileset>
  195. <formatter type="plain" usefile="false"/>
  196. </batchtest>
  197. </junit>
  198. </target>
  199. <target name="test" description="Run all tests" depends="test.server">
  200. </target>
  201. <target name="clean" description="Delete build files">
  202. <delete dir="${build.dir}" />
  203. </target>
  204. <target name="clean.full" depends="clean"
  205. description="Delete build files and dependencies">
  206. <delete dir="${ivy.jar}"/>
  207. <delete dir="${lib.dir}"/>
  208. <ivy:cleancache/>
  209. </target>
  210. <target name="deploy" depends="war,deploy.load" description="Deploy to tomcat">
  211. <deploy url="http://localhost:8080/manager/text"
  212. username="${tomcat.username}"
  213. password="${tomcat.password}"
  214. update="true"
  215. path="/${app.name}-${build.version}"
  216. war="file:./${build.warfile}" />
  217. </target>
  218. <target name="undeploy" depends="deploy.load" description="Undeploy from tomcat">
  219. <undeploy url="http://localhost:8080/manager/text"
  220. username="${tomcat.username}"
  221. password="${tomcat.password}"
  222. path="/${app.name}-${build.version}"/>
  223. </target>
  224. </project>