/** * Return the tool specified by the 'toolName' argument. * (package-protected for use by the HelpTool, and for testing.) * * @param toolName the name of the tool to instantiate. * @return the FijiTool that provides for that name, or null if none does. */ FijiTool getToolForName(String toolName) { FijiTool tool = null; // Iterate over available tools, searching for the one with // the same name as the supplied tool name argument. for (FijiTool candidate : Lookups.get(FijiTool.class)) { if (toolName.equals(candidate.getName())) { tool = candidate; break; } } return tool; }
FijiTool subTool = new FijiToolLauncher().getToolForName(toolName); if (null != subTool) { System.out.println(subTool.getName() + ": " + subTool.getDescription()); System.out.println(""); subTool.toolMain(Collections.singletonList("--help")); return 0; } else { String name = tool.getName(); if (null == name) { System.out.println("Error: Got null from getName() in class: " String desc = tool.getDescription(); if (null != desc) { System.out.print(" " + name);
/** * 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)); }