build.xml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. <?xml version="1.0"?>
  2. <project default="build">
  3. <path id="yuicompressor.classpath">
  4. <fileset dir="./lib">
  5. <include name="*.jar"/>
  6. </fileset>
  7. </path>
  8. <target name="yui.minify">
  9. <java jar="./lib/yuicompressor-2.4.2.jar" fork="true" output="${output}">
  10. <arg value="${input}"/>
  11. <classpath>
  12. <path refid="yuicompressor.classpath"/>
  13. </classpath>
  14. </java>
  15. </target>
  16. <!-- ant-contrib taskdefs -->
  17. <taskdef resource="net/sf/antcontrib/antlib.xml">
  18. <classpath>
  19. <pathelement location="./lib/ant-contrib-0.6.jar"/>
  20. </classpath>
  21. </taskdef>
  22. <!-- main build dir, inside which we have one dir per build number -->
  23. <property name="build.dir" value="./build"/>
  24. <!-- create final version number -->
  25. <propertyregex property="final.version"
  26. input="${version}"
  27. regexp="[0-9]+\.[0-9]+\.[0-9]+"
  28. select="\0"
  29. casesensitive="false" />
  30. <!-- js input directory -->
  31. <property name="dir" value="./js/${final.version}/"/>
  32. <!-- input demo directory -->
  33. <property name="demo.dir" value="./demo"/>
  34. <!-- output directory -->
  35. <property name="output.dir" value="${build.dir}/${final.version}"/>
  36. <!-- output JS directory -->
  37. <property name="output.js.dir" value="${build.dir}/${final.version}/js"/>
  38. <!-- output demo directory -->
  39. <property name="output.demo.dir" value="${build.dir}/${final.version}/demo"/>
  40. <!-- output demo js directory -->
  41. <property name="output.demo.js.dir" value="${build.dir}/${final.version}/demo/js"/>
  42. <!-- output tests directory -->
  43. <property name="output.tests.dir" value="${build.dir}/${final.version}/tests"/>
  44. <!--
  45. fails the build if no "version" parameter supplied.
  46. -->
  47. <target name="checkForVersion" unless="version">
  48. <fail message="You must supply the version to bundle, eg. ant -Dversion=x.y.c-RCn"/>
  49. </target>
  50. <!-- fails if the desired build dir already exists and force was not specified on the command line. -->
  51. <target name="checkForExistingBuildDir" unless="force">
  52. <if>
  53. <available file="${output.dir}" type="dir"/>
  54. <then>
  55. <echo>Output directory already exists and "-Dforce=true" was not specified - exiting.</echo>
  56. <fail message="output directory already exists"/>
  57. </then>
  58. </if>
  59. </target>
  60. <!-- creates the output dir, if necessary -->
  61. <target name="init" depends="checkForExistingBuildDir,checkForVersion">
  62. <!-- this will fail silently if the dir already exists; that's ok. it's because this is the first build this user has run. -->
  63. <mkdir dir="${build.dir}"/>
  64. <!-- but these should not already exist; we will have bailed before here if that's the case, unless the user
  65. specified the '-Dforce=true' argument on the command line -->
  66. <delete dir="${output.dir}"/>
  67. <mkdir dir="${output.dir}"/>
  68. <mkdir dir="${output.dir}/doc"/>
  69. <mkdir dir="${output.js.dir}"/>
  70. <mkdir dir="${output.demo.dir}"/>
  71. <mkdir dir="${output.tests.dir}"/>
  72. <echo/>
  73. <echo>Building Version : ${final.version} into directory ${output.dir}</echo>
  74. </target>
  75. <!--
  76. concats a single library.
  77. expects "library" parameter to be set.
  78. -->
  79. <target name="concatLibrary">
  80. <echo>Concatenating ${library}</echo>
  81. <concat destfile="${output.js.dir}/${library}.jsPlumb-${final.version}-all.js">
  82. <filelist dir="${dir}" files="jsPlumb-${version}.js,jsPlumb-defaults-${version}.js,jsPlumb-connectors-statemachine-${version}.js, jsPlumb-renderers-vml-${version}.js, jsPlumb-renderers-svg-${version}.js, jsPlumb-renderers-canvas-${version}.js, ${library}.jsPlumb-${version}.js, ../lib/jsBezier-0.3-min.js"/>
  83. </concat>
  84. </target>
  85. <!-- minifies a concatenated library -->
  86. <target name="minLibrary" depends="concatLibrary">
  87. <echo>Minifying ${library}</echo>
  88. <antcall target="yui.minify">
  89. <param name="input" value="${output.js.dir}/${library}.jsPlumb-${final.version}-all.js"/>
  90. <param name="output" value="${output.js.dir}/${library}.jsPlumb-${final.version}-all-min.js"/>
  91. </antcall>
  92. </target>
  93. <!--
  94. generates minified and concatenated scripts for supported libraries.
  95. -->
  96. <target name="minAll">
  97. <antcall target="minLibrary">
  98. <param name="library" value="jquery"/>
  99. </antcall>
  100. <antcall target="minLibrary">
  101. <param name="library" value="mootools"/>
  102. </antcall>
  103. <antcall target="minLibrary">
  104. <param name="library" value="yui"/>
  105. </antcall>
  106. </target>
  107. <!-- replaces JS imports in HTML files with minified versions and with production links to dependencies -->
  108. <target name="html">
  109. <echo>Replacing Javascript imports for ${library}</echo>
  110. <!-- replace JS dependency with the prod version -->
  111. <replaceregexp>
  112. <regexp pattern="(&lt;!-- DEP.*&gt;.*\n)(.*\n)*(.*/DEP --&gt;)"/>
  113. <substitution expression="${dependencies}"/>
  114. <fileset dir="${output.demo.dir}/${libraryDir}">
  115. <include name="*.html"/>
  116. </fileset>
  117. </replaceregexp>
  118. <!-- replace all JS with the minified file -->
  119. <replaceregexp>
  120. <regexp pattern="(&lt;!-- JS.*&gt;.*\n)(.*\n)*(.*/JS --&gt;)"/>
  121. <substitution expression="&lt;script type='text/javascript' src='../js/${library}.jsPlumb-${final.version}-all-min.js'&gt;&lt;/script&gt;"/>
  122. <fileset dir="${output.demo.dir}/${libraryDir}">
  123. <include name="*.html"/>
  124. </fileset>
  125. </replaceregexp>
  126. </target>
  127. <!-- copies the demos and replaces their JS imports with final versions -->
  128. <target name="demo">
  129. <echo>Processing demo code...</echo>
  130. <copy todir="${output.demo.dir}">
  131. <fileset dir="${demo.dir}"/>
  132. </copy>
  133. <!-- copy built JS -->
  134. <copy todir="${output.demo.js.dir}">
  135. <fileset dir="${output.js.dir}"/>
  136. </copy>
  137. <!-- replace dev JS imports with final versions -->
  138. <antcall target="html">
  139. <param name="libraryDir" value="jquery"/>
  140. <param name="library" value="jquery"/>
  141. <param name="dependencies" value="&lt;script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js'&gt;&lt;/script&gt;&lt;script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.13/jquery-ui.min.js'&gt;&lt;/script&gt;"/>
  142. </antcall>
  143. <antcall target="html">
  144. <param name="libraryDir" value="mootools"/>
  145. <param name="library" value="mootools"/>
  146. <param name="dependencies" value="&lt;script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/mootools/1.3.2/mootools-yui-compressed.js'&gt;&lt;/script&gt;"/>
  147. </antcall>
  148. <antcall target="html">
  149. <param name="libraryDir" value="yui3"/>
  150. <param name="library" value="yui"/>
  151. </antcall>
  152. </target>
  153. <!-- copies the jsPlumb documentation into the build area -->
  154. <target name="copy-documentation">
  155. <echo>Copying documentation...</echo>
  156. <copy todir="${output.dir}/demo/doc">
  157. <fileset dir="./demo/doc">
  158. <include name="*.html"/>
  159. <include name="*.css"/>
  160. </fileset>
  161. </copy>
  162. <copy todir="${output.dir}/demo/doc">
  163. <fileset dir="./demo/doc">
  164. <include name="*.html"/>
  165. <include name="*.css"/>
  166. </fileset>
  167. </copy>
  168. </target>
  169. <target name="update-tests-js">
  170. <replaceregexp>
  171. <regexp pattern="(&lt;!-- JS.*&gt;.*\n)(.*\n)*(.*/JS --&gt;)"/>
  172. <substitution expression="&lt;script type='text/javascript' src='../js/${library}.jsPlumb-${final.version}-all-min.js'&gt;&lt;/script&gt;"/>
  173. <fileset dir="${output.tests.dir}">
  174. <include name="*${library}.html"/>
  175. <include name="*${library}-instance.html"/>
  176. </fileset>
  177. </replaceregexp>
  178. <replaceregexp>
  179. <regexp pattern="(&lt;!-- TEST.*&gt;.*\n)(.*\n)*(.*/TEST --&gt;)"/>
  180. <substitution expression="&lt;script type='text/javascript' src='../js/jsPlumb-${final.version}-tests.js'&gt;&lt;/script&gt;"/>
  181. <fileset dir="${output.tests.dir}">
  182. <include name="*${library}.html"/>
  183. <include name="*${library}-instance.html"/>
  184. </fileset>
  185. </replaceregexp>
  186. </target>
  187. <!-- copies the tests directory into the build dir -->
  188. <target name="copy-tests">
  189. <copy todir="${output.js.dir}">
  190. <fileset dir="js/${final.version}">
  191. <include name="jsPlumb-${final.version}-tests.js"/>
  192. </fileset>
  193. </copy>
  194. <copy todir="${output.tests.dir}">
  195. <fileset dir="tests">
  196. <include name="*.html"/>
  197. <include name="*.css"/>
  198. </fileset>
  199. </copy>
  200. <mkdir dir="${output.js.dir}/lib"/>
  201. <copy todir="${output.js.dir}/lib">
  202. <fileset dir="js/lib">
  203. <include name="qunit.js"/>
  204. </fileset>
  205. </copy>
  206. <!-- now replace the JS with minified ones! -->
  207. <antcall target="update-tests-js">
  208. <param name="library" value="jquery"/>
  209. </antcall>
  210. <antcall target="update-tests-js">
  211. <param name="library" value="mootools"/>
  212. </antcall>
  213. <antcall target="update-tests-js">
  214. <param name="library" value="yui"/>
  215. </antcall>
  216. </target>
  217. <target name="doc-version" unless="final.version">
  218. <fail message="You must supply the final version to build api docs from"/>
  219. </target>
  220. <!-- generates the API docs -->
  221. <target name="docs" depends="doc-version">
  222. <mkdir dir="js/TEMP"/>
  223. <mkdir dir="js/TEMPOUT"/>
  224. <copy todir="js/TEMP">
  225. <fileset dir="build/${final.version}/js">
  226. <include name="jquery.jsPlumb-${final.version}-all.js"/>
  227. </fileset>
  228. </copy>
  229. <mkdir dir="apidocs"/>
  230. <exec executable="naturaldocs">
  231. <arg line="-i"/>
  232. <arg path="js/TEMP"/>
  233. <arg line="-o"/>
  234. <arg line="HTML"/>
  235. <arg line="js/TEMPOUT"/>
  236. <arg line="-p"/>
  237. <arg line="."/>
  238. </exec>
  239. <!-- replace the jquery.blah title stuff that apidocs comes up with -->
  240. <replace dir="js/TEMPOUT" token="&lt;wbr&gt;"/>
  241. <replace dir="js/TEMPOUT" token="jquery.jsPlumb-${final.version}-all.js" value="jsPlumb ${final.version}"/>
  242. <!-- get a copy of the version number with dashes not dots -->
  243. <propertyregex property="version.with.dashes"
  244. input="${final.version}"
  245. regexp="([0-9])\.([0-9])\.([0-9])"
  246. replace="\1-\2-\3"/>
  247. <!-- write the index file -->
  248. <echo file="js/TEMPOUT/index.html" append="false">&lt;html&gt;&lt;head&gt;&lt;meta http-equiv="Refresh" CONTENT="0; URL=./files/jquery-jsPlumb-${version.with.dashes}-all-js.html"&gt;&lt;/head&gt;&lt;/html&gt;</echo>
  249. <delete dir="js/TEMP"/>
  250. <delete dir="demo/apidocs"/>
  251. <mkdir dir="demo/apidocs"/>
  252. <copy todir="demo/apidocs">
  253. <fileset dir="js/TEMPOUT">
  254. <include name="**/*"/>
  255. </fileset>
  256. </copy>
  257. <copy todir="build/${final.version}/demo/apidocs">
  258. <fileset dir="demo/apidocs">
  259. <include name="**/*"/>
  260. </fileset>
  261. </copy>
  262. <delete dir="js/TEMPOUT"/>
  263. </target>
  264. <target name="build" depends="init">
  265. <antcall target="minAll"/>
  266. <antcall target="demo"/>
  267. <antcall target="copy-documentation"/>
  268. <antcall target="copy-tests"/>
  269. </target>
  270. <target name="build-all" depends="build">
  271. <antcall target="docs"/>
  272. </target>
  273. </project>