|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| |
|
17 |
| |
|
18 |
| |
|
19 |
| |
|
20 |
| |
|
21 |
| |
|
22 |
| |
|
23 |
| |
|
24 |
| |
|
25 |
| |
|
26 |
| |
|
27 |
| |
|
28 |
| |
|
29 |
| |
|
30 |
| |
|
31 |
| |
|
32 |
| |
|
33 |
| |
|
34 |
| |
|
35 |
| |
|
36 |
| |
|
37 |
| package edu.rice.cs.drjava.config; |
|
38 |
| |
|
39 |
| import java.util.HashSet; |
|
40 |
| import java.util.List; |
|
41 |
| import java.util.ArrayList; |
|
42 |
| import java.io.*; |
|
43 |
| import edu.rice.cs.util.StringOps; |
|
44 |
| import edu.rice.cs.plt.text.TextUtil; |
|
45 |
| |
|
46 |
| |
|
47 |
| |
|
48 |
| |
|
49 |
| public class RecursiveFileListProperty extends FileListProperty { |
|
50 |
| |
|
51 |
| protected String _start; |
|
52 |
| |
|
53 |
84
| public RecursiveFileListProperty(String name, String sep, String dir, String start, String help) {
|
|
54 |
84
| super(name, sep, dir, help);
|
|
55 |
84
| _start = start;
|
|
56 |
84
| resetAttributes();
|
|
57 |
| } |
|
58 |
| |
|
59 |
| public static class RegexFilter implements FileFilter { |
|
60 |
| protected String _regex; |
|
61 |
2
| public RegexFilter(String regex) {
|
|
62 |
2
| _regex = regex;
|
|
63 |
| } |
|
64 |
5
| public boolean accept(File pathname) {
|
|
65 |
5
| return pathname.getName().matches(_regex);
|
|
66 |
| } |
|
67 |
| } |
|
68 |
| public static class FileMaskFilter extends RegexFilter { |
|
69 |
| private HashSet<File> _include = new HashSet<File>(); |
|
70 |
| private HashSet<File> _exclude = new HashSet<File>(); |
|
71 |
1
| public FileMaskFilter(String mask) {
|
|
72 |
1
| super(TextUtil.regexEscape(mask)
|
|
73 |
| .replaceAll("\\\\\\*",".*") |
|
74 |
| .replaceAll("\\\\\\?",".")); |
|
75 |
| } |
|
76 |
5
| public boolean accept(File pathname) {
|
|
77 |
1
| if (_include.contains(pathname)) { return true; }
|
|
78 |
1
| if (_exclude.contains(pathname)) { return false; }
|
|
79 |
3
| return super.accept(pathname);
|
|
80 |
| } |
|
81 |
1
| public void addIncludedFile(File f) { _include.add(f); }
|
|
82 |
1
| public void removeIncludedFile(File f) { _include.remove(f); }
|
|
83 |
1
| public void clearIncludedFile() { _include.clear(); }
|
|
84 |
1
| public void addExcludedFile(File f) { _exclude.add(f); }
|
|
85 |
1
| public void removeExcludedFile(File f) { _exclude.remove(f); }
|
|
86 |
1
| public void clearExcludedFile() { _exclude.clear(); }
|
|
87 |
| } |
|
88 |
| |
|
89 |
| |
|
90 |
| |
|
91 |
0
| protected List<File> getList(PropertyMaps pm) {
|
|
92 |
0
| FileMaskFilter fFilter = new FileMaskFilter(_attributes.get("filter"));
|
|
93 |
0
| FileMaskFilter fDirFilter = new FileMaskFilter(_attributes.get("dirfilter"));
|
|
94 |
0
| String start = StringOps.replaceVariables(_attributes.get("dir"), pm, PropertyMaps.GET_CURRENT);
|
|
95 |
0
| start = StringOps.unescapeFileName(start);
|
|
96 |
0
| File fStart = new File(start);
|
|
97 |
| |
|
98 |
0
| if (fStart.isDirectory()) { fDirFilter.addIncludedFile(fStart); }
|
|
99 |
0
| Iterable<File> it = edu.rice.cs.plt.io.IOUtil.listFilesRecursively(fStart, fFilter, fDirFilter);
|
|
100 |
| |
|
101 |
0
| ArrayList<File> l = new ArrayList<File>();
|
|
102 |
0
| for(File f: it) { l.add(f); }
|
|
103 |
0
| return l;
|
|
104 |
| } |
|
105 |
| |
|
106 |
| |
|
107 |
138
| public void resetAttributes() {
|
|
108 |
138
| _attributes.clear();
|
|
109 |
138
| _attributes.put("sep", _sep);
|
|
110 |
138
| _attributes.put("rel", _dir);
|
|
111 |
138
| _attributes.put("dir", _start);
|
|
112 |
138
| _attributes.put("filter", "*");
|
|
113 |
138
| _attributes.put("dirfilter", "*");
|
|
114 |
138
| _attributes.put("squote", null);
|
|
115 |
138
| _attributes.put("dquote", null);
|
|
116 |
| } |
|
117 |
| } |