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.server" value="src/server"/>
  26. <property name="source.dir.server.java" value="${source.dir.server}/java"/>
  27. <property name="target.dir.server"
  28. value="${build.dir}/${app.name}/WEB-INF/classes"/>
  29. <property name="target.dir.client" value="${build.dir}/${app.name}/js"/>
  30. <property prefix="compile" file="${ant.conf.dir}/compile.properties"/>
  31. <property name="compile.lib" value="${lib.dir}/compile"/>
  32. <path id="compile.classpath">
  33. <pathelement location="${target.dir.server}"/>
  34. <fileset dir="${compile.lib}" includes="*.jar"/>
  35. </path>
  36. <property name="ivy.jar" value="${ant.lib}/ivy.jar"/>
  37. <property name="ivy.dep.file" value="${ant.conf.dir}/ivy.xml" />
  38. <available property="ivy.installed" file="${ivy.jar}"/>
  39. <target name="help" description="Display build help">
  40. <echo>iEat v${build.version}</echo>
  41. <echo>To see list of targets, use ant -p</echo>
  42. </target>
  43. <target name="skip.ivy" description="Do not check dependencies. (Saves laptop battery)">
  44. <property name="ivy.skip" value="true"/>
  45. </target>
  46. <target name="ivy.install" unless="ivy.installed">
  47. <mkdir dir="${ant.lib}"/>
  48. <get dest="${ivy.jar}"
  49. src="http://search.maven.org/remotecontent?filepath=org/apache/ivy/ivy/2.3.0/ivy-2.3.0.jar"/>
  50. <taskdef resource="org/apache/ivy/ant/antlib.xml" uri="antlib:org.apache.ivy.ant" classpath="${ivy.jar}"/>
  51. <property name="ivy.installed" value="true"/>
  52. </target>
  53. <target name="ivy.tree" depends="ivy.install" description="Show the dependency tree.">
  54. <ivy:dependencytree />
  55. </target>
  56. <target name="ivy.resolve.compile" unless="ivy.skip" depends="ivy.install">
  57. <ivy:retrieve pattern="${lib.dir}/[conf]/[artifact].[ext]" conf="compile"/>
  58. </target>
  59. <target name="ivy.resolve.war" unless="ivy.skip" depends="ivy.install">
  60. <ivy:retrieve pattern="${lib.dir}/[conf]/[artifact].[ext]" conf="war"/>
  61. </target>
  62. <target name="ivy.resolve.test" unless="ivy.skip" depends="ivy.install">
  63. <ivy:retrieve pattern="${lib.dir}/[conf]/[artifact].[ext]" conf="test"/>
  64. </target>
  65. <target name="ivy.resolve.ant" unless="ivy.skip" depends="ivy.install">
  66. <ivy:retrieve pattern="${ant.lib}/[artifact].[ext]" conf="ant"/>
  67. </target>
  68. <target name="test.load" depends="ivy.resolve.ant">
  69. <taskdef name="junit" classname="org.apache.tools.ant.taskdefs.optional.junit.JUnitTask" />
  70. </target>
  71. <target name="init.db"
  72. description="Pre-populate database with seed from USDA. (Unix Only)">
  73. <!-- TODO: Port Unix scripts to batch -->
  74. <exec executable="${script.dir}/import_weights.sh" />
  75. </target>
  76. <target name="deploy.load" depends="ivy.resolve.ant">
  77. <path id="ant.lib.path">
  78. <fileset dir="${ant.lib}" includes="*.jar"/>
  79. </path>
  80. <taskdef resource="org/apache/catalina/ant/antlib.xml"
  81. uri="antlib:org.apache.catalina.ant">
  82. <classpath refid="ant.lib.path"/>
  83. </taskdef>
  84. <taskdef name="deploy"
  85. classname="org.apache.catalina.ant.DeployTask">
  86. <classpath refid="ant.lib.path"/>
  87. </taskdef>
  88. <taskdef name="undeploy"
  89. classname="org.apache.catalina.ant.UndeployTask">
  90. <classpath refid="ant.lib.path"/>
  91. </taskdef>
  92. </target>
  93. <target name="ivy.resolve"
  94. depends="ivy.resolve.compile,ivy.resolve.war,ivy.resolve.ant"
  95. description="Use ivy to resolve compilation dependencies"/>
  96. <target name="compile.server" depends="ivy.resolve.compile"
  97. description="Compile server source files">
  98. <mkdir dir="${target.dir.server}"/>
  99. <javac srcdir="${source.dir.server.java}"
  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>