001/*
002 * Cobertura - http://cobertura.sourceforge.net/
003 *
004 * Copyright (C) 2006 John Lewis
005 *
006 * Note: This file is dual licensed under the GPL and the Apache
007 * Source License (so that it can be used from both the main
008 * Cobertura classes and the ant tasks).
009 *
010 * Cobertura is free software; you can redistribute it and/or modify
011 * it under the terms of the GNU General Public License as published
012 * by the Free Software Foundation; either version 2 of the License,
013 * or (at your option) any later version.
014 *
015 * Cobertura is distributed in the hope that it will be useful, but
016 * WITHOUT ANY WARRANTY; without even the implied warranty of
017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
018 * General Public License for more details.
019 *
020 * You should have received a copy of the GNU General Public License
021 * along with Cobertura; if not, write to the Free Software
022 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
023 * USA
024 */
025
026package net.sourceforge.cobertura.instrument;
027
028import java.io.File;
029
030import net.sourceforge.cobertura.util.ArchiveUtil;
031
032/**
033 * This represents a regular File, but unlike java.io.File, the baseDir and 
034 * relative pathname used to create it are saved for later use.
035 * 
036 * @author John Lewis
037 */
038class CoberturaFile extends File
039{
040
041        private static final long serialVersionUID = 0L;
042
043        private String baseDir;
044        private String pathname;
045
046        CoberturaFile(String baseDir, String pathname)
047        {
048                super(baseDir, pathname);
049                this.baseDir = baseDir;
050                this.pathname = pathname;
051        }
052
053        public String getBaseDir()
054        {
055                return baseDir;
056        }
057
058        public String getPathname()
059        {
060                return pathname;
061        }
062
063        /**
064         * @return True if file has an extension that matches one of the
065         *         standard java archives, false otherwise.
066         */
067        boolean isArchive()
068        {
069                if (!isFile())
070                {
071                        return false;
072                }
073                return ArchiveUtil.isArchive(pathname);
074        }
075
076        /**
077         * @return True if file has "class" as its extension,
078         *         false otherwise.
079         */
080        boolean isClass()
081        {
082                return isFile() && pathname.endsWith(".class");
083        }
084
085        public String toString()
086        {
087                return "pathname=" + pathname + " and baseDir=" + baseDir;
088        }
089
090}