View Javadoc
1   package org.codehaus.plexus.compiler.util.scan;
2   
3   /*
4    * Copyright 2001-2005 The Apache Software Foundation.
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *      http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  
19  import org.codehaus.plexus.compiler.util.scan.mapping.SourceMapping;
20  import org.codehaus.plexus.util.DirectoryScanner;
21  
22  import java.io.File;
23  import java.util.ArrayList;
24  import java.util.Collections;
25  import java.util.List;
26  import java.util.Set;
27  
28  /**
29   * @author jdcasey
30   */
31  public abstract class AbstractSourceInclusionScanner
32      implements SourceInclusionScanner
33  {
34      private final List<SourceMapping> sourceMappings = new ArrayList<SourceMapping>();
35  
36      public final void addSourceMapping( SourceMapping sourceMapping )
37      {
38          sourceMappings.add( sourceMapping );
39      }
40  
41      protected final List<SourceMapping> getSourceMappings()
42      {
43          return Collections.unmodifiableList( sourceMappings );
44      }
45  
46      protected String[] scanForSources( File sourceDir, Set<String> sourceIncludes, Set<String> sourceExcludes )
47      {
48          DirectoryScanner ds = new DirectoryScanner();
49          ds.setFollowSymlinks( true );
50          ds.setBasedir( sourceDir );
51  
52          String[] includes;
53          if ( sourceIncludes.isEmpty() )
54          {
55              includes = new String[0];
56          }
57          else
58          {
59              includes = sourceIncludes.toArray( new String[sourceIncludes.size()] );
60          }
61  
62          ds.setIncludes( includes );
63  
64          String[] excludes;
65          if ( sourceExcludes.isEmpty() )
66          {
67              excludes = new String[0];
68          }
69          else
70          {
71              excludes = sourceExcludes.toArray( new String[sourceExcludes.size()] );
72          }
73  
74          ds.setExcludes( excludes );
75          ds.addDefaultExcludes();
76  
77          ds.scan();
78  
79          return ds.getIncludedFiles();
80      }
81  }