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.

loadfile.xml 3.6 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <?xml version="1.0" encoding="ISO-8859-1"?>
  2. <project name="loadfile-test" basedir="." default="testLoadAFile">
  3. <target name="init">
  4. </target>
  5. <target name="testNoSourcefileDefined" depends="init">
  6. <loadfile property="foo" />
  7. </target>
  8. <target name="testNoPropertyDefined"
  9. depends="init">
  10. <loadfile srcFile="somefile" />
  11. </target>
  12. <target name="testNoSourcefilefound"
  13. depends="init">
  14. <loadfile property="missing" srcFile="somefile" />
  15. </target>
  16. <target name="testFailOnError"
  17. depends="init">
  18. <loadfile
  19. property="testFailOnError"
  20. srcFile="somefile"
  21. failonerror="false"/>
  22. </target>
  23. <target name="testLoadAFile"
  24. depends="init">
  25. <echo
  26. message="What's it going to be then, eh?"
  27. file="loadfile1.tmp"
  28. />
  29. <loadfile property="testLoadAFile" srcFile="loadfile1.tmp" />
  30. <echo>${testLoadAFile}</echo>
  31. </target>
  32. <target name="testLoadAFileEnc"
  33. depends="init">
  34. <loadfile property="testLoadAFileEnc"
  35. srcFile="loadfile.xml"
  36. encoding="ISO-8859-1"/>
  37. </target>
  38. <target name="testEvalProps"
  39. depends="init">
  40. <property name="weather" value="rain" />
  41. <echo
  42. message="All these moments will be lost in time, like teardrops in the ${weather}"
  43. file="loadfile1.tmp"
  44. />
  45. <loadfile property="testEvalProps"
  46. srcFile="loadfile1.tmp">
  47. <filterchain>
  48. <expandproperties/>
  49. </filterchain>
  50. </loadfile>
  51. <echo>${testEvalProps}</echo>
  52. </target>
  53. <target name="testFilterChain"
  54. depends="init">
  55. <echo file="loadfile1.tmp">#Line 1
  56. REM Line 2
  57. --Line 3
  58. Line 4
  59. Hello World!</echo>
  60. <loadfile srcFile="loadfile1.tmp"
  61. property="testFilterChain">
  62. <filterchain>
  63. <headfilter lines="5"/>
  64. <striplinecomments>
  65. <comment value="--"/>
  66. <comment value="REM "/>
  67. <comment value="#"/>
  68. </striplinecomments>
  69. <filterreader classname="org.apache.tools.ant.filters.TailFilter">
  70. <param name="lines" value="1"/>
  71. </filterreader>
  72. <linecontains>
  73. <contains value="World!"/>
  74. </linecontains>
  75. </filterchain>
  76. </loadfile>
  77. </target>
  78. <target name="testStripJavaComments"
  79. depends="init">
  80. <echo file="loadfile1.tmp">
  81. /*
  82. Comment "1"
  83. */
  84. public class test1 {
  85. //Some comment
  86. int x = 1/2;
  87. private static final String GREETING="*/Hello/*";
  88. private static final String GREETING1="/*Hello*/";
  89. public static void main( String args[] ) {
  90. }
  91. }</echo>
  92. <echo file="nocomments.tmp">
  93. public class test1 {
  94. int x = 1/2;
  95. private static final String GREETING="*/Hello/*";
  96. private static final String GREETING1="/*Hello*/";
  97. public static void main( String args[] ) {
  98. }
  99. }</echo>
  100. <loadfile srcFile="loadfile1.tmp"
  101. property="testStripJavaComments">
  102. <filterchain>
  103. <stripjavacomments/>
  104. </filterchain>
  105. </loadfile>
  106. <loadfile srcFile="nocomments.tmp"
  107. property="expected"/>
  108. </target>
  109. <target name="testOneLine"
  110. depends="init">
  111. <echo
  112. message="1,&#10;2,&#13;3,&#13;&#10;4"
  113. file="loadfile1.tmp"
  114. />
  115. <loadfile property="testOneLine"
  116. srcFile="loadfile1.tmp">
  117. <filterchain>
  118. <striplinebreaks/>
  119. </filterchain>
  120. </loadfile>
  121. <echo>${testOneLine}</echo>
  122. </target>
  123. <target name="cleanup">
  124. <delete file="loadfile1.tmp"/>
  125. <delete file="nocomments.tmp"/>
  126. </target>
  127. </project>