defs.xml 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <!--
  3. Name: include/defs.xml
  4. Purpose: Common declarations for buildbot
  5. Author: Mike Wetherell
  6. Copyright: (c) 2007 Mike Wetherell
  7. Licence: wxWindows licence
  8. -->
  9. <bot xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  10. xmlns:exsl="http://exslt.org/common"
  11. xmlns:func="http://exslt.org/functions"
  12. xmlns:get="local"
  13. xsl:extension-element-prefixes="func"
  14. xsl:version="1.0">
  15. <!--
  16. Constants
  17. -->
  18. <xsl:template name="SVN_URL">http://svn.wxwidgets.org/svn/wx/wxWidgets/</xsl:template>
  19. <xsl:template name="STABLE_BRANCH">branches/WX_2_8_BRANCH</xsl:template>
  20. <xsl:variable name="STABLE_BRANCH"><STABLE_BRANCH/></xsl:variable>
  21. <xsl:template name="RELEASE_BRANCH">branches/WX_2_9_0_BRANCH</xsl:template>
  22. <xsl:variable name="RELEASE_BRANCH"><RELEASE_BRANCH/></xsl:variable>
  23. <xsl:template name="SNAPSHOT_URL">http://biolpc22.york.ac.uk/pub</xsl:template>
  24. <!--
  25. disable - comment out a section.
  26. Usage: <disable>
  27. e.g. <build> ... etc.
  28. </disable>
  29. XML comments can't contain a double hyphen which tends to be used in
  30. configure commands, so <disable> can be used instead.
  31. -->
  32. <xsl:template name="disable"/>
  33. <!--
  34. checkout - build step for source checkout.
  35. Usage: as <svn> with defaults for <baseURL> and <defaultBranch>
  36. Typically just:
  37. <checkout/>
  38. for the trunk, or:
  39. <checkout branch="branches/WX_2_8_BRANCH"/>
  40. to checkout a branch.
  41. -->
  42. <xsl:template name="checkout">
  43. <xsl:param name="content"/>
  44. <xsl:param name="branch" select="'trunk'"/>
  45. <xsl:variable name="nodes" select="exsl:node-set($content)"/>
  46. <svn>
  47. <xsl:if test="not($nodes/svnurl)">
  48. <xsl:if test="not($nodes/baseURL)">
  49. <baseURL><SVN_URL/></baseURL>
  50. </xsl:if>
  51. <xsl:if test="not($nodes/defaultBranch)">
  52. <defaultBranch><xsl:value-of select="$branch"/></defaultBranch>
  53. </xsl:if>
  54. </xsl:if>
  55. <xsl:copy-of select="$content"/>
  56. </svn>
  57. </xsl:template>
  58. <!--
  59. configure - add the options attribute to <configure>
  60. Usage: <configure options="-with-foobar"/>
  61. -->
  62. <xsl:template name="configure">
  63. <xsl:param name="content"/>
  64. <xsl:param name="options"/>
  65. <configure>
  66. <copy-with-defaults content="{$content}">
  67. <command>./configure <xsl:value-of select="normalize-space($options)"/></command>
  68. </copy-with-defaults>
  69. </configure>
  70. </xsl:template>
  71. <!--
  72. make - specify the make command.
  73. Usage: <make>nmake -f makefile.vc SHARED=1</make>
  74. Used as a child of <build> to specify the make command used by the
  75. <compile> elements below, if omitted 'make' is used.
  76. -->
  77. <xsl:template name="make"/>
  78. <!--
  79. compile - modifiy <compile> to default to the command given by <make>
  80. Usage: as <compile>
  81. The <make> element of <build> spcecifies the make command used by all
  82. compile build steps in the build. If <make> is not given 'make' is used.
  83. The command for a particular compile build step can be further overridden
  84. using its <command> element:
  85. <compile>
  86. <command>myscript</command>
  87. </compile>
  88. -->
  89. <xsl:template name="compile">
  90. <xsl:param name="content"/>
  91. <compile>
  92. <copy-with-defaults content="{$content}">
  93. <command><get name="make" default="make"/></command>
  94. </copy-with-defaults>
  95. </compile>
  96. </xsl:template>
  97. <!--
  98. Adds build steps to compile the library and the usual subdirectories.
  99. Usage: as <compile> with the additional attributes below.
  100. Usually the attributes default to suitable values, so typical usage
  101. is just <compile-all/>.
  102. <compile-all [ gui = 'true'|'false' ]
  103. [ msw = 'true'|'false' ]
  104. [ wx = 'true'|'false' ]
  105. [ samples = 'true'|'false' ]
  106. [ utils = 'true'|'false' ]
  107. [ demos = 'true'|'false' ]
  108. [ contrib = 'true'|'false' ]
  109. [ tests = 'true'|'false' ] />
  110. gui - if 'true' then build fully the subdirectories specified,
  111. otherwise only the wxBase subset of the directories are built.
  112. msw - if 'true' then build the directory 'build/msw' when building the
  113. library instead of the root.
  114. wx - build the library itself.
  115. samples, utils, demos, contrib, tests
  116. - build subdirectories.
  117. -->
  118. <xsl:template name="compile-all">
  119. <xsl:param name="content"/>
  120. <xsl:param name="gui"><is-gui/></xsl:param>
  121. <xsl:param name="msw"><is-msw/></xsl:param>
  122. <xsl:param name="wx" select="'true'"/>
  123. <xsl:param name="samples" select="'true'"/>
  124. <xsl:param name="utils" select="'true'"/>
  125. <xsl:param name="demos" select="$gui"/>
  126. <xsl:param name="contrib"><has-contrib/></xsl:param>
  127. <xsl:param name="tests"><has-tests/></xsl:param>
  128. <xsl:param name="wx-dirs">
  129. <get-dirs wx="{$wx}" gui="{$gui}" msw="{$msw}"/>
  130. </xsl:param>
  131. <xsl:param name="sample-dirs">
  132. <get-dirs samples="{$samples}" gui="{$gui}" msw="{$msw}"/>
  133. </xsl:param>
  134. <xsl:param name="util-dirs">
  135. <get-dirs utils="{$utils}" gui="{$gui}" msw="{$msw}"/>
  136. </xsl:param>
  137. <xsl:param name="demo-dirs">
  138. <get-dirs demos="{$demos}" gui="{$gui}" msw="{$msw}"/>
  139. </xsl:param>
  140. <xsl:param name="contrib-dirs">
  141. <get-dirs contrib="{$contrib}" gui="{$gui}" msw="{$msw}"/>
  142. </xsl:param>
  143. <xsl:param name="test-dirs">
  144. <get-dirs tests="{$tests}" gui="{$gui}" msw="{$msw}"/>
  145. </xsl:param>
  146. <compile-subdirs dirs="{$wx-dirs}" halt="true">
  147. <xsl:copy-of select="$content"/>
  148. </compile-subdirs>
  149. <compile-subdirs name="samples" dirs="{$sample-dirs}">
  150. <xsl:copy-of select="$content"/>
  151. </compile-subdirs>
  152. <compile-subdirs name="utils" dirs="{$util-dirs}">
  153. <xsl:copy-of select="$content"/>
  154. </compile-subdirs>
  155. <compile-subdirs name="demos" dirs="{$demo-dirs}">
  156. <xsl:copy-of select="$content"/>
  157. </compile-subdirs>
  158. <compile-subdirs name="contrib" dirs="{$contrib-dirs}">
  159. <xsl:copy-of select="$content"/>
  160. </compile-subdirs>
  161. <compile-subdirs name="tests" dirs="{$test-dirs}" halt="true">
  162. <xsl:copy-of select="$content"/>
  163. </compile-subdirs>
  164. </xsl:template>
  165. <!--
  166. Helper for compile-all.
  167. Returns the directories that need to be built for the various components:
  168. wx (the library itself), samples, utils, demos, contrib and tests.
  169. -->
  170. <xsl:template name="get-dirs">
  171. <xsl:param name="contents"/>
  172. <xsl:param name="gui"/>
  173. <xsl:param name="msw"/>
  174. <xsl:param name="wx"/>
  175. <xsl:param name="samples"/>
  176. <xsl:param name="utils"/>
  177. <xsl:param name="demos"/>
  178. <xsl:param name="contrib"/>
  179. <xsl:param name="tests"/>
  180. <xsl:if test="$wx = 'true'">
  181. <xsl:choose>
  182. <xsl:when test="$msw = 'true'">build/msw</xsl:when>
  183. <xsl:otherwise>.</xsl:otherwise>
  184. </xsl:choose>
  185. <xsl:text> </xsl:text>
  186. </xsl:if>
  187. <xsl:if test="$samples = 'true'">
  188. <xsl:choose>
  189. <xsl:when test="$gui = 'true'">samples</xsl:when>
  190. <xsl:otherwise>samples/console</xsl:otherwise>
  191. </xsl:choose>
  192. <xsl:text> </xsl:text>
  193. </xsl:if>
  194. <xsl:if test="$utils = 'true' and $gui = 'true'">utils </xsl:if>
  195. <xsl:if test="$demos = 'true' and $gui = 'true'">demos </xsl:if>
  196. <xsl:if test="$contrib = 'true' and $gui = 'true'">contrib </xsl:if>
  197. <xsl:if test="$tests = 'true'">tests</xsl:if>
  198. </xsl:template>
  199. <!--
  200. compile-subdir - build step to compile a subdirectory.
  201. Usage: as <compile> plus the following attributes,
  202. <compile-subdir dir="foobar" [ halt="true" ]/>
  203. Compiles the named subdirectory 'foobar'. Continues with the next build
  204. step on failure, unless the optional attibute 'halt="true"' is given.
  205. The make command used is as described for the compile step above.
  206. -->
  207. <xsl:template name="compile-subdir">
  208. <xsl:param name="content"/>
  209. <xsl:param name="dir"/>
  210. <xsl:param name="halt" select="'false'"/>
  211. <compile-subdirs name="{$dir}" dirs="{$dir}" halt="{$halt}">
  212. <xsl:copy-of select="$content"/>
  213. </compile-subdirs>
  214. </xsl:template>
  215. <!--
  216. compile-subdirs - adds a compile build step for each directory in a list.
  217. Usage: as <compile> plus the following attributes,
  218. <compile-subdir dirs="foobar1 foobar2"
  219. [ name="foobars" ]
  220. [ sep=" " ]
  221. [ halt="true" ]/>
  222. Compiles the named subdirectories. Continues with the next build
  223. step on failure, unless the optional attibute 'halt="true"' is given.
  224. The make command used is as described for the compile step above.
  225. The 'name' attribute can be used to give a collective name for the
  226. subdirectories, and the 'sep' attibute can be used to specify the
  227. separator in the 'dirs' list (defaults to space).
  228. -->
  229. <xsl:template name="compile-subdirs">
  230. <xsl:param name="content"/>
  231. <xsl:param name="name"/>
  232. <xsl:param name="dirs"/>
  233. <xsl:param name="sep" select="' '"/>
  234. <xsl:param name="halt" select="'false'"/>
  235. <xsl:if test="translate($dirs, $sep, '')">
  236. <compile>
  237. <defaults content="{$content}">
  238. <name>
  239. <xsl:value-of select="normalize-space(concat('compile ', $name))"/>
  240. </name>
  241. <description>
  242. <xsl:value-of select="normalize-space(concat('compiling ', $name))"/>
  243. </description>
  244. <descriptionDone>
  245. <xsl:value-of select="normalize-space(concat('compile ', $name))"/>
  246. </descriptionDone>
  247. <haltOnFailure>
  248. <xsl:value-of select="$halt"/>
  249. </haltOnFailure>
  250. <warnOnFailure/>
  251. </defaults>
  252. <copy-with-defaults content="{$content}">
  253. <command>
  254. <compile-subdirs-cmd dirs="{$dirs}" sep="{$sep}"/>
  255. </command>
  256. </copy-with-defaults>
  257. </compile>
  258. </xsl:if>
  259. </xsl:template>
  260. <xsl:template name="compile-subdirs-cmd">
  261. <xsl:param name="content"/>
  262. <xsl:param name="dirs"/>
  263. <xsl:param name="sep"/>
  264. <xsl:choose>
  265. <xsl:when test="contains($dirs, $sep)">
  266. <xsl:variable name="before" select="substring-before($dirs, $sep)"/>
  267. <xsl:variable name="after" select="substring-after($dirs, $sep)"/>
  268. <xsl:call-template name="compile-subdirs-cmd">
  269. <xsl:with-param name="dirs" select="$before"/>
  270. <xsl:with-param name="sep" select="$sep"/>
  271. </xsl:call-template>
  272. <xsl:if test="$after and substring($after, 1, 1) != ' '">
  273. <xsl:text> &amp;&amp; </xsl:text>
  274. </xsl:if>
  275. <xsl:call-template name="compile-subdirs-cmd">
  276. <xsl:with-param name="dirs" select="$after"/>
  277. <xsl:with-param name="sep" select="$sep"/>
  278. </xsl:call-template>
  279. </xsl:when>
  280. <xsl:when test="string($dirs)">
  281. <xsl:if test="$dirs != '.'">cd <xsl:value-of select="$dirs"/> &amp;&amp; </xsl:if>
  282. <get name="make" default="make"/>
  283. </xsl:when>
  284. </xsl:choose>
  285. </xsl:template>
  286. <!--
  287. run-tests - build step to run the test suites.
  288. Usage: as <test>
  289. Typically just:
  290. <run-tests/>
  291. -->
  292. <xsl:template name="run-tests">
  293. <xsl:param name="content"/>
  294. <xsl:param name="options" select="'-t'"/>
  295. <xsl:param name="guioptions" select="$options"/>
  296. <xsl:param name="msw"><is-msw/></xsl:param>
  297. <test>
  298. <defaults content="{$content}">
  299. <description>running tests</description>
  300. <descriptionDone>run tests</descriptionDone>
  301. <warnOnFailure/>
  302. </defaults>
  303. <copy-with-defaults content="{$content}">
  304. <command>
  305. <xsl:choose>
  306. <xsl:when test="$msw = 'true'">
  307. <run-tests-win options="{$options}" guioptions="{$guioptions}"/>
  308. </xsl:when>
  309. <xsl:otherwise>
  310. <run-tests-unix options="{$options}" guioptions="{$guioptions}"/>
  311. </xsl:otherwise>
  312. </xsl:choose>
  313. </command>
  314. </copy-with-defaults>
  315. </test>
  316. </xsl:template>
  317. <xsl:template name="run-tests-win">
  318. <xsl:param name="options"/>
  319. <xsl:param name="guioptions"/>
  320. <normalize-space>
  321. cd tests &amp;&amp; runtests.bat
  322. </normalize-space>
  323. </xsl:template>
  324. <xsl:template name="run-tests-unix">
  325. <xsl:param name="options"/>
  326. <xsl:param name="guioptions"/>
  327. ERR=0
  328. cd tests || exit 0
  329. ulimit -c unlimited
  330. try()
  331. {
  332. rm -f core
  333. echo Running: "$@"
  334. "$@" || ERR=$?
  335. if [ -f core -a -x "`which gdb`" ]; then
  336. echo Crashed, attempting to display backtrace:
  337. gdb -batch -c core -ex 'set pagination off' -ex bt "$1"
  338. fi
  339. echo
  340. }
  341. try ./test <xsl:value-of select="normalize-space($options)"/>
  342. test -x test_gui || exit $ERR
  343. if [ -z "$DISPLAY" ]; then
  344. echo '$DISPLAY is not set, skipping GUI tests.'
  345. exit $ERR
  346. fi
  347. echo 'Checking window manager:'
  348. WINDOW_MANAGER=$(xprop -root 32x '\n$0\n' _NET_SUPPORTING_WM_CHECK | grep ^0x)
  349. if [ -z "$WINDOW_MANAGER" ]; then
  350. echo 'Window manager not present, skipping GUI tests.'
  351. exit $ERR
  352. fi
  353. xprop -id $WINDOW_MANAGER 8s _NET_WM_NAME
  354. echo
  355. try ./test_gui <xsl:value-of select="normalize-space($guioptions)"/>
  356. exit $ERR
  357. </xsl:template>
  358. <!--
  359. defaults - supply default content for an element.
  360. Usage: <defaults content="{$content}">
  361. <foo>foo</foo>
  362. <bar>bar</bar>
  363. </defaults>
  364. Copies those child elements that do not already exist in $content.
  365. -->
  366. <xsl:template name="defaults">
  367. <xsl:param name="defaults"/>
  368. <xsl:param name="content"/>
  369. <xsl:variable name="def-nodes" select="exsl:node-set($defaults)"/>
  370. <xsl:variable name="cont-nodes" select="exsl:node-set($content)"/>
  371. <xsl:for-each select="$def-nodes/*">
  372. <xsl:if test="not($cont-nodes/*[name() = name(current())])">
  373. <xsl:copy-of select="."/>
  374. </xsl:if>
  375. </xsl:for-each>
  376. </xsl:template>
  377. <!--
  378. copy-with-defaults - copy elements supplying defaults for any that are
  379. missing or empty.
  380. Usage: <copy-with-defaults content="{$content}">
  381. <foo>foo</foo>
  382. <bar>bar</bar>
  383. </copy-with-defaults>
  384. Copies $content plus any child elements that do not exist in $content,
  385. substituting empty elements in $content with any child elements of the
  386. same name.
  387. -->
  388. <xsl:template name="copy-with-defaults">
  389. <xsl:param name="defaults"/>
  390. <xsl:param name="content"/>
  391. <xsl:variable name="def-nodes" select="exsl:node-set($defaults)"/>
  392. <xsl:variable name="cont-nodes" select="exsl:node-set($content)"/>
  393. <xsl:for-each select="$def-nodes/*">
  394. <xsl:if test="not($cont-nodes/*[name() = name(current())])">
  395. <xsl:copy-of select="."/>
  396. </xsl:if>
  397. </xsl:for-each>
  398. <xsl:for-each select="$cont-nodes/*">
  399. <xsl:choose>
  400. <xsl:when test="not(node())">
  401. <xsl:copy-of select="$def-nodes/*[name() = name(current())]"/>
  402. </xsl:when>
  403. <xsl:otherwise>
  404. <xsl:copy-of select="."/>
  405. </xsl:otherwise>
  406. </xsl:choose>
  407. </xsl:for-each>
  408. </xsl:template>
  409. <!--
  410. get - gets the text from a child element of the current build.
  411. Usage: <get name="foobar" [ default="value" ]/>
  412. Gets the text from the <foobar> element of the current build, or returns
  413. $default if there is not such element.
  414. -->
  415. <xsl:template name="get">
  416. <xsl:param name="content"/>
  417. <xsl:param name="build" select="get:build()"/>
  418. <xsl:param name="name"/>
  419. <xsl:param name="default"/>
  420. <xsl:variable name="property" select="get:property($name, $build)"/>
  421. <strip>
  422. <xsl:choose>
  423. <xsl:when test="$property">
  424. <xsl:apply-templates select="$property/node()"/>
  425. </xsl:when>
  426. <xsl:otherwise>
  427. <xsl:value-of select="$default"/>
  428. </xsl:otherwise>
  429. </xsl:choose>
  430. </strip>
  431. </xsl:template>
  432. <!--
  433. Accessors to get builds and their fields. XSLT code should use these
  434. instead of traversing the input tree directly.
  435. -->
  436. <func:function name="get:build">
  437. <func:result select="ancestor-or-self::build[last()]"/>
  438. </func:function>
  439. <func:function name="get:all-builds">
  440. <func:result select="//build[not(ancestor::*[name() != name(/*)])]"/>
  441. </func:function>
  442. <func:function name="get:preceding-builds">
  443. <func:result select="get:build()/preceding-sibling::build"/>
  444. </func:function>
  445. <func:function name="get:property">
  446. <xsl:param name="name"/>
  447. <xsl:param name="build" select="get:build()"/>
  448. <func:result select="$build/*[name() = $name]"/>
  449. </func:function>
  450. <func:function name="get:step">
  451. <xsl:param name="name"/>
  452. <xsl:param name="build" select="get:build()"/>
  453. <func:result select="get:property('steps', $build)/*[name() = $name]"/>
  454. </func:function>
  455. <!--
  456. Returns true if this is an msw build.
  457. -->
  458. <xsl:template name="is-msw">
  459. <xsl:param name="content"/>
  460. <xsl:param name="build" select="get:build()"/>
  461. <xsl:value-of select="not(get:step('configure', $build))"/>
  462. </xsl:template>
  463. <!--
  464. Returns true if this a gui build.
  465. -->
  466. <xsl:template name="is-gui">
  467. <xsl:param name="content"/>
  468. <xsl:param name="build" select="get:build()"/>
  469. <xsl:variable name="make"><get name="make" build="{$build}"/></xsl:variable>
  470. <xsl:variable name="configure"><xsl:apply-templates select="get:step('configure', $build)"/></xsl:variable>
  471. <xsl:value-of select="not(contains($make, 'USE_GUI=0') or contains($configure, '--disable-gui'))"/>
  472. </xsl:template>
  473. <!--
  474. Returns true if the branch we're building has a contrib subdirectory.
  475. -->
  476. <xsl:template name="has-contrib">
  477. <xsl:param name="content"/>
  478. <xsl:param name="build" select="get:build()"/>
  479. <xsl:variable name="checkout"><xsl:apply-templates select="get:step('checkout', $build)"/></xsl:variable>
  480. <xsl:value-of select="contains($checkout, 'WX_2_') and not(contains($checkout, 'WX_2_9_'))"/>
  481. </xsl:template>
  482. <!--
  483. Returns true if the build should build the test suite.
  484. -->
  485. <xsl:template name="has-tests">
  486. <xsl:param name="content"/>
  487. <xsl:param name="build" select="get:build()"/>
  488. <xsl:variable name="configure"><xsl:apply-templates select="get:step('configure', $build)"/></xsl:variable>
  489. <xsl:value-of select="get:step('run-tests', $build) or contains($configure, '--host=')"/>
  490. </xsl:template>
  491. <!--
  492. strip - strips leading and trailing whitespace
  493. Usage: <strip>
  494. foobar
  495. </strip>
  496. Converts to text and strips leading and trailing whitespace.
  497. -->
  498. <xsl:template name="strip">
  499. <xsl:param name="content"/>
  500. <xsl:variable name="len" select="string-length($content)"/>
  501. <xsl:variable name="norm" select="normalize-space($content)"/>
  502. <xsl:variable name="normlen" select="string-length($norm)"/>
  503. <xsl:choose>
  504. <xsl:when test="substring($content, 1, 1) != substring($norm, 1, 1)">
  505. <xsl:call-template name="strip">
  506. <xsl:with-param name="content" select="substring($content, 2)"/>
  507. </xsl:call-template>
  508. </xsl:when>
  509. <xsl:when test="substring($content, $len, 1) != substring($norm, $normlen, 1)">
  510. <xsl:call-template name="strip">
  511. <xsl:with-param name="content" select="substring($content, 1, $len - 1)"/>
  512. </xsl:call-template>
  513. </xsl:when>
  514. <xsl:otherwise>
  515. <xsl:value-of select="$content"/>
  516. </xsl:otherwise>
  517. </xsl:choose>
  518. </xsl:template>
  519. <!--
  520. normalize-space - normalises whitespace.
  521. Usage: <normalize-space>
  522. foobar
  523. </normalize-space>
  524. Converts to text, strips leading and trailing whitespace and replaces
  525. sequences of whitespace characters by a single space.
  526. -->
  527. <xsl:template name="normalize-space">
  528. <xsl:param name="content"/>
  529. <xsl:value-of select="normalize-space($content)"/>
  530. </xsl:template>
  531. <!--
  532. lower-case - converts to lower case.
  533. Usage: <lower-case>FooBar</lower-case>
  534. -->
  535. <xsl:template name="lower-case">
  536. <xsl:param name="content"/>
  537. <xsl:variable name="lower">abcdefghijklmnopqrstuvwxyz</xsl:variable>
  538. <xsl:variable name="upper">ABCDEFGHIJKLMNOPQRSTUVWXYZ</xsl:variable>
  539. <xsl:value-of select="translate($content, $upper, $lower)"/>
  540. </xsl:template>
  541. <!--
  542. Helpers to convert between day numbers and names.
  543. -->
  544. <xsl:template name="day-number">
  545. <xsl:param name="content"/>
  546. <xsl:param name="name"/>
  547. <xsl:choose>
  548. <xsl:when test="$name = 'monday'">0</xsl:when>
  549. <xsl:when test="$name = 'tuesday'">1</xsl:when>
  550. <xsl:when test="$name = 'wednesday'">2</xsl:when>
  551. <xsl:when test="$name = 'thursday'">3</xsl:when>
  552. <xsl:when test="$name = 'friday'">4</xsl:when>
  553. <xsl:when test="$name = 'saturday'">5</xsl:when>
  554. <xsl:when test="$name = 'sunday'">6</xsl:when>
  555. </xsl:choose>
  556. </xsl:template>
  557. <xsl:template name="day-name">
  558. <xsl:param name="content"/>
  559. <xsl:param name="number"/>
  560. <xsl:choose>
  561. <xsl:when test="$number = '0'">monday</xsl:when>
  562. <xsl:when test="$number = '1'">tuesday</xsl:when>
  563. <xsl:when test="$number = '2'">wednesday</xsl:when>
  564. <xsl:when test="$number = '3'">thursday</xsl:when>
  565. <xsl:when test="$number = '4'">friday</xsl:when>
  566. <xsl:when test="$number = '5'">saturday</xsl:when>
  567. <xsl:when test="$number = '6'">sunday</xsl:when>
  568. </xsl:choose>
  569. </xsl:template>
  570. <!--
  571. Helpers to convert between time in the format 'hhmm' and an integer
  572. count of the minutes since midnight.
  573. -->
  574. <xsl:template name="time-minutes">
  575. <xsl:param name="content"/>
  576. <xsl:param name="hhmm"/>
  577. <xsl:if test="string-length($hhmm) = 4 and format-number($hhmm, '0000') = $hhmm">
  578. <xsl:variable name="hour" select="substring($hhmm, 1, 2)"/>
  579. <xsl:variable name="min" select="substring($hhmm, 3, 2)"/>
  580. <xsl:if test="$hour >= 0 and $hour &lt; 24 and $min >= 0 and $min &lt; 60">
  581. <xsl:value-of select="$hour * 60 + $min"/>
  582. </xsl:if>
  583. </xsl:if>
  584. </xsl:template>
  585. <xsl:template name="time-hhmm">
  586. <xsl:param name="content"/>
  587. <xsl:param name="minutes"/>
  588. <xsl:value-of select="format-number(floor($minutes div 60) * 100 + $minutes mod 60, '0000')"/>
  589. </xsl:template>
  590. <!--
  591. Create schedulers.
  592. -->
  593. <xsl:template name="nightly-schedulers">
  594. <xsl:param name="content"/>
  595. <xsl:param name="name"/>
  596. <xsl:param name="day"><day-number name="{$name}"/></xsl:param>
  597. <xsl:param name="hour" select="0"/>
  598. <xsl:param name="minute" select="0"/>
  599. <xsl:param name="step" select="30"/>
  600. <xsl:if test="$hour &lt; 24">
  601. <nightly>
  602. <name>
  603. <xsl:value-of select="concat($name, '_', format-number($hour, '00'), format-number($minute, '00'))"/>
  604. </name>
  605. <hour>
  606. <xsl:value-of select="$hour"/>
  607. </hour>
  608. <minute>
  609. <xsl:value-of select="$minute"/>
  610. </minute>
  611. <xsl:if test="$day != ''">
  612. <dayOfWeek>
  613. <xsl:value-of select="$day"/>
  614. </dayOfWeek>
  615. </xsl:if>
  616. </nightly>
  617. <xsl:variable name="next" select="$hour * 60 + $minute + $step"/>
  618. <xsl:call-template name="nightly-schedulers">
  619. <xsl:with-param name="name" select="$name"/>
  620. <xsl:with-param name="day" select="$day"/>
  621. <xsl:with-param name="hour" select="floor($next div 60)"/>
  622. <xsl:with-param name="minute" select="$next mod 60"/>
  623. <xsl:with-param name="step" select="$step"/>
  624. </xsl:call-template>
  625. </xsl:if>
  626. </xsl:template>
  627. <!--
  628. scheduler - provide default for the <scheduler> build element.
  629. -->
  630. <xsl:template name="scheduler">
  631. <xsl:param name="content"/>
  632. <xsl:param name="previous" select="get:property('scheduler', get:preceding-builds()[last()])"/>
  633. <xsl:param name="step" select="60"/>
  634. <xsl:choose>
  635. <xsl:when test="exsl:node-set($content)/node()">
  636. <scheduler>
  637. <xsl:copy-of select="$content"/>
  638. </scheduler>
  639. </xsl:when>
  640. <xsl:otherwise>
  641. <xsl:for-each select="$previous">
  642. <xsl:variable name="text">
  643. <xsl:apply-templates select="."/>
  644. </xsl:variable>
  645. <scheduler>
  646. <scheduler-subst text="{$text}" step="{$step}"/>
  647. </scheduler>
  648. </xsl:for-each>
  649. </xsl:otherwise>
  650. </xsl:choose>
  651. </xsl:template>
  652. <xsl:template name="scheduler-subst">
  653. <xsl:param name="content"/>
  654. <xsl:param name="text"/>
  655. <xsl:param name="step"/>
  656. <xsl:variable name="name" select="substring-before($text, '_')"/>
  657. <xsl:variable name="hhmm" select="substring-after($text, '_')"/>
  658. <xsl:variable name="day"><day-number name="{$name}"/></xsl:variable>
  659. <xsl:variable name="mins"><time-minutes hhmm="{$hhmm}"/></xsl:variable>
  660. <xsl:choose>
  661. <xsl:when test="$mins = ''">
  662. <xsl:value-of select="$text"/>
  663. </xsl:when>
  664. <xsl:when test="$day = ''">
  665. <xsl:value-of select="$name"/>
  666. <xsl:text>_</xsl:text>
  667. <time-hhmm minutes="{$mins + $step}"/>
  668. </xsl:when>
  669. <xsl:otherwise>
  670. <xsl:variable name="day-mins" select="24 * 60"/>
  671. <xsl:variable name="week-mins" select="7 * $day-mins"/>
  672. <xsl:variable name="tmp" select="($day + 1) * $day-mins + $mins"/>
  673. <xsl:variable name="next" select="$tmp mod $week-mins + floor($tmp div $week-mins) * $step"/>
  674. <day-name number="{floor($next div $day-mins)}"/>
  675. <xsl:text>_</xsl:text>
  676. <time-hhmm minutes="{$next mod $day-mins}"/>
  677. </xsl:otherwise>
  678. </xsl:choose>
  679. </xsl:template>
  680. <!--
  681. email - substitute '@' for ' -at- ' in email addresses.
  682. -->
  683. <xsl:template name="emailfield">
  684. <xsl:param name="content"/>
  685. <xsl:param name="addr"/>
  686. <xsl:variable name="at"> -at- </xsl:variable>
  687. <xsl:choose>
  688. <xsl:when test="contains($addr, $at)">
  689. <xsl:value-of select="substring-before($addr, $at)"/>
  690. <xsl:text>@</xsl:text>
  691. <xsl:value-of select="substring-after($addr, $at)"/>
  692. </xsl:when>
  693. <xsl:otherwise>
  694. <xsl:value-of select="$addr"/>
  695. </xsl:otherwise>
  696. </xsl:choose>
  697. </xsl:template>
  698. <xsl:template name="email">
  699. <xsl:param name="content"/>
  700. <xsl:param name="id"/>
  701. <email id="{$id}"><emailfield addr="{$content}"/></email>
  702. </xsl:template>
  703. <xsl:template name="fromaddr">
  704. <xsl:param name="content"/>
  705. <fromaddr><emailfield addr="{$content}"/></fromaddr>
  706. </xsl:template>
  707. <xsl:template name="extraRecipient">
  708. <xsl:param name="content"/>
  709. <extraRecipient><emailfield addr="{$content}"/></extraRecipient>
  710. </xsl:template>
  711. <!--
  712. mailnotifier - add a default value for <fromaddr> to <mailnotifier>
  713. -->
  714. <xsl:template name="mailnotifier">
  715. <xsl:param name="content"/>
  716. <mailnotifier>
  717. <defaults content="{$content}">
  718. <fromaddr>noreply -at- wxsite.net</fromaddr>
  719. </defaults>
  720. <xsl:copy-of select="$content"/>
  721. </mailnotifier>
  722. </xsl:template>
  723. </bot>