<s> import java . io . BufferedWriter ; import java . io . File ; import java . io . FileFilter ; import java . io . FileWriter ; import java . io . IOException ; import java . io . Writer ; import java . text . MessageFormat ; import java . util . ArrayList ; public class GenerateBuildScript { private static final String LINE_SEPARATOR = System . getProperty ( "" ) ; private static final String HEADER = "" + LINE_SEPARATOR + "" + LINE_SEPARATOR + "" + LINE_SEPARATOR ; private static final String SOURCE_FILES = "" + LINE_SEPARATOR + "" + LINE_SEPARATOR + "" + LINE_SEPARATOR + "" + LINE_SEPARATOR + "" + LINE_SEPARATOR + "" + LINE_SEPARATOR + "" + LINE_SEPARATOR + "" + LINE_SEPARATOR + "" + LINE_SEPARATOR + "" + LINE_SEPARATOR + "" + LINE_SEPARATOR + "" + LINE_SEPARATOR + "" + LINE_SEPARATOR + "" + LINE_SEPARATOR + "" + LINE_SEPARATOR + LINE_SEPARATOR ; private static final String FOOTER = "" + LINE_SEPARATOR + "" + LINE_SEPARATOR + "" + LINE_SEPARATOR + "" + LINE_SEPARATOR + "" + LINE_SEPARATOR + "" + LINE_SEPARATOR + "" + LINE_SEPARATOR + "" + LINE_SEPARATOR + "" + LINE_SEPARATOR + "" + LINE_SEPARATOR + "" + LINE_SEPARATOR + "</project>" + LINE_SEPARATOR ; private static void collectAllFiles ( File root , ArrayList collector , FileFilter fileFilter ) { File [ ] files = root . listFiles ( fileFilter ) ; for ( int i = 0 ; i < files . length ; i ++ ) { if ( files [ i ] . isDirectory ( ) ) { collectAllFiles ( files [ i ] , collector , fileFilter ) ; } else { String newElement = files [ i ] . getAbsolutePath ( ) ; newElement = newElement . replace ( '\\' , '/' ) ; collector . add ( newElement ) ; } } } private static void dumpAllProperties ( Writer writer , File sourceDir , ArrayList collector , String gcj_exe , String dest_dir ) throws IOException { writer . write ( "" + LINE_SEPARATOR ) ; for ( int i = 0 , max = collector . size ( ) ; i < max ; i ++ ) { String absolutePath = ( String ) collector . get ( i ) ; String fileName = absolutePath . substring ( sourceDir . getAbsolutePath ( ) . length ( ) + 1 ) ; writer . write ( MessageFormat . format ( "" + LINE_SEPARATOR , new Object [ ] { gcj_exe , dest_dir } ) ) ; writer . write ( "" ) ; writer . write ( fileName + " " + fileName + " -c -o " + getObjectName ( fileName ) + "\"/>" + LINE_SEPARATOR ) ; writer . write ( " tt</exec>" + LINE_SEPARATOR ) ; } } private static void dumpAllClassFiles ( Writer writer , File sourceDir , ArrayList collector , String gcj_exe , String dest_dir ) throws IOException { writer . write ( "" + LINE_SEPARATOR ) ; writer . write ( MessageFormat . format ( "" + LINE_SEPARATOR + "" + LINE_SEPARATOR + "" + LINE_SEPARATOR + "" + LINE_SEPARATOR + "" + LINE_SEPARATOR + "" + LINE_SEPARATOR + "" + LINE_SEPARATOR + "" + LINE_SEPARATOR + "" + LINE_SEPARATOR + "" + LINE_SEPARATOR + "" + LINE_SEPARATOR + "" + LINE_SEPARATOR + "" + LINE_SEPARATOR + "" + LINE_SEPARATOR + LINE_SEPARATOR , new Object [ ] { gcj_exe , dest_dir } ) ) ; } private static String getObjectName ( String fileName ) { return fileName . substring ( 0 , fileName . lastIndexOf ( '.' ) ) + ".o" ; } public static void main ( String [ ] args ) { if ( args . length != 5 ) { System . out . println ( "" ) ; return ; } try { BufferedWriter writer = new BufferedWriter ( new FileWriter ( new File ( args [ 0 ] ) ) ) ; writer . write ( HEADER ) ; File sourceDir = new File ( args [ 1 ] ) ; if ( sourceDir . exists ( ) ) { ArrayList collector = new ArrayList ( ) ; collectAllFiles ( sourceDir , collector , new FileFilter ( ) { public boolean accept ( File pathname ) { String fileName = pathname . getAbsolutePath ( ) ; return pathname . isDirectory ( ) || fileName . endsWith ( ".rsc" ) || fileName . endsWith ( ".properties" ) ; } } ) ; dumpAllProperties ( writer , sourceDir , collector , args [ 2 ] , args [ 3 ] ) ; if ( "source" . equals ( args [ 4 ] ) ) { writer . write ( MessageFormat . format ( SOURCE_FILES , new Object [ ] { args [ 2 ] , args [ 3 ] } ) ) ; } else { collector = new ArrayList ( ) ; collectAllFiles ( sourceDir , collector , new FileFilter ( ) { public boolean accept ( File pathname ) { String fileName = pathname . getAbsolutePath ( ) ; return pathname . isDirectory ( ) || fileName . endsWith ( ".class" ) ; } } ) ; dumpAllClassFiles ( writer , sourceDir , collector , args [ 2 ] , args [ 3 ] ) ; } } writer . write ( MessageFormat . format ( FOOTER , new Object [ ] { args [ 2 ] , args [ 3 ] } ) ) ; writer . flush ( ) ; writer . close ( ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } } } </s>