001    /*
002     * Cobertura - http://cobertura.sourceforge.net/
003     *
004     * Copyright (C) 2005 Mark Doliner <thekingant@users.sourceforge.net>
005     *
006     * Cobertura is free software; you can redistribute it and/or modify
007     * it under the terms of the GNU General Public License as published
008     * by the Free Software Foundation; either version 2 of the License,
009     * or (at your option) any later version.
010     *
011     * Cobertura is distributed in the hope that it will be useful, but
012     * WITHOUT ANY WARRANTY; without even the implied warranty of
013     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014     * General Public License for more details.
015     *
016     * You should have received a copy of the GNU General Public License
017     * along with Cobertura; if not, write to the Free Software
018     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019     * USA
020     */
021    
022    package net.sourceforge.cobertura.reporting;
023    
024    import java.io.File;
025    import java.util.Iterator;
026    import java.util.List;
027    import java.util.Vector;
028    
029    public abstract class Util
030    {
031    
032            /**
033             * Calculates the code complexity number for a given class.
034             * "CCN" stands for "code complexity number."  This is
035             * sometimes referred to as McCabe's number.  This method
036             * calculates the average cyclomatic code complexity of all
037             * methods in a given class, or of all methods of all classes
038             * in a given directory.  This recursive calculation is useful
039             * for calculating the average CCN for a specific package.
040             *
041             * @param file The source of a Java class for which you want
042             *        to calculate the complexity, or a directory containing
043             *        Java source files for which you want to calculate the
044             *        complexity.
045             * @param recursive If file is a directory, this parameter is
046             *        used to decide whether to only list the files in the
047             *        given directory, or to list all files in all 
048             *        subdirectories of the given directory.
049             * @return The average cyclomatic code complexity for this class.
050             */
051            public static double getCCN(File file, boolean recursive)
052            {
053                    return -1;
054            }
055    
056            /**
057             * Create a <code>Vector</code> containing the file names of
058             * Java source code.  If the given file parameter is a regular
059             * file, then the return value only contains the absolute
060             * path of this file.  However, if the given file parameter
061             * is a directory, this vector contains absolute paths to all
062             * files under this directory and all subdirectories.
063             *
064             * @param file A Java source file or a directory containing
065             *        Java source files.
066             * @return A Vector containing <code>String</code>s that
067             *         are absolute paths to Java source files.
068             */
069            private static Vector getListOfFiles(File file, boolean recursive)
070            {
071                    Vector ret = new Vector();
072    
073                    if (file.isFile())
074                    {
075                            ret.add(file.getAbsolutePath());
076                    }
077                    else if (file.isDirectory())
078                    {
079                            File[] files = file.listFiles();
080                            for (int i = 0; i < files.length; i++)
081                            {
082                                    if (recursive)
083                                    {
084                                            ret.addAll(getListOfFiles(files[i], true));
085                                    }
086                                    else
087                                    {
088                                            if (files[i].isFile())
089                                            {
090                                                    ret.add(files[i].getAbsolutePath());
091                                            }
092                                    }
093                            }
094                    }
095    
096                    return ret;
097            }
098    
099    }