View Javadoc

1   /**
2    * Copyright (C) 2008 http://code.google.com/p/maven-license-plugin/
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *         http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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   * <b>Date:</b> 16-Feb-2008<br>
29   * <b>Author:</b> Mathieu Carbou (mathieu.carbou@gmail.com)
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              // Miscellaneous typical temporary files
91              "**/*~", "**/#*#", "**/.#*",
92              "**/%*%",
93              "**/._*",
94              "**/.repository/**",
95  
96              // CVS
97              "**/CVS",
98              "**/CVS/**",
99              "**/.cvsignore",
100 
101             // RCS
102             "**/RCS",
103             "**/RCS/**",
104 
105             // SCCS
106             "**/SCCS",
107             "**/SCCS/**",
108 
109             // Visual SourceSafe
110             "**/vssver.scc",
111 
112             // Subversion
113             "**/.svn",
114             "**/.svn/**",
115 
116             // Arch
117             "**/.arch-ids",
118             "**/.arch-ids/**",
119 
120             // Bazaar
121             "**/.bzr",
122             "**/.bzr/**",
123 
124             // SurroundSCM
125             "**/.MySCMServerInfo",
126 
127             // Mac
128             "**/.DS_Store",
129 
130             // Serena Dimensions Version 10
131             "**/.metadata",
132             "**/.metadata/**",
133 
134             // Mercurial
135             "**/.hg",
136             "**/.hg/**",
137 
138             // git
139             "**/.git",
140             "**/.git/**",
141 
142             // BitKeeper
143             "**/BitKeeper", "**/BitKeeper/**", "**/ChangeSet",
144             "**/ChangeSet/**",
145 
146             // darcs
147             "**/_darcs", "**/_darcs/**", "**/.darcsrepo", "**/.darcsrepo/**", "**/-darcs-backup*",
148             "**/.darcs-temp-mail",
149 
150             // maven project's temporary files
151             "**/target/**", "**/test-output/**", "**/release.properties", "**/dependency-reduced-pom.xml",
152 
153             // code coverage tools
154             "**/cobertura.ser", "**/.clover/**",
155 
156             // eclipse project files
157             "**/.classpath", "**/.project", "**/.settings/**",
158 
159             // IDEA projet files
160             "**/*.iml", "**/*.ipr", "**/*.iws",
161 
162             // descriptors
163             "**/MANIFEST.MF",
164 
165             // binary files - images
166             "**/*.jpg", "**/*.png", "**/*.gif", "**/*.ico", "**/*.bmp", "**/*.tiff", "**/*.tif", "**/*.cr2",
167             "**/*.xcf",
168 
169             // binary files - programs
170             "**/*.class", "**/*.exe",
171 
172             // checksum files
173             "**/*.md5", "**/*.sha1",
174 
175             // binary files - archives
176             "**/*.jar", "**/*.zip", "**/*.rar", "**/*.tar", "**/*.tar.gz", "**/*.tar.bz2", "**/*.gz",
177 
178             // binary files - documents
179             "**/*.xls",
180 
181             // ServiceLoader files
182             "**/META-INF/services/**" };
183 
184 }