1 | package org.greenstone.anttasks;
|
---|
2 |
|
---|
3 | import java.io.BufferedWriter;
|
---|
4 | import java.io.File;
|
---|
5 | import java.io.FileWriter;
|
---|
6 | import java.util.ArrayList;
|
---|
7 |
|
---|
8 | import org.apache.tools.ant.BuildException;
|
---|
9 | import org.apache.tools.ant.DirectoryScanner;
|
---|
10 | import org.apache.tools.ant.Task;
|
---|
11 | import org.apache.tools.ant.types.FileSet;
|
---|
12 | import 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 | */
|
---|
19 | public 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<PatternSet> _sets = new ArrayList<PatternSet>();
|
---|
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(PatternSet set : _sets)
|
---|
40 | {
|
---|
41 | FileSet fs = new FileSet();
|
---|
42 | fs.setDir(_dir);
|
---|
43 | PatternSet ps = fs.createPatternSet();
|
---|
44 | ps.append(set, this.getProject());
|
---|
45 |
|
---|
46 | DirectoryScanner ds = fs.getDirectoryScanner(this.getProject());
|
---|
47 | for (String s : ds.getIncludedFiles())
|
---|
48 | {
|
---|
49 | out.write(s + "\n");
|
---|
50 | }
|
---|
51 | }
|
---|
52 | out.close();
|
---|
53 | }
|
---|
54 | catch(Exception ex)
|
---|
55 | {
|
---|
56 | ex.printStackTrace();
|
---|
57 | }
|
---|
58 | }
|
---|
59 |
|
---|
60 | public void setOutfile(File outfile)
|
---|
61 | {
|
---|
62 | _outfile = outfile;
|
---|
63 | }
|
---|
64 |
|
---|
65 | public void setDir(File dir)
|
---|
66 | {
|
---|
67 | _dir = dir;
|
---|
68 | }
|
---|
69 |
|
---|
70 | public void addConfiguredPatternset(PatternSet patternset)
|
---|
71 | {
|
---|
72 | if (patternset == null || !(patternset instanceof PatternSet))
|
---|
73 | {
|
---|
74 | return;
|
---|
75 | }
|
---|
76 |
|
---|
77 | _sets.add((PatternSet) patternset);
|
---|
78 | }
|
---|
79 | }
|
---|