Coverage Report - net.sourceforge.cobertura.instrument.CoberturaFile
 
Classes in this File Line Coverage Branch Coverage Complexity
CoberturaFile
73%
8/11
50%
3/6
1.333
 
 1  
 /*
 2  
  * Cobertura - http://cobertura.sourceforge.net/
 3  
  *
 4  
  * Copyright (C) 2006 John Lewis
 5  
  *
 6  
  * Note: This file is dual licensed under the GPL and the Apache
 7  
  * Source License (so that it can be used from both the main
 8  
  * Cobertura classes and the ant tasks).
 9  
  *
 10  
  * Cobertura is free software; you can redistribute it and/or modify
 11  
  * it under the terms of the GNU General Public License as published
 12  
  * by the Free Software Foundation; either version 2 of the License,
 13  
  * or (at your option) any later version.
 14  
  *
 15  
  * Cobertura is distributed in the hope that it will be useful, but
 16  
  * WITHOUT ANY WARRANTY; without even the implied warranty of
 17  
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 18  
  * General Public License for more details.
 19  
  *
 20  
  * You should have received a copy of the GNU General Public License
 21  
  * along with Cobertura; if not, write to the Free Software
 22  
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 23  
  * USA
 24  
  */
 25  
 
 26  
 package net.sourceforge.cobertura.instrument;
 27  
 
 28  
 import java.io.File;
 29  
 
 30  
 import net.sourceforge.cobertura.util.ArchiveUtil;
 31  
 
 32  
 /**
 33  
  * This represents a regular File, but unlike java.io.File, the baseDir and 
 34  
  * relative pathname used to create it are saved for later use.
 35  
  * 
 36  
  * @author John Lewis
 37  
  */
 38  
 class CoberturaFile extends File
 39  
 {
 40  
 
 41  
         private static final long serialVersionUID = 0L;
 42  
 
 43  
         private String baseDir;
 44  
         private String pathname;
 45  
 
 46  
         CoberturaFile(String baseDir, String pathname)
 47  
         {
 48  14
                 super(baseDir, pathname);
 49  14
                 this.baseDir = baseDir;
 50  14
                 this.pathname = pathname;
 51  14
         }
 52  
 
 53  
         public String getBaseDir()
 54  
         {
 55  0
                 return baseDir;
 56  
         }
 57  
 
 58  
         public String getPathname()
 59  
         {
 60  14
                 return pathname;
 61  
         }
 62  
 
 63  
         /**
 64  
          * @return True if file has an extension that matches one of the
 65  
          *         standard java archives, false otherwise.
 66  
          */
 67  
         boolean isArchive()
 68  
         {
 69  14
                 if (!isFile())
 70  
                 {
 71  0
                         return false;
 72  
                 }
 73  14
                 return ArchiveUtil.isArchive(pathname);
 74  
         }
 75  
 
 76  
         /**
 77  
          * @return True if file has "class" as its extension,
 78  
          *         false otherwise.
 79  
          */
 80  
         boolean isClass()
 81  
         {
 82  13
                 return isFile() && pathname.endsWith(".class");
 83  
         }
 84  
 
 85  
         public String toString()
 86  
         {
 87  0
                 return "pathname=" + pathname + " and baseDir=" + baseDir;
 88  
         }
 89  
 
 90  
 }