build.xml 8.3 KB

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