Coverage Report - org.codehaus.plexus.archiver.DotDirectiveArchiveFinalizer
 
Classes in this File Line Coverage Branch Coverage Complexity
DotDirectiveArchiveFinalizer
77 %
28/36
87 %
7/8
2,5
 
 1  
 package org.codehaus.plexus.archiver;
 2  
 
 3  
 import java.io.BufferedReader;
 4  
 import java.io.File;
 5  
 import java.io.FileReader;
 6  
 import java.io.IOException;
 7  
 import java.util.Collections;
 8  
 import java.util.List;
 9  
 import org.codehaus.plexus.util.FileUtils;
 10  
 import org.codehaus.plexus.util.IOUtil;
 11  
 import org.codehaus.plexus.util.StringUtils;
 12  
 
 13  
 /**
 14  
  * An {@link ArchiveFinalizer} that process dot files with archiver directives
 15  
  * contained within. This basically means you can communicate archive creation
 16  
  * instructions between processes using dot files.
 17  
  *
 18  
  * @author Jason van Zyl
 19  
  */
 20  
 public class DotDirectiveArchiveFinalizer
 21  
     extends AbstractArchiveFinalizer
 22  
 {
 23  
 
 24  
     private static final String DEFAULT_DOT_FILE_PREFIX = ".plxarc";
 25  
 
 26  
     private final File dotFileDirectory;
 27  
 
 28  
     private final String dotFilePrefix;
 29  
 
 30  
     public DotDirectiveArchiveFinalizer( File dotFileDirectory )
 31  
     {
 32  2
         this( dotFileDirectory, DEFAULT_DOT_FILE_PREFIX );
 33  2
     }
 34  
 
 35  0
     public DotDirectiveArchiveFinalizer( File dotFileDirectory, String dotFilePrefix )
 36  2
     {
 37  2
         this.dotFileDirectory = dotFileDirectory;
 38  
 
 39  2
         this.dotFilePrefix = dotFilePrefix;
 40  2
     }
 41  
 
 42  
     @Override
 43  
     public void finalizeArchiveCreation( Archiver archiver )
 44  
         throws ArchiverException
 45  
     {
 46  2
         BufferedReader in = null;
 47  
         try
 48  
         {
 49  2
             List dotFiles = FileUtils.getFiles( dotFileDirectory, dotFilePrefix + "*", null );
 50  
 
 51  2
             for ( Object dotFile1 : dotFiles )
 52  
             {
 53  2
                 File dotFile = (File) dotFile1;
 54  
 
 55  2
                 in = new BufferedReader( new FileReader( dotFile ) );
 56  
 
 57  6
                 for ( String line = in.readLine(); line != null; line = in.readLine() )
 58  
                 {
 59  4
                     String[] s = StringUtils.split( line, ":" );
 60  
 
 61  4
                     if ( s.length == 1 )
 62  
                     {
 63  2
                         File directory = new File( dotFileDirectory, s[0] );
 64  
 
 65  2
                         System.out.println( "adding directory = " + directory );
 66  
 
 67  2
                         archiver.addDirectory( directory );
 68  2
                     }
 69  
                     else
 70  
                     {
 71  2
                         File directory = new File( dotFileDirectory, s[0] );
 72  
 
 73  2
                         System.out.println( "adding directory = " + directory + " to: " + s[1] );
 74  
 
 75  2
                         if ( s[1].endsWith( "/" ) )
 76  
                         {
 77  0
                             archiver.addDirectory( directory, s[1] );
 78  0
                         }
 79  
                         else
 80  
                         {
 81  2
                             archiver.addDirectory( directory, s[1] + "/" );
 82  
                         }
 83  
                     }
 84  
                 }
 85  
 
 86  2
                 in.close();
 87  2
                 in = null;
 88  2
             }
 89  0
         }
 90  0
         catch ( IOException e )
 91  
         {
 92  0
             throw new ArchiverException( "Error processing dot files.", e );
 93  
         }
 94  
         finally
 95  0
         {
 96  2
             IOUtil.close( in );
 97  2
         }
 98  2
     }
 99  
 
 100  
     @Override
 101  
     public List getVirtualFiles()
 102  
     {
 103  0
         return Collections.EMPTY_LIST;
 104  
     }
 105  
 
 106  
 }