groovy.ui.GroovyMain Java Examples

The following examples show how to use groovy.ui.GroovyMain. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Shell.java    From knox with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("PMD.DoNotUseThreads") // we need to define a Thread to be able to register a shutdown hook
public static void main( String... args ) throws Exception {
  PropertyConfigurator.configure( System.getProperty( "log4j.configuration" ) );
  if( args.length > 0 ) {
    if (NON_INTERACTIVE_COMMANDS.contains(args[0])) {
        final String[] arguments = new String[args.length == 1 ? 1:3];
        arguments[0] = args[0];
        if (args.length > 1) {
          arguments[1] = "--gateway";
          arguments[2] = args[1];
        }
        KnoxSh.main(arguments);
    } else {
        GroovyMain.main( args );
    }
  } else {
    Groovysh shell = new Groovysh();
    Runtime.getRuntime().addShutdownHook(new Thread() {
      @Override
      public void run() {
        System.out.println("Closing any open connections ...");
        AbstractSQLCommandSupport sqlcmd = (AbstractSQLCommandSupport) shell.getRegistry().getProperty(":ds");
        sqlcmd.closeConnections();
        sqlcmd = (AbstractSQLCommandSupport) shell.getRegistry().getProperty(":sql");
        sqlcmd.closeConnections();
      }
    });
    for( String name : IMPORTS ) {
      shell.execute( "import " + name );
    }
    // register custom groovysh commands
    shell.register(new SelectCommand(shell));
    shell.register(new DataSourceCommand(shell));
    shell.register(new CSVCommand(shell));
    shell.register(new WebHDFSCommand(shell));
    shell.run( null );
  }
}
 
Example #2
Source File: GroovyShell.java    From groovy with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) {
    GroovyMain.main(args);
}