List of usage examples for org.apache.commons.cli Option setRequired
public void setRequired(boolean required)
From source file:com.genentech.chemistry.openEye.apps.SDFConformerSampler.java
/** * @param args/*from w w w. j a v a 2 s.c o m*/ */ public static void main(String... args) throws IOException { // create command line Options object Options options = new Options(); Option opt = new Option(OPT_INFILE, true, "input file oe-supported Use .sdf|.smi to specify the file type."); opt.setRequired(true); options.addOption(opt); opt = new Option(OPT_OUTFILE, true, "output file oe-supported. Use .sdf|.smi to specify the file type."); opt.setRequired(true); options.addOption(opt); opt = new Option(OPT_MAX_CONFS, true, "Maximum number of conformations per input."); opt.setRequired(true); options.addOption(opt); opt = new Option(OPT_TORSION_FILE, true, "Optional: to overwrite torsion definition file."); opt.setRequired(false); options.addOption(opt); CommandLineParser parser = new PosixParser(); CommandLine cmd = null; try { cmd = parser.parse(options, args); } catch (Exception e) { System.err.println(e.getMessage()); exitWithHelp(options); } args = cmd.getArgs(); if (cmd.hasOption("d")) { System.err.println("Start debugger and press return:"); new BufferedReader(new InputStreamReader(System.in)).readLine(); } String inFile = cmd.getOptionValue(OPT_INFILE); String outFile = cmd.getOptionValue(OPT_OUTFILE); String smartsFile = cmd.getOptionValue(OPT_TORSION_FILE); long maxConfs = Long.parseLong(cmd.getOptionValue(OPT_MAX_CONFS)); SDFConformerSampler scanner = new SDFConformerSampler(smartsFile, outFile, maxConfs); scanner.run(inFile); scanner.close(); }
From source file:com.genentech.chemistry.openEye.apps.SDFMolSeparator.java
/** * @param args/*from ww w . j a va2 s . c om*/ */ public static void main(String... args) throws IOException { // create command line Options object Options options = new Options(); Option opt = new Option(OPT_INFILE, true, "input file oe-supported Use .sdf|.smi to specify the file type."); opt.setRequired(true); options.addOption(opt); opt = new Option(OPT_OUTFILE, true, "output file oe-supported. Use .sdf|.smi to specify the file type."); opt.setRequired(true); options.addOption(opt); CommandLineParser parser = new PosixParser(); CommandLine cmd = null; try { cmd = parser.parse(options, args); } catch (Exception e) { System.err.println(e.getMessage()); exitWithHelp(options); } args = cmd.getArgs(); if (cmd.hasOption("d")) { System.err.println("Start debugger and press return:"); new BufferedReader(new InputStreamReader(System.in)).readLine(); } String inFile = cmd.getOptionValue(OPT_INFILE); String outFile = cmd.getOptionValue(OPT_OUTFILE); SDFMolSeparator separator = new SDFMolSeparator(outFile); try { separator.run(inFile); } catch (IndexOutOfBoundsException iie) { System.err.println(iie.toString()); exitWithHelp(options); } finally { separator.close(); } }
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 ww w. j av a2s. 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:com.genentech.chemistry.openEye.apps.SDFSubRMSD.java
public static void main(String... args) throws IOException { // create command line Options object Options options = new Options(); Option opt = new Option("in", true, "input file oe-supported"); opt.setRequired(true); options.addOption(opt);//from w w w .j a v a 2s . c om opt = new Option("out", true, "output file oe-supported"); opt.setRequired(false); options.addOption(opt); opt = new Option("fragFile", true, "file with single 3d substructure query"); opt.setRequired(false); options.addOption(opt); opt = new Option("isMDL", false, "if given the fragFile is suposed to be an mdl query file, query features are supported."); opt.setRequired(false); options.addOption(opt); CommandLineParser parser = new PosixParser(); CommandLine cmd = null; try { cmd = parser.parse(options, args); } catch (Exception e) { System.err.println(e.getMessage()); exitWithHelp(options); } args = cmd.getArgs(); if (cmd.hasOption("d")) { System.err.println("Start debugger and press return:"); new BufferedReader(new InputStreamReader(System.in)).readLine(); } String inFile = cmd.getOptionValue("in"); String outFile = cmd.getOptionValue("out"); String fragFile = cmd.getOptionValue("fragFile"); // read fragment OESubSearch ss; oemolistream ifs = new oemolistream(fragFile); OEMolBase mol; if (!cmd.hasOption("isMDL")) { mol = new OEGraphMol(); oechem.OEReadMolecule(ifs, mol); ss = new OESubSearch(mol, OEExprOpts.AtomicNumber, OEExprOpts.BondOrder); } else { int aromodel = OEIFlavor.Generic.OEAroModelOpenEye; int qflavor = ifs.GetFlavor(ifs.GetFormat()); ifs.SetFlavor(ifs.GetFormat(), (qflavor | aromodel)); int opts = OEMDLQueryOpts.Default | OEMDLQueryOpts.SuppressExplicitH; OEQMol qmol = new OEQMol(); oechem.OEReadMDLQueryFile(ifs, qmol, opts); ss = new OESubSearch(qmol); mol = qmol; } double nSSatoms = mol.NumAtoms(); double sssCoords[] = new double[mol.GetMaxAtomIdx() * 3]; mol.GetCoords(sssCoords); mol.Clear(); ifs.close(); if (!ss.IsValid()) throw new Error("Invalid query " + args[0]); ifs = new oemolistream(inFile); oemolostream ofs = new oemolostream(outFile); int count = 0; while (oechem.OEReadMolecule(ifs, mol)) { count++; double rmsd = Double.MAX_VALUE; double molCoords[] = new double[mol.GetMaxAtomIdx() * 3]; mol.GetCoords(molCoords); for (OEMatchBase mb : ss.Match(mol, false)) { double r = 0; for (OEMatchPairAtom mp : mb.GetAtoms()) { OEAtomBase asss = mp.getPattern(); double sx = sssCoords[asss.GetIdx() * 3]; double sy = sssCoords[asss.GetIdx() * 3]; double sz = sssCoords[asss.GetIdx() * 3]; OEAtomBase amol = mp.getTarget(); double mx = molCoords[amol.GetIdx() * 3]; double my = molCoords[amol.GetIdx() * 3]; double mz = molCoords[amol.GetIdx() * 3]; r += Math.sqrt((sx - mx) * (sx - mx) + (sy - my) * (sy - my) + (sz - mz) * (sz - mz)); } r /= nSSatoms; rmsd = Math.min(rmsd, r); } if (rmsd != Double.MAX_VALUE) oechem.OESetSDData(mol, "SSSrmsd", String.format("%.3f", rmsd)); oechem.OEWriteMolecule(ofs, mol); mol.Clear(); } ifs.close(); ofs.close(); mol.delete(); ss.delete(); }
From source file:com.github.braully.graph.UtilResult.java
public static void main(String... args) throws Exception { Options options = new Options(); Option input = new Option("i", "input", true, "input file path"); input.setRequired(false); options.addOption(input);//from w w w. j a v a 2 s . com Option verb = new Option("v", "verbose", false, "verbose process"); input.setRequired(false); options.addOption(verb); Option output = new Option("o", "output", true, "output file"); output.setRequired(false); options.addOption(output); CommandLineParser parser = new DefaultParser(); HelpFormatter formatter = new HelpFormatter(); CommandLine cmd; try { cmd = parser.parse(options, args); } catch (ParseException e) { System.out.println(e.getMessage()); formatter.printHelp("UtilResult", options); System.exit(1); return; } String inputFilePath = cmd.getOptionValue("input"); if (inputFilePath == null) { inputFilePath = "/home/strike/grafos-para-processar/mft2/resultado.txt"; } if (inputFilePath != null) { if (inputFilePath.toLowerCase().endsWith(".txt")) { processFileTxt(inputFilePath); } else if (inputFilePath.toLowerCase().endsWith(".json")) { processFileJson(inputFilePath); } } }
From source file:com.versusoft.packages.jodl.gui.CommandLineGUI.java
public static void main(String args[]) throws SAXException, IOException { Handler fh = new FileHandler(LOG_FILENAME_PATTERN); fh.setFormatter(new SimpleFormatter()); //removeAllLoggersHandlers(Logger.getLogger("")); Logger.getLogger("").addHandler(fh); Logger.getLogger("").setLevel(Level.FINEST); Options options = new Options(); Option option1 = new Option("in", "ODT file (required)"); option1.setRequired(true); option1.setArgs(1);/*from w ww.ja v a 2 s . c o m*/ Option option2 = new Option("out", "Output file (required)"); option2.setRequired(false); option2.setArgs(1); Option option3 = new Option("pic", "extract pics"); option3.setRequired(false); option3.setArgs(1); Option option4 = new Option("page", "enable pagination processing"); option4.setRequired(false); option4.setArgs(0); options.addOption(option1); options.addOption(option2); options.addOption(option3); options.addOption(option4); CommandLineParser parser = new BasicParser(); CommandLine cmd = null; try { cmd = parser.parse(options, args); } catch (ParseException e) { printHelp(); return; } if (cmd.hasOption("help")) { printHelp(); return; } File outFile = new File(cmd.getOptionValue("out")); OdtUtils utils = new OdtUtils(); utils.open(cmd.getOptionValue("in")); //utils.correctionStep(); utils.saveXML(outFile.getAbsolutePath()); try { if (cmd.hasOption("page")) { OdtUtils.paginationProcessing(outFile.getAbsolutePath()); } OdtUtils.correctionProcessing(outFile.getAbsolutePath()); } catch (ParserConfigurationException ex) { logger.log(Level.SEVERE, null, ex); } catch (SAXException ex) { logger.log(Level.SEVERE, null, ex); } catch (IOException ex) { logger.log(Level.SEVERE, null, ex); } catch (TransformerConfigurationException ex) { logger.log(Level.SEVERE, null, ex); } catch (TransformerException ex) { logger.log(Level.SEVERE, null, ex); } if (cmd.hasOption("pic")) { String imageDir = cmd.getOptionValue("pic"); if (!imageDir.endsWith("/")) { imageDir += "/"; } try { String basedir = new File(cmd.getOptionValue("out")).getParent().toString() + System.getProperty("file.separator"); OdtUtils.extractAndNormalizeEmbedPictures(cmd.getOptionValue("out"), cmd.getOptionValue("in"), basedir, imageDir); } catch (SAXException ex) { logger.log(Level.SEVERE, null, ex); } catch (ParserConfigurationException ex) { logger.log(Level.SEVERE, null, ex); } catch (TransformerConfigurationException ex) { logger.log(Level.SEVERE, null, ex); } catch (TransformerException ex) { logger.log(Level.SEVERE, null, ex); } } }
From source file:fr.inria.atlanmod.kyanos.benchmarks.XmiTraverser.java
public static void main(String[] args) { Options options = new Options(); Option inputOpt = OptionBuilder.create(IN); inputOpt.setArgName("INPUT"); inputOpt.setDescription("Input model"); inputOpt.setArgs(1);/*from w w w. jav a2 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 { CommandLine commandLine = parser.parse(options, args); URI uri = URI.createFileURI(commandLine.getOptionValue(IN)); Class<?> inClazz = XmiTraverser.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()); Resource resource = resourceSet.createResource(uri); Map<String, Object> loadOpts = new HashMap<String, Object>(); 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))); 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.genentech.retrival.tabExport.TABExporter.java
public static void main(String[] args) throws ParseException, JDOMException, IOException { long start = System.currentTimeMillis(); int nStruct = 0; // create command line Options object Options options = new Options(); Option opt = new Option("sqlFile", true, "sql-xml file"); opt.setRequired(true); options.addOption(opt);/* w w w. j a v a2 s . c om*/ opt = new Option("sqlName", true, "name of SQL element in xml file"); opt.setRequired(true); options.addOption(opt); opt = new Option("o", true, "output file"); opt.setRequired(false); options.addOption(opt); opt = new Option("newLineReplacement", true, "If given newlines in fields will be replaced by this string."); options.addOption(opt); opt = new Option("noHeader", false, "Do not output header line"); options.addOption(opt); CommandLineParser parser = new BasicParser(); CommandLine cmd = null; try { cmd = parser.parse(options, args); } catch (Exception e) { System.err.println(e.getMessage()); exitWithHelp(options); } args = cmd.getArgs(); String outFile = cmd.getOptionValue("o"); String sqlFile = cmd.getOptionValue("sqlFile"); String sqlName = cmd.getOptionValue("sqlName"); String newLineReplacement = cmd.getOptionValue("newLineReplacement"); args = cmd.getArgs(); try { PrintStream out = System.out; if (outFile != null) out = new PrintStream(outFile); SQLStatement stmt = SQLStatement.createFromFile(new File(sqlFile), sqlName); Object[] sqlArgs = args; if (stmt.getParamTypes().length != args.length) { System.err.printf( "\nWarining sql statement needs %d parameters but got only %d. Filling up with NULLs.\n", stmt.getParamTypes().length, args.length); sqlArgs = new Object[stmt.getParamTypes().length]; System.arraycopy(args, 0, sqlArgs, 0, args.length); } Selecter sel = Selecter.factory(stmt); if (!sel.select(sqlArgs)) { System.err.println("No rows returned!"); System.exit(0); } String[] fieldNames = sel.getFieldNames(); if (fieldNames.length == 0) { System.err.println("Query did not return any columns"); exitWithHelp(options); } if (!cmd.hasOption("noHeader")) { StringBuilder sb = new StringBuilder(200); for (String f : fieldNames) sb.append(f).append('\t'); if (sb.length() > 1) sb.setLength(sb.length() - 1); // chop last \t String header = sb.toString(); out.println(header); } StringBuilder sb = new StringBuilder(200); while (sel.hasNext()) { Record sqlRec = sel.next(); sb.setLength(0); for (int i = 0; i < fieldNames.length; i++) { String fld = sqlRec.getStrg(i); if (newLineReplacement != null) fld = NEWLinePattern.matcher(fld).replaceAll(newLineReplacement); sb.append(fld).append('\t'); } if (sb.length() > 1) sb.setLength(sb.length() - 1); // chop last \t String row = sb.toString(); out.println(row); nStruct++; } } catch (Exception e) { throw new Error(e); } finally { System.err.printf("TABExporter: Exported %d records in %dsec\n", nStruct, (System.currentTimeMillis() - start) / 1000); } }
From source file:de.binfalse.jatter.App.java
/** * Run jatter's main.// w w w . j a v a 2 s.c om * * @param args * the arguments * @throws Exception * the exception */ public static void main(String[] args) throws Exception { Options options = new Options(); Option conf = new Option("c", "config", true, "config file path"); conf.setRequired(false); options.addOption(conf); Option t = new Option("t", "template", false, "show a config template"); t.setRequired(false); options.addOption(t); Option v = new Option("v", "verbose", false, "print information messages"); v.setRequired(false); options.addOption(v); Option d = new Option("d", "debug", false, "print debugging messages incl stack traces"); d.setRequired(false); options.addOption(d); Option h = new Option("h", "help", false, "show help"); h.setRequired(false); options.addOption(h); CommandLineParser parser = new DefaultParser(); CommandLine cmd; try { cmd = parser.parse(options, args); if (cmd.hasOption("h")) throw new RuntimeException("showing the help page"); } catch (Exception e) { help(options, e.getMessage()); return; } if (cmd.hasOption("t")) { System.out.println(); BufferedReader br = new BufferedReader(new InputStreamReader( App.class.getClassLoader().getResourceAsStream("config.properties.template"))); while (br.ready()) System.out.println(br.readLine()); br.close(); System.exit(0); } if (cmd.hasOption("v")) LOGGER.setMinLevel(LOGGER.INFO); if (cmd.hasOption("d")) { LOGGER.setMinLevel(LOGGER.DEBUG); LOGGER.setLogStackTrace(true); } if (!cmd.hasOption("c")) help(options, "a config file is required for running jatter"); startJatter(cmd.getOptionValue("c")); }
From source file:com.fiveclouds.jasper.JasperRunner.java
public static void main(String[] args) { // Set-up the options for the utility Options options = new Options(); Option report = new Option("report", true, "jasper report to run (i.e. /path/to/report.jrxml)"); options.addOption(report);// w ww . ja v a 2 s . c om Option driver = new Option("driver", true, "the jdbc driver class (i.e. com.mysql.jdbc.Driver)"); driver.setRequired(true); options.addOption(driver); options.addOption("jdbcurl", true, "database jdbc url (i.e. jdbc:mysql://localhost:3306/database)"); options.addOption("excel", true, "Will override the PDF default and export to Microsoft Excel"); options.addOption("username", true, "database username"); options.addOption("password", true, "database password"); options.addOption("output", true, "the output filename (i.e. path/to/report.pdf"); options.addOption("help", false, "print this message"); Option propertyOption = OptionBuilder.withArgName("property=value").hasArgs(2).withValueSeparator() .withDescription("use value as report property").create("D"); options.addOption(propertyOption); // Parse the options and build the report CommandLineParser parser = new PosixParser(); try { CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("help")) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("jasper-runner", options); } else { System.out.println("Building report " + cmd.getOptionValue("report")); try { Class.forName(cmd.getOptionValue("driver")); Connection connection = DriverManager.getConnection(cmd.getOptionValue("jdbcurl"), cmd.getOptionValue("username"), cmd.getOptionValue("password")); System.out.println("Connected to " + cmd.getOptionValue("jdbcurl")); JasperReport jasperReport = JasperCompileManager.compileReport(cmd.getOptionValue("report")); JRPdfExporter pdfExporter = new JRPdfExporter(); Properties properties = cmd.getOptionProperties("D"); Map<String, Object> parameters = new HashMap<String, Object>(); Map<String, JRParameter> reportParameters = new HashMap<String, JRParameter>(); for (JRParameter param : jasperReport.getParameters()) { reportParameters.put(param.getName(), param); } for (Object propertyKey : properties.keySet()) { String parameterName = String.valueOf(propertyKey); String parameterValue = String.valueOf(properties.get(propertyKey)); JRParameter reportParam = reportParameters.get(parameterName); if (reportParam != null) { if (reportParam.getValueClass().equals(String.class)) { System.out.println( "Property " + parameterName + " set to String = " + parameterValue); parameters.put(parameterName, parameterValue); } else if (reportParam.getValueClass().equals(Integer.class)) { System.out.println( "Property " + parameterName + " set to Integer = " + parameterValue); parameters.put(parameterName, Integer.parseInt(parameterValue)); } else { System.err.print("Unsupported type for property " + parameterName); System.exit(1); } } else { System.out.println("Property " + parameterName + " not found in the report! IGNORING"); } } JasperPrint print = JasperFillManager.fillReport(jasperReport, parameters, connection); pdfExporter.setParameter(JRExporterParameter.JASPER_PRINT, print); pdfExporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, cmd.getOptionValue("output")); System.out.println("Exporting report to " + cmd.getOptionValue("output")); pdfExporter.exportReport(); } catch (JRException e) { System.err.print("Unable to parse report file (" + cmd.getOptionValue("r") + ")"); e.printStackTrace(); System.exit(1); } catch (ClassNotFoundException e) { System.err.print("Unable to find the database driver, is it on the classpath?"); e.printStackTrace(); System.exit(1); } catch (SQLException e) { System.err.print("An SQL exception has occurred (" + e.getMessage() + ")"); e.printStackTrace(); System.exit(1); } } } catch (ParseException e) { System.err.print("Unable to parse command line options (" + e.getMessage() + ")"); System.exit(1); } }