static void main ( String [ ] args , PrintStream out ) throws IOException { try { Main main = null ; Option [ ] options = Option . parseCLArgs ( args , TEMPLATES ) ; Option helpOption = ( options == null ) ? null : findOption ( HELP_OPTION . getName ( ) , options ) ; Option installOption = ( options == null ) ? null : findOption ( INSTALL_OPTION . getName ( ) , options ) ; Option configOption = ( options == null ) ? null : findOption ( CONFIG_OPTION . getName ( ) , options ) ; Option typeOption = ( options == null ) ? null : findOption ( TYPE_OPTION . getName ( ) , options ) ; if ( helpOption != null ) { out . println ( usage ( ) ) ; } else if ( installOption != null ) { SystemConfiguration . generateConfiguration ( System . in , out , new File ( installOption . getValue ( ) ) ) ; } else if ( configOption != null ) { FileInputStream fis = null ; Properties props = new Properties ( ) ; try { fis = new FileInputStream ( configOption . getValue ( ) ) ; props . load ( fis ) ; } finally { if ( fis != null ) { fis . close ( ) ; } } main = new Main ( props ) ; } else { main = new Main ( ) ; } if ( main != null ) { ClientType type ; try { type = typeOption == null ? COMMIT_METRICS : ClientType . valueOf ( typeOption . getValue ( ) ) ; } catch ( Exception ex ) { type = COMMIT_METRICS ; } final Thread mainThread = Thread . currentThread ( ) ; Runtime . getRuntime ( ) . addShutdownHook ( new Thread ( new Runnable ( ) { @ Override public void run ( ) { mainThread . interrupt ( ) ; try { mainThread . join ( ) ; } catch ( InterruptedException ex ) { LOGGER . warn ( "Interrupted while shutting down. Giving up." ) ; } } } ) ) ; main . invoke ( type ) ; } } catch ( IllegalArgumentException ex ) { out . println ( usage ( ) ) ; } // end try-catch }
The main invocation method .