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.

tstamp-test.xml 4.0 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. <target name="-adjust-for-offset-at-epoch">
  19. <property name="ant-package" location="${input}/org/apache/ant"/>
  20. <mkdir dir="${ant-package}"/>
  21. <mkdir dir="${output}"/>
  22. <echo file="${ant-package}/IsEpochIn1969Here.java"><![CDATA[
  23. package org.apache.ant;
  24. import org.apache.tools.ant.taskdefs.condition.Condition;
  25. import java.util.Calendar;
  26. import java.util.Date;
  27. public class IsEpochIn1969Here implements Condition {
  28. @Override
  29. public boolean eval() {
  30. final Calendar c = Calendar.getInstance();
  31. c.setTime(new Date(0));
  32. final int offset = (c.get(Calendar.ZONE_OFFSET) + c.get(Calendar.DST_OFFSET));
  33. return offset < 0;
  34. }
  35. }
  36. ]]></echo>
  37. <javac srcdir="${input}" destdir="${output}"/>
  38. <typedef name="isepochin1969here" classname="org.apache.ant.IsEpochIn1969Here">
  39. <classpath>
  40. <pathelement location="${output}"/>
  41. </classpath>
  42. </typedef>
  43. <condition property="expected-dstamp" value="19700101">
  44. <isepochin1969here/>
  45. </condition>
  46. <property name="expected-dstamp" value="19700102"/>
  47. <echo>${expected-dstamp}</echo>
  48. </target>
  49. <target name="testMagicProperty" depends="-adjust-for-offset-at-epoch">
  50. <local name="ant.tstamp.now"/>
  51. <property name="ant.tstamp.now" value="86400"/>
  52. <tstamp/>
  53. <au:assertPropertyEquals name="DSTAMP" value="${expected-dstamp}"/>
  54. </target>
  55. <target name="testMagicPropertyIso">
  56. <local name="ant.tstamp.now.iso"/>
  57. <property name="ant.tstamp.now.iso" value="1972-04-17T08:07:00Z"/>
  58. <tstamp/>
  59. <au:assertPropertyEquals name="DSTAMP" value="19720417"/>
  60. </target>
  61. <target name="testMagicPropertyBoth">
  62. <local name="ant.tstamp.now"/>
  63. <local name="ant.tstamp.now.iso"/>
  64. <property name="ant.tstamp.now" value="100000"/>
  65. <property name="ant.tstamp.now.iso" value="1972-04-17T08:07:22Z"/>
  66. <tstamp/>
  67. <!-- 'iso' overrides 'simple' -->
  68. <au:assertPropertyEquals name="DSTAMP" value="19720417"/>
  69. </target>
  70. <target name="testSourceDateEpoch">
  71. <mkdir dir="${input}"/>
  72. <mkdir dir="${output}"/>
  73. <echo file="${input}/TstampAntunitTest.java"><![CDATA[
  74. import org.apache.tools.ant.*;
  75. import org.apache.tools.ant.taskdefs.*;
  76. public class TstampAntunitTest {
  77. public static void main(String[] args) {
  78. Task task = new Tstamp();
  79. task.setProject(new Project());
  80. task.execute();
  81. String today = task.getProject().getProperty("TODAY");
  82. System.out.println("TODAY is " + today);
  83. }
  84. }
  85. ]]></echo>
  86. <javac srcdir="${input}" destdir="${output}"/>
  87. <local name="testout"/>
  88. <java classname="TstampAntunitTest"
  89. failonerror="true"
  90. outputproperty="testout"
  91. fork="true">
  92. <sysproperty key="user.timezone" value="GMT"/>
  93. <classpath>
  94. <pathelement location="${output}"/>
  95. <pathelement path="${java.class.path}"/>
  96. </classpath>
  97. <env key="SOURCE_DATE_EPOCH" value="1650585600"/>
  98. </java>
  99. <au:assertEquals expected="TODAY is April 22 2022" actual="${testout}"/>
  100. </target>
  101. </project>