View Javadoc
1   package org.apache.maven.plugin.cxx.utils;
2   
3   /*
4    * Copyright (C) 2011-2016, Neticoa SAS France - Tous droits réservés.
5    * Author(s) : Franck Bonin, Neticoa SAS France
6    *
7    * Licensed under the Apache License, Version 2.0 (the "License");
8    * you may not use this file except in compliance with the License.
9    * You may obtain a copy of the License at
10   *
11   *     http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing, software
14   * distributed under the License is distributed on an "AS IS" BASIS,
15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   * See the License for the specific language governing permissions and
17   * limitations under the License.
18   *
19   */
20  
21  import java.io.File;
22  import java.util.List;
23  
24  import org.apache.maven.model.FileSet;
25  
26  import org.codehaus.plexus.util.DirectoryScanner;
27  
28  /**
29   * This FileSetManager always exclude default files (.svn, etc.) and scan symlinks.
30   *
31   * @author Franck Bonin 
32   * 
33   */
34  public class FileSetManager
35  {
36      private DirectoryScanner scan( FileSet fileSet )
37      {
38          File basedir = new File( fileSet.getDirectory() );
39  
40          if ( !basedir.exists() || !basedir.isDirectory() )
41          {
42               return null;
43          }
44  
45          DirectoryScanner scanner = new DirectoryScanner();
46  
47          List<String> includesList = fileSet.getIncludes();
48          List<String> excludesList = fileSet.getExcludes();
49  
50          if ( includesList.size() > 0 )
51          {
52               scanner.setIncludes( (String[]) includesList.toArray( new String[0] ) );
53          }
54  
55          if ( excludesList.size() > 0 )
56          {
57               scanner.setExcludes( (String[]) excludesList.toArray( new String[0] ) );
58          }
59  
60          if ( true )//fileSet.isUseDefaultExcludes() )
61          {
62               scanner.addDefaultExcludes();
63          }
64  
65          scanner.setBasedir( basedir );
66          scanner.setFollowSymlinks( true ); //fileSet.isFollowSymlinks() );
67  
68          scanner.scan();
69  
70          return scanner;
71      }
72      
73      private static final String[] EMPTY_STRING_ARRAY = new String[0];
74  
75      public String[] getIncludedFiles( FileSet fileSet )
76      {
77          DirectoryScanner scanner = scan( fileSet );
78       
79          if ( scanner != null )
80          {
81              return scanner.getIncludedFiles();
82          }
83       
84          return EMPTY_STRING_ARRAY;
85      }
86      
87      public String[] getExcludedFiles( FileSet fileSet )
88      {
89           DirectoryScanner scanner = scan( fileSet );
90     
91           if ( scanner != null )
92           {
93               return scanner.getExcludedFiles();
94           }
95     
96           return EMPTY_STRING_ARRAY;
97       }
98  
99      public String[] getIncludedDirectories( FileSet fileSet )
100     {
101         DirectoryScanner scanner = scan( fileSet );
102 
103         if ( scanner != null )
104         {
105             return scanner.getIncludedDirectories();
106         }
107 
108         return EMPTY_STRING_ARRAY;
109     }
110     
111     public String[] getExcludedDirectories( FileSet fileSet )
112     {
113         DirectoryScanner scanner = scan( fileSet );
114 
115         if ( scanner != null )
116         {
117             return scanner.getExcludedDirectories();
118         }
119 
120         return EMPTY_STRING_ARRAY;
121     }
122 }