List of usage examples for org.apache.commons.cli CommandLine getOptionValue
public String getOptionValue(char opt)
From source file:gr.forth.ics.isl.preprocessfilter1.controller.Controller.java
public static void main(String[] args) throws XPathExpressionException, ParserConfigurationException, SAXException, IOException, PreprocessFilterException, org.apache.commons.cli.ParseException { PropertyReader prop = new PropertyReader(); //The following block of code is executed if there are arguments from the command line if (args.length > 0) { try {/* w ww .j a v a 2 s . c o m*/ //The values of the arguments are handled as Option instances Options options = new Options(); CommandLineParser PARSER = new PosixParser(); Option inputFile = new Option("inputFile", true, "input xml file"); Option outputFile = new Option("outputFile", true, "output xml file"); Option parentNode = new Option("parentNode", true, "output xml file"); Option delimeter = new Option("delimeter", true, "output xml file"); Option newParentNode = new Option("newParentNode", true, "output xml file"); Option intermediateNodes = new Option("intermediateNodes", true, "output xml file"); Option intermediateNode = new Option("intermediateNode", true, "output xml file"); options.addOption(inputFile).addOption(outputFile).addOption(parentNode).addOption(newParentNode) .addOption(intermediateNode).addOption(intermediateNodes).addOption(delimeter); CommandLine cli = PARSER.parse(options, args); String inputFileArg = cli.getOptionValue("inputFile"); String outputFileArg = cli.getOptionValue("outputFile"); String parentNodeArg = cli.getOptionValue("parentNode"); String newParentNodeArg = cli.getOptionValue("newParentNode"); String intermediateNodeArg = cli.getOptionValue("intermediateNode"); String intermediateNodesArg = cli.getOptionValue("intermediateNodes"); String delimeterArg = cli.getOptionValue("delimeter"); PreprocessFilterUtilities process = new PreprocessFilterUtilities(); //System.out.println("INPUT:"+inputFileArg); //System.out.println("OUTPUT:"+outputFileArg); //System.out.println("PARENT NODE:"+parentNodeArg); //System.out.println("NEW PARENT NODE:"+newParentNodeArg); //System.out.println("INTERMEDIATE NODE:"+intermediateNodeArg); //System.out.println("INTERMEDIATE NODES:"+intermediateNodesArg); //System.out.println("DELIMETER:"+delimeterArg); //The filter's code is executed with the command line arguments as parameters if (process.createOutputFile(inputFileArg, outputFileArg, parentNodeArg, newParentNodeArg, intermediateNodeArg, intermediateNodesArg, delimeterArg)) { System.out.println("Succesfull PreProcessing!!!"); } } catch (PreprocessFilterException ex) { Logger.getLogger(Controller.class.getName()).log(Level.SEVERE, null, ex); throw new PreprocessFilterException("PreProcess Filter Exception:", ex); } } //If there are no command line arguments then the .config file is being used. else { try { String inputFilePathProp = prop.getProperty(inputFilePath); String outputFilePathProp = prop.getProperty(outputFilePath); String parentNodeProp = prop.getProperty(parentNode); String delimeterProp = prop.getProperty(delimeter); String newParentNodeProp = prop.getProperty(newParentNode); String intermediateNodesProp = prop.getProperty(intermediateNodes); String intermediateNodeProp = prop.getProperty(intermediateNode); PreprocessFilterUtilities process = new PreprocessFilterUtilities(); //The filter's code is executed with the .config file's resources as parameters if (process.createOutputFile(inputFilePathProp, outputFilePathProp, parentNodeProp, newParentNodeProp, intermediateNodeProp, intermediateNodesProp, delimeterProp)) { System.out.println("Succesfull PreProcessing!!!"); } } catch (PreprocessFilterException ex) { Logger.getLogger(Controller.class.getName()).log(Level.SEVERE, null, ex); throw new PreprocessFilterException("PreProcess Filter Exception:", ex); } } }
From source file:com.thoughtworks.xstream.benchmark.cache.CacheBenchmark.java
public static void main(String[] args) { int counter = 10000; Product product = null;/*w w w .j av a2 s . com*/ 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"); Parser parser = new PosixParser(); try { CommandLine commandLine = parser.parse(options, args); if (commandLine.hasOption('p')) { product = (Product) Class.forName(commandLine.getOptionValue('p')).newInstance(); } if (commandLine.hasOption('n')) { counter = Integer.parseInt(commandLine.getOptionValue('n')); } } catch (ParseException e) { e.printStackTrace(); } catch (InstantiationException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (ClassNotFoundException e) { e.printStackTrace(); } Harness harness = new Harness(); // harness.addMetric(new SerializationSpeedMetric(1) { // public String toString() { // return "Initial run serialization"; // } // }); // harness.addMetric(new DeserializationSpeedMetric(1, false) { // public String toString() { // return "Initial run deserialization"; // } // }); harness.addMetric(new SerializationSpeedMetric(counter)); harness.addMetric(new DeserializationSpeedMetric(counter, false)); if (product == null) { harness.addProduct(new NoCache()); harness.addProduct(new Cache122()); harness.addProduct(new RealClassCache()); harness.addProduct(new SerializedClassCache()); harness.addProduct(new AliasedAttributeCache()); harness.addProduct(new DefaultImplementationCache()); harness.addProduct(new NoCache()); } else { harness.addProduct(product); } harness.addTarget(new BasicTarget()); harness.addTarget(new ExtendedTarget()); harness.addTarget(new ReflectionTarget()); harness.addTarget(new SerializableTarget()); harness.run(new TextReporter(new PrintWriter(System.out, true))); System.out.println("Done."); }
From source file:com.genentech.chemistry.tool.SDFFilter.java
public static void main(String args[]) { String usage = "java sdfFilter [options]\n" + "Filters out molecules that contain the following:\n" + "1. More than maxHeavy atoms (default is 100)\n" + "2. Have more than one component\n" + "3. Does not have any atoms\n" + "4. Have invalid atoms, like R, * etc ...\n" + "5. Have atomic number greater than 53 (Iodine)"; // create Options object Options options = new Options(); // add options options.addOption("h", false, ""); options.addOption("in", true, "inFile in OE formats: Ex: a.sdf or .sdf"); options.addOption("out", true, "outFile in OE formats. Ex: a.sdf or .sdf"); options.addOption("filtered", true, "Optional: filteredFile in OE formats. Ex: a.sdf or .sdf"); options.addOption("maxHeavy", true, "Number of heavy atom cutoff. Default is 100"); CommandLineParser parser = new PosixParser(); try {/* w w w . j a va 2 s.c o m*/ CommandLine cmd = parser.parse(options, args); String inFile = cmd.getOptionValue("in"); if (inFile == null) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(usage, options); System.exit(1); } String outFile = cmd.getOptionValue("out"); if (outFile == null) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(usage, options); System.exit(1); } String filteredFile = null; if (cmd.hasOption("filtered")) { filteredFile = cmd.getOptionValue("filtered"); } int maxHeavy = 100; if (cmd.hasOption("maxHeavy")) { maxHeavy = Integer.parseInt(cmd.getOptionValue("maxHeavy")); maxAtoms = maxHeavy; } if (cmd.hasOption("h")) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(usage, options); System.exit(1); } oemolistream ifs = new oemolistream(inFile); oemolostream ofs = new oemolostream(outFile); oemolostream ffs = null; if (filteredFile != null) { ffs = new oemolostream(filteredFile); } /*it appears that we don't have license to molprop toolkit oeisstream iss = new oeisstream(); OEFilter filter = new OEFilter(iss); filter.SetTypeCheck(true); oechem.OEThrow.SetLevel(OEErrorLevel.Warning); */ OEGraphMol mol = new OEGraphMol(); while (oechem.OEReadMolecule(ifs, mol)) { // if (passFilters(mol, filter)) { //needs license to molprop toolkit if (passFilters(mol)) { oechem.OEWriteMolecule(ofs, mol); } else { if (ffs != null) { oechem.OEWriteMolecule(ffs, mol); } } } } catch (ParseException e) { // TODO print explaination throw new Error(e); } }
From source file:edu.cmu.lti.oaqa.annographix.apps.SolrSimpleIndexApp.java
public static void main(String[] args) { Options options = new Options(); options.addOption("i", null, true, "Input File"); options.addOption("u", null, true, "Solr URI"); options.addOption("n", null, true, "Batch size"); CommandLineParser parser = new org.apache.commons.cli.GnuParser(); try {//from www. ja va2s . co m CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("i")) { inputFile = cmd.getOptionValue("i"); } else { Usage("Specify Input File"); } if (cmd.hasOption("u")) { solrURI = cmd.getOptionValue("u"); } else { Usage("Specify Solr URI"); } if (cmd.hasOption("n")) { batchQty = Integer.parseInt(cmd.getOptionValue("n")); } SolrServerWrapper solrServer = new SolrServerWrapper(solrURI); BufferedReader inpText = new BufferedReader( new InputStreamReader(CompressUtils.createInputStream(inputFile))); XmlHelper xmlHlp = new XmlHelper(); String docText = XmlHelper.readNextXMLIndexEntry(inpText); for (int docNum = 1; docText != null; ++docNum, docText = XmlHelper.readNextXMLIndexEntry(inpText)) { // 1. Read document text Map<String, String> docFields = null; HashMap<String, Object> objDocFields = new HashMap<String, Object>(); try { docFields = xmlHlp.parseXMLIndexEntry(docText); } catch (SAXException e) { System.err.println("Parsing error, offending DOC:" + NL + docText); throw new Exception("Parsing error."); } for (Map.Entry<String, String> e : docFields.entrySet()) { //System.out.println(e.getKey() + " " + e.getValue()); objDocFields.put(e.getKey(), e.getValue()); } solrServer.indexDocument(objDocFields); if ((docNum - 1) % batchQty == 0) solrServer.indexCommit(); } solrServer.indexCommit(); } catch (ParseException e) { Usage("Cannot parse arguments"); } catch (Exception e) { System.err.println("Terminating due to an exception: " + e); System.exit(1); } }
From source file:com.contentful.generator.Main.java
public static void main(String[] args) { CommandLineParser parser = new GnuParser(); Options options = constructOptions(); try {//from ww w .j a va 2 s .co m CommandLine line = parser.parse(options, args); if (line.hasOption("space") && line.hasOption("package") && line.hasOption("folder") && line.hasOption("token")) { new Generator().generate(line.getOptionValue("space"), line.getOptionValue("package"), line.getOptionValue("folder"), line.getOptionValue("token")); } else { usage(options); } } catch (ParseException e) { System.err.println("Parsing failed, reason: " + e.getMessage()); } }
From source file:fr.inria.atlanmod.kyanos.benchmarks.ReferencesCounter.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 w w .j av a 2 s .c om*/ inputOpt.setRequired(true); Option outputOpt = OptionBuilder.create(OUT); outputOpt.setArgName("OUTPUT"); outputOpt.setDescription("Output file"); outputOpt.setArgs(1); outputOpt.setRequired(true); Option inClassOpt = OptionBuilder.create(IN_EPACKAGE_CLASS); inClassOpt.setArgName("CLASS"); inClassOpt.setDescription("FQN of input EPackage implementation class"); inClassOpt.setArgs(1); inClassOpt.setRequired(true); Option labelOpt = OptionBuilder.create(LABEL); labelOpt.setArgName("LABEL"); labelOpt.setDescription("Label for the data set"); labelOpt.setArgs(1); labelOpt.setRequired(true); options.addOption(inputOpt); options.addOption(outputOpt); options.addOption(inClassOpt); options.addOption(labelOpt); CommandLineParser parser = new PosixParser(); try { CommandLine commandLine = parser.parse(options, args); URI sourceUri = URI.createFileURI(commandLine.getOptionValue(IN)); Class<?> inClazz = ReferencesCounter.class.getClassLoader() .loadClass(commandLine.getOptionValue(IN_EPACKAGE_CLASS)); @SuppressWarnings("unused") EPackage inEPackage = (EPackage) inClazz.getMethod("init").invoke(null); ResourceSet resourceSet = new ResourceSetImpl(); resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("xmi", new XMIResourceFactoryImpl()); resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("zxmi", new XMIResourceFactoryImpl()); Resource sourceResource = resourceSet.getResource(sourceUri, true); FileWriter writer = new FileWriter(new File(commandLine.getOptionValue(OUT))); try { writer.write(commandLine.getOptionValue(LABEL)); writer.write("\n"); for (Iterator<EObject> iterator = sourceResource.getAllContents(); iterator.hasNext();) { EObject eObject = iterator.next(); for (EStructuralFeature feature : eObject.eClass().getEAllStructuralFeatures()) { if (feature.isMany() && eObject.eIsSet(feature)) { EList<?> value = (EList<?>) eObject.eGet(feature); // if (value.size() > 10) writer.write(String.format("%d\n", value.size())); } } } } finally { IOUtils.closeQuietly(writer); } } catch (ParseException e) { showError(e.toString()); showError("Current arguments: " + Arrays.toString(args)); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("java -jar <this-file.jar>", options, true); } catch (Throwable e) { showError(e.toString()); } }
From source file:edu.hku.sdb.driver.SdbDriver.java
/** * @param args/*from w w w. j a v a 2 s. c om*/ */ public static void main(String[] args) { CommandLine line = parseAndValidateInput(args); String confDir = line.getOptionValue(CONF); Properties properties = line.getOptionProperties("D"); File sdbConnectionConfigFile = new File(confDir + "/" + ConnectionConf.CONF_FILE); File sdbServerConfigFile = new File(confDir + "/" + ServerConf.CONF_FILE); File sdbMetadbConfigFile = new File(confDir + "/" + MetadbConf.CONF_FILE); XMLPropParser propParser = new XMLPropParser(); // Parse all the sdb connection config Map<String, String> prop = propParser.importXML(sdbConnectionConfigFile); // Parse all the server config prop.putAll(propParser.importXML(sdbServerConfigFile)); // Parse all the metadb config prop.putAll(propParser.importXML(sdbMetadbConfigFile)); // Override the config if any Set<Object> states = properties.keySet(); // get set-view of keys for (Object object : states) { String key = (String) object; String value = properties.getProperty(key); prop.put(key, value); } // Cet log4j config PropertyConfigurator.configure(confDir + "/" + "log4j.properties"); ServerConf serverConf = ServerConfFactory.getServerConf(prop); MetadbConf metadbConf = MetadbConfFactory.getMetadbConf(prop); ConnectionConf connectionConf = new ConnectionConf(prop); SdbConf sdbConf = new SdbConf(connectionConf, serverConf, metadbConf); // Start the SDB proxy startConnectionPool(sdbConf); }
From source file:net.geoprism.FileMerger.java
public static void main(String[] args) throws ParseException, IOException { CommandLineParser parser = new DefaultParser(); Options options = new Options(); options.addOption(Option.builder("b").hasArg().argName("baseFile").longOpt("baseFile") .desc("The path to the base properties file.").build()); options.addOption(Option.builder("o").hasArg().argName("overrideFile").longOpt("overrideFile") .desc("The path to the override properties file.").build()); options.addOption(Option.builder("e").hasArg().argName("exportFile").longOpt("exportFile") .desc("The path to the export properties file. A null value defaults to base.").build()); options.addOption(Option.builder("B").hasArg().argName("baseDir").longOpt("baseDir") .desc("The path to the base directory.").build()); options.addOption(Option.builder("O").hasArg().argName("overrideDir").longOpt("overrideDir") .desc("The path to the override directory.").build()); options.addOption(Option.builder("E").hasArg().argName("exportDir").longOpt("exportDir") .desc("The path to the export directory. A null value defaults to base.").build()); CommandLine line = parser.parse(options, args); String sBase = line.getOptionValue("b"); String sOverride = line.getOptionValue("o"); String sExport = line.getOptionValue("e"); String sBaseDir = line.getOptionValue("B"); String sOverrideDir = line.getOptionValue("O"); String sExportDir = line.getOptionValue("E"); if (sBase != null && sOverride != null) { if (sExport == null) { sExport = sBase;//w ww . j av a 2s . c om } File fBase = new File(sBase); File fOverride = new File(sOverride); File fExport = new File(sExport); if (!fBase.exists() || !fOverride.exists()) { throw new RuntimeException( "The base [" + sBase + "] and the override [" + sOverride + "] paths must both exist."); } FileMerger merger = new FileMerger(); merger.mergeProperties(fBase, fOverride, fExport); } else if (sBaseDir != null && sOverrideDir != null) { if (sExportDir == null) { sExportDir = sBaseDir; } File fBaseDir = new File(sBaseDir); File fOverrideDir = new File(sOverrideDir); File fExportDir = new File(sExportDir); if (!fBaseDir.exists() || !fOverrideDir.exists()) { throw new RuntimeException("The base [" + sBaseDir + "] and the override [" + sOverrideDir + "] paths must both exist."); } FileMerger merger = new FileMerger(); merger.mergeDirectories(fBaseDir, fOverrideDir, fExportDir); } else { throw new RuntimeException("Invalid arguments"); } }
From source file:com.github.sdnwiselab.sdnwise.mote.standalone.Loader.java
/** * @param args the command line arguments */// w w w . ja v a 2s. co m public static void main(final String[] args) { Options options = new Options(); options.addOption(Option.builder("n").argName("net").hasArg().required().desc("Network ID of the node") .numberOfArgs(1).build()); options.addOption(Option.builder("a").argName("address").hasArg().required() .desc("Address of the node <0-65535>").numberOfArgs(1).build()); options.addOption(Option.builder("p").argName("port").hasArg().required().desc("Listening UDP port") .numberOfArgs(1).build()); options.addOption(Option.builder("t").argName("filename").hasArg().required() .desc("Use given file for neighbors discovery").numberOfArgs(1).build()); options.addOption(Option.builder("c").argName("ip:port").hasArg() .desc("IP address and TCP port of the controller. (SINK ONLY)").numberOfArgs(1).build()); options.addOption(Option.builder("sp").argName("port").hasArg() .desc("Port number of the switch. (SINK ONLY)").numberOfArgs(1).build()); options.addOption(Option.builder("sm").argName("mac").hasArg() .desc("MAC address of the switch. Example: <00:00:00:00:00:00>." + " (SINK ONLY)").numberOfArgs(1) .build()); options.addOption(Option.builder("sd").argName("dpid").hasArg().desc("DPID of the switch (SINK ONLY)") .numberOfArgs(1).build()); options.addOption(Option.builder("l").argName("level").hasArg() .desc("Use given log level. Values: SEVERE, WARNING, INFO, " + "CONFIG, FINE, FINER, FINEST.") .numberOfArgs(1).optionalArg(true).build()); // create the parser CommandLineParser parser = new DefaultParser(); try { CommandLine line = parser.parse(options, args); Thread th; byte cmdNet = (byte) Integer.parseInt(line.getOptionValue("n")); NodeAddress cmdAddress = new NodeAddress(Integer.parseInt(line.getOptionValue("a"))); int cmdPort = Integer.parseInt(line.getOptionValue("p")); String cmdTopo = line.getOptionValue("t"); String cmdLevel; if (!line.hasOption("l")) { cmdLevel = "SEVERE"; } else { cmdLevel = line.getOptionValue("l"); } if (line.hasOption("c")) { if (!line.hasOption("sd")) { throw new ParseException("-sd option missing"); } if (!line.hasOption("sp")) { throw new ParseException("-sp option missing"); } if (!line.hasOption("sm")) { throw new ParseException("-sm option missing"); } String cmdSDpid = line.getOptionValue("sd"); String cmdSMac = line.getOptionValue("sm"); long cmdSPort = Long.parseLong(line.getOptionValue("sp")); String[] ipport = line.getOptionValue("c").split(":"); th = new Thread(new Sink(cmdNet, cmdAddress, cmdPort, new InetSocketAddress(ipport[0], Integer.parseInt(ipport[1])), cmdTopo, cmdLevel, cmdSDpid, cmdSMac, cmdSPort)); } else { th = new Thread(new Mote(cmdNet, cmdAddress, cmdPort, cmdTopo, cmdLevel)); } th.start(); th.join(); } catch (InterruptedException | ParseException ex) { System.out.println("Parsing failed. Reason: " + ex.getMessage()); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("sdn-wise-data -n id -a address -p port" + " -t filename [-l level] [-sd dpid -sm mac -sp port]", options); } }
From source file:edu.gslis.ts.RunQuery.java
public static void main(String[] args) { try {/*from w w w . j a v a2s. c o m*/ // Get the commandline options Options options = createOptions(); CommandLineParser parser = new GnuParser(); CommandLine cmd = parser.parse(options, args); String inputPath = cmd.getOptionValue("input"); String eventsPath = cmd.getOptionValue("events"); String stopPath = cmd.getOptionValue("stop"); int queryId = Integer.valueOf(cmd.getOptionValue("query")); List<String> ids = FileUtils.readLines(new File(inputPath + File.separator + "ids.txt")); Stopper stopper = new Stopper(stopPath); Map<Integer, FeatureVector> queries = readEvents(eventsPath, stopper); FeatureVector query = queries.get(queryId); Pairtree ptree = new Pairtree(); Bag<String> words = new HashBag<String>(); for (String streamId : ids) { String ppath = ptree.mapToPPath(streamId.replace("-", "")); String inpath = inputPath + File.separator + ppath + File.separator + streamId + ".xz"; // System.out.println(inpath); File infile = new File(inpath); InputStream in = new XZInputStream(new FileInputStream(infile)); TTransport inTransport = new TIOStreamTransport(new BufferedInputStream(in)); TBinaryProtocol inProtocol = new TBinaryProtocol(inTransport); inTransport.open(); final StreamItem item = new StreamItem(); while (true) { try { item.read(inProtocol); // System.out.println("Read " + item.stream_id); } catch (TTransportException tte) { // END_OF_FILE is used to indicate EOF and is not an exception. if (tte.getType() != TTransportException.END_OF_FILE) tte.printStackTrace(); break; } } // Do something with this document... String docText = item.getBody().getClean_visible(); StringTokenizer itr = new StringTokenizer(docText); while (itr.hasMoreTokens()) { words.add(itr.nextToken()); } inTransport.close(); } for (String term : words.uniqueSet()) { System.out.println(term + ":" + words.getCount(term)); } } catch (Exception e) { e.printStackTrace(); } }