build.xml 9.1 KB

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