Example usage for org.apache.commons.cli ParseException ParseException

List of usage examples for org.apache.commons.cli ParseException ParseException

Introduction

In this page you can find the example usage for org.apache.commons.cli ParseException ParseException.

Prototype

public ParseException(String message) 

Source Link

Document

Construct a new ParseException with the specified detail message.

Usage

From source file:com.conversantmedia.mapreduce.tool.AnnotatedToolContext.java

@Override
protected void populateExtendedContext(CommandLine line) throws ParseException {
    // Populate the underlying annotated context object
    // with the values from the parsed command line arguments.
    SimpleTypeConverter converter = new SimpleTypeConverter();

    for (Entry<String, Field> e : this.fieldsMap.entrySet()) {
        String optName = e.getKey();
        Field field = e.getValue();
        String defaultValue = defaultValuesMap.get(optName);
        field.setAccessible(true);/*w  w w. j av  a 2 s . c o  m*/
        try {
            if (line.hasOption(optName)) {
                Object value = line.getOptionValue(optName);
                if (value == null) {
                    value = Boolean.TRUE;
                }
                value = converter.convertIfNecessary(value, field.getType());
                field.set(this.bean, value);
            } else if (StringUtils.isNotBlank(defaultValue)) {
                Object value = converter.convertIfNecessary(defaultValue, field.getType());
                field.set(this.bean, value);
            }
        } catch (IllegalArgumentException | IllegalAccessException e1) {
            throw new ParseException(e1.getMessage());
        }
    }
}

From source file:fr.ens.biologie.genomique.eoulsan.actions.IntegrationTestAction.java

@Override
public void action(final List<String> arguments) {

    final Options options = makeOptions();
    final CommandLineParser parser = new GnuParser();

    File testNGReportDirectory = null;
    File testOutputDirectory = null;
    int argsOptions = 0;

    try {/*w w  w.j ava  2  s  .  co  m*/

        // parse the command line arguments
        final CommandLine line = parser.parse(options, arguments.toArray(new String[arguments.size()]), true);

        // Help option
        if (line.hasOption("help")) {
            help(options);
        }

        if (line.hasOption("testconf")) {
            final String val = line.getOptionValue("testconf").trim();

            if (!(new File(val).exists() && new File(val).canRead())) {
                Common.errorExit(null, "Integration test configuration file doesn't exists");
            }

            // Configuration test files
            System.setProperty(ITFactory.IT_CONF_PATH_SYSTEM_KEY, val);
            argsOptions += 2;

        }

        if (line.hasOption("exec")) {

            // Path to application version
            System.setProperty(ITFactory.IT_APPLICATION_PATH_KEY_SYSTEM_KEY,
                    line.getOptionValue("exec").trim());
            argsOptions += 2;
        }

        // Optional argument
        if (line.hasOption("f")) {

            // List all test to launch
            System.setProperty(ITFactory.IT_TEST_LIST_PATH_SYSTEM_KEY, line.getOptionValue("f").trim());
            argsOptions += 2;
        }

        // Optional argument
        if (line.hasOption("t")) {

            // Test to launch
            System.setProperty(ITFactory.IT_TEST_SYSTEM_KEY, line.getOptionValue("t").trim());
            argsOptions += 2;
        }

        // Optional argument
        if (line.hasOption("expected")) {
            final String s = line.getOptionValue("expected").trim();

            // Value equals all, regenerate all expected directories generated
            // automatically
            if (s.toLowerCase(Globals.DEFAULT_LOCALE).equals("all")) {
                System.setProperty(ITFactory.IT_GENERATE_ALL_EXPECTED_DATA_SYSTEM_KEY, "true");
            }
            // Value equals new, regenerate expected directories doesn't exists
            else if (s.toLowerCase(Globals.DEFAULT_LOCALE).equals("new")) {
                System.setProperty(ITFactory.IT_GENERATE_NEW_EXPECTED_DATA_SYSTEM_KEY, "true");
            }

            argsOptions += 2;
        }

        // Optional argument
        if (line.hasOption("d")) {
            // List all test to launch
            testOutputDirectory = new File(line.getOptionValue("d").trim());

            // Add property for test output directory
            System.setProperty(ITFactory.IT_OUTPUT_DIR_SYSTEM_KEY, testOutputDirectory.getAbsolutePath());

            argsOptions += 2;
        }

        if (line.hasOption("o")) {

            // List all test to launch
            testNGReportDirectory = new File(line.getOptionValue("o").trim());

            try {
                FileUtils.checkExistingDirectoryFile(testNGReportDirectory, "Output TestNG report");
            } catch (IOException e) {

                throw new ParseException(e.getMessage());
            }

            argsOptions += 2;
        }

    } catch (final ParseException e) {
        Common.errorExit(e, "Error while parse parameter file: " + e.getMessage());
    }

    if (argsOptions == 0 || arguments.size() != argsOptions) {
        help(options);
    }

    // Execute program in local mode
    runIT(testNGReportDirectory);
}

From source file:com.aliyun.odps.ship.DShip.java

private static void show(String[] args) throws ParseException, IOException {

    OptionsBuilder.buildShowOption(args);
    String cmd = DshipContext.INSTANCE.get(Constants.SHOW_COMMAND);
    if (cmd.equals("history")) {
        int n = DshipContext.INSTANCE.get("number") == null ? 20
                : Integer.valueOf(DshipContext.INSTANCE.get("number"));
        SessionHistoryManager.showHistory(n);
    } else if (cmd.equals("log")) {
        Util.checkSession(DshipContext.INSTANCE.get(Constants.SESSION_ID));
        SessionHistory sh = DshipContext.INSTANCE.get(Constants.SESSION_ID) == null
                ? SessionHistoryManager.getLatest()
                : SessionHistoryManager.createSessionHistory(DshipContext.INSTANCE.get(Constants.SESSION_ID));
        sh.showLog();/*from w ww. java 2 s . c  om*/
    } else if (cmd.equals("bad")) {
        Util.checkSession(DshipContext.INSTANCE.get(Constants.SESSION_ID));
        SessionHistory sh = DshipContext.INSTANCE.get(Constants.SESSION_ID) == null
                ? SessionHistoryManager.getLatest()
                : SessionHistoryManager.createSessionHistory(DshipContext.INSTANCE.get(Constants.SESSION_ID));
        sh.showBad();
    } else {
        throw new ParseException("Unknown command: '" + cmd + "'\nType 'tunnel help show' for usage.");
    }
}

From source file:co.turnus.analysis.pipelining.SimplePipeliningCliLauncher.java

private static Configuration parseCommandLine(CommandLine cmd) throws ParseException {
    Configuration config = new BaseConfiguration();

    StringBuffer s = new StringBuffer();

    config.setProperty(VERBOSE, cmd.hasOption("v"));

    if (!cmd.hasOption("t")) {
        s.append("Trace project directory not specified. ");
    } else {//w  w w  .  j a v  a 2s .  co m
        String fileName = cmd.getOptionValue("t", "");
        File file = new File(fileName);
        if (file == null || !file.exists()) {
            s.append("Trace project does not exists. ");
        } else {
            config.setProperty(TRACE_PROJECT, fileName);
        }
    }

    if (!cmd.hasOption("o")) {
        s.append("Output directory not specified. ");
    } else {
        String fileName = cmd.getOptionValue("o", "");
        File file = new File(fileName);
        if (file == null || !file.exists()) {
            s.append("Output directory does not exists. ");
        } else {
            config.setProperty(OUTPUT_PATH, fileName);
        }
    }

    if (cmd.hasOption("xls")) {
        String fileName = cmd.getOptionValue("xls", "");
        if (fileName == null || fileName.isEmpty()) {
            s.append("XLS file name is not correct. ");
        } else {
            config.setProperty(XLS, fileName);
        }

    }

    String error = s.toString();
    if (!error.isEmpty()) {
        throw new ParseException(error);
    }

    return config;
}

From source file:com.symbian.driver.plugins.ftptelnet.FtpTransfer.java

private FtpTransfer(String aTransport) throws ParseException {
    // check transport is valid
    String lTransport = aTransport;
    if (!isTransportValid(lTransport)) {
        throw new ParseException("Transport " + lTransport + " incorrect.");
    }//w w  w .  j a  v a2s  .  c  o  m

    // connect FTP
    connectFTP();

}

From source file:com.schatzforensic.byteplotter.Main.java

private boolean getBoolean(CommandLine line, String parameter) throws ParseException {
    if (line.hasOption(parameter)) {
        return Boolean.parseBoolean(line.getOptionValue(parameter));
    } else {/*from   w ww  .  java 2 s  .  c om*/
        throw new ParseException(parameter);
    }
}

From source file:com.paxxis.cornerstone.messaging.service.shell.ServiceShell.java

private boolean processDatabaseUpdates(CommandLine cmd) throws Exception {
    String vals[] = getCommandLine().getOptionValues("dbupdate");
    if (vals != null) {
        if (vals.length != 2 && vals.length != 3) {
            throw new ParseException("Invalid argument for database update option");
        }// w ww . j  a  v  a2 s.com
        doDatabaseUpdate(vals);
        return true;
    }

    return false;
}

From source file:bdsup2sub.cli.CommandLineParser.java

private void parseInputFileOption(CommandLine line) throws ParseException {
    if (line.getArgList().isEmpty() && line.hasOption(OUTPUT_FILE)) {
        throw new ParseException("Missing input file.");
    } else if (line.getArgList().size() > 1) {
        throw new ParseException("Too many input files.");
    } else if (line.getArgList().size() == 1) {
        inputFile = new File(line.getArgList().get(0).toString());
        if (!inputFile.exists()) {
            throw new ParseException("Input file not found: " + inputFile.getAbsolutePath());
        }/*ww  w.  j a v a2  s  .  co m*/
    }
}

From source file:com.aliyun.odps.ship.common.RecordConverter.java

/**
 * byte array to tunnel record/*from  w  w  w . j a  v  a  2 s  . c  o  m*/
 */
public Record parse(byte[][] line) throws ParseException, UnsupportedEncodingException {

    if (line == null) {
        return null;
    }
    int cols = schema.getColumns().size();

    if (line.length != cols) {
        throw new ParseException(
                Constants.ERROR_INDICATOR + "column mismatch, expected " + schema.getColumns().size()
                        + " columns, " + line.length + " columns found, please check data or delimiter\n");
    }

    boolean isIgnoreCharset = Util.isIgnoreCharset(charset);

    int idx = 0;
    for (byte[] v : line) {
        OdpsType type = schema.getColumn(idx).getType();
        String eMsg = "";
        try {
            if (Arrays.equals(v, nullBytes)) {
                r.set(idx, null);
                idx++;
                continue;
            }

            switch (type) {
            case BIGINT: {
                String vStr = new String(v, defaultCharset);
                r.setBigint(idx, Long.valueOf(vStr));
                break;
            }
            case DOUBLE: {
                String vStr = new String(v, defaultCharset);
                r.setDouble(idx, Double.valueOf(vStr));
                break;
            }
            case DATETIME: {
                String vStr = new String(v, defaultCharset);
                r.setDatetime(idx, dateFormatter.parse(vStr));
                break;
            }
            case BOOLEAN: {
                String vStr = new String(v, defaultCharset);
                vStr = vStr.trim().toLowerCase();
                if (vStr.equals("true") || vStr.equals("false")) {
                    r.setBoolean(idx, vStr.equals("true"));
                } else if (vStr.equals("0") || vStr.equals("1")) {
                    r.setBoolean(idx, vStr.equals("1"));
                } else {
                    eMsg = "invalid boolean type, expect: 'true'|'false'|'0'|'1'";
                    throw new IllegalArgumentException(eMsg);
                }
                break;
            }
            case STRING:
                try {
                    if (isIgnoreCharset) {
                        r.setString(idx, v);
                    } else {
                        r.setString(idx, new String(v, charset));
                    }
                } catch (IllegalArgumentException e) {
                    // for big than 8M
                    eMsg = "string type big than 8M";
                    throw new IllegalArgumentException(eMsg);
                }
                break;
            case DECIMAL:
                String vStr = new String(v, defaultCharset);
                r.setDecimal(idx, new BigDecimal(vStr));
                break;
            default:
                eMsg = "Unknown column type";
                throw new IllegalArgumentException(eMsg);
            }
        } catch (Exception e) {
            String val;
            String vStr;
            if (isIgnoreCharset) {
                vStr = new String(v, Constants.REMOTE_CHARSET);
            } else {
                vStr = new String(v, charset);
            }
            if (vStr.length() > 20) {
                val = vStr.substring(0, 17) + "...";
            } else {
                val = vStr;
            }
            throw new ParseException(Constants.ERROR_INDICATOR + "format error - " + ":" + (idx + 1) + ", "
                    + type + ":'" + val + "'  " + eMsg);
        }
        idx++;
    }
    return r;
}

From source file:com.archivas.clienttools.arcmover.cli.AbstractArcCli.java

public static String validateProfileNameExists(String value) throws ParseException {
    // Fix up local file system here, we also take LFS
    if (value.equalsIgnoreCase(LFS)) {
        value = FileSystemProfile.DEFAULT_FILESYSTEM_PROFILE_NAME;
    }/*from   w  ww . j  av a 2  s.  c  o m*/

    AbstractProfileBase profile = ProfileManager.getProfileByName(value);
    if (profile == null) {
        throw new ParseException("Profile does not exist with name:  " + value);
    }

    return value;
}