List of usage examples for org.apache.commons.cli CommandLine getOptionValue
public String getOptionValue(char opt)
From source file:fr.inria.atlanmod.kyanos.benchmarks.KyanosMapQueryClassDeclarationAttributes.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. ja v a 2 s. 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); options.addOption(inputOpt); options.addOption(inClassOpt); CommandLineParser parser = new PosixParser(); try { PersistenceBackendFactoryRegistry.getFactories().put(NeoMapURI.NEO_MAP_SCHEME, new MapPersistenceBackendFactory()); CommandLine commandLine = parser.parse(options, args); URI uri = NeoMapURI.createNeoMapURI(new File(commandLine.getOptionValue(IN))); Class<?> inClazz = KyanosMapQueryClassDeclarationAttributes.class.getClassLoader() .loadClass(commandLine.getOptionValue(EPACKAGE_CLASS)); inClazz.getMethod("init").invoke(null); ResourceSet resourceSet = new ResourceSetImpl(); resourceSet.getResourceFactoryRegistry().getProtocolToFactoryMap().put(NeoMapURI.NEO_MAP_SCHEME, PersistentResourceFactory.eINSTANCE); Resource resource = resourceSet.createResource(uri); Map<String, Object> loadOpts = new HashMap<String, Object>(); resource.load(loadOpts); { LOG.log(Level.INFO, "Start query"); long begin = System.currentTimeMillis(); HashMap<String, EList<NamedElement>> list = JavaQueries.getClassDeclarationAttributes(resource); long end = System.currentTimeMillis(); LOG.log(Level.INFO, "End query"); LOG.log(Level.INFO, MessageFormat.format("Query result contains {0} elements", list.entrySet().size())); 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:fr.inria.atlanmod.kyanos.benchmarks.KyanosMapQueryRenameAllMethods.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);// w ww. j av a2s . co 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); options.addOption(inputOpt); options.addOption(inClassOpt); CommandLineParser parser = new PosixParser(); try { PersistenceBackendFactoryRegistry.getFactories().put(NeoMapURI.NEO_MAP_SCHEME, new MapPersistenceBackendFactory()); CommandLine commandLine = parser.parse(options, args); URI uri = NeoMapURI.createNeoMapURI(new File(commandLine.getOptionValue(IN))); Class<?> inClazz = KyanosMapQueryRenameAllMethods.class.getClassLoader() .loadClass(commandLine.getOptionValue(EPACKAGE_CLASS)); inClazz.getMethod("init").invoke(null); ResourceSet resourceSet = new ResourceSetImpl(); resourceSet.getResourceFactoryRegistry().getProtocolToFactoryMap().put(NeoMapURI.NEO_MAP_SCHEME, PersistentResourceFactory.eINSTANCE); Resource resource = resourceSet.createResource(uri); Map<String, Object> loadOpts = new HashMap<String, Object>(); resource.load(loadOpts); String name = UUID.randomUUID().toString(); { LOG.log(Level.INFO, "Start query"); long begin = System.currentTimeMillis(); JavaQueries.renameAllMethods(resource, name); long end = System.currentTimeMillis(); resource.save(Collections.emptyMap()); LOG.log(Level.INFO, "End query"); 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.adobe.aem.demomachine.Updates.java
public static void main(String[] args) { String rootFolder = null;/*from ww w. j a v a 2 s . co m*/ // Command line options for this tool Options options = new Options(); options.addOption("f", true, "Demo Machine root folder"); CommandLineParser parser = new BasicParser(); try { CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("f")) { rootFolder = cmd.getOptionValue("f"); } } catch (Exception e) { System.exit(-1); } Properties md5properties = new Properties(); try { URL url = new URL( "https://raw.githubusercontent.com/Adobe-Marketing-Cloud/aem-demo-machine/master/conf/checksums.properties"); InputStream in = url.openStream(); Reader reader = new InputStreamReader(in, "UTF-8"); md5properties.load(reader); reader.close(); } catch (Exception e) { System.out.println("Error: Cannot connect to GitHub.com to check for updates"); System.exit(-1); } System.out.println(AemDemoConstants.HR); int nbUpdateAvailable = 0; List<String[]> listPaths = Arrays.asList(AemDemoConstants.demoPaths); for (String[] path : listPaths) { if (path.length == 5) { logger.debug(path[1]); File pathFolder = new File(rootFolder + (path[1].length() > 0 ? (File.separator + path[1]) : "")); if (pathFolder.exists()) { String newMd5 = AemDemoUtils.calcMD5HashForDir(pathFolder, Boolean.parseBoolean(path[3]), false); logger.debug("MD5 is: " + newMd5); String oldMd5 = md5properties.getProperty("demo.md5." + path[0]); if (oldMd5 == null || oldMd5.length() == 0) { logger.error("Cannot find MD5 for " + path[0]); System.out.println(path[2] + " : Cannot find M5 checksum"); continue; } if (newMd5.equals(oldMd5)) { continue; } else { System.out.println(path[2] + " : New update available" + (path[0].equals("0") ? " (use 'git pull' to get the latest changes)" : "")); nbUpdateAvailable++; } } else { System.out.println(path[2] + " : Not installed"); } } } if (nbUpdateAvailable == 0) { System.out.println("Your AEM Demo Machine is up to date!"); } System.out.println(AemDemoConstants.HR); }
From source file:fr.inria.atlanmod.kyanos.benchmarks.KyanosMapQueryLoop.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);/* ww w .ja v a 2s .co 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); options.addOption(inputOpt); options.addOption(inClassOpt); CommandLineParser parser = new PosixParser(); try { PersistenceBackendFactoryRegistry.getFactories().put(NeoMapURI.NEO_MAP_SCHEME, new MapPersistenceBackendFactory()); CommandLine commandLine = parser.parse(options, args); URI uri = NeoMapURI.createNeoMapURI(new File(commandLine.getOptionValue(IN))); Class<?> inClazz = KyanosMapQueryLoop.class.getClassLoader() .loadClass(commandLine.getOptionValue(EPACKAGE_CLASS)); inClazz.getMethod("init").invoke(null); ResourceSet resourceSet = new ResourceSetImpl(); resourceSet.getResourceFactoryRegistry().getProtocolToFactoryMap().put(NeoMapURI.NEO_MAP_SCHEME, PersistentResourceFactory.eINSTANCE); Resource resource = resourceSet.createResource(uri); Map<String, Object> loadOpts = new HashMap<String, Object>(); resource.load(loadOpts); { LOG.log(Level.INFO, "Start query"); long begin = System.currentTimeMillis(); EList<MethodDeclaration> list = JavaQueries.getUnusedMethodsLoop(resource); long end = System.currentTimeMillis(); LOG.log(Level.INFO, "End query"); LOG.log(Level.INFO, MessageFormat.format("Query result (loops) contains {0} elements", list.size())); 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:fr.inria.atlanmod.kyanos.benchmarks.CdoQuery.java
public static void main(String[] args) { Options options = new Options(); Option inputOpt = OptionBuilder.create(IN); inputOpt.setArgName("INPUT"); inputOpt.setDescription("Input CDO resource directory"); inputOpt.setArgs(1);/*from ww w . jav a 2s . co 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 repoOpt = OptionBuilder.create(REPO_NAME); repoOpt.setArgName("REPO_NAME"); repoOpt.setDescription("CDO Repository name"); repoOpt.setArgs(1); repoOpt.setRequired(true); options.addOption(inputOpt); options.addOption(inClassOpt); options.addOption(repoOpt); CommandLineParser parser = new PosixParser(); try { CommandLine commandLine = parser.parse(options, args); String repositoryDir = commandLine.getOptionValue(IN); String repositoryName = commandLine.getOptionValue(REPO_NAME); Class<?> inClazz = CdoQuery.class.getClassLoader() .loadClass(commandLine.getOptionValue(EPACKAGE_CLASS)); inClazz.getMethod("init").invoke(null); EmbeddedCDOServer server = new EmbeddedCDOServer(repositoryDir, repositoryName); try { server.run(); CDOSession session = server.openSession(); CDOTransaction transaction = session.openTransaction(); Resource resource = transaction.getRootResource(); { LOG.log(Level.INFO, "Start query"); long begin = System.currentTimeMillis(); EList<MethodDeclaration> list = JavaQueries.getUnusedMethodsList(resource); long end = System.currentTimeMillis(); LOG.log(Level.INFO, "End query"); LOG.log(Level.INFO, MessageFormat.format("Query result (list) contains {0} elements", list.size())); LOG.log(Level.INFO, MessageFormat.format("Time spent: {0}", MessageUtil.formatMillis(end - begin))); } { LOG.log(Level.INFO, "Start query"); long begin = System.currentTimeMillis(); EList<MethodDeclaration> list = JavaQueries.getUnusedMethodsLoop(resource); long end = System.currentTimeMillis(); LOG.log(Level.INFO, "End query"); LOG.log(Level.INFO, MessageFormat.format("Query result (loops) contains {0} elements", list.size())); LOG.log(Level.INFO, MessageFormat.format("Time spent: {0}", MessageUtil.formatMillis(end - begin))); } transaction.close(); session.close(); } finally { server.stop(); } } 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.adobe.aem.demo.Analytics.java
public static void main(String[] args) { String hostname = null;/*from w w w .ja v a 2s . c o m*/ String url = null; String eventfile = null; // Command line options for this tool Options options = new Options(); options.addOption("h", true, "Hostname"); options.addOption("u", true, "Url"); options.addOption("f", true, "Event data file"); CommandLineParser parser = new BasicParser(); try { CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("u")) { url = cmd.getOptionValue("u"); } if (cmd.hasOption("f")) { eventfile = cmd.getOptionValue("f"); } if (cmd.hasOption("h")) { hostname = cmd.getOptionValue("h"); } if (eventfile == null || hostname == null || url == null) { System.out.println("Command line parameters: -h hostname -u url -f path_to_XML_file"); System.exit(-1); } } catch (ParseException ex) { logger.error(ex.getMessage()); } URLConnection urlConn = null; DataOutputStream printout = null; BufferedReader input = null; String u = "http://" + hostname + "/" + url; String tmp = null; try { URL myurl = new URL(u); urlConn = myurl.openConnection(); urlConn.setDoInput(true); urlConn.setDoOutput(true); urlConn.setUseCaches(false); urlConn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); printout = new DataOutputStream(urlConn.getOutputStream()); String xml = readFile(eventfile, StandardCharsets.UTF_8); printout.writeBytes(xml); printout.flush(); printout.close(); input = new BufferedReader(new InputStreamReader(urlConn.getInputStream())); logger.debug(xml); while (null != ((tmp = input.readLine()))) { logger.debug(tmp); } printout.close(); input.close(); } catch (Exception ex) { logger.error(ex.getMessage()); } }
From source file:com.google.infrastructuredmap.MapAndMarkdownExtractorMain.java
public static void main(String[] args) throws IOException, ParseException { Options options = new Options(); options.addOption(ARG_KML, true, "path to KML input"); options.addOption(ARG_MARKDOWN, true, "path to Markdown input"); options.addOption(ARG_JSON_OUTPUT, true, "path to write json output"); options.addOption(ARG_JSONP, true, "JSONP template to wrap output JSON data"); CommandLineParser parser = new DefaultParser(); CommandLine cli = parser.parse(options, args); // Extract map features from the input KML. MapData data = null;/* ww w. ja v a 2 s .c o m*/ try (InputStream in = openStream(cli.getOptionValue(ARG_KML))) { Kml kml = Kml.unmarshal(in); data = MapDataExtractor.extractMapData(kml); } // Extract project features from the input Markdown. Map<String, List<ProjectReference>> references = MarkdownReferenceExtractor .extractReferences(Paths.get(cli.getOptionValue(ARG_MARKDOWN))); for (MapFeature feature : data.features) { List<ProjectReference> referencesForId = references.get(feature.id); if (referencesForId == null) { throw new IllegalStateException("Unknown project reference: " + feature.id); } feature.projects = referencesForId; } // Write the resulting data to the output path. Gson gson = new Gson(); try (FileWriter out = new FileWriter(cli.getOptionValue(ARG_JSON_OUTPUT))) { String json = gson.toJson(data); if (cli.hasOption(ARG_JSONP)) { json = String.format(cli.getOptionValue(ARG_JSONP), json); } out.write(json); } }
From source file:com.servioticy.dispatcher.DispatcherTopology.java
/** * @param args//ww w . ja va 2s .com * @throws InvalidTopologyException * @throws AlreadyAliveException * @throws InterruptedException */ public static void main(String[] args) throws AlreadyAliveException, InvalidTopologyException, InterruptedException, ParseException { Options options = new Options(); options.addOption( OptionBuilder.withArgName("file").hasArg().withDescription("Config file path.").create("f")); options.addOption(OptionBuilder.withArgName("topology").hasArg() .withDescription("Name of the topology in storm. If no name is given it will run in local mode.") .create("t")); options.addOption(OptionBuilder.withDescription("Enable debugging").create("d")); CommandLineParser parser = new GnuParser(); CommandLine cmd = parser.parse(options, args); String path = null; if (cmd.hasOption("f")) { path = cmd.getOptionValue("f"); } DispatcherContext dc = new DispatcherContext(); dc.loadConf(path); TopologyBuilder builder = new TopologyBuilder(); // TODO Auto-assign workers to the spout in function of the number of Kestrel IPs builder.setSpout("updates", new KestrelThriftSpout(Arrays.asList(dc.updatesAddresses), dc.updatesPort, dc.updatesQueue, new UpdateDescriptorScheme())); builder.setSpout("actions", new KestrelThriftSpout(Arrays.asList(dc.actionsAddresses), dc.actionsPort, dc.actionsQueue, new ActuationScheme())); builder.setBolt("prepare", new PrepareBolt(dc)).shuffleGrouping("updates"); builder.setBolt("actuationdispatcher", new ActuationDispatcherBolt(dc)).shuffleGrouping("actions"); builder.setBolt("subretriever", new SubscriptionRetrieveBolt(dc)).shuffleGrouping("prepare", "subscription"); builder.setBolt("externaldispatcher", new ExternalDispatcherBolt(dc)).fieldsGrouping("subretriever", "externalSub", new Fields("subid")); builder.setBolt("internaldispatcher", new InternalDispatcherBolt(dc)).fieldsGrouping("subretriever", "internalSub", new Fields("subid")); builder.setBolt("streamdispatcher", new StreamDispatcherBolt(dc)) .shuffleGrouping("subretriever", "streamSub").shuffleGrouping("prepare", "stream"); builder.setBolt("streamprocessor", new StreamProcessorBolt(dc)).shuffleGrouping("streamdispatcher", "default"); if (dc.benchmark) { builder.setBolt("benchmark", new BenchmarkBolt(dc)).shuffleGrouping("streamdispatcher", "benchmark") .shuffleGrouping("subretriever", "benchmark").shuffleGrouping("streamprocessor", "benchmark") .shuffleGrouping("prepare", "benchmark"); } Config conf = new Config(); conf.setDebug(cmd.hasOption("d")); if (cmd.hasOption("t")) { StormSubmitter.submitTopology(cmd.getOptionValue("t"), conf, builder.createTopology()); } else { conf.setMaxTaskParallelism(4); LocalCluster cluster = new LocalCluster(); cluster.submitTopology("dispatcher", conf, builder.createTopology()); } }
From source file:de.drippinger.cytricHelper.CommandLineStart.java
public static void main(String[] args) throws ParseException { CommandLineParser parser = new DefaultParser(); CommandLine cmd = parser.parse(createOptions(), args); CytricHelper helper = new CytricHelper(); if (cmd.hasOption("f") && cmd.hasOption("e")) { try {//w w w .ja v a 2 s .c o m helper.manipulatePdf(cmd.getOptionValue("f"), cmd.getOptionValue("e")); } catch (IOException e) { e.printStackTrace(); } catch (DocumentException e) { e.printStackTrace(); } } else { printHelp(); } }
From source file:gov.lanl.adore.djatoka.DjatokaExtract.java
/** * Uses apache commons cli to parse input args. Passes parsed * parameters to IExtract implementation. * @param args command line parameters to defined input,output,etc. *///from ww w.jav a2 s .com public static void main(String[] args) { // create the command line parser CommandLineParser parser = new PosixParser(); // create the Options Options options = new Options(); options.addOption("i", "input", true, "Filepath of the input file."); options.addOption("o", "output", true, "Filepath of the output file."); options.addOption("l", "level", true, "Resolution level to extract."); options.addOption("d", "reduce", true, "Resolution levels to subtract from max resolution."); options.addOption("r", "region", true, "Format: Y,X,H,W. "); options.addOption("c", "cLayer", true, "Compositing Layer Index."); options.addOption("s", "scale", true, "Format: Option 1. Define a long-side dimension (e.g. 96); Option 2. Define absolute w,h values (e.g. 1024,768); Option 3. Define a single dimension (e.g. 1024,0) with or without Level Parameter; Option 4. Use a single decimal scaling factor (e.g. 0.854)"); options.addOption("t", "rotate", true, "Number of degrees to rotate image (i.e. 90, 180, 270)."); options.addOption("f", "format", true, "Mimetype of the image format to be provided as response. Default: image/jpeg"); options.addOption("a", "AltImpl", true, "Alternate IExtract Implemenation"); try { if (args.length == 0) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("gov.lanl.adore.djatoka.DjatokaExtract", options); System.exit(0); } // parse the command line arguments CommandLine line = parser.parse(options, args); String input = line.getOptionValue("i"); String output = line.getOptionValue("o"); DjatokaDecodeParam p = new DjatokaDecodeParam(); String level = line.getOptionValue("l"); if (level != null) p.setLevel(Integer.parseInt(level)); String reduce = line.getOptionValue("d"); if (level == null && reduce != null) p.setLevelReductionFactor(Integer.parseInt(reduce)); String region = line.getOptionValue("r"); if (region != null) p.setRegion(region); String cl = line.getOptionValue("c"); if (cl != null) { int clayer = Integer.parseInt(cl); if (clayer > 0) p.setCompositingLayer(clayer); } String scale = line.getOptionValue("s"); if (scale != null) { String[] v = scale.split(","); if (v.length == 1) { if (v[0].contains(".")) p.setScalingFactor(Double.parseDouble(v[0])); else { int[] dims = new int[] { -1, Integer.parseInt(v[0]) }; p.setScalingDimensions(dims); } } else if (v.length == 2) { int[] dims = new int[] { Integer.parseInt(v[0]), Integer.parseInt(v[1]) }; p.setScalingDimensions(dims); } } String rotate = line.getOptionValue("t"); if (rotate != null) p.setRotationDegree(Integer.parseInt(rotate)); String format = line.getOptionValue("f"); if (format == null) format = "image/jpeg"; String alt = line.getOptionValue("a"); if (output == null) output = input + ".jpg"; long x = System.currentTimeMillis(); IExtract ex = new KduExtractExe(); if (alt != null) ex = (IExtract) Class.forName(alt).newInstance(); DjatokaExtractProcessor e = new DjatokaExtractProcessor(ex); e.extractImage(input, output, p, format); logger.info("Extraction Time: " + ((double) (System.currentTimeMillis() - x) / 1000) + " seconds"); } catch (ParseException e) { logger.error("Parse exception:" + e.getMessage(), e); } catch (DjatokaException e) { logger.error("djatoka Extraction exception:" + e.getMessage(), e); } catch (InstantiationException e) { logger.error("Unable to initialize alternate implemenation:" + e.getMessage(), e); } catch (Exception e) { logger.error("Unexpected exception:" + e.getMessage(), e); } }