2
* The Apache Software License, Version 1.1
4
* Copyright (c) 2000 The Apache Software Foundation. All rights
7
* Redistribution and use in source and binary forms, with or without
8
* modification, are permitted provided that the following conditions
11
* 1. Redistributions of source code must retain the above copyright
12
* notice, this list of conditions and the following disclaimer.
14
* 2. Redistributions in binary form must reproduce the above copyright
15
* notice, this list of conditions and the following disclaimer in
16
* the documentation and/or other materials provided with the
19
* 3. The end-user documentation included with the redistribution, if
20
* any, must include the following acknowlegement:
21
* "This product includes software developed by the
22
* Apache Software Foundation (http://www.apache.org/)."
23
* Alternately, this acknowlegement may appear in the software itself,
24
* if and wherever such third-party acknowlegements normally appear.
26
* 4. The names "The Jakarta Project", "Ant", and "Apache Software
27
* Foundation" must not be used to endorse or promote products derived
28
* from this software without prior written permission. For written
29
* permission, please contact apache@apache.org.
31
* 5. Products derived from this software may not be called "Apache"
32
* nor may "Apache" appear in their names without prior written
33
* permission of the Apache Group.
35
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
36
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
37
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
38
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
39
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
41
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
42
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
43
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
44
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
45
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
47
* ====================================================================
49
* This software consists of voluntary contributions made by many
50
* individuals on behalf of the Apache Software Foundation. For more
51
* information on the Apache Software Foundation, please see
52
* <http://www.apache.org/>.
55
package org.apache.tools.ant.types;
57
import org.apache.tools.ant.BuildException;
58
import org.apache.tools.ant.Project;
60
import junit.framework.TestCase;
61
import junit.framework.AssertionFailedError;
66
* JUnit 3 testcases for org.apache.tools.ant.types.FileSet.
68
* <p>This doesn't actually test much, mainly reference handling.
70
* @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a>
73
public class FileSetTest extends TestCase {
75
private Project project;
77
public FileSetTest(String name) {
82
project = new Project();
83
project.setBasedir(".");
86
public void testEmptyElementIfIsReference() {
87
FileSet f = new FileSet();
88
f.setIncludes("**/*.java");
90
f.setRefid(new Reference("dummyref"));
91
fail("Can add reference to FileSet with elements from setIncludes");
92
} catch (BuildException be) {
93
assertEquals("You must not specify more than one attribute when using refid",
100
f.setRefid(new Reference("dummyref"));
101
fail("Can add reference to FileSet with nested patternset element.");
102
} catch (BuildException be) {
103
assertEquals("You must not specify nested elements when using refid",
110
f.setRefid(new Reference("dummyref"));
111
fail("Can add reference to FileSet with nested include element.");
112
} catch (BuildException be) {
113
assertEquals("You must not specify more than one attribute when using refid",
118
f.setRefid(new Reference("dummyref"));
120
f.setIncludes("**/*.java");
121
fail("Can set includes in FileSet that is a reference.");
122
} catch (BuildException be) {
123
assertEquals("You must not specify more than one attribute when using refid",
127
f.setIncludesfile(new File("/a"));
128
fail("Can set includesfile in FileSet that is a reference.");
129
} catch (BuildException be) {
130
assertEquals("You must not specify more than one attribute when using refid",
134
f.setExcludes("**/*.java");
135
fail("Can set excludes in FileSet that is a reference.");
136
} catch (BuildException be) {
137
assertEquals("You must not specify more than one attribute when using refid",
141
f.setExcludesfile(new File("/a"));
142
fail("Can set excludesfile in FileSet that is a reference.");
143
} catch (BuildException be) {
144
assertEquals("You must not specify more than one attribute when using refid",
148
f.setDir(project.resolveFile("."));
149
fail("Can set dir in FileSet that is a reference.");
150
} catch (BuildException be) {
151
assertEquals("You must not specify more than one attribute when using refid",
156
fail("Can add nested include in FileSet that is a reference.");
157
} catch (BuildException be) {
158
assertEquals("You must not specify nested elements when using refid",
163
fail("Can add nested exclude in FileSet that is a reference.");
164
} catch (BuildException be) {
165
assertEquals("You must not specify nested elements when using refid",
169
f.createIncludesFile();
170
fail("Can add nested includesfile in FileSet that is a reference.");
171
} catch (BuildException be) {
172
assertEquals("You must not specify nested elements when using refid",
176
f.createExcludesFile();
177
fail("Can add nested excludesfile in FileSet that is a reference.");
178
} catch (BuildException be) {
179
assertEquals("You must not specify nested elements when using refid",
183
f.createPatternSet();
184
fail("Can add nested patternset in FileSet that is a reference.");
185
} catch (BuildException be) {
186
assertEquals("You must not specify nested elements when using refid",
191
public void testCircularReferenceCheck() {
192
FileSet f = new FileSet();
193
project.addReference("dummy", f);
194
f.setRefid(new Reference("dummy"));
197
fail("Can make FileSet a Reference to itself.");
198
} catch (BuildException be) {
199
assertEquals("This data type contains a circular reference.",
203
f.getDirectoryScanner(project);
204
fail("Can make FileSet a Reference to itself.");
205
} catch (BuildException be) {
206
assertEquals("This data type contains a circular reference.",
210
// dummy1 --> dummy2 --> dummy3 --> dummy1
211
FileSet f1 = new FileSet();
212
project.addReference("dummy1", f1);
213
f1.setRefid(new Reference("dummy2"));
214
FileSet f2 = new FileSet();
215
project.addReference("dummy2", f2);
216
f2.setRefid(new Reference("dummy3"));
217
FileSet f3 = new FileSet();
218
project.addReference("dummy3", f3);
219
f3.setRefid(new Reference("dummy1"));
222
fail("Can make circular reference.");
223
} catch (BuildException be) {
224
assertEquals("This data type contains a circular reference.",
228
f1.getDirectoryScanner(project);
229
fail("Can make circular reference.");
230
} catch (BuildException be) {
231
assertEquals("This data type contains a circular reference.",
235
// dummy1 --> dummy2 --> dummy3
236
// (which has the Project's basedir as root).
238
project.addReference("dummy1", f1);
239
f1.setRefid(new Reference("dummy2"));
241
project.addReference("dummy2", f2);
242
f2.setRefid(new Reference("dummy3"));
244
project.addReference("dummy3", f3);
245
f3.setDir(project.resolveFile("."));
246
File dir = f1.getDir(project);
247
assertEquals("Die is basedir", dir, project.getBaseDir());