Subversion Repositories DevTools

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1974 jgill 1
/**
2
 * AntShield - A project release tool for ant.
3
 */
4
package com.erggroup.mass.ant;
5
 
6
import org.apache.tools.ant.BuildException;
7
import org.apache.tools.ant.Project;
8
import org.apache.tools.ant.types.FileList;
9
import org.apache.tools.ant.types.FileSet;
10
import org.apache.tools.ant.types.DirSet;
11
import java.util.ArrayList;
12
import java.util.Iterator;
13
import java.util.TreeSet;
14
 
15
/**
16
 * Implements the AntShield task's nested field tag.
17
 */
18
public class FieldElement
19
{
20
    private AntShield parent = null;
21
    private Project project = null;
22
    private String name = null;
23
    private String prompt = null;
24
    private String defaultValue = null;
25
    private String value = null;
26
    private ArrayList options = new ArrayList();
27
    private ArrayList filelist = new ArrayList();
28
    private TreeSet fileset = new TreeSet();
29
    private TreeSet dirset = new TreeSet();
30
 
31
    /**
32
     * Constructor.
33
     * @param a
34
     */
35
    public FieldElement(AntShield a, Project p)
36
    {
37
        parent = a;
38
        project = p;
39
    }
40
 
41
    /**
42
     * Set the name property.
43
     * @param s
44
     */
45
    public void setName(String s)
46
    {
47
        name = s;
48
    }
49
 
50
    /**
51
     * Set the prompt property.
52
     * @param s
53
     */
54
    public void setPrompt(String s)
55
    {
56
        prompt = s;
57
    }
58
 
59
    /**
60
     * Set the defaultValue property.
61
     * @param s
62
     */
63
    public void setDefaultValue(String s)
64
    {
65
        defaultValue = project.replaceProperties( s );
66
    }
67
 
68
    /**
69
     * Set the value property -  internal use only.
70
     * @param s
71
     */
72
    public void setValue(String s)
73
    {
74
        value = s;
75
    }
76
 
77
    /**
78
     * Create, store and return an option nested tag.
79
     * @return
80
     */
81
    public OptionElement createOption()
82
    {
83
        OptionElement option = new OptionElement(this);
84
        options.add(option);
85
        return option;
86
    }
87
 
88
    /**
89
     * Adds a fileset nested tag.
90
     * @return
91
     */
92
    public void addConfiguredFilelist(FileList list)
93
    {
94
        String[] files = list.getFiles(project);
95
        for (int i = 0; i < files.length; i++)
96
        {
97
            filelist.add(new String(files[i]));
98
        }
99
    }
100
 
101
    /**
102
     * Adds a fileset nested tag.
103
     * @return
104
     */
105
    public void addConfiguredFileset(FileSet set)
106
    {
107
        String[] files = set.getDirectoryScanner(project).getIncludedFiles();
108
        for (int i = 0; i < files.length; i++)
109
        {
110
            fileset.add(new String(files[i]));
111
        }
112
    }
113
 
114
    /**
115
     * Adds a dirset nested tag.
116
     * @return
117
     */
118
    public void addConfiguredDirset(DirSet set)
119
    {
120
        String[] dirs = set.getDirectoryScanner(project).getIncludedDirectories();
121
        for (int i = 0; i < dirs.length; i++)
122
        {
123
            dirset.add(new String(dirs[i]));
124
        }
125
    }
126
 
127
    /**
128
     * Return this field's name.
129
     * @return
130
     */
131
	public String getName()
132
    {
133
        return name;
134
    }
135
 
136
    /**
137
     * Return this field's prompt.
138
     * @return
139
     */
140
    public String getPrompt()
141
    {
142
        return prompt;
143
    }
144
 
145
    /**
146
     * Return this field's default value.
147
     * @return
148
     */
149
    public String getDefaultValue()
150
    {
151
        return defaultValue;
152
    }
153
 
154
    /**
155
     * Return this field's value.
156
     * @return
157
     */
158
    public String getValue()
159
    {
160
        return value;
161
    }
162
 
163
    /**
164
     * Return this field's nested options.
165
     * @return
166
     */
167
    public TreeSet getOptions()
168
    {
169
        TreeSet optionset = new TreeSet();
170
        Iterator i;
171
        //add options
172
        i = options.iterator();
173
        while (i.hasNext())
174
        {
175
            OptionElement o = (OptionElement)i.next();
176
            optionset.add(o.getValue());
177
        }
178
        //add filelists
179
        i = filelist.iterator();
180
        while (i.hasNext())
181
        {
182
            optionset.add(i.next());
183
        }
184
        //add filesets
185
        i = fileset.iterator();
186
        while (i.hasNext())
187
        {
188
            optionset.add(i.next());
189
        }
190
        //add dirsets
191
        i = dirset.iterator();
192
        while (i.hasNext())
193
        {
194
            optionset.add(i.next());
195
        }
196
        return optionset;
197
    }
198
 
199
    /**
200
     * Get the task name from the parent.
201
     * @return
202
     */
203
    public String getTaskName()
204
    {
205
        return parent.getTaskName();
206
    }
207
 
208
    /**
209
     * Check the parameters of this field, and all nested options and paths.
210
     */
211
    public void check()
212
    {
213
        if ((name == null) || (name.length() == 0) || (prompt == null) || (prompt.length() == 0))
214
        {
215
            throw new BuildException("<" + parent.getTaskName() + "> Invalid field specification");
216
        }
217
        Iterator i = options.iterator();
218
        while (i.hasNext())
219
        {
220
            OptionElement o = (OptionElement)i.next();
221
            o.check();
222
        }
223
    }
224
}