Coverage Report - org.codehaus.plexus.archiver.resources.PlexusIoVirtualFileResource
 
Classes in this File Line Coverage Branch Coverage Complexity
PlexusIoVirtualFileResource
62%
10/16
50%
1/2
1,25
 
 1  
 /*
 2  
  * Copyright 2014 The Codehaus Foundation.
 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.resources;
 17  
 
 18  
 import java.io.File;
 19  
 import java.io.IOException;
 20  
 import java.io.InputStream;
 21  
 import java.net.URL;
 22  
 import javax.annotation.Nonnull;
 23  
 import org.codehaus.plexus.components.io.attributes.AttributeUtils;
 24  
 import org.codehaus.plexus.components.io.attributes.PlexusIoResourceAttributes;
 25  
 import org.codehaus.plexus.components.io.functions.ResourceAttributeSupplier;
 26  
 import org.codehaus.plexus.components.io.resources.AbstractPlexusIoResource;
 27  
 
 28  
 /**
 29  
  * A file resource that does not necessarily exist (anywhere).
 30  
  */
 31  
 public class PlexusIoVirtualFileResource
 32  
     extends AbstractPlexusIoResource
 33  
     implements ResourceAttributeSupplier
 34  
 {
 35  
 
 36  
     private final File file;
 37  
 
 38  
     protected PlexusIoVirtualFileResource( File file, String name )
 39  
     {
 40  3
         super( name, file.lastModified(), file.length(), file.isFile(), file.isDirectory(), file.exists() );
 41  3
         this.file = file;
 42  3
     }
 43  
 
 44  
     protected static String getName( File file )
 45  
     {
 46  3
         return file.getPath().replace( '\\', '/' );
 47  
     }
 48  
 
 49  
     /**
 50  
      * Returns the resources file.
 51  
      */
 52  
     public File getFile()
 53  
     {
 54  6
         return file;
 55  
     }
 56  
 
 57  
     @Nonnull
 58  
     @Override
 59  
     public InputStream getContents()
 60  
         throws IOException
 61  
     {
 62  0
         throw new UnsupportedOperationException( "We're not really sure we can do this" );
 63  
         //return new FileInputStream( getFile() );
 64  
     }
 65  
 
 66  
     @Override
 67  
     public URL getURL()
 68  
         throws IOException
 69  
     {
 70  0
         return getFile().toURI().toURL();
 71  
     }
 72  
 
 73  
     @Override
 74  
     public long getSize()
 75  
     {
 76  0
         return getFile().length();
 77  
     }
 78  
 
 79  
     @Override
 80  
     public boolean isDirectory()
 81  
     {
 82  3
         return getFile().isDirectory();
 83  
     }
 84  
 
 85  
     @Override
 86  
     public boolean isExisting()
 87  
     {
 88  0
         return getFile().exists();
 89  
     }
 90  
 
 91  
     @Override
 92  
     public boolean isFile()
 93  
     {
 94  3
         return getFile().isFile();
 95  
     }
 96  
 
 97  
     @Override
 98  
     public PlexusIoResourceAttributes getAttributes()
 99  
     {
 100  3
         return null;
 101  
     }
 102  
 
 103  
     @Override
 104  
     public long getLastModified()
 105  
     {
 106  3
         if ( file.exists() )
 107  
         {
 108  0
             return AttributeUtils.getLastModified( getFile() );
 109  
         }
 110  
         else
 111  
         {
 112  3
             return System.currentTimeMillis();
 113  
         }
 114  
     }
 115  
 
 116  
     @Override public boolean isSymbolicLink()
 117  
     {
 118  0
         return getAttributes().isSymbolicLink();
 119  
     }
 120  
 
 121  
 }