aboutsummaryrefslogtreecommitdiffstats
path: root/framework/src/ant/apache-ant-1.9.6/src/etc/testcases/taskdefs/copy.xml
blob: bf4441c172f6eb64adba6868c73e42fdd1fe8433 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
<?xml version="1.0"?>
<!--
  Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->

<project name="copy-test" basedir="." default="test1">

  <import file="../buildfiletest-base.xml"/>

  <target name="setUp">
    <mkdir dir="${output}" />
  </target>

  <target name="test1">
    <copy file="copy.xml" tofile="${output}/copytest1.tmp" />
  </target>

  <target name="test2">
    <copy file="copy.xml" todir="${output}/copytest1dir" overwrite="true"/>
  </target>

  <target name="filtertest">
    <!-- check fix for bugzilla 23154 -->
    <concat destfile="${output}/copy.filter.inp">
PRODUCT_VERSION=6.2.1.4
PRODUCT_BUILD=6.5 (BLD_65036)
PRODUCT_VERSION=6.2.1.4
PRODUCT_BUILD=6.5 (BLD_65036)
    </concat>
    <copy file="${output}/copy.filter.inp" tofile="${output}/copy.filter.out">
      <filterset begintoken="6" endtoken="4">
        <filter token=".2.1." value="2.6.4" />
      </filterset>
    </copy>
    <concat><path path="${output}/copy.filter.out"/></concat>
  </target>

  <target name="infinitetest">
    <concat destfile="${output}/copy.filter.inp">
a=b=
    </concat>
    <copy file="${output}/copy.filter.inp" tofile="${output}/copy.filter.out">
      <filterset begintoken="=" endtoken="=">
        <filter token="b" value="=b="/>
      </filterset>
    </copy>
    <concat><path path="${output}/copy.filter.out"/></concat>
  </target>

  <target name="test3">
    <!-- create an empty file -->
    <touch file="${output}/copytest3.tmp"/>
    <!-- copy a different file to two places -->
    <copy file="copy.xml" tofile="${output}/copytest3a.tmp" overwrite="true"/>
    <copy file="copy.xml" tofile="${output}/copytest3b.tmp" overwrite="true"/>
      </target><target name="test3Part2">
    <!-- copy an old file onto a newer file (should not work) -->
    <copy file="${output}/copytest3.tmp" tofile="${output}/copytest3b.tmp" />
    <!-- copy an older file onto a new one, should succeed -->
    <copy file="${output}/copytest3.tmp" tofile="${output}/copytest3c.tmp"
      overwrite="true"
      preservelastmodified="true" />
    <!-- copy a newer file onto an older one (should work) -->
    <copy file="${output}/copytest3a.tmp" tofile="${output}/copytest3.tmp"
      preservelastmodified="true" />
    <!-- expected state :
      3a.tmp==3.tmp==copy.xml
      timeof(3a.tmp)==timeof(3.tmp)==now()-4
      sizeof(3c)==0
      timeof(3c.tmp)<timeof(3a.tmp);
      3b.tmp==copy.xml
    -->
  </target>

  <target name="test_single_file_fileset">
    <copy tofile="${output}/copytest_single_file_fileset.tmp">
      <fileset dir="." includes="copy.xml"/>
    </copy>
  </target>

  <target name="test_single_file_path">
    <copy tofile="${output}/copytest_single_file_path.tmp">
      <path>
        <pathelement location="copy.xml"/>
      </path>
    </copy>
  </target>

  <target name="testFilterSet">
    <copy file="copy.filterset" tofile="${output}/copy.filterset.tmp">
      <filterset>
        <filter token="TITLE" value="Apache Ant Project"/>
      </filterset>
    </copy>
  </target>

  <target name="testFilterChain">
    <copy file="copy.filterset" tofile="${output}/copy.filterchain.tmp">
      <filterchain>
        <replacetokens>
          <token key="TITLE" value="Apache Ant Project"/>
        </replacetokens>
      </filterchain>
    </copy>
  </target>

  <target name="testTranscoding">
    <copy file="copy/input/iso8859-1" tofile="${output}/copytest1.tmp"
          encoding="ISO8859_1" outputencoding="UTF8"/>
  </target>

  <target name="testMissingFileIgnore">
    <copy file="not-there" tofile="${output}/copytest1.tmp"
          failonerror="false"/>
  </target>

  <target name="testMissingFileBail">
    <copy file="not-there" tofile="${output}/copytest1.tmp"
          failonerror="true"/>
  </target>

  <target name="testMissingDirIgnore">
    <copy todir="${output}" failonerror="false">
      <fileset dir="not-there"/>
    </copy>
  </target>

  <target name="testMissingDirBail">
    <copy todir="${output}" failonerror="true">
      <fileset dir="not-there"/>
    </copy>
  </target>

  <property name="to.dir" value="${output}/copy-todir-tmp"/>
  <property name="from.dir" value="${output}/copy-fromdir-tmp"/>

  <target name="testResource.prepare">
    <mkdir dir="${from.dir}"/>
    <concat destfile="${from.dir}/file1.txt">This is file 1</concat>
    <concat destfile="${from.dir}/file2.txt">This is file 2</concat>
    <concat destfile="${from.dir}/file3.txt">This is file 3</concat>
    <concat destfile="${from.dir}/fileNR.txt">This is file @NR@</concat>
  </target>

  <target name="testFileResourcePlain" depends="testResource.prepare">
    <copy todir="${to.dir}" flatten="true">
      <resources>
        <file file="${from.dir}/file1.txt"/>
        <file file="${from.dir}/file2.txt"/>
        <file file="${from.dir}/file3.txt"/>
      </resources>
    </copy>
  </target>

  <target name="testFileResourceWithMapper" depends="testResource.prepare">
    <copy todir="${to.dir}" flatten="true">
      <resources>
        <file file="${from.dir}/file1.txt"/>
        <file file="${from.dir}/file2.txt"/>
        <file file="${from.dir}/file3.txt"/>
      </resources>
      <regexpmapper from="^(.*)\.txt$$" to="\1.txt.bak"/>
    </copy>
  </target>

  <target name="testFileResourceWithFilter" depends="testResource.prepare">
    <copy todir="${to.dir}" flatten="true">
      <resources>
        <file file="${from.dir}/fileNR.txt"/>
      </resources>
      <filterset>
        <filter token="NR" value="42"/>
      </filterset>
    </copy>
  </target>

  <target name="testResourcePlain">
  </target>

  <target name="testResourcePlainWithMapper">
  </target>

  <target name="testResourcePlainWithFilter">
  </target>

  <target name="testOnlineResources">
  </target>

  <target name="testPathAsResource" depends="testResource.prepare">
    <copy todir="${to.dir}">
      <path>
        <fileset dir="${from.dir}"/>
      </path>
    </copy>
  </target>

  <target name="testZipfileset" depends="testResource.prepare">
    <zip destfile="${from.dir}/test.zip" roundup="false">
      <fileset dir="${from.dir}" excludes="*.zip"/>
    </zip>
    <copy todir="${to.dir}">
      <zipfileset src="${from.dir}/test.zip"/>
    </copy>
  </target>

  <target name="prepareDirset">
    <touch mkdirs="true">
      <filelist dir="${from.dir}/dirset">
        <file name="a/x/foo" />
        <file name="a/y/foo" />
        <file name="a/z/foo" />
        <file name="b/x/foo" />
        <file name="b/y/foo" />
        <file name="b/z/foo" />
      </filelist>
    </touch>
    <fail>
      <condition>
        <or>
          <resourcecount when="ne" count="9">
            <dirset id="dirset" dir="${from.dir}/dirset" />
          </resourcecount>
          <resourcecount when="ne" count="6">
            <fileset dir="${from.dir}/dirset" />
          </resourcecount>
        </or>
      </condition>
    </fail>
    <delete dir="${to.dir}/dirset" />
    <fail>
      <condition>
        <available file="${to.dir}/dirset" />
      </condition>
    </fail>
  </target>

  <target name="testDirset" depends="prepareDirset">
    <copy todir="${to.dir}/dirset">
      <resources refid="dirset" />
    </copy>
    <fail>
      <condition>
        <or>
          <resourcecount when="ne" count="9">
            <dirset dir="${to.dir}/dirset" />
          </resourcecount>
          <resourcecount when="ne" count="0">
            <fileset dir="${to.dir}/dirset" />
          </resourcecount>
        </or>
      </condition>
    </fail>
  </target>

</project>