List of usage examples for org.apache.commons.cli ParseException initCause
public synchronized Throwable initCause(Throwable cause)
From source file:de.ncoder.studipsync.ui.StandardUIAdapter.java
public static UIAdapter loadUIAdapter(String classname) throws ParseException, ClassNotFoundException { try {// w w w . j a v a 2s . c o m Class<?> clazz = Class.forName(classname); Object instance = clazz.newInstance(); if (!(instance instanceof UIAdapter)) { throw new ParseException(instance + " is not an UI adapter"); } return (UIAdapter) instance; } catch (InstantiationException | IllegalAccessException e) { ParseException pe = new ParseException( "Could not instantiate class " + classname + ". " + e.getMessage()); pe.initCause(e); throw pe; } }
From source file:de.ncoder.studipsync.storage.StandardPathResolver.java
public static PathResolver loadPathResolver(String classname) throws ParseException, ClassNotFoundException { try {//from w w w . j a v a 2 s . c o m Class<?> clazz = Class.forName(classname); Object instance = clazz.newInstance(); if (!(instance instanceof PathResolver)) { throw new ParseException(instance + " is not a PathResolver"); } return (PathResolver) instance; } catch (InstantiationException | IllegalAccessException e) { ParseException pe = new ParseException( "Could not instantiate class " + classname + ". " + e.getMessage()); pe.initCause(e); throw pe; } }
From source file:de.ncoder.studipsync.ui.StandardUIAdapter.java
public static UIAdapter getUIAdapter(String type) throws ParseException { if (type != null) { try {/*from www . j a va 2 s. co m*/ StandardUIAdapter ui = valueOf(type); ui.init(); return ui; } catch (IllegalArgumentException earg) { try { return loadUIAdapter(type); } catch (ClassNotFoundException eclass) { ParseException pe = new ParseException( type + " is neither an UIType nor can it be resolved to a Java class."); pe.initCause(eclass); pe.addSuppressed(earg); throw pe; } } } else { return getDefaultUIAdapter(); } }
From source file:de.ncoder.studipsync.storage.StandardPathResolver.java
public static PathResolver getPathResolver(String type) throws ParseException { if (type != null) { try {// www.j av a 2s . c o m return valueOf(type); } catch (IllegalArgumentException earg) { try { return loadPathResolver(type); } catch (ClassNotFoundException eclass) { ParseException pe = new ParseException( type + " is neither an UIType nor can it be resolved to a Java class."); pe.initCause(eclass); pe.addSuppressed(earg); throw pe; } } } else { return getDefaultPathResolver(); } }
From source file:com.cloudera.sqoop.tool.SqoopTool.java
/** * Configures a SqoopOptions according to the specified arguments. * Reads a set of arguments and uses them to configure a SqoopOptions * and its embedded configuration (i.e., through GenericOptionsParser.) * Stores any unparsed arguments in the extraArguments field. * * @param args the arguments to parse./*from w w w . ja va 2s .c o m*/ * @param conf if non-null, set as the configuration for the returned * SqoopOptions. * @param in a (perhaps partially-configured) SqoopOptions. If null, * then a new SqoopOptions will be used. If this has a null configuration * and conf is null, then a new Configuration will be inserted in this. * @param useGenericOptions if true, will also parse generic Hadoop * options into the Configuration. * @return a SqoopOptions that is fully configured by a given tool. */ public SqoopOptions parseArguments(String[] args, Configuration conf, SqoopOptions in, boolean useGenericOptions) throws ParseException, SqoopOptions.InvalidOptionsException { SqoopOptions out = in; if (null == out) { out = new SqoopOptions(); } if (null != conf) { // User specified a configuration; use it and override any conf // that may have been in the SqoopOptions. out.setConf(conf); } else if (null == out.getConf()) { // User did not specify a configuration, but neither did the // SqoopOptions. Fabricate a new one. out.setConf(new Configuration()); } String[] toolArgs = args; // args after generic parser is done. if (useGenericOptions) { try { toolArgs = ConfigurationHelper.parseGenericOptions(out.getConf(), args); } catch (IOException ioe) { ParseException pe = new ParseException("Could not parse generic arguments"); pe.initCause(ioe); throw pe; } } // Parse tool-specific arguments. ToolOptions toolOptions = new ToolOptions(); configureOptions(toolOptions); CommandLineParser parser = new SqoopParser(); CommandLine cmdLine = parser.parse(toolOptions.merge(), toolArgs, true); applyOptions(cmdLine, out); this.extraArguments = cmdLine.getArgs(); return out; }
From source file:org.apache.sqoop.tool.SqoopTool.java
/** * Configures a SqoopOptions according to the specified arguments. * Reads a set of arguments and uses them to configure a SqoopOptions * and its embedded configuration (i.e., through GenericOptionsParser.) * Stores any unparsed arguments in the extraArguments field. * * @param args the arguments to parse./*from ww w . java 2 s .co m*/ * @param conf if non-null, set as the configuration for the returned * SqoopOptions. * @param in a (perhaps partially-configured) SqoopOptions. If null, * then a new SqoopOptions will be used. If this has a null configuration * and conf is null, then a new Configuration will be inserted in this. * @param useGenericOptions if true, will also parse generic Hadoop * options into the Configuration. * @return a SqoopOptions that is fully configured by a given tool. */ public SqoopOptions parseArguments(String[] args, Configuration conf, SqoopOptions in, boolean useGenericOptions) throws ParseException, SqoopOptions.InvalidOptionsException { SqoopOptions out = in; if (null == out) { out = new SqoopOptions(); } if (null != conf) { // User specified a configuration; use it and override any conf // that may have been in the SqoopOptions. out.setConf(conf); } else if (null == out.getConf()) { // User did not specify a configuration, but neither did the // SqoopOptions. Fabricate a new one. out.setConf(new Configuration()); } // This tool is the "active" tool; bind it in the SqoopOptions. //TODO(jarcec): Remove the cast when SqoopOptions will be moved // to apache package out.setActiveSqoopTool((com.cloudera.sqoop.tool.SqoopTool) this); String[] toolArgs = args; // args after generic parser is done. if (useGenericOptions) { try { toolArgs = ConfigurationHelper.parseGenericOptions(out.getConf(), args); } catch (IOException ioe) { ParseException pe = new ParseException("Could not parse generic arguments"); pe.initCause(ioe); throw pe; } } // Parse tool-specific arguments. ToolOptions toolOptions = new ToolOptions(); configureOptions(toolOptions); CommandLineParser parser = new SqoopParser(); CommandLine cmdLine = parser.parse(toolOptions.merge(), toolArgs, true); applyOptions(cmdLine, out); this.extraArguments = cmdLine.getArgs(); return out; }
From source file:org.finra.dm.core.ArgumentParser.java
/** * Retrieves the argument value, if any, as a String object and converts it to a boolean value. * * @param option the option that we want to query for * @param defaultValue the default value to return if option is not set or missing an argument value * * @return the value of the argument converted to a boolean value or default value when the option is not set or missing an argument value * @throws ParseException if the value of the argument is an invalid boolean value * *//*from w w w . ja v a2 s. co m*/ @SuppressFBWarnings(value = "UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR", justification = "This is a false positive. A null check is present.") public Boolean getStringValueAsBoolean(Option option, Boolean defaultValue) throws ParseException { Boolean result; ensureCommandLineNotNull(); String stringValue = getStringValue(option); if (StringUtils.isNotBlank(stringValue)) { // Use custom boolean editor without allowed empty strings to convert the value of the argument to a boolean value. CustomBooleanEditor customBooleanEditor = new CustomBooleanEditor(false); try { customBooleanEditor.setAsText(stringValue); } catch (IllegalArgumentException e) { ParseException parseException = new ParseException(e.getMessage()); parseException.initCause(e); throw parseException; } result = (Boolean) customBooleanEditor.getValue(); } else { result = defaultValue; } return result; }