1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package com.dhptech.maven.stripbom;
18
19 import static java.util.Arrays.asList;
20
21 import java.io.File;
22 import java.util.ArrayList;
23 import java.util.List;
24
25 import org.codehaus.plexus.util.DirectoryScanner;
26
27
28
29
30
31 public final class SimpleScanner {
32
33 private final File basedir;
34 private final String[] included;
35 private final String[] excluded;
36
37 private DirectoryScanner scanner;
38
39 public SimpleScanner(File basedir, String[] included, String[] excluded, boolean useDefaultExcludes) {
40 this.basedir = basedir;
41 this.included = buildInclusions(included);
42 this.excluded = buildExclusions(useDefaultExcludes, excluded);
43 }
44
45 public String[] getSelectedFiles() {
46 scanIfneeded();
47 return scanner.getIncludedFiles();
48 }
49
50 public File getBasedir() {
51 return basedir;
52 }
53
54 public String[] getIncluded() {
55 return included;
56 }
57
58 public String[] getExcluded() {
59 return excluded;
60 }
61
62 private synchronized void scanIfneeded() {
63 if (scanner == null) {
64 scanner = new DirectoryScanner();
65 scanner.setBasedir(basedir);
66 scanner.setIncludes(included);
67 scanner.setExcludes(excluded);
68 scanner.scan();
69 }
70 }
71
72 private static String[] buildExclusions(boolean useDefaultExcludes, String... excludes) {
73 List<String> exclusions = new ArrayList<String>();
74 if (useDefaultExcludes) {
75 exclusions.addAll(asList(DEFAULT_EXCLUDES));
76 }
77 if (excludes != null && excludes.length > 0) {
78 exclusions.addAll(asList(excludes));
79 }
80 return exclusions.toArray(new String[exclusions.size()]);
81 }
82
83 private static String[] buildInclusions(String... includes) {
84 return includes != null && includes.length > 0 ? includes : DEFAULT_INCLUDE;
85 }
86
87 static final String[] DEFAULT_INCLUDE = new String[] { "**" };
88
89 static final String[] DEFAULT_EXCLUDES = {
90
91 "**/*~", "**/#*#", "**/.#*",
92 "**/%*%",
93 "**/._*",
94 "**/.repository/**",
95
96
97 "**/CVS",
98 "**/CVS/**",
99 "**/.cvsignore",
100
101
102 "**/RCS",
103 "**/RCS/**",
104
105
106 "**/SCCS",
107 "**/SCCS/**",
108
109
110 "**/vssver.scc",
111
112
113 "**/.svn",
114 "**/.svn/**",
115
116
117 "**/.arch-ids",
118 "**/.arch-ids/**",
119
120
121 "**/.bzr",
122 "**/.bzr/**",
123
124
125 "**/.MySCMServerInfo",
126
127
128 "**/.DS_Store",
129
130
131 "**/.metadata",
132 "**/.metadata/**",
133
134
135 "**/.hg",
136 "**/.hg/**",
137
138
139 "**/.git",
140 "**/.git/**",
141
142
143 "**/BitKeeper", "**/BitKeeper/**", "**/ChangeSet",
144 "**/ChangeSet/**",
145
146
147 "**/_darcs", "**/_darcs/**", "**/.darcsrepo", "**/.darcsrepo/**", "**/-darcs-backup*",
148 "**/.darcs-temp-mail",
149
150
151 "**/target/**", "**/test-output/**", "**/release.properties", "**/dependency-reduced-pom.xml",
152
153
154 "**/cobertura.ser", "**/.clover/**",
155
156
157 "**/.classpath", "**/.project", "**/.settings/**",
158
159
160 "**/*.iml", "**/*.ipr", "**/*.iws",
161
162
163 "**/MANIFEST.MF",
164
165
166 "**/*.jpg", "**/*.png", "**/*.gif", "**/*.ico", "**/*.bmp", "**/*.tiff", "**/*.tif", "**/*.cr2",
167 "**/*.xcf",
168
169
170 "**/*.class", "**/*.exe",
171
172
173 "**/*.md5", "**/*.sha1",
174
175
176 "**/*.jar", "**/*.zip", "**/*.rar", "**/*.tar", "**/*.tar.gz", "**/*.tar.bz2", "**/*.gz",
177
178
179 "**/*.xls",
180
181
182 "**/META-INF/services/**" };
183
184 }