build.xml 7.8 KB

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