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

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

Introduction

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

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:com.thoughtworks.xstream.tools.benchmark.parsers.ParserBenchmark.java

public static void main(String[] args) {
    int counter = 1000;

    Options options = new Options();
    options.addOption("p", "product", true, "Class name of the product to use for benchmark");
    options.addOption("n", true, "Number of repetitions");

    Harness harness = new Harness();
    harness.addMetric(new DeserializationSpeedMetric(0, false) {
        public String toString() {
            return "Initial run deserialization";
        }//from   ww w .j  av a2  s . c om
    });

    Parser parser = new PosixParser();
    try {
        CommandLine commandLine = parser.parse(options, args);
        String name = null;
        if (commandLine.hasOption('p')) {
            name = commandLine.getOptionValue('p');
        }
        if (name == null || name.equals("DOM")) {
            harness.addProduct(new XStreamDom());
        }
        if (name == null || name.equals("JDOM")) {
            harness.addProduct(new XStreamJDom());
        }
        if (name == null || name.equals("DOM4J")) {
            harness.addProduct(new XStreamDom4J());
        }
        if (name == null || name.equals("XOM")) {
            harness.addProduct(new XStreamXom());
        }
        if (name == null || name.equals("BEAStAX")) {
            harness.addProduct(new XStreamBEAStax());
        }
        if (name == null || name.equals("Woodstox")) {
            harness.addProduct(new XStreamWoodstox());
        }
        if (JVM.is16() && (name == null || name.equals("SJSXP"))) {
            harness.addProduct(new XStreamSjsxp());
        }
        if (name == null || name.equals("Xpp3")) {
            harness.addProduct(new XStreamXpp3());
        }
        if (name == null || name.equals("kXML2")) {
            harness.addProduct(new XStreamKXml2());
        }
        if (name == null || name.equals("Xpp3DOM")) {
            harness.addProduct(new XStreamXpp3DOM());
        }
        if (name == null || name.equals("kXML2DOM")) {
            harness.addProduct(new XStreamKXml2DOM());
        }
        if (commandLine.hasOption('n')) {
            counter = Integer.parseInt(commandLine.getOptionValue('n'));
        }
    } catch (ParseException e) {
        e.printStackTrace();
    }

    harness.addMetric(new DeserializationSpeedMetric(counter, false));
    harness.addTarget(new BasicTarget());
    harness.addTarget(new ExtendedTarget());
    harness.addTarget(new ReflectionTarget());
    harness.addTarget(new SerializableTarget());
    harness.addTarget(new JavaBeanTarget());
    if (false) {
        harness.addTarget(new FieldReflection());
        harness.addTarget(new HierarchyLevelReflection());
        harness.addTarget(new InnerClassesReflection());
        harness.addTarget(new StaticInnerClassesReflection());
    }
    harness.run(new TextReporter(new PrintWriter(System.out, true)));
    System.out.println("Done.");
}

From source file:com.cws.esolutions.core.main.EmailUtility.java

public static final void main(final String[] args) {
    final String methodName = EmailUtility.CNAME + "#main(final String[] args)";

    if (DEBUG) {/* w  w w .  j  a v a 2  s.  co m*/
        DEBUGGER.debug(methodName);
        DEBUGGER.debug("Value: {}", (Object) args);
    }

    if (args.length == 0) {
        HelpFormatter usage = new HelpFormatter();
        usage.printHelp(EmailUtility.CNAME, options, true);

        return;
    }

    try {
        CommandLineParser parser = new PosixParser();
        CommandLine commandLine = parser.parse(options, args);

        URL xmlURL = null;
        JAXBContext context = null;
        Unmarshaller marshaller = null;
        CoreConfigurationData configData = null;

        xmlURL = FileUtils.getFile(commandLine.getOptionValue("config")).toURI().toURL();
        context = JAXBContext.newInstance(CoreConfigurationData.class);
        marshaller = context.createUnmarshaller();
        configData = (CoreConfigurationData) marshaller.unmarshal(xmlURL);

        EmailMessage message = new EmailMessage();
        message.setMessageTo(new ArrayList<String>(Arrays.asList(commandLine.getOptionValues("to"))));
        message.setMessageSubject(commandLine.getOptionValue("subject"));
        message.setMessageBody((String) commandLine.getArgList().get(0));
        message.setEmailAddr((StringUtils.isNotEmpty(commandLine.getOptionValue("from")))
                ? new ArrayList<String>(Arrays.asList(commandLine.getOptionValue("from")))
                : new ArrayList<String>(Arrays.asList(configData.getMailConfig().getMailFrom())));

        if (DEBUG) {
            DEBUGGER.debug("EmailMessage: {}", message);
        }

        try {
            EmailUtils.sendEmailMessage(configData.getMailConfig(), message, false);
        } catch (MessagingException mx) {
            System.err.println(
                    "An error occurred while sending the requested message. Exception: " + mx.getMessage());
        }
    } catch (ParseException px) {
        px.printStackTrace();
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(EmailUtility.CNAME, options, true);
    } catch (MalformedURLException mx) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(EmailUtility.CNAME, options, true);
    } catch (JAXBException jx) {
        jx.printStackTrace();
        System.err.println("An error occurred while loading the provided configuration file. Cannot continue.");
    }
}

From source file:io.github.azige.whitespace.Cli.java

public static void main(String[] args) {
    Options options = new Options().addOption("h", "help", false, "??")
            .addOptionGroup(new OptionGroup()
                    .addOption(new Option("p",
                            "????????"))
                    .addOption(new Option("c", "?????")))
            .addOption(null, "szm", false,
                    "????")
            .addOption("e", "encoding", true, "??" + DEFAULT_ENCODING);

    try {/*from   w  w  w .jav  a 2s  .  c o  m*/
        CommandLineParser parser = new BasicParser();
        CommandLine cl = parser.parse(options, args);

        if (cl.hasOption('h')) {
            printHelp(System.out, options);
            return;
        }

        if (cl.hasOption('e')) {
            encoding = Charset.forName(cl.getOptionValue('e'));
        } else {
            encoding = Charset.forName(DEFAULT_ENCODING);
        }

        if (cl.hasOption("szm")) {
            useSzm = true;
        }

        String[] fileArgs = cl.getArgs();
        if (fileArgs.length != 1) {
            printHelp(System.err, options);
            return;
        }

        try (InputStream input = Files.newInputStream(Paths.get(fileArgs[0]))) {
            if (cl.hasOption('p')) {
                printPseudoCode(input);
            } else if (cl.hasOption('c')) {
                compile(input, fileArgs[0]);
            } else {
                execute(input, fileArgs[0]);
            }
        }
    } catch (ParseException ex) {
        ex.printStackTrace();
        printHelp(System.err, options);
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

From source file:com.osrdata.etltoolbox.fileloader.Main.java

/**
 * Main entry point into the application.
 * @param args command line argunemtns//w w w  .ja  v  a 2 s .com
 */
public static void main(String[] args) {
    Options options = new Options();
    options.addOption(new Option("s", "spec", true, "Source-to-target specification file"));
    options.addOption(new Option("d", "directory", true, "Source directory to load"));
    options.addOption(new Option("f", "file", true, "File to perform operation on"));
    options.addOption(new Option("r", "replace", false, "Replace previously loaded data"));
    options.addOption(new Option("t", "trace", true, "Trace records processed at specified interval"));

    CommandLineParser parser = new BasicParser();

    try {
        CommandLine line = parser.parse(options, args);

        if (line.hasOption("spec") && (line.hasOption("directory") || line.hasOption("file"))) {
            FileLoader loader = new FileLoader(line);

            loader.init();

            if (line.hasOption("file")) {
                loader.load(new File(line.getOptionValue("file")));
            } else if (line.hasOption("directory")) {
                File directory = new File(line.getOptionValue("directory"));

                if (directory.isDirectory()) {
                    File[] files = directory.listFiles();

                    for (File file : files) {
                        loader.load(file);
                    }
                } else {
                    log.fatal(directory.getAbsolutePath() + " does not appear to be a directory.");
                }
            }
        } else {
            usage();
        }
    } catch (ParseException e) {
        usage();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:com.aleggeup.util.App.java

public static void main(final String[] args) {
    final CommandLineParser parser = new PosixParser();
    final Options options = buildOptions();

    File sourceFile = null;/*from   w  ww .j  a v  a2s. co m*/
    File targetFile = null;

    try {
        final CommandLine commandLine = parser.parse(options, args);

        if (commandLine.getOptions().length == 0 || commandLine.hasOption('h')) {
            printHelp(options);
            System.exit(0);
        }

        if (commandLine.hasOption('s')) {
            sourceFile = new File(commandLine.getOptionValue('s')).getCanonicalFile();
        }

        if (commandLine.hasOption('t')) {
            targetFile = new File(commandLine.getOptionValue('t')).getCanonicalFile();
        }

    } catch (final ParseException e) {
        printHelp(options);
        System.exit(-1);
    } catch (final IOException e) {
        e.printStackTrace();
    }

}

From source file:edu.kit.checkstyle.Main.java

/**
 * Loops over the files specified checking them for errors. The exit code
 * is the number of errors found in all the files.
 * @param aArgs the command line arguments
 **//*from   ww  w  . j av  a  2 s  . c om*/
public static void main(String[] aArgs) {
    // parse the parameters
    final CommandLineParser clp = new PosixParser();
    CommandLine line = null;
    try {
        line = clp.parse(OPTS, aArgs);
    } catch (final ParseException e) {
        e.printStackTrace();
        usage();
    }
    assert line != null;

    // setup the properties
    final Properties properties = System.getProperties();

    final Configuration config = loadConfig(properties);

    AuditListener listener = new QualifiedListener();
    final List<File> files = getFilesToProcess(line);
    final Checker checker = createChecker(config);
    checker.addListener(listener);
    checker.process(files);
    checker.destroy();
    System.exit(0);
}

From source file:com.browseengine.bobo.index.MakeBobo.java

/**
 * @param args/*from  w  ww .  ja v a 2s.c o m*/
 */
public static void main(String[] args) throws IOException {
    // TODO Auto-generated method stub

    Option help = new Option("help", false, "print this message");

    OptionBuilder.withArgName("path");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("data source - required");
    Option src = OptionBuilder.create("source");
    src.setRequired(true);

    OptionBuilder.withArgName("path");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("index to create - required");
    Option index = OptionBuilder.create("index");
    index.setRequired(true);

    OptionBuilder.withArgName("file");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("field configuration - optional");
    Option conf = OptionBuilder.create("conf");

    OptionBuilder.withArgName("class");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("class name of the data digester - default: xml digester");
    Option digesterOpt = OptionBuilder.create("digester");

    OptionBuilder.withArgName("name");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("character set name - default: UTF-8");
    Option charset = OptionBuilder.create("charset");

    OptionBuilder.withArgName("maxdocs");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("maximum number of documents - default: 100");
    Option maxdocs = OptionBuilder.create("maxdocs");

    Options options = new Options();
    options.addOption(help);
    options.addOption(conf);
    options.addOption(index);
    options.addOption(src);
    options.addOption(charset);
    options.addOption(digesterOpt);
    options.addOption(maxdocs);

    //       create the parser

    CommandLineParser parser = new BasicParser();
    try {
        // parse the command line arguments
        CommandLine line = parser.parse(options, args);
        String output = line.getOptionValue("index");
        File data = new File(line.getOptionValue("source"));

        Class digesterClass;
        if (line.hasOption("digester"))
            digesterClass = Class.forName(line.getOptionValue("digester"));
        else
            throw new RuntimeException("digester not specified");

        Charset chset;
        if (line.hasOption("charset")) {
            chset = Charset.forName(line.getOptionValue("charset"));
        } else {
            chset = Charset.forName("UTF-8");
        }

        int maxDocs;
        try {
            maxDocs = Integer.parseInt(line.getOptionValue("maxdocs"));
        } catch (Exception e) {
            maxDocs = 100;
        }

        FileDigester digester;
        try {
            Constructor constructor = digesterClass.getConstructor(new Class[] { File.class });
            digester = (FileDigester) constructor.newInstance(new Object[] { data });
            digester.setCharset(chset);
            digester.setMaxDocs(maxDocs);
        } catch (Exception e) {
            throw new RuntimeException("Invalid digester class.", e);
        }

        BoboIndexer indexer = new BoboIndexer(digester, FSDirectory.open(new File(output)));
        indexer.index();
    } catch (ParseException exp) {
        exp.printStackTrace();
        usage(options);
    } catch (ClassNotFoundException e) {
        System.out.println("Invalid digester class.");
        usage(options);
    }
}

From source file:fr.jamgotchian.jcompgen.example.Example1.java

public static void main(String[] args) {
    if (args.length < 1) {
        printUsage();/*from   ww  w  .j  a  v a 2s .co m*/
    }
    String command = args[0];
    Options options = OPTIONS_PER_COMMAND.get(command);
    if (options == null) {
        printUsage();
    }
    try {
        CommandLineParser parser = new PosixParser();
        CommandLine line = parser.parse(options, Arrays.copyOfRange(args, 1, args.length));
        System.out.println("executing command " + command + "...");
    } catch (ParseException e) {
        System.err.println("error: " + e.getMessage());
        printCommandUsage(command, options);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:fr.ens.biologie.genomique.toullig.Main.java

/**
 * The main function parse the options of the command line
 *///from  ww  w  .  ja  va  2s.  c  o m
public static void main(String[] args) {

    // make options
    final Options options = makeOptions();

    // make parser of the command line
    final CommandLineParser parser = new GnuParser();

    try {

        // parse the command line arguments
        final CommandLine line = parser.parse(options, args, true);

        // test if no arguments is given
        if (args.length == 0) {

            showErrorMessageAndExit(
                    "ERROR: Toullig need in the first argument the tool what you want use!\nSee the help with "
                            + Globals.APP_NAME_LOWER_CASE + ".sh -h, --help\n");

        }

        // display help
        if (line.hasOption("help")) {
            help();
        }

        // About option
        if (line.hasOption("about")) {
            Common.showMessageAndExit(Globals.ABOUT_TXT);
        }

        // Version option
        if (line.hasOption("version")) {
            Common.showMessageAndExit(Globals.WELCOME_MSG);
        }

        // Licence option
        if (line.hasOption("license")) {
            Common.showMessageAndExit(Globals.LICENSE_TXT);
        }

        String mode = args[0];

        switch (mode) {

        // process fast5tofastq module
        case "fast5tofastq":

            new Fast5tofastqAction().action(new ArrayList<>(Arrays.asList(args)).subList(1, args.length));

            break;

        // display help
        default:

            showMessageAndExit("ERROR: The name of the tool is not correct!\nSee the help with "
                    + Globals.APP_NAME_LOWER_CASE + ".sh -h, --help\n");

            break;

        // process trim module
        case "trim":

            new TrimAction().action(new ArrayList<>(Arrays.asList(args)).subList(1, args.length));

            break;

        // process gtftogpd module
        case "gtftogpd":

            new GtftogpdAction().action(new ArrayList<>(Arrays.asList(args)).subList(1, args.length));

            break;

        // // process test module
        // case "test":
        // new SamDiffAnnot();
        // break;

        }
    } catch (ParseException e) {
        e.printStackTrace();
    }
}

From source file:net.hedges.fandangled.commandline.GenericCli.java

public static void main(String[] args) {
    options = buildOptions();//from w  w w . j ava 2s .co m

    try {
        CommandLineParser parser = new GnuParser();
        CommandLine line = parser.parse(options, args);
        verbose = line.hasOption('v');
        if (line.hasOption('h')) {
            usage();
            System.exit(0);
        }
        String template = line.getOptionValue("templates");
        String input = line.getOptionValue("input");
        String output = line.getOptionValue("output");

        String prefix = line.getOptionValue("prefix", "");
        String extension = line.getOptionValue("extension", ".txt");

        File inputFile = new File(input);
        File outputDir = new File(output);
        File templateDir = new File(template);

        checkFilesAndDirectories(inputFile, outputDir, templateDir);

        GenericCodec codec = new GenericCodec();
        codec.setTemplatePath(templateDir.getAbsolutePath());
        codec.setExtension(extension);
        codec.setPrefix(prefix);

        Interface _interface = InterfaceBuilder.parse(inputFile);

        codec.encode(_interface, outputDir);

    } catch (ParseException e) {
        System.err.print(e.getMessage() + "\n");
        usage();
    } catch (Exception e) {
        e.printStackTrace();
    }
}