1
|
|
/*
|
2
|
|
* The Apache Software License, Version 1.1
|
3
|
|
*
|
4
|
|
* Copyright (c) 2001-2002 The Apache Software Foundation. All rights
|
5
|
|
* reserved.
|
6
|
|
*
|
7
|
|
* Redistribution and use in source and binary forms, with or without
|
8
|
|
* modification, are permitted provided that the following conditions
|
9
|
|
* are met:
|
10
|
|
*
|
11
|
|
* 1. Redistributions of source code must retain the above copyright
|
12
|
|
* notice, this list of conditions and the following disclaimer.
|
13
|
|
*
|
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
|
17
|
|
* distribution.
|
18
|
|
*
|
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.
|
25
|
|
*
|
26
|
|
* 4. The names "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.
|
30
|
|
*
|
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.
|
34
|
|
*
|
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
|
46
|
|
* SUCH DAMAGE.
|
47
|
|
* ====================================================================
|
48
|
|
*
|
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/>.
|
53
|
|
*/
|
54
|
|
|
55
|
|
package org.apache.tools.ant.types;
|
56
|
|
|
57
|
|
import java.io.File;
|
58
|
|
import java.util.Stack;
|
59
|
|
import java.util.StringTokenizer;
|
60
|
|
import java.util.Vector;
|
61
|
|
import org.apache.tools.ant.BuildException;
|
62
|
|
import org.apache.tools.ant.Project;
|
63
|
|
|
64
|
|
/**
|
65
|
|
* FileList represents an explicitly named list of files. FileLists
|
66
|
|
* are useful when you want to capture a list of files regardless of
|
67
|
|
* whether they currently exist. By contrast, FileSet operates as a
|
68
|
|
* filter, only returning the name of a matched file if it currently
|
69
|
|
* exists in the file system.
|
70
|
|
*
|
71
|
|
* @author <a href="mailto:cstrong@arielpartners.com">Craeg Strong</a>
|
72
|
|
* @version $Revision: 1.9 $ $Date: 2003/02/10 14:14:30 $
|
73
|
|
*/
|
74
|
|
public class FileList extends DataType {
|
75
|
|
|
76
|
|
private Vector filenames = new Vector();
|
77
|
|
private File dir;
|
78
|
|
|
79
|
18
|
public FileList() {
|
80
|
18
|
super();
|
81
|
|
}
|
82
|
|
|
83
|
0
|
protected FileList(FileList filelist) {
|
84
|
0
|
this.dir = filelist.dir;
|
85
|
0
|
this.filenames = filelist.filenames;
|
86
|
0
|
setProject(filelist.getProject());
|
87
|
|
}
|
88
|
|
|
89
|
|
/**
|
90
|
|
* Makes this instance in effect a reference to another FileList
|
91
|
|
* instance.
|
92
|
|
*
|
93
|
|
* <p>You must not set another attribute or nest elements inside
|
94
|
|
* this element if you make it a reference.</p>
|
95
|
|
*/
|
96
|
9
|
public void setRefid(Reference r) throws BuildException {
|
97
|
9
|
if ((dir != null) || (filenames.size() != 0)) {
|
98
|
2
|
throw tooManyAttributes();
|
99
|
|
}
|
100
|
7
|
super.setRefid(r);
|
101
|
|
}
|
102
|
|
|
103
|
10
|
public void setDir(File dir) throws BuildException {
|
104
|
10
|
if (isReference()) {
|
105
|
1
|
throw tooManyAttributes();
|
106
|
|
}
|
107
|
9
|
this.dir = dir;
|
108
|
|
}
|
109
|
|
|
110
|
10
|
public File getDir(Project p) {
|
111
|
10
|
if (isReference()) {
|
112
|
4
|
return getRef(p).getDir(p);
|
113
|
|
}
|
114
|
6
|
return dir;
|
115
|
|
}
|
116
|
|
|
117
|
8
|
public void setFiles(String filenames) {
|
118
|
8
|
if (isReference()) {
|
119
|
1
|
throw tooManyAttributes();
|
120
|
|
}
|
121
|
7
|
if (filenames != null && filenames.length() > 0) {
|
122
|
7
|
StringTokenizer tok = new StringTokenizer(filenames, ", \t\n\r\f", false);
|
123
|
7
|
while (tok.hasMoreTokens()) {
|
124
|
9
|
this.filenames.addElement(tok.nextToken());
|
125
|
|
}
|
126
|
|
}
|
127
|
|
}
|
128
|
|
|
129
|
|
/**
|
130
|
|
* Returns the list of files represented by this FileList.
|
131
|
|
*/
|
132
|
7
|
public String[] getFiles(Project p) {
|
133
|
7
|
if (isReference()) {
|
134
|
2
|
return getRef(p).getFiles(p);
|
135
|
|
}
|
136
|
|
|
137
|
5
|
if (dir == null) {
|
138
|
0
|
throw new BuildException("No directory specified for filelist.");
|
139
|
|
}
|
140
|
|
|
141
|
5
|
if (filenames.size() == 0) {
|
142
|
0
|
throw new BuildException("No files specified for filelist.");
|
143
|
|
}
|
144
|
|
|
145
|
5
|
String[] result = new String[filenames.size()];
|
146
|
5
|
filenames.copyInto(result);
|
147
|
5
|
return result;
|
148
|
|
}
|
149
|
|
|
150
|
|
/**
|
151
|
|
* Performs the check for circular references and returns the
|
152
|
|
* referenced FileList.
|
153
|
|
*/
|
154
|
6
|
protected FileList getRef(Project p) {
|
155
|
6
|
if (!isChecked()) {
|
156
|
5
|
Stack stk = new Stack();
|
157
|
5
|
stk.push(this);
|
158
|
5
|
dieOnCircularReference(stk, p);
|
159
|
|
}
|
160
|
|
|
161
|
2
|
Object o = getRefid().getReferencedObject(p);
|
162
|
2
|
if (!(o instanceof FileList)) {
|
163
|
0
|
String msg = getRefid().getRefId() + " doesn\'t denote a filelist";
|
164
|
0
|
throw new BuildException(msg);
|
165
|
|
} else {
|
166
|
2
|
return (FileList) o;
|
167
|
|
}
|
168
|
|
}
|
169
|
|
|
170
|
|
} //-- FileList.java
|
171
|
|
|