List of usage examples for org.apache.commons.cli ParseException printStackTrace
public void printStackTrace()
From source file:org.dspace.health.Report.java
public static void main(String[] args) { log.info("Starting healthcheck report..."); final String option_help = "h"; final String option_email = "e"; final String option_check = "c"; final String option_last_n = "f"; final String option_verbose = "v"; // command line options Options options = new Options(); options.addOption(option_help, "help", false, "Show available checks and their index."); options.addOption(option_email, "email", true, "Send report to this email address."); options.addOption(option_check, "check", true, "Perform only specific check (use index starting from 0)."); options.addOption(option_last_n, "for", true, "For last N days."); options.addOption(option_verbose, "verbose", false, "Verbose report."); CommandLine cmdline = null;/*from ww w.j av a 2 s . c o m*/ try { cmdline = new PosixParser().parse(options, args); } catch (ParseException e) { log.fatal("Invalid command line " + e.toString(), e); System.exit(1); } if (cmdline.hasOption(option_help)) { String checks_summary = ""; int pos = 0; for (String check_name : checks().keySet()) { checks_summary += String.format("%d. %s\n", pos++, check_name); } HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("dspace healthcheck", options); System.out.println("\nAvailable checks:\n" + checks_summary); return; } // what to perform List<Integer> to_perform = null; if (null != cmdline.getOptionValues(option_check)) { to_perform = new ArrayList<>(); for (String s : cmdline.getOptionValues('c')) { to_perform.add(Integer.valueOf(s)); } } try { // last n days int for_last_n_days = ConfigurationManager.getIntProperty("healthcheck", "last_n_days"); if (cmdline.hasOption(option_last_n)) { for_last_n_days = Integer.getInteger(cmdline.getOptionValue(option_last_n)); } ReportInfo ri = new ReportInfo(for_last_n_days); if (cmdline.hasOption(option_verbose)) { ri.verbose(true); } // run report Report r = new Report(); r.run(to_perform, ri); log.info("reports generated..."); // send/output the report if (cmdline.hasOption(option_email)) { String to = cmdline.getOptionValue(option_email); if (!to.contains("@")) { to = ConfigurationManager.getProperty(to); } try { String dspace_dir = ConfigurationManager.getProperty("dspace.dir"); String email_path = dspace_dir.endsWith("/") ? dspace_dir : dspace_dir + "/"; email_path += Report.EMAIL_PATH; log.info(String.format("Looking for email template at [%s]", email_path)); Email email = Email.getEmail(email_path); email.addRecipient(to); email.addArgument(r.toString()); email.send(); } catch (Exception e) { log.fatal("Error sending email:", e); System.err.println("Error sending email:\n" + e.getMessage()); System.exit(1); } } } catch (Exception e) { log.fatal(e); e.printStackTrace(); } }
From source file:org.factpub.ui.gui.core.EntryPoint.java
public static void main(String[] args) throws ParseException { // TODO Auto-generated method stub // Initialize %userhome%/factpub folder InitTempDir.initTempDir();/* w ww . j ava 2 s . c o m*/ if (args.length > 0) { // CUI mode //Create Option instance Options options = new Options(); //-f Option Option file = OptionBuilder.hasArg(true) //Does parameter take argument? .withArgName("file") //Name of the parameter. .isRequired(true) //Is parameter required? .withDescription("academic papers (pdfs): -f paper1.pdf -f paper2.pdf ...") //Usage .withLongOpt("file") //Synonym for the option .create("f"); //Create the option Option user = OptionBuilder.hasArg(true).withArgName("username").isRequired(false) .withDescription("factpub id (requires <password>)").withLongOpt("user").create("u"); Option password = OptionBuilder.hasArg(true).withArgName("password").isRequired(false) .withDescription("password (requires <username>)").withLongOpt("password").create("p"); options.addOption(file); options.addOption(password); options.addOption(user); //Create Parser CommandLineParser parser = new PosixParser(); //Analyze CommandLine cmd = null; try { cmd = parser.parse(options, args); } catch (ParseException e) { //Show help and close HelpFormatter help = new HelpFormatter(); help.printHelp("java -jar factpub_uploader.jar", options, true); return; } System.out.println("Run in CUI mode"); if (cmd.hasOption("u") && cmd.hasOption("p")) { System.out.println("User authentication starts."); try { AuthMediaWikiIdHTTP.authMediaWikiAccount(cmd.getOptionValue("u"), cmd.getOptionValue("p")); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); System.out.println("login failed"); } } else if ((cmd.hasOption("u") && !cmd.hasOption("p")) || (!cmd.hasOption("u") && cmd.hasOption("p"))) { System.out.println("<username> and <password> must be given together."); System.out.println("Log in as Anonymouse user."); } //Check result if (cmd.hasOption("f")) { String[] pdfs = cmd.getOptionValues("f"); for (String pdf : pdfs) { File pdf_file = new File(pdf); String status = FEWrapper.GUI_Wrapper(pdf_file); //Networking function for CUI if (!status.equals(FE_STATUS_CODE_0)) { File json = new File( FEConstants.DIR_JSON_OUTPUT + File.separator + Utility.getFileNameMD5(pdf_file)); try { System.out .println("Start uploading " + json.getName() + " to " + FEConstants.SERVER_API); List<String> res = PostFile.uploadToFactpub(json); System.out.println("PostFile.uploadToFactpub end"); // If the server returns page title, put it into the array so browser can open the page when user click it. if (res.get(0).contains(FEConstants.SERVER_RES_TITLE_BEGIN)) { //Embedding HyperLink String pageTitle = (String) res.get(0).subSequence( res.get(0).indexOf(FEConstants.SERVER_RES_TITLE_BEGIN) + FEConstants.SERVER_RES_TITLE_BEGIN.length(), res.get(0).indexOf(FEConstants.SERVER_RES_TITLE_END)); pageTitle = pageTitle.replace(" ", "_"); System.out.println(pageTitle); String uriString = FEConstants.PAGE_CREATED + pageTitle; status = "Page is created: " + uriString; //change table color } else { status = "Upload success but page was not created."; } // embed HTML to the label } catch (Exception e) { status = FEConstants.STATUS_UPLOAD_FAILED; } System.out.println(status); } } } } else { // GUI mode System.out.println("If you want to run in console, please give me arguments."); /* usage: factpub_uploader.jar -f <pdf file> [-p <password>] [-u <username>] -f,--file <pdf file> academic papers (pdfs) -p,--password <password> password (requires <username>) -u,--user <username> factpub id (requires <password>) */ System.out.println("Run in GUI mode"); MainFrame.launchGUI(); } }
From source file:org.fcrepo.modeshape.ModeshapeServer.java
public static void main(String[] args) { /* setup the command line options */ final Options ops = createOptions(); /* set the defaults */ int numBinaries = 1; long size = 1024; int numThreads = 1; String logPath = "durations.log"; boolean benchEnabled = false; /* and get the individual settings from the command line */ final CommandLineParser parser = new BasicParser(); try {/*from w ww.java2 s .c o m*/ final CommandLine cli = parser.parse(ops, args); if (cli.hasOption("h")) { printUsage(ops); return; } if (cli.hasOption("n")) { numBinaries = Integer.parseInt(cli.getOptionValue("n")); } if (cli.hasOption("s")) { size = getSizeFromArgument(cli.getOptionValue("s")); } if (cli.hasOption("t")) { numThreads = Integer.parseInt(cli.getOptionValue("t")); } if (cli.hasOption("l")) { logPath = cli.getOptionValue("l"); } if (cli.hasOption("b")) { benchEnabled = true; } } catch (ParseException e) { e.printStackTrace(); return; } ModeshapeServer server = new ModeshapeServer(); try { server.start(benchEnabled, numBinaries, size, numThreads); } catch (Exception e) { e.printStackTrace(); } }
From source file:org.forgerock.json.crypto.cli.Main.java
/** * Validate and set command line arguments. Exit after printing usage if anything is * astray./*from ww w . j a va 2 s . co m*/ * * @param args String[] args as featured in public static void main() */ private void loadArgs(String[] args) { CommandLineParser parser = new PosixParser(); try { cmd = parser.parse(options, args); } catch (ParseException e) { System.err.println("Error parsing arguments"); e.printStackTrace(); System.exit(1); } if (cmd.hasOption('h')) { usage(); System.exit(0); } // Check for mandatory args if (cmd.hasOption(PROPERTIES_HELP_COMMAND)) { usage(); System.exit(0); } }
From source file:org.fusesource.hawtjni.generator.HawtJNI.java
public int execute(String[] args) { CommandLine cli = null;/*from w w w . j a v a 2s . c om*/ try { cli = new PosixParser().parse(createOptions(), args, true); } catch (ParseException e) { System.err.println("Unable to parse command line options: " + e.getMessage()); displayHelp(); return 1; } if (cli.hasOption("h")) { displayHelp(); return 0; } if (cli.hasOption("v")) { progress = new ProgressMonitor() { public void step() { } public void setTotal(int total) { } public void setMessage(String message) { System.out.println(message); } }; } name = cli.getOptionValue("n", "hawtjni_native"); nativeOutput = new File(cli.getOptionValue("o", ".")); // javaOutputDir = new File(cli.getOptionValue("j", ".")); String[] values = cli.getOptionValues("p"); if (values != null) { packages = Arrays.asList(values); } values = cli.getArgs(); if (values != null) { classpaths = Arrays.asList(values); } try { if (classpaths.isEmpty()) { throw new UsageException("No classpath supplied."); } generate(); } catch (UsageException e) { System.err.println("Invalid usage: " + e.getMessage()); displayHelp(); return 1; } catch (Throwable e) { System.out.flush(); System.err.println("Unexpected failure:"); e.printStackTrace(); Set<Throwable> exceptions = new HashSet<Throwable>(); exceptions.add(e); for (int i = 0; i < 10; i++) { e = e.getCause(); if (e != null && exceptions.add(e)) { System.err.println("Reason: " + e); e.printStackTrace(); } else { break; } } return 2; } return 0; }
From source file:org.fusesource.mop.MOP.java
public int execute(String[] args) { CommandLine cli = null;/*from w w w .ja va 2 s .co m*/ try { cli = new GnuParser().parse(createOptions(), args, true); } catch (ParseException e) { System.err.println("Unable to parse command line options: " + e.getMessage()); displayHelp(); return 1; } // lets process the options Logger.debug = cli.hasOption("X"); if (cli.hasOption("n")) { getRemoteRepositories().clear(); } String scope = cli.getOptionValue("s", "runtime"); repository.setScope(scope); String[] repos = cli.getOptionValues("r"); if (repos != null) { for (String repo : repos) { String[] rc = repo.split("=", 2); if (rc.length != 2) { System.err.println("Invalid repository. Expected format is: <id>=<url>, actual: " + repo); displayHelp(); return 1; } getRemoteRepositories().put(rc[0], rc[1]); } } // repository.setOnline(!cli.hasOption("o")); // LOG.debug("online mode: " + repository.isOnline()); String localRepo = cli.getOptionValue('l'); if (localRepo != null) { repository.setLocalRepo(new File(localRepo)); } if (cli.hasOption("h")) { displayHelp(); return 0; } // now the remaining command line args try { LinkedList<String> argList = new LinkedList<String>(Arrays.asList(cli.getArgs())); executeCommand(argList); } catch (UsageException e) { displayHelp(); return 1; } catch (Throwable e) { System.err.println(); System.err.println("Failed: " + e); e.printStackTrace(); Set<Throwable> exceptions = new HashSet<Throwable>(); exceptions.add(e); for (int i = 0; i < 10; i++) { e = e.getCause(); if (e != null && exceptions.add(e)) { System.err.println("Reason: " + e); e.printStackTrace(); } else { break; } } return 2; } return 0; }
From source file:org.hammurapi.HammurapiArchiver.java
/** * Use it for inspector debugging//from ww w .j av a 2 s. c o m * @param args */ public static void main(String[] args) { System.out.println("Hammurapi 3.18.4 Copyright (C) 2004 Hammurapi Group"); Options options = new Options(); Option classPathOption = OptionBuilder.withArgName("classpath").hasArg().withDescription("ClassPath") .isRequired(false).create("c"); options.addOption(classPathOption); Option hostIdOption = OptionBuilder.withArgName("hostId").hasArg().withDescription("Host id") .isRequired(false).create("H"); options.addOption(hostIdOption); Option titleOption = OptionBuilder.withArgName("title").hasArg().withDescription("Report title") .isRequired(false).create("T"); options.addOption(titleOption); Option baseLineOption = OptionBuilder.withDescription("Baseline date").withArgName("date").hasArg() .isRequired(false).create("n"); options.addOption(baseLineOption); Option forceOption = OptionBuilder.withDescription("Force reviews on unchanged files").isRequired(false) .create("f"); options.addOption(forceOption); Option forceOnWarningsOption = OptionBuilder.withDescription("Do not force reviews of files with warnings") .isRequired(false).create("k"); options.addOption(forceOnWarningsOption); Option descriptionOption = OptionBuilder.withDescription("Review description").withArgName("description") .hasArg().isRequired(false).create("y"); options.addOption(descriptionOption); //Anu :20050701 Added baselining parameter Option baseliningOption = OptionBuilder.withArgName("off|on|set").hasArg() .withDescription("Baselining mode").isRequired(false).create("B"); options.addOption(descriptionOption); Option helpOption = OptionBuilder.withDescription("Print this message").isRequired(false).create("h"); options.addOption(helpOption); CommandLineParser parser = new PosixParser(); CommandLine line = null; try { line = parser.parse(options, args); } catch (ParseException e) { System.err.println(e.getMessage()); System.err.flush(); printHelpAndExit(options); } if (line.hasOption("h")) { printHelpAndExit(options); } HammurapiArchiver task = new HammurapiArchiver(); Project project = new Project(); task.setProject(project); project.setCoreLoader(task.getClass().getClassLoader()); String[] values = line.getOptionValues('c'); for (int i = 0; values != null && i < values.length; i++) { task.createClasspath().append(new Path(project, values[i])); } String[] largs = line.getArgs(); if (largs.length == 0) { System.out.println("Output file has to be provided"); printHelpAndExit(options); } if (line.hasOption('f')) { task.setForce(true); } if (line.hasOption('k')) { task.setForceOnWarnings(false); } if (line.hasOption('n')) { task.setBaseLine(new Date(line.getOptionValue('n'))); } if (line.hasOption('H')) { task.setHostId(line.getOptionValue('H')); } if (line.hasOption('y')) { task.setReviewDescription(line.getOptionValue('y')); } if (line.hasOption('T')) { task.setTitle(line.getOptionValue('T')); } //Anu :20050701 Added for Baselining attribute if (line.hasOption('B')) { task.setBaselining(line.getOptionValue('B')); } task.setOutput(new File(largs[0])); for (int i = 1; i < largs.length; i++) { File file = new File(largs[i]); if (file.isFile()) { task.srcFiles.add(file); } else if (file.isDirectory()) { task.createSrc().setDir(file); } } task.setTaskName("har"); try { task.execute(); System.exit(0); } catch (Exception e) { e.printStackTrace(); System.exit(2); } }
From source file:org.hammurapi.HammurapiTask.java
/** * Use it for inspector debugging// w ww. j a v a 2 s . co m * @param args */ public static void main(String[] args) { System.out.println("Hammurapi 3.18.4 Copyright (C) 2004 Hammurapi Group"); Options options = new Options(); populateOptions(options); CommandLineParser parser = new PosixParser(); CommandLine line = null; try { line = parser.parse(options, args); } catch (ParseException e) { System.err.println(e.getMessage()); System.err.flush(); printHelpAndExit(options); } if (line.hasOption("h")) { printHelpAndExit(options); } HammurapiTask task = new HammurapiTask(); Project project = new Project(); task.setProject(project); project.setCoreLoader(task.getClass().getClassLoader()); task.configure(options, line); task.suppressLogo = true; task.setTaskName("hammurapi"); try { task.execute(); System.exit(0); } catch (Exception e) { e.printStackTrace(); System.exit(2); } }
From source file:org.hammurapi.QuickHammurapiTask.java
/** * Use it for inspector debugging//from ww w.ja v a 2 s .c o m * @param args */ public static void main(String[] args) { System.out.println("Hammurapi 3.18.4 Copyright (C) 2004 Hammurapi Group"); Options options = new Options(); populateOptions(options); CommandLineParser parser = new PosixParser(); CommandLine line = null; try { line = parser.parse(options, args); } catch (org.apache.commons.cli.ParseException e) { System.err.println(e.getMessage()); System.err.flush(); printHelpAndExit(options); } if (line.hasOption("h")) { printHelpAndExit(options); } QuickHammurapiTask task = new QuickHammurapiTask(); Project project = new Project(); task.setProject(project); project.setCoreLoader(task.getClass().getClassLoader()); task.configure(options, line); task.suppressLogo = true; task.setTaskName("quickurapi"); try { task.execute(); System.exit(0); } catch (Exception e) { e.printStackTrace(); System.exit(2); } }
From source file:org.jf.smali.main.java
/** * Run!// ww w . java2 s .c o m */ public static void main(String[] args) { Locale locale = new Locale("en", "US"); Locale.setDefault(locale); CommandLineParser parser = new PosixParser(); CommandLine commandLine; try { commandLine = parser.parse(options, args); } catch (ParseException ex) { usage(); return; } int jobs = -1; boolean allowOdex = false; boolean verboseErrors = false; boolean printTokens = false; int apiLevel = 15; String outputDexFile = "out.dex"; String[] remainingArgs = commandLine.getArgs(); Option[] options = commandLine.getOptions(); for (int i = 0; i < options.length; i++) { Option option = options[i]; String opt = option.getOpt(); switch (opt.charAt(0)) { case 'v': version(); return; case '?': while (++i < options.length) { if (options[i].getOpt().charAt(0) == '?') { usage(true); return; } } usage(false); return; case 'o': outputDexFile = commandLine.getOptionValue("o"); break; case 'x': allowOdex = true; break; case 'a': apiLevel = Integer.parseInt(commandLine.getOptionValue("a")); break; case 'j': jobs = Integer.parseInt(commandLine.getOptionValue("j")); break; case 'V': verboseErrors = true; break; case 'T': printTokens = true; break; default: assert false; } } if (remainingArgs.length == 0) { usage(); return; } try { LinkedHashSet<File> filesToProcess = new LinkedHashSet<File>(); for (String arg : remainingArgs) { File argFile = new File(arg); if (!argFile.exists()) { throw new RuntimeException("Cannot find file or directory \"" + arg + "\""); } if (argFile.isDirectory()) { getSmaliFilesInDir(argFile, filesToProcess); } else if (argFile.isFile()) { filesToProcess.add(argFile); } } if (jobs <= 0) { jobs = Runtime.getRuntime().availableProcessors(); if (jobs > 6) { jobs = 6; } } boolean errors = false; final DexBuilder dexBuilder = DexBuilder.makeDexBuilder(apiLevel); ExecutorService executor = Executors.newFixedThreadPool(jobs); List<Future<Boolean>> tasks = Lists.newArrayList(); final boolean finalVerboseErrors = verboseErrors; final boolean finalPrintTokens = printTokens; final boolean finalAllowOdex = allowOdex; final int finalApiLevel = apiLevel; for (final File file : filesToProcess) { tasks.add(executor.submit(new Callable<Boolean>() { @Override public Boolean call() throws Exception { return assembleSmaliFile(file, dexBuilder, finalVerboseErrors, finalPrintTokens, finalAllowOdex, finalApiLevel); } })); } for (Future<Boolean> task : tasks) { while (true) { try { if (!task.get()) { errors = true; } } catch (InterruptedException ex) { continue; } break; } } executor.shutdown(); if (errors) { System.exit(1); } dexBuilder.writeTo(new FileDataStore(new File(outputDexFile))); } catch (RuntimeException ex) { System.err.println("\nUNEXPECTED TOP-LEVEL EXCEPTION:"); ex.printStackTrace(); System.exit(2); } catch (Throwable ex) { System.err.println("\nUNEXPECTED TOP-LEVEL ERROR:"); ex.printStackTrace(); System.exit(3); } }