Coverage Report - org.codehaus.plexus.archiver.tar.PlexusIoTarFileResourceCollection
 
Classes in this File Line Coverage Branch Coverage Complexity
PlexusIoTarFileResourceCollection
71%
10/14
33%
2/6
1,857
PlexusIoTarFileResourceCollection$1
80%
4/5
100%
2/2
1,857
 
 1  
 /*
 2  
  * Copyright 2010-2015 The plexus developers.
 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  
 package org.codehaus.plexus.archiver.tar;
 17  
 
 18  
 import java.io.Closeable;
 19  
 import java.io.File;
 20  
 import java.io.IOException;
 21  
 import java.util.Enumeration;
 22  
 import java.util.Iterator;
 23  
 import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
 24  
 import org.codehaus.plexus.components.io.resources.AbstractPlexusIoArchiveResourceCollection;
 25  
 import org.codehaus.plexus.components.io.resources.PlexusIoResource;
 26  
 
 27  8
 public class PlexusIoTarFileResourceCollection
 28  
     extends AbstractPlexusIoArchiveResourceCollection implements Closeable
 29  
 {
 30  
 
 31  
     /**
 32  
      * The zip file resource collections role hint.
 33  
      */
 34  
     public static final String ROLE_HINT = "tar";
 35  
 
 36  
     protected TarFile newTarFile( File file )
 37  
     {
 38  5
         return new TarFile( file );
 39  
     }
 40  
 
 41  8
     TarFile tarFile = null;
 42  
 
 43  
     @Override
 44  
     public void close()
 45  
         throws IOException
 46  
     {
 47  0
         if ( tarFile != null )
 48  
         {
 49  0
             tarFile.close();
 50  
         }
 51  0
     }
 52  
 
 53  
     @Override
 54  
     public boolean isConcurrentAccessSupported()
 55  
     {
 56  1021
         return false;
 57  
     }
 58  
 
 59  
     @Override
 60  
     protected Iterator<PlexusIoResource> getEntries()
 61  
         throws IOException
 62  
     {
 63  8
         final File f = getFile();
 64  8
         if ( f == null )
 65  
         {
 66  0
             throw new IOException( "The tar archive file has not been set." );
 67  
         }
 68  8
         if ( tarFile == null )
 69  
         {
 70  8
             tarFile = newTarFile( f );
 71  
         }
 72  8
         final Enumeration en = tarFile.getEntries();
 73  8
         return new Iterator<PlexusIoResource>()
 74  1326
         {
 75  
 
 76  
             @Override
 77  
             public boolean hasNext()
 78  
             {
 79  1326
                 return en.hasMoreElements();
 80  
             }
 81  
 
 82  
             @Override
 83  
             public PlexusIoResource next()
 84  
             {
 85  1318
                 final TarArchiveEntry entry = (TarArchiveEntry) en.nextElement();
 86  1318
                 return entry.isSymbolicLink()
 87  
                            ? new TarSymlinkResource( tarFile, entry )
 88  
                            : new TarResource( tarFile, entry );
 89  
             }
 90  
 
 91  
             @Override
 92  
             public void remove()
 93  
             {
 94  0
                 throw new UnsupportedOperationException( "Removing isn't implemented." );
 95  
             }
 96  
 
 97  
         };
 98  
     }
 99  
 
 100  
 }