2
* Copyright 1999,2004 The Apache Software Foundation.
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
8
* http://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.
16
package org.apache.axis.tools.ant.foreach;
18
import org.apache.tools.ant.DirectoryScanner;
19
import org.apache.tools.ant.Project;
20
import org.apache.tools.ant.types.EnumeratedAttribute;
21
import org.apache.tools.ant.types.FileSet;
24
import java.util.Enumeration;
25
import java.util.Vector;
28
* Inner class stores sets of <param>s.
29
* It can hold <fileset>s or <item>s or both.
31
* @author <a href="mailto:tpv@spamcop.net">Tim Vernum</a>
32
* @author Davanum Srinivas
33
* @author Richard A. Sitze
35
public class ParamSet {
36
public static final String TYPE_FILE = "file".intern();
37
public static final String TYPE_DIR = "dir".intern();
38
public static final String TYPE_BOTH = "both".intern();
41
* Enumerated attribute with the values "file", "dir" and "both"
42
* for the type attribute.
44
public static class FileDirBoth extends EnumeratedAttribute {
45
public String[] getValues() {
47
TYPE_FILE, TYPE_DIR, TYPE_BOTH
52
/** Defaults to "file". */
53
protected String type = TYPE_FILE;
54
private Vector filesets;
59
filesets = new Vector();
63
public void addFileset(FileSet fileset) {
64
filesets.addElement(fileset);
67
public ParamItem createItem() {
68
ParamItem item = new ParamItem();
69
items.addElement(item);
73
public void setName(String name) {
77
public String getName() {
81
public Enumeration getValues(Project project) {
82
/* As an arbitrary rule, this will return filesets first,
83
and then <item>s. The ordering of the buildfile is
85
Vector values = new Vector();
86
Enumeration enum = filesets.elements();
87
while (enum.hasMoreElements()) {
88
FileSet fileSet = (FileSet) enum.nextElement();
89
File base = fileSet.getDir(project);
90
DirectoryScanner scanner = fileSet.getDirectoryScanner(project);
91
if (TYPE_DIR != type) {
92
String[] files = getFiles(base, scanner);
93
for (int j = 0; j < files.length; j++) {
94
File f = new File(base, files[j]);
95
values.addElement(f.getAbsolutePath());
98
if (TYPE_FILE != type) {
99
String[] dirs = getDirs(base, scanner);
100
for (int j = 0; j < dirs.length; j++) {
101
File f = new File(base, dirs[j]);
102
values.addElement(f.getAbsolutePath());
106
enum = items.elements();
107
while (enum.hasMoreElements()) {
108
ParamItem item = (ParamItem) enum.nextElement();
109
values.addElement(item.getValue());
111
return values.elements();
115
* Shall the command work only on files, directories or both?
117
public void setType(FileDirBoth type) {
118
this.type = type.getValue().intern();
122
* Return the list of files from this DirectoryScanner that should
123
* be included on the command line.
125
protected String[] getFiles(File basedir, DirectoryScanner ds) {
126
return ds.getIncludedFiles();
130
* Return the list of Directories from this DirectoryScanner that
131
* should be included on the command line.
133
protected String[] getDirs(File basedir, DirectoryScanner ds) {
134
return ds.getIncludedDirectories();