build.xml 7.8 KB

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