You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

scriptdef-test.xml 5.1 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <?xml version="1.0"?>
  2. <!--
  3. Licensed to the Apache Software Foundation (ASF) under one or more
  4. contributor license agreements. See the NOTICE file distributed with
  5. this work for additional information regarding copyright ownership.
  6. The ASF licenses this file to You under the Apache License, Version 2.0
  7. (the "License"); you may not use this file except in compliance with
  8. the License. You may obtain a copy of the License at
  9. https://www.apache.org/licenses/LICENSE-2.0
  10. Unless required by applicable law or agreed to in writing, software
  11. distributed under the License is distributed on an "AS IS" BASIS,
  12. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. See the License for the specific language governing permissions and
  14. limitations under the License.
  15. -->
  16. <project default="antunit" xmlns:au="antlib:org.apache.ant.antunit">
  17. <import file="../../../antunit-base.xml" />
  18. <description>
  19. In which we test interesting aspects of scripting.
  20. The targeted language is javascript; this lets us run without
  21. additions on Java6+.
  22. </description>
  23. <condition property="prereqs-ok">
  24. <and>
  25. <!-- Starting Java 15, there's no "javascript" script engine (not even nashorn) bundled in JRE -->
  26. <javaversion atmost="14"/>
  27. <or>
  28. <and>
  29. <available classname="org.apache.bsf.BSFManager" />
  30. <available classname="org.apache.bsf.engines.javascript.JavaScriptEngine" />
  31. </and>
  32. <available classname="javax.script.ScriptEngineManager" />
  33. </or>
  34. </and>
  35. </condition>
  36. <!-- auto doesn't verify the language is supported and selects BSF
  37. even if the JavaScriptEngine is not there -->
  38. <condition property="script.manager" value="javax">
  39. <and>
  40. <not>
  41. <available classname="org.apache.bsf.engines.javascript.JavaScriptEngine" />
  42. </not>
  43. <isset property="prereqs-ok"/>
  44. </and>
  45. </condition>
  46. <property name="script.manager" value="auto" />
  47. <string id="script.code">
  48. self.log("Ant version =${ant.version}");
  49. project.setNewProperty("property","live");
  50. </string>
  51. <presetdef name="js">
  52. <scriptdef language="javascript" name="scripttest" manager="${script.manager}">
  53. <!-- optional property attribute-->
  54. <attribute name="property" />
  55. <attribute name="propertywithdefault" default="prop_dv" />
  56. </scriptdef>
  57. </presetdef>
  58. <property name="prop" value='self.log("Ant version =${ant.version}");project.setNewProperty("property","live");' />
  59. <presetdef name="assertPropSet">
  60. <au:assertPropertyEquals name="property" value="live" />
  61. </presetdef>
  62. <!--purely to test that everything works -->
  63. <target name="testInline" if="prereqs-ok">
  64. <js>self.log("Hello");</js>
  65. <scripttest />
  66. </target>
  67. <target name="testStringResource" if="prereqs-ok">
  68. <js>
  69. <string value='self.log("Ant version =${ant.version}");' />
  70. </js>
  71. <scripttest />
  72. </target>
  73. <target name="testStringResourceRef" if="prereqs-ok">
  74. <js>
  75. <string refid="script.code" />
  76. </js>
  77. <scripttest />
  78. <assertPropSet />
  79. </target>
  80. <target name="testStringResourceInline" if="prereqs-ok">
  81. <js>
  82. <string>
  83. self.log("Ant version =${ant.version}");
  84. project.setNewProperty("property","live");
  85. </string>
  86. </js>
  87. <scripttest />
  88. <assertPropSet />
  89. </target>
  90. <target name="testPropertyResource" if="prereqs-ok">
  91. <js>
  92. <propertyresource name="prop" />
  93. </js>
  94. <scripttest />
  95. <assertPropSet />
  96. </target>
  97. <target name="testMixedResources" if="prereqs-ok">
  98. <js>
  99. <string refid="script.code" />
  100. <propertyresource name="prop" />
  101. <string>
  102. project.setNewProperty("property2","live");
  103. </string>
  104. </js>
  105. <scripttest />
  106. <assertPropSet name="property2" />
  107. </target>
  108. <target name="testExceptionNesting" description="https://issues.apache.org/bugzilla/show_bug.cgi?id=47509" if="prereqs-ok">
  109. <scriptdef name="quickfail" language="javascript">
  110. <![CDATA[
  111. self.fail("I failed!");
  112. ]]>
  113. </scriptdef>
  114. <au:expectfailure message="I failed!">
  115. <quickfail />
  116. </au:expectfailure>
  117. </target>
  118. <target name="testAttribute" if="prereqs-ok">
  119. <js>
  120. project.setNewProperty(attributes.get('property'), 'live');
  121. </js>
  122. <scripttest property="property" />
  123. <assertPropSet />
  124. </target>
  125. <target name="testAttributeDefaultValue" if="prereqs-ok">
  126. <js>
  127. project.setNewProperty(attributes.get('propertywithdefault'), 'live');
  128. </js>
  129. <scripttest />
  130. <assertPropSet name="prop_dv" />
  131. </target>
  132. <target name="testInvalidAttribute" if="prereqs-ok">
  133. <js />
  134. <au:expectfailure expectedMessage="does not support">
  135. <scripttest foo="bar" />
  136. </au:expectfailure>
  137. </target>
  138. <target name="testSetbeans" if="prereqs-ok">
  139. <js setbeans="true">
  140. project.setNewProperty('property', sourceProperty)
  141. </js>
  142. <property name="sourceProperty" value="live" />
  143. <scripttest />
  144. <assertPropSet />
  145. </target>
  146. </project>