From: <cry...@us...> - 2002-07-31 06:50:13
|
Update of /cvsroot/cdchamber/CDChamber/src/org/cdchamber/util/testtools In directory usw-pr-cvs1:/tmp/cvs-serv13504 Modified Files: AllTestsGenerator.java Log Message: use memory string.equal to check if file is different Index: AllTestsGenerator.java =================================================================== RCS file: /cvsroot/cdchamber/CDChamber/src/org/cdchamber/util/testtools/AllTestsGenerator.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** AllTestsGenerator.java 31 Jul 2002 06:02:05 -0000 1.3 --- AllTestsGenerator.java 31 Jul 2002 06:50:10 -0000 1.4 *************** *** 10,58 **** public class AllTestsGenerator { ! static String testSrc = DirPath.BaseDir + DirPath.SEP + "test" + DirPath.SEP + "src" + DirPath.SEP ; ! static PrintWriter allTest; ! static String tmpFile = testSrc + "AllTests.java2"; ! static String targetFile = testSrc + "AllTests.java"; public static void main( String[] args) throws IOException { ! allTest = new PrintWriter( new FileWriter( tmpFile)); File testsDir = new File( DirPath.BaseDir + DirPath.SEP + "test" + DirPath.SEP + "src"); ! prefix(); ! generate( testsDir, ""); ! postfix(); ! allTest.close(); ! ! if ( !FileComparator.diff( targetFile, tmpFile)) delete( tmpFile); ! else { ! delete( targetFile); ! rename(); ! } ! } ! ! static void rename( ) { ! File file = new File( tmpFile); ! File target = new File( targetFile); ! file.renameTo( target); ! } ! ! static void delete( String fileName) { ! File file = new File( fileName); ! System.out.println( file.delete()); } ! static void generate( File testsDir, String packageName) { File[] files = testsDir.listFiles(); for ( int i=0; i< files.length; i++) { File file = files[i]; ! if ( file.isDirectory()) generate( file, getPackageName( packageName, file.getName())); if ( file.getName().endsWith( "Test.java")) { int point = file.getName().lastIndexOf('.'); String name = file.getName().substring( 0, point); ! allTest.print( " suite.addTest(new TestSuite("); ! allTest.print( packageName+"."+ name); ! allTest.println( ".class));"); } } } --- 10,53 ---- public class AllTestsGenerator { ! static String testSrc = DirPath.BaseDir + DirPath.SEP + "test" + DirPath.SEP + "src"; ! ! private static String readFile( String filename ) throws IOException{ ! File file = new File(filename); ! FileReader reader = new FileReader(file); ! char[] buf = new char[(int)file.length()]; ! reader.read(buf,0,(int)file.length()); ! reader.close(); ! return new String(buf); ! } public static void main( String[] args) throws IOException { ! String original = readFile(testSrc + DirPath.SEP + "AllTests.java"); File testsDir = new File( DirPath.BaseDir + DirPath.SEP + "test" + DirPath.SEP + "src"); ! String result = prefix(); ! result += generate( testsDir, ""); ! result += postfix(); ! if ( !result.equals(original) ) { ! PrintWriter allTest = new PrintWriter( new FileWriter(testSrc + DirPath.SEP + "AllTests.java")); ! allTest.print(result); ! allTest.close(); ! } // end of if () } ! static String generate( File testsDir, String packageName) { File[] files = testsDir.listFiles(); + String result = ""; for ( int i=0; i< files.length; i++) { File file = files[i]; ! if ( file.isDirectory()) ! result += generate( file, getPackageName( packageName, file.getName())); if ( file.getName().endsWith( "Test.java")) { int point = file.getName().lastIndexOf('.'); String name = file.getName().substring( 0, point); ! result += " suite.addTest(new TestSuite("; ! result += packageName+"."+ name + ".class));\n"; } } + return result; } *************** *** 63,80 **** } ! static void prefix() { ! allTest.println( "import junit.framework.*;"); ! allTest.println( "public class AllTests {"); ! allTest.println( " public static void main (String[] args) {"); ! allTest.println( " junit.textui.TestRunner.run (suite());"); ! allTest.println( " }"); ! allTest.println( " public static Test suite ( ) {"); ! allTest.println( " TestSuite suite= new TestSuite(\"All CDChamber Tests\");"); } ! static void postfix() { ! allTest.println( " return suite;"); ! allTest.println( " }"); ! allTest.println( "}"); } } --- 58,79 ---- } ! static String prefix() { ! String result = ""; ! result += "import junit.framework.*;\n"; ! result += "public class AllTests {\n"; ! result += " public static void main (String[] args) {\n"; ! result += " junit.textui.TestRunner.run (suite());\n"; ! result += " }\n"; ! result += " public static Test suite ( ) {\n"; ! result += " TestSuite suite= new TestSuite(\"All CDChamber Tests\");\n"; ! return result; } ! static String postfix() { ! String result = ""; ! result += " return suite;\n"; ! result += " }\n"; ! result += "}\n"; ! return result; } } |