DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT <http://issues.apache.org/bugzilla/show_bug.cgi?id=29634>. ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND INSERTED IN THE BUG DATABASE.
http://issues.apache.org/bugzilla/show_bug.cgi?id=29634 CodeInfo Task Summary: CodeInfo Task Product: Ant Version: unspecified Platform: Other OS/Version: Other Status: NEW Severity: Enhancement Priority: Other Component: Core tasks AssignedTo: [EMAIL PROTECTED] ReportedBy: [EMAIL PROTECTED] To know how many files(based on included and excluded pattern set) are present with in the product src. It would be better to have simple codeInfo task which could print source code info. This may need to work in conjuction with some report formatter to display the result in more clean way e.g How *.java files are present How **/test/** files are present to take cound of test files Total lines of the product including the whitespace line Total size of the product source Total code lines (with out whitespaces) A sample code is inline which address few of the queries.. Regards, Nagendra import org.apache.tools.ant.DirectoryScanner; import java.io.File; import java.text.Collator; import java.util.Comparator; import java.util.HashMap; import java.util.Iterator; import java.util.Set; import java.util.TreeSet; public class CodeInfo { private static final float KB_SIZE = 1024; private static final float MB_SIZE = 1024 * KB_SIZE; private static final HashMap CODE_INFO_MAP = new HashMap(); private static final String[] DEFAULT_EXCLUDES = {"**/SCCS/**", "**/.*", "**/CVS/*", "**/vssver.scc"}; public static void main( String[] args ) { File rootDir = new File( "I:/work/sunmc/ws/35Upd2" ); String[] includes = {}; String[] excludes = DEFAULT_EXCLUDES; switch ( args.length ) { case 3: { } case 2: { } case 1: { rootDir = new File( args[0] ); break; } case 0: { System.out.println( "Assuming the Root Directory to be:" + rootDir ); break; } default: { System.out.println( "Ussage: java CodeInfo [<root directory>] [; seperated included file patterns>] [<; seperated excluded file patterns>]" ); break; } }//switch/case DirectoryScanner ds = new DirectoryScanner(); ds.setExcludes( excludes ); ds.setCaseSensitive( false ); ds.setBasedir( rootDir ); scan( ds ); }//main() static void scan( final DirectoryScanner aDirectoryScanner ) { aDirectoryScanner.scan(); String[] files = aDirectoryScanner.getIncludedFiles(); for ( int j = 0; j < files.length; j++ ) { File f = new File( aDirectoryScanner.getBasedir(), files[j] ); String fileName = f.getName().trim(); int index = fileName.lastIndexOf( '.' ); String extention = fileName; if ( index != -1 ) { extention = fileName.substring( index ); } long[] values = (long[]) CODE_INFO_MAP.get( extention ); if ( values == null ) { values = new long[2]; CODE_INFO_MAP.put( extention, values ); } values[0] += 1; values[1] += f.length(); } System.out.println( "Extention\t\t\tCount\t\tSize" ); Set keySet = new TreeSet( new ExtentionLengthComparator() ); keySet.addAll( CODE_INFO_MAP.keySet() ); long[] total = new long[2]; for ( Iterator lIterator = keySet.iterator(); lIterator.hasNext(); ) { Object ext = lIterator.next(); long[] values = (long[]) CODE_INFO_MAP.get( ext ); total[0] += values[0]; total[1] += values[1]; doPrint( ext, values ); } doPrint( "Total", total ); } private static void doPrint( Object aExt, long[] aValues ) { String size = ((aValues[1] / 1000000) == 0) ? "" + aValues[1] / KB_SIZE + " kB" : "" + aValues[1] / MB_SIZE + " MB"; System.out.println( aExt + "\t\t\t" + (aExt.toString().length() < 8 ? "\t" : "") + aValues [0] + "\t\t" + size ); }//doPrint() private static final class ExtentionLengthComparator implements Comparator { Collator c = Collator.getInstance(); public int compare( Object o, Object o1 ) { String obj1 = o.toString(); String obj2 = o1.toString(); if ( obj1.charAt( 0 ) == '.' && obj2.charAt( 0 ) != '.' ) { return -1; } else if ( obj1.charAt( 0 ) != '.' && obj2.charAt( 0 ) == '.' ) { return 1; } int result = obj1.length() - obj2.length(); if ( result == 0 ) { return c.compare( o, o1 ); } return result; }//compare() }//ExtentionLengthComparator }//class CodeInfo --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
