/** * Programmatic entry point to the tool launcher if a tool is already selected. * Hadoop property-based arguments will be parsed by FijiToolLauncher.run() * in a manner similar to Hadoop's ToolRunner. * * @param tool The FijiTool to run. * @param args The command-line arguments, excluding the name of the tool to run. * @throws Exception If there is an error. * @return 0 on program success, non-zero on error. */ public int run(FijiTool tool, String[] args) throws Exception { Configuration conf = getConf(); if (conf == null) { conf = new Configuration(); setConf(conf); } // Mimic behavior of Hadoop's ToolRunner.run(). GenericOptionsParser parser = new GenericOptionsParser(conf, args); conf = HBaseConfiguration.addHbaseResources(conf); tool.setConf(conf); // Get remaining arguments and invoke the tool with them. String[] toolArgs = parser.getRemainingArgs(); // Work around for CDH4 and Hadoop1 setting different "GenericOptionsParser used" flags. conf.setBooleanIfUnset("mapred.used.genericoptionsparser", true); conf.setBooleanIfUnset("mapreduce.client.genericoptionsparser.used", true); return tool.toolMain(Arrays.asList(toolArgs)); }