Coverage Report - org.codehaus.plexus.compiler.util.scan.AbstractSourceInclusionScanner
 
Classes in this File Line Coverage Branch Coverage Complexity
AbstractSourceInclusionScanner
94%
18/19
75%
3/4
1,667
 
 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  15
 public abstract class AbstractSourceInclusionScanner
 32  
     implements SourceInclusionScanner
 33  
 {
 34  15
     private final List<SourceMapping> sourceMappings = new ArrayList<SourceMapping>();
 35  
 
 36  
     public final void addSourceMapping( SourceMapping sourceMapping )
 37  
     {
 38  11
         sourceMappings.add( sourceMapping );
 39  11
     }
 40  
 
 41  
     protected final List<SourceMapping> getSourceMappings()
 42  
     {
 43  14
         return Collections.unmodifiableList( sourceMappings );
 44  
     }
 45  
 
 46  
     protected String[] scanForSources( File sourceDir, Set<String> sourceIncludes, Set<String> sourceExcludes )
 47  
     {
 48  14
         DirectoryScanner ds = new DirectoryScanner();
 49  14
         ds.setFollowSymlinks( true );
 50  14
         ds.setBasedir( sourceDir );
 51  
 
 52  
         String[] includes;
 53  14
         if ( sourceIncludes.isEmpty() )
 54  
         {
 55  0
             includes = new String[0];
 56  
         }
 57  
         else
 58  
         {
 59  14
             includes = sourceIncludes.toArray( new String[sourceIncludes.size()] );
 60  
         }
 61  
 
 62  14
         ds.setIncludes( includes );
 63  
 
 64  
         String[] excludes;
 65  14
         if ( sourceExcludes.isEmpty() )
 66  
         {
 67  13
             excludes = new String[0];
 68  
         }
 69  
         else
 70  
         {
 71  1
             excludes = sourceExcludes.toArray( new String[sourceExcludes.size()] );
 72  
         }
 73  
 
 74  14
         ds.setExcludes( excludes );
 75  14
         ds.addDefaultExcludes();
 76  
 
 77  14
         ds.scan();
 78  
 
 79  14
         return ds.getIncludedFiles();
 80  
     }
 81  
 }