source: main/trunk/ant-tasks/src/org/greenstone/anttasks/PatternSetToFile.java@ 23211

Last change on this file since 23211 was 23211, checked in by sjm84, 13 years ago

Made PatternSetToFile Java 1.4 compatible

File size: 1.9 KB
Line 
1package org.greenstone.anttasks;
2
3import java.io.BufferedWriter;
4import java.io.File;
5import java.io.FileWriter;
6import java.util.ArrayList;
7
8import org.apache.tools.ant.BuildException;
9import org.apache.tools.ant.DirectoryScanner;
10import org.apache.tools.ant.Task;
11import org.apache.tools.ant.types.FileSet;
12import org.apache.tools.ant.types.PatternSet;
13
14/**
15 * PatternSetToFile is an Ant task used to take an Ant PatternSet and output to a
16 * file all the files that it encompasses
17 * @author sjm84
18 */
19public class PatternSetToFile extends Task
20{
21 //The file the set will be written to
22 public File _outfile = null;
23
24 //The directory to check the PatternSet within
25 public File _dir = null;
26
27 //An array of the child PatternSets of this task
28 public ArrayList _sets = new ArrayList();
29
30 /**
31 * This function performs the main task
32 */
33 public void execute() throws BuildException
34 {
35 try
36 {
37 System.out.println("Creating " + _outfile.getAbsolutePath());
38 BufferedWriter out = new BufferedWriter(new FileWriter(_outfile));
39 for(int i = 0; i < _sets.size(); i++)
40 {
41 PatternSet set = (PatternSet)_sets.get(i);
42 FileSet fs = new FileSet();
43 fs.setDir(_dir);
44 PatternSet ps = fs.createPatternSet();
45 ps.append(set, this.getProject());
46
47 DirectoryScanner ds = fs.getDirectoryScanner(this.getProject());
48
49 String[] includedFiles = ds.getIncludedFiles();
50 for (int j = 0; j < includedFiles.length; j++)
51 {
52 out.write(includedFiles[j] + "\n");
53 }
54 }
55 out.close();
56 }
57 catch(Exception ex)
58 {
59 ex.printStackTrace();
60 }
61 }
62
63 public void setOutfile(File outfile)
64 {
65 _outfile = outfile;
66 }
67
68 public void setDir(File dir)
69 {
70 _dir = dir;
71 }
72
73 public void addConfiguredPatternset(PatternSet patternset)
74 {
75 if (patternset == null || !(patternset instanceof PatternSet))
76 {
77 return;
78 }
79
80 _sets.add(patternset);
81 }
82}
Note: See TracBrowser for help on using the repository browser.