List of usage examples for org.apache.commons.cli ParseException getMessage
public String getMessage()
From source file:it.polimi.tower4clouds.rules.batch.BatchTool.java
public static void main(String[] args) { Options options = buildOptions();//w w w .jav a 2 s.c o m CommandLineParser parser = new BasicParser(); HelpFormatter formatter = new HelpFormatter(); FileInputStream inputFile = null; try { // parse the command line arguments CommandLine cmd = parser.parse(options, args); if (cmd.getOptions().length != 1) { System.err.println("Parsing failed: Reason: one and only one option is required"); formatter.printHelp("qos-models", options); } else if (cmd.hasOption("h")) { formatter.printHelp("qos-models", options); } else if (cmd.hasOption("v")) { String file = cmd.getOptionValue("v"); inputFile = new FileInputStream(file); MonitoringRules rules = XMLHelper.deserialize(inputFile, MonitoringRules.class); RulesValidator validator = new RulesValidator(); Set<Problem> problems = validator.validateAllRules(rules); printResult(problems); } else if (cmd.hasOption("c")) { String file = cmd.getOptionValue("c"); inputFile = new FileInputStream(file); Constraints constraints = XMLHelper.deserialize(inputFile, Constraints.class); QoSValidator validator = new QoSValidator(); Set<Problem> problems = validator.validateAllConstraints(constraints); printResult(problems); } else if (cmd.hasOption("r")) { String file = cmd.getOptionValue("r"); inputFile = new FileInputStream(file); Constraints constraints = XMLHelper.deserialize(inputFile, Constraints.class); MonitoringRuleFactory factory = new MonitoringRuleFactory(); MonitoringRules rules = factory.makeRulesFromQoSConstraints(constraints); XMLHelper.serialize(rules, System.out); } } catch (ParseException e) { System.err.println("Parsing failed. Reason: " + e.getMessage()); formatter.printHelp("qos-models", options); } catch (FileNotFoundException e) { System.err.println("Could not locate input file: " + e.getMessage()); } catch (JAXBException | SAXException e) { System.err.println("Input file could not be parsed: "); e.printStackTrace(); } catch (Exception e) { System.err.println("Unknown error: "); e.printStackTrace(); } finally { if (inputFile != null) { try { inputFile.close(); } catch (IOException e) { } } } }
From source file:dk.netarkivet.harvester.tools.CreateIndex.java
/** * The main method that does the parsing of the commandline, and makes the actual index request. * * @param args the arguments//from w w w . j a v a 2 s . c om */ public static void main(String[] args) { Options options = new Options(); CommandLineParser parser = new PosixParser(); CommandLine cmd = null; Option indexType = new Option("t", "type", true, "Type of index"); Option jobList = new Option("l", "jobids", true, "list of jobids"); indexType.setRequired(true); jobList.setRequired(true); options.addOption(indexType); options.addOption(jobList); try { // parse the command line arguments cmd = parser.parse(options, args); } catch (MissingOptionException e) { System.err.println("Some of the required parameters are missing: " + e.getMessage()); dieWithUsage(); } catch (ParseException exp) { System.err.println("Parsing of parameters failed: " + exp.getMessage()); dieWithUsage(); } String typeValue = cmd.getOptionValue(INDEXTYPE_OPTION); String jobidsValue = cmd.getOptionValue(JOBIDS_OPTION); String[] jobidsAsStrings = jobidsValue.split(","); Set<Long> jobIDs = new HashSet<Long>(); for (String idAsString : jobidsAsStrings) { jobIDs.add(Long.valueOf(idAsString)); } JobIndexCache cache = null; String indexTypeAstring = ""; if (typeValue.equalsIgnoreCase("CDX")) { indexTypeAstring = "CDX"; cache = IndexClientFactory.getCDXInstance(); } else if (typeValue.equalsIgnoreCase("DEDUP")) { indexTypeAstring = "DEDUP"; cache = IndexClientFactory.getDedupCrawllogInstance(); } else if (typeValue.equalsIgnoreCase("CRAWLLOG")) { indexTypeAstring = "CRAWLLOG"; cache = IndexClientFactory.getFullCrawllogInstance(); } else { System.err.println("Unknown indextype '" + typeValue + "' requested."); dieWithUsage(); } System.out.println("Creating " + indexTypeAstring + " index for ids: " + jobIDs); Index<Set<Long>> index = cache.getIndex(jobIDs); JMSConnectionFactory.getInstance().cleanup(); }
From source file:info.bitoo.Main.java
public static void main(String[] args) throws InterruptedException, IOException, NoSuchAlgorithmException, ClientAdapterException { CommandLineParser parser = new PosixParser(); CommandLine cmd = null;//from www. jav a 2 s . co m try { cmd = parser.parse(createCommandLineOptions(), args); } catch (ParseException e) { System.err.println("Parsing failed. Reason: " + e.getMessage()); } Properties props = readConfiguration(cmd); BiToo biToo = new BiToo(props); URL torrentURL = null; if (cmd.hasOption("f")) { String parmValue = cmd.getOptionValue("f"); String torrentName = parmValue + ".torrent"; biToo.setTorrent(torrentName); } else if (cmd.hasOption("t")) { torrentURL = new URL(cmd.getOptionValue("t")); biToo.setTorrent(torrentURL); } else { return; } try { Thread main = new Thread(biToo); main.setName("BiToo"); main.start(); //wait until thread complete main.join(); } finally { biToo.destroy(); } if (biToo.isCompleted()) { System.out.println("Download completed"); System.exit(0); } else { System.out.println("Download failed"); System.exit(1); } }
From source file:it.tizianofagni.sparkboost.BoostClassifierExe.java
public static void main(String[] args) { Options options = new Options(); options.addOption("b", "binaryProblem", false, "Indicate if the input dataset contains a binary problem and not a multilabel one"); options.addOption("z", "labels0based", false, "Indicate if the labels IDs in the dataset to classifyLibSvmWithResults are already assigned in the range [0, numLabels-1] included"); options.addOption("l", "enableSparkLogging", false, "Enable logging messages of Spark"); options.addOption("w", "windowsLocalModeFix", true, "Set the directory containing the winutils.exe command"); options.addOption("p", "parallelismDegree", true, "Set the parallelism degree (default: number of available cores in the Spark runtime"); CommandLineParser parser = new BasicParser(); CommandLine cmd = null;// w w w .j a v a 2s . c o m String[] remainingArgs = null; try { cmd = parser.parse(options, args); remainingArgs = cmd.getArgs(); if (remainingArgs.length != 3) throw new ParseException("You need to specify all mandatory parameters"); } catch (ParseException e) { System.out.println("Parsing failed. Reason: " + e.getMessage()); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp( BoostClassifierExe.class.getSimpleName() + " [OPTIONS] <inputFile> <inputModel> <outputFile>", options); System.exit(-1); } boolean binaryProblem = false; if (cmd.hasOption("b")) binaryProblem = true; boolean labels0Based = false; if (cmd.hasOption("z")) labels0Based = true; boolean enablingSparkLogging = false; if (cmd.hasOption("l")) enablingSparkLogging = true; if (cmd.hasOption("w")) { System.setProperty("hadoop.home.dir", cmd.getOptionValue("w")); } String inputFile = remainingArgs[0]; String inputModel = remainingArgs[1]; String outputFile = remainingArgs[2]; long startTime = System.currentTimeMillis(); // Disable Spark logging. if (!enablingSparkLogging) { Logger.getLogger("org").setLevel(Level.OFF); Logger.getLogger("akka").setLevel(Level.OFF); } // Create and configure Spark context. SparkConf conf = new SparkConf().setAppName("Spark MPBoost classifier"); JavaSparkContext sc = new JavaSparkContext(conf); // Load boosting classifier from disk. BoostClassifier classifier = DataUtils.loadModel(sc, inputModel); // Get the parallelism degree. int parallelismDegree = sc.defaultParallelism(); if (cmd.hasOption("p")) { parallelismDegree = Integer.parseInt(cmd.getOptionValue("p")); } // Classify documents available on specified input file. classifier.classifyLibSvm(sc, inputFile, parallelismDegree, labels0Based, binaryProblem, outputFile); long endTime = System.currentTimeMillis(); System.out.println("Execution time: " + (endTime - startTime) + " milliseconds."); }
From source file:com.act.utils.parser.UniprotInterpreter.java
public static void main(String[] args) throws ParserConfigurationException, IOException, SAXException, CompoundNotFoundException { Options opts = new Options(); for (Option.Builder b : OPTION_BUILDERS) { opts.addOption(b.build());/* w w w . java 2 s. co m*/ } CommandLine cl = null; try { CommandLineParser parser = new DefaultParser(); cl = parser.parse(opts, args); } catch (ParseException e) { LOGGER.error("Argument parsing failed: %s", e.getMessage()); HELP_FORMATTER.printHelp(UniprotInterpreter.class.getCanonicalName(), HELP_MESSAGE, opts, null, true); System.exit(1); } if (cl.hasOption("help")) { HELP_FORMATTER.printHelp(UniprotInterpreter.class.getCanonicalName(), HELP_MESSAGE, opts, null, true); System.exit(1); } File uniprotFile = new File(cl.getOptionValue(OPTION_UNIPROT_PATH)); if (!uniprotFile.exists()) { String msg = "Uniprot file path is null"; LOGGER.error(msg); throw new RuntimeException(msg); } else { UniprotInterpreter reader = new UniprotInterpreter(uniprotFile); reader.init(); } }
From source file:com.dustindoloff.s3websitedeploy.Main.java
public static void main(final String[] args) { final Options options = buildOptions(); final CommandLineParser parser = new DefaultParser(); final CommandLine commandLine; try {//from w w w .jav a 2 s. c o m commandLine = parser.parse(options, args); } catch (final ParseException e) { System.out.println(e.getMessage()); new HelpFormatter().printHelp("s3WebsiteDeploy", options); System.exit(1); return; } final File websiteZip = new File(commandLine.getOptionValue(ARG_WEBSITE_ZIP)); final String s3Bucket = commandLine.getOptionValue(ARG_BUCKET); final String awsAccessKey = commandLine.getOptionValue(ARG_AWS_ACCESS_KEY); final String awsSecretKey = commandLine.getOptionValue(ARG_AWS_SECRET_KEY); final ZipFile zipFile = getAsValidZip(websiteZip); if (zipFile == null) { System.out.println("Invalid zip file passed in"); System.exit(2); return; } System.out.println("Running S3 Website Deploy"); final AmazonS3 s3Client = new AmazonS3Client(new BasicAWSCredentials(awsAccessKey, awsSecretKey)); final Region bucketRegion = getBucketRegion(s3Client, s3Bucket); if (bucketRegion == null) { System.out.println("Unable to get the region for the bucket."); System.exit(3); return; } s3Client.setRegion(bucketRegion); if (!emptyBucket(s3Client, s3Bucket)) { System.out.println("Unable to upload to empty bucket."); System.exit(4); return; } if (!upload(s3Client, s3Bucket, zipFile)) { System.out.println("Unable to upload to S3."); System.exit(5); return; } System.out.println("Deployment Complete"); }
From source file:com.incapture.rapgen.persistence.GenPersistence.java
public static void main(String[] args) { Options options = new Options(); options.addOption("o", true, "Output root folder for kernel files"); options.addOption("g", true, "The type of grammar to generate, current options are 'SDK' or 'API'"); options.addOption("mainApiFile", true, "FileName specifying the api"); CommandLineParser cparser = new PosixParser(); try {//from w ww. j a va 2 s. co m CommandLine cmd = cparser.parse(options, args); String mainApiFile = cmd.getOptionValue("mainApiFile"); String outputFolder = cmd.getOptionValue('o'); GenType genType = GenType.valueOf(cmd.getOptionValue('g')); StringTemplateGroup templateLib = loadTemplates(genType); List<StorableAttributes> storableAttributes = parseApiFiles(cmd, mainApiFile, templateLib, genType); StorableSerDeserRepo mappersRepo = StorableMappersLoader.loadSerDeserHelpers(); log.info(String.format("Got %s storable mapper(s)", mappersRepo.getAll().size())); Generator generator = new Generator(templateLib); Map<String, StringTemplate> pathToTemplate = generator.generatePersistenceFiles(storableAttributes, mappersRepo); log.info(String.format("Writing persistence files in [%s]", outputFolder)); OutputWriter.writeTemplates(outputFolder, pathToTemplate); } catch (ParseException e) { System.err.println("Error parsing command line - " + e.getMessage()); System.out.println("Usage: " + options.toString()); } catch (IOException | RecognitionException e) { System.err.println("Error running GenApi: " + ExceptionToString.format(e)); } }
From source file:de.zazaz.iot.bosch.indego.util.IndegoMqttAdapter.java
public static void main(String[] args) { System.setProperty("log4j.configurationFile", "log4j2-indegoMqttAdapter-normal.xml"); Options options = new Options(); StringBuilder commandList = new StringBuilder(); for (DeviceCommand cmd : DeviceCommand.values()) { if (commandList.length() > 0) { commandList.append(", "); }/*from w w w .j av a2 s . c o m*/ commandList.append(cmd.toString()); } options.addOption(Option // .builder("c") // .longOpt("config") // .desc("The configuration file to use") // .required() // .hasArg() // .build()); options.addOption(Option // .builder("d") // .longOpt("debug") // .desc("Logs more details") // .build()); options.addOption(Option // .builder("?") // .longOpt("help") // .desc("Prints this help") // .build()); CommandLineParser parser = new DefaultParser(); CommandLine cmds = null; try { cmds = parser.parse(options, args); } catch (ParseException ex) { System.err.println(ex.getMessage()); System.err.println(); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(IndegoMqttAdapter.class.getName(), options); System.exit(1); return; } if (cmds.hasOption("?")) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(CmdLineTool.class.getName(), options); return; } if (cmds.hasOption("d")) { System.setProperty("log4j.configurationFile", "log4j2-indegoMqttAdapter-debug.xml"); } String configFileName = cmds.getOptionValue('c'); File configFile = new File(configFileName); if (!configFile.exists()) { System.err.println(String.format("The specified config file (%s) does not exist", configFileName)); System.err.println(); System.exit(2); return; } Properties properties = new Properties(); try (InputStream in = new FileInputStream(configFile)) { properties.load(in); } catch (IOException ex) { System.err.println(ex.getMessage()); System.err.println(String.format("Was not able to load the properties file (%s)", configFileName)); System.err.println(); } MqttIndegoAdapterConfiguration config = new MqttIndegoAdapterConfiguration(); config.setIndegoBaseUrl(properties.getProperty("indego.mqtt.device.base-url")); config.setIndegoUsername(properties.getProperty("indego.mqtt.device.username")); config.setIndegoPassword(properties.getProperty("indego.mqtt.device.password")); config.setMqttBroker(properties.getProperty("indego.mqtt.broker.connection")); config.setMqttClientId(properties.getProperty("indego.mqtt.broker.client-id")); config.setMqttUsername(properties.getProperty("indego.mqtt.broker.username")); config.setMqttPassword(properties.getProperty("indego.mqtt.broker.password")); config.setMqttTopicRoot(properties.getProperty("indego.mqtt.broker.topic-root")); config.setPollingIntervalMs(Integer.parseInt(properties.getProperty("indego.mqtt.polling-interval-ms"))); MqttIndegoAdapter adapter = new MqttIndegoAdapter(config); adapter.startup(); }
From source file:jlite.cli.JobCancel.java
public static void main(String[] args) { System.out.println(); // extra line CommandLineParser parser = new GnuParser(); Options options = setupOptions();/* w ww . ja va 2 s. c om*/ HelpFormatter helpFormatter = new HelpFormatter(); helpFormatter.setSyntaxPrefix("Usage: "); CommandLine line = null; try { line = parser.parse(options, args); if (line.hasOption("help")) { helpFormatter.printHelp(100, COMMAND, "\noptions:", options, "\n" + CLI.FOOTER, false); System.out.println(); // extra line System.exit(0); } else { if (line.hasOption("xml")) { System.out.println("<output>"); } run(line.getArgs(), line); } } catch (ParseException e) { System.err.println(e.getMessage() + "\n"); helpFormatter.printHelp(100, COMMAND, "\noptions:", options, "\n" + CLI.FOOTER, false); System.out.println(); // extra line System.exit(-1); } catch (Exception e) { if (line.hasOption("xml")) { System.out.println("<error>" + e.getMessage() + "</error>"); } else { System.err.println(e.getMessage()); } } finally { if (line.hasOption("xml")) { System.out.println("</output>"); } } System.out.println(); // extra line }
From source file:edu.sdsc.scigraph.owlapi.loader.BatchOwlLoader.java
public static void main(String[] args) throws Exception { CommandLineParser parser = new PosixParser(); CommandLine cmd = null;/* w w w.j av a2 s. co m*/ try { cmd = parser.parse(getOptions(), args); } catch (ParseException e) { System.err.println(e.getMessage()); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(BatchOwlLoader.class.getSimpleName(), getOptions()); System.exit(-1); } ObjectMapper mapper = new ObjectMapper(new YAMLFactory()); OwlLoadConfiguration config = mapper.readValue(new File(cmd.getOptionValue('c').trim()), OwlLoadConfiguration.class); load(config); // TODO: Is Guice causing this to hang? #44 System.exit(0); }