List of usage examples for org.apache.commons.cli CommandLine getOptionValue
public String getOptionValue(char opt)
From source file:fr.inria.atlanmod.kyanos.benchmarks.MorsaCreator.java
public static void main(String[] args) { Options options = new Options(); Option inputOpt = OptionBuilder.create(IN); inputOpt.setArgName("INPUT"); inputOpt.setDescription("Input file"); inputOpt.setArgs(1);/*from w ww. j ava 2 s. c om*/ inputOpt.setRequired(true); Option outputOpt = OptionBuilder.create(OUT); outputOpt.setArgName("OUTPUT"); outputOpt.setDescription("Output directory"); outputOpt.setArgs(1); outputOpt.setRequired(true); Option inClassOpt = OptionBuilder.create(EPACKAGE_CLASS); inClassOpt.setArgName("CLASS"); inClassOpt.setDescription("FQN of EPackage implementation class"); inClassOpt.setArgs(1); inClassOpt.setRequired(true); options.addOption(inputOpt); options.addOption(outputOpt); options.addOption(inClassOpt); CommandLineParser parser = new PosixParser(); try { CommandLine commandLine = parser.parse(options, args); URI sourceUri = URI.createFileURI(commandLine.getOptionValue(IN)); URI targetUri = URI.createURI("morsa://" + commandLine.getOptionValue(OUT)); Class<?> inClazz = MorsaCreator.class.getClassLoader() .loadClass(commandLine.getOptionValue(EPACKAGE_CLASS)); inClazz.getMethod("init").invoke(null); ResourceSet resourceSet = new ResourceSetImpl(); resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("xmi", new XMIResourceFactoryImpl()); resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("zxmi", new XMIResourceFactoryImpl()); resourceSet.getResourceFactoryRegistry().getProtocolToFactoryMap().put("morsa", new MorsaResourceFactoryImpl(new MongoDBMorsaBackendFactory())); Resource sourceResource = resourceSet.createResource(sourceUri); Map<String, Object> loadOpts = new HashMap<String, Object>(); if ("zxmi".equals(sourceUri.fileExtension())) { loadOpts.put(XMIResource.OPTION_ZIP, Boolean.TRUE); } Runtime.getRuntime().gc(); long initialUsedMemory = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory(); LOG.log(Level.INFO, MessageFormat.format("Used memory before loading: {0}", MessageUtil.byteCountToDisplaySize(initialUsedMemory))); LOG.log(Level.INFO, "Loading source resource"); sourceResource.load(loadOpts); LOG.log(Level.INFO, "Source resource loaded"); Runtime.getRuntime().gc(); long finalUsedMemory = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory(); LOG.log(Level.INFO, MessageFormat.format("Used memory after loading: {0}", MessageUtil.byteCountToDisplaySize(finalUsedMemory))); LOG.log(Level.INFO, MessageFormat.format("Memory use increase: {0}", MessageUtil.byteCountToDisplaySize(finalUsedMemory - initialUsedMemory))); Resource targetResource = resourceSet.createResource(targetUri); Map<String, Object> saveOpts = new HashMap<String, Object>(); //URI of the MongoDB database (e.g. localhost) saveOpts.put(IMorsaResource.OPTION_SERVER_URI, "localhost"); saveOpts.put(IMorsaResource.OPTION_MAX_SAVE_CACHE_SIZE, 30000); saveOpts.put(IMorsaResource.OPTION_DEMAND_LOAD, false); targetResource.save(saveOpts); LOG.log(Level.INFO, "Start moving elements"); targetResource.getContents().clear(); targetResource.getContents().addAll(sourceResource.getContents()); LOG.log(Level.INFO, "End moving elements"); LOG.log(Level.INFO, "Start saving"); targetResource.save(saveOpts); LOG.log(Level.INFO, "Saved"); targetResource.unload(); } catch (ParseException e) { MessageUtil.showError(e.toString()); MessageUtil.showError("Current arguments: " + Arrays.toString(args)); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("java -jar <this-file.jar>", options, true); } catch (Throwable e) { MessageUtil.showError(e.toString()); } }
From source file:net.anthonypoon.ngram.correlation.Main.java
public static void main(String[] args) throws Exception { Options options = new Options(); options.addOption("a", "action", true, "Action"); options.addOption("i", "input", true, "input"); options.addOption("o", "output", true, "output"); //options.addOption("f", "format", true, "Format"); options.addOption("u", "upbound", true, "Year up bound"); options.addOption("l", "lowbound", true, "Year low bound"); options.addOption("t", "target", true, "Correlation Target URI"); // Can only take file from S# or HDFS options.addOption("L", "lag", true, "Lag factor"); options.addOption("T", "threshold", true, "Correlation threshold"); CommandLineParser parser = new GnuParser(); CommandLine cmd = parser.parse(options, args); Configuration conf = new Configuration(); if (cmd.hasOption("lag")) { conf.set("lag", cmd.getOptionValue("lag")); }/* w w w . j av a2 s . com*/ if (cmd.hasOption("threshold")) { conf.set("threshold", cmd.getOptionValue("threshold")); } if (cmd.hasOption("upbound")) { conf.set("upbound", cmd.getOptionValue("upbound")); } else { conf.set("upbound", "9999"); } if (cmd.hasOption("lowbound")) { conf.set("lowbound", cmd.getOptionValue("lowbound")); } else { conf.set("lowbound", "0"); } if (cmd.hasOption("target")) { conf.set("target", cmd.getOptionValue("target")); } else { throw new Exception("Missing correlation target file uri"); } Job job = Job.getInstance(conf); /** if (cmd.hasOption("format")) { switch (cmd.getOptionValue("format")) { case "compressed": job.setInputFormatClass(SequenceFileAsTextInputFormat.class); break; case "text": job.setInputFormatClass(KeyValueTextInputFormat.class); break; } }**/ job.setJarByClass(Main.class); switch (cmd.getOptionValue("action")) { case "get-correlation": job.setOutputKeyClass(Text.class); job.setOutputValueClass(Text.class); for (String inputPath : cmd.getOptionValue("input").split(",")) { MultipleInputs.addInputPath(job, new Path(inputPath), KeyValueTextInputFormat.class, CorrelationMapper.class); } job.setReducerClass(CorrelationReducer.class); break; default: throw new IllegalArgumentException("Missing action"); } String timestamp = new SimpleDateFormat("yyyy_MM_dd_HH_mm_ss").format(new Date()); //FileInputFormat.setInputPaths(job, new Path(cmd.getOptionValue("input"))); FileOutputFormat.setOutputPath(job, new Path(cmd.getOptionValue("output") + "/" + timestamp)); System.exit(job.waitForCompletion(true) ? 0 : 1); }
From source file:com.boulmier.machinelearning.jobexecutor.JobExecutor.java
public static void main(String[] args) throws ParseException, IOException, InterruptedException { Options options = defineOptions();/*from w w w. ja va2 s.c o m*/ sysMon = new JavaSysMon(); InetAddress vmscheduler_ip, mongodb_ip = null; Integer vmscheduler_port = null, mongodb_port = null; CommandLineParser parser = new BasicParser(); try { CommandLine cmd = parser.parse(options, args); if (cmd.hasOption(JobExecutorConfig.OPTIONS.CMD.LONGPORTFIELD)) { vmscheduler_port = Integer.valueOf(cmd.getOptionValue(JobExecutorConfig.OPTIONS.CMD.LONGPORTFIELD)); } mongodb_port = (int) (cmd.hasOption(JobExecutorConfig.OPTIONS.CMD.LONGMONGOPORTFIELD) ? cmd.hasOption(JobExecutorConfig.OPTIONS.CMD.LONGMONGOPORTFIELD) : JobExecutorConfig.OPTIONS.LOGGING.MONGO_DEFAULT_PORT); mongodb_ip = InetAddress.getByName(cmd.getOptionValue(JobExecutorConfig.OPTIONS.CMD.LONGMONGOIPFIELD)); vmscheduler_ip = InetAddress.getByName(cmd.getOptionValue(JobExecutorConfig.OPTIONS.CMD.LONGIPFIELD)); decryptKey = cmd.getOptionValue("decrypt-key"); debugState = cmd.hasOption(JobExecutorConfig.OPTIONS.CMD.LONGDEBUGFIELD); logger = LoggerFactory.getLogger(); logger.info("Attempt to connect on master @" + vmscheduler_ip + ":" + vmscheduler_port); new RequestConsumer().start(); } catch (MissingOptionException moe) { logger.error(moe.getMissingOptions() + " are missing"); HelpFormatter help = new HelpFormatter(); help.printHelp(JobExecutor.class.getSimpleName(), options); } catch (UnknownHostException ex) { logger.error(ex.getMessage()); } finally { Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { logger.info("JobExeutor is shutting down"); } }); } }
From source file:fr.inria.atlanmod.kyanos.benchmarks.KyanosGraphTraverser.java
public static void main(String[] args) { Options options = new Options(); Option inputOpt = OptionBuilder.create(IN); inputOpt.setArgName("INPUT"); inputOpt.setDescription("Input Kyanos resource directory"); inputOpt.setArgs(1);// www .j ava2s. c o m inputOpt.setRequired(true); Option inClassOpt = OptionBuilder.create(EPACKAGE_CLASS); inClassOpt.setArgName("CLASS"); inClassOpt.setDescription("FQN of EPackage implementation class"); inClassOpt.setArgs(1); inClassOpt.setRequired(true); Option optFileOpt = OptionBuilder.create(OPTIONS_FILE); optFileOpt.setArgName("FILE"); optFileOpt.setDescription("Properties file holding the options to be used in the Kyanos Resource"); optFileOpt.setArgs(1); options.addOption(inputOpt); options.addOption(inClassOpt); options.addOption(optFileOpt); CommandLineParser parser = new PosixParser(); try { PersistenceBackendFactoryRegistry.getFactories().put(NeoBlueprintsURI.NEO_GRAPH_SCHEME, new BlueprintsPersistenceBackendFactory()); CommandLine commandLine = parser.parse(options, args); URI uri = NeoBlueprintsURI.createNeoGraphURI(new File(commandLine.getOptionValue(IN))); Class<?> inClazz = KyanosGraphTraverser.class.getClassLoader() .loadClass(commandLine.getOptionValue(EPACKAGE_CLASS)); inClazz.getMethod("init").invoke(null); ResourceSet resourceSet = new ResourceSetImpl(); resourceSet.getResourceFactoryRegistry().getProtocolToFactoryMap() .put(NeoBlueprintsURI.NEO_GRAPH_SCHEME, PersistentResourceFactory.eINSTANCE); Resource resource = resourceSet.createResource(uri); Map<String, Object> loadOpts = new HashMap<String, Object>(); if (commandLine.hasOption(OPTIONS_FILE)) { Properties properties = new Properties(); properties.load(new FileInputStream(new File(commandLine.getOptionValue(OPTIONS_FILE)))); for (final Entry<Object, Object> entry : properties.entrySet()) { loadOpts.put((String) entry.getKey(), (String) entry.getValue()); } } resource.load(loadOpts); LOG.log(Level.INFO, "Start counting"); int count = 0; long begin = System.currentTimeMillis(); for (Iterator<EObject> iterator = resource.getAllContents(); iterator.hasNext(); iterator .next(), count++) ; long end = System.currentTimeMillis(); LOG.log(Level.INFO, "End counting"); LOG.log(Level.INFO, MessageFormat.format("Resource {0} contains {1} elements", uri, count)); LOG.log(Level.INFO, MessageFormat.format("Time spent: {0}", MessageUtil.formatMillis(end - begin))); if (resource instanceof PersistentResourceImpl) { PersistentResourceImpl.shutdownWithoutUnload((PersistentResourceImpl) resource); } else { resource.unload(); } } catch (ParseException e) { MessageUtil.showError(e.toString()); MessageUtil.showError("Current arguments: " + Arrays.toString(args)); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("java -jar <this-file.jar>", options, true); } catch (Throwable e) { MessageUtil.showError(e.toString()); } }
From source file:com.mvdb.etl.actions.FetchConfigValue.java
/** * @param args/*from w ww. j a v a 2 s.c om*/ * @throws IOException */ public static void main(String[] args) throws IOException { String customerName = null; String valueName = null; String outputFileName = null; ActionUtils.setUpInitFileProperty(); final CommandLineParser cmdLinePosixParser = new PosixParser(); final Options posixOptions = constructPosixOptions(); CommandLine commandLine; try { commandLine = cmdLinePosixParser.parse(posixOptions, args); if (commandLine.hasOption("customer")) { customerName = commandLine.getOptionValue("customer"); } if (commandLine.hasOption("name")) { valueName = commandLine.getOptionValue("name"); } if (commandLine.hasOption("outputFile")) { outputFileName = commandLine.getOptionValue("outputFile"); } System.out.println("customerName:" + customerName); System.out.println("valueName:" + valueName); System.out.println("outputFileName:" + outputFileName); } catch (ParseException parseException) // checked exception { System.err.println( "Encountered exception while parsing using PosixParser:\n" + parseException.getMessage()); } if (customerName == null) { System.err.println("Could not find customerName. Aborting..."); System.exit(1); } if (valueName == null) { System.err.println("Could not find valueName. Aborting..."); System.exit(1); } if (outputFileName == null) { System.err.println("Could not find outputFileName. Aborting..."); System.exit(1); } String value = ActionUtils.getConfigurationValue(customerName, valueName); FileUtils.writeStringToFile(new File(outputFileName), value); }
From source file:it.codestudio.callbyj.CallByJ.java
/** * The main method.//w w w . j a va 2 s.c om * * @param args the arguments */ public static void main(String[] args) { options.addOption("aCom", "audio_com", true, "Specify serial COM port for audio streaming (3G APPLICATION ...)"); options.addOption("cCom", "command_com", true, "Specify serial COM port for modem AT command (PC UI INTERFACE ...)"); options.addOption("p", "play_message", false, "Play recorded message instead to respond with audio from mic"); options.addOption("h", "help", false, "Print help for this application"); try { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String audioCOM = ""; String commandCOM = ""; Boolean playMessage = false; args = Utils.fitlerNullString(args); CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("aCom")) { audioCOM = cmd.getOptionValue("aCom"); ; } if (cmd.hasOption("cCom")) { commandCOM = cmd.getOptionValue("cCom"); ; } if (cmd.hasOption("p")) { playMessage = true; } if (audioCOM != null && commandCOM != null && !audioCOM.isEmpty() && !commandCOM.isEmpty()) { comManager = ComManager.getInstance(commandCOM, audioCOM, playMessage); } else { HelpFormatter f = new HelpFormatter(); f.printHelp("\r Exaple: CallByJ -aCom COM11 -cCom COM10 \r OptionsTip", options); return; } options = new Options(); options.addOption("h", "help", false, "Print help for this application"); options.addOption("p", "pin", true, "Specify pin of device, if present"); options.addOption("c", "call", true, "Start call to specified number"); options.addOption("e", "end", false, "End all active call"); options.addOption("t", "terminate", false, "Terminate application"); options.addOption("r", "respond", false, "Respond to incoming call"); comManager.startModemCommandManager(); while (true) { try { String[] commands = { br.readLine() }; commands = Utils.fitlerNullString(commands); cmd = parser.parse(options, commands); if (cmd.hasOption('h')) { HelpFormatter f = new HelpFormatter(); f.printHelp("OptionsTip", options); } if (cmd.hasOption('p')) { String devicePin = cmd.getOptionValue("p"); comManager.insertPin(devicePin); } if (cmd.hasOption('c')) { String numberToCall = cmd.getOptionValue("c"); comManager.sendCommandToModem(ATCommands.CALL, numberToCall); } if (cmd.hasOption('r')) { comManager.respondToIncomingCall(); } if (cmd.hasOption('e')) { comManager.sendCommandToModem(ATCommands.END_CALL); } if (cmd.hasOption('t')) { comManager.sendCommandToModem(ATCommands.END_CALL); comManager.terminate(); System.out.println("CallByJ closed!"); break; //System.exit(0); } } catch (Exception e) { logger.error(e.getMessage(), e); } } } catch (Exception e) { logger.error(e.getMessage(), e); } finally { if (comManager != null) comManager.terminate(); } }
From source file:com.google.api.codegen.DiscoveryFragmentGeneratorTool.java
public static void main(String[] args) throws Exception { Options options = new Options(); options.addOption("h", "help", false, "show usage"); options.addOption(Option.builder().longOpt("discovery_doc") .desc("The Discovery doc representing the service description.").hasArg().argName("DISCOVERY-DOC") .required(true).build());/*from w w w . ja v a 2 s . co m*/ options.addOption(Option.builder().longOpt("overrides").desc("The path to the sample config overrides file") .hasArg().argName("OVERRIDES").build()); options.addOption(Option.builder().longOpt("gapic_yaml").desc("The GAPIC YAML configuration file or files.") .hasArg().argName("GAPIC-YAML").required(true).build()); options.addOption(Option.builder("o").longOpt("output") .desc("The directory in which to output the generated fragments.").hasArg() .argName("OUTPUT-DIRECTORY").build()); options.addOption(Option.builder().longOpt("auth_instructions") .desc("An @-delimited map of language to auth instructions URL: lang:URL@lang:URL@...").hasArg() .argName("AUTH-INSTRUCTIONS").build()); CommandLine cl = (new DefaultParser()).parse(options, args); if (cl.hasOption("help")) { HelpFormatter formater = new HelpFormatter(); formater.printHelp("CodeGeneratorTool", options); } generate(cl.getOptionValue("discovery_doc"), cl.getOptionValues("gapic_yaml"), cl.getOptionValue("overrides", ""), cl.getOptionValue("output", ""), cl.getOptionValue("auth_instructions", "")); }
From source file:di.uniba.it.tee2.search.Search.java
/** * language maindir query temp_query//w w w . j a v a 2 s . com * * @param args the command line arguments */ public static void main(String[] args) { try { CommandLine cmd = cmdParser.parse(options, args); if (cmd.hasOption("l") && cmd.hasOption("d") && cmd.hasOption("q")) { try { TemporalExtractor te = new TemporalExtractor(cmd.getOptionValue("l")); te.init(); TemporalEventSearch search = new TemporalEventSearch(cmd.getOptionValue("d"), te); search.init(); List<SearchResult> res = search.search(cmd.getOptionValue("q"), cmd.getOptionValue("t", ""), 100); for (SearchResult r : res) { System.out.println(r); } search.close(); te.close(); } catch (Exception ex) { Logger.getLogger(Search.class.getName()).log(Level.SEVERE, null, ex); } } else { HelpFormatter helpFormatter = new HelpFormatter(); helpFormatter.printHelp("Run searching", options, true); } } catch (ParseException ex) { Logger.getLogger(Search.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:knowledgeMiner.InformationDripBootstrapping.java
public static void main(String[] args) { Options options = new Options(); options.addOption("r", true, "The number of ripples (-1 for unlimited)."); options.addOption("c", true, "The concept to begin with (\"article\" or #concept)."); options.addOption("N", true, "The initial hashmap size for the nodes."); options.addOption("i", true, "Initial run number."); CommandLineParser parser = new BasicParser(); try {/*from w w w. ja v a 2s . c o m*/ CommandLine parse = parser.parse(options, args); InformationDripBootstrapping rb = new InformationDripBootstrapping(parse.getOptionValue("c"), parse.getOptionValue("r"), parse.getOptionValue("N"), parse.getOptionValue("i")); rb.run(); } catch (Exception e) { e.printStackTrace(); System.exit(1); } }
From source file:mosaicsimulation.MosaicLockstepServer.java
public static void main(String[] args) { Options opts = new Options(); opts.addOption("s", "serverPort", true, "Listening TCP port used to initiate handshakes"); opts.addOption("n", "nClients", true, "Number of clients that will participate in the session"); opts.addOption("t", "tickrate", true, "Number of transmission session to execute per second"); opts.addOption("m", "maxUDPPayloadLength", true, "Max number of bytes per UDP packet"); opts.addOption("c", "connectionTimeout", true, "Timeout for UDP connections"); DefaultParser parser = new DefaultParser(); CommandLine commandLine = null; try {// w ww . j a v a 2 s . com commandLine = parser.parse(opts, args); } catch (ParseException ex) { ex.printStackTrace(); System.exit(1); } int serverPort = Integer.parseInt(commandLine.getOptionValue("serverPort")); int nClients = Integer.parseInt(commandLine.getOptionValue("nClients")); int tickrate = Integer.parseInt(commandLine.getOptionValue("tickrate")); int maxUDPPayloadLength = Integer.parseInt(commandLine.getOptionValue("maxUDPPayloadLength")); int connectionTimeout = Integer.parseInt(commandLine.getOptionValue("connectionTimeout")); Thread serverThread = LockstepServer.builder().clientsNumber(nClients).tcpPort(serverPort) .tickrate(tickrate).maxUDPPayloadLength(maxUDPPayloadLength).connectionTimeout(connectionTimeout) .build(); serverThread.setName("Main-server-thread"); serverThread.start(); try { serverThread.join(); } catch (InterruptedException ex) { LOG.error("Server interrupted while joining"); } }