List of usage examples for org.apache.commons.cli Option setRequired
public void setRequired(boolean required)
From source file:fr.tpt.s3.mcdag.scheduling.Main.java
public static void main(String[] args) throws IOException, InterruptedException { /* Command line options */ Options options = new Options(); Option input = new Option("i", "input", true, "MC-DAG XML Models"); input.setRequired(true); input.setArgs(Option.UNLIMITED_VALUES); // Sets maximum number of threads to be launched options.addOption(input);/*from w ww . j av a 2 s .c o m*/ Option outSched = new Option("os", "out-scheduler", false, "Write the scheduling tables into a file."); outSched.setRequired(false); options.addOption(outSched); Option outPrism = new Option("op", "out-prism", false, "Write PRISM model into a file."); outPrism.setRequired(false); options.addOption(outPrism); Option jobs = new Option("j", "jobs", true, "Number of threads to be launched."); jobs.setRequired(false); options.addOption(jobs); Option debugOpt = new Option("d", "debug", false, "Enabling debug."); debugOpt.setRequired(false); options.addOption(debugOpt); Option preemptOpt = new Option("p", "preempt", false, "Count for preemptions."); preemptOpt.setRequired(false); options.addOption(preemptOpt); CommandLineParser parser = new DefaultParser(); HelpFormatter formatter = new HelpFormatter(); CommandLine cmd; try { cmd = parser.parse(options, args); } catch (ParseException e) { System.err.println(e.getMessage()); formatter.printHelp("MC-DAG framework", options); System.exit(1); return; } String inputFilePath[] = cmd.getOptionValues("input"); boolean bOutSched = cmd.hasOption("out-scheduler"); boolean bOutPrism = cmd.hasOption("out-prism"); boolean debug = cmd.hasOption("debug"); boolean preempt = cmd.hasOption("preempt"); boolean levels = cmd.hasOption("n-levels"); int nbFiles = inputFilePath.length; int nbJobs = 1; if (cmd.hasOption("jobs")) nbJobs = Integer.parseInt(cmd.getOptionValue("jobs")); if (debug) System.out.println("[DEBUG] Launching " + inputFilePath.length + " thread(s)."); int i_files = 0; ExecutorService executor = Executors.newFixedThreadPool(nbJobs); /* Launch threads to solve allocation */ while (i_files != nbFiles) { SchedulingThread ft = new SchedulingThread(inputFilePath[i_files], bOutSched, bOutPrism, debug, preempt); ft.setLevels(levels); executor.execute(ft); i_files++; } executor.shutdown(); executor.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS); System.out.println("[FRAMEWORK Main] DONE"); }
From source file:com.aestel.chemistry.openEye.fp.apps.SDFFPSphereExclusion.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 [.sdf,...]"); opt.setRequired(true); options.addOption(opt);/*from www . ja va 2 s . c o m*/ opt = new Option("out", true, "output file oe-supported"); opt.setRequired(false); options.addOption(opt); opt = new Option("ref", true, "refrence file to be loaded before starting"); opt.setRequired(false); options.addOption(opt); opt = new Option("fpTag", true, "field containing fingerpPrint"); opt.setRequired(true); options.addOption(opt); opt = new Option("maxTanimoto", false, "If given the modified maxTanimoto will be used = common/(2*Max(na,nb)-common)."); opt.setRequired(false); options.addOption(opt); opt = new Option("radius", true, "radius of exclusion sphere, exclude anything with similarity >= radius."); opt.setRequired(true); options.addOption(opt); opt = new Option("printSphereMatchCount", false, "check and print membership of candidates not " + " only to the first centroid which has sim >= radius but to all centroids" + " found up to that input. This will output a candidate multiple times." + " Implies checkSpheresInOrder."); options.addOption(opt); opt = new Option("checkSpheresInOrder", false, "For each candiate: compare to centroids from first to last (default is last to first)"); options.addOption(opt); opt = new Option("printAll", false, "print all molecule, check includeIdx tag"); 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(); } // the only reason not to match centroids in reverse order id if // a non-centroid is to be assigned to multiple centroids boolean printSphereMatchCount = cmd.hasOption("printSphereMatchCount"); boolean reverseMatch = !cmd.hasOption("checkSpheresInOrder") && !printSphereMatchCount; boolean printAll = cmd.hasOption("printAll") || printSphereMatchCount; boolean doMaxTanimoto = cmd.hasOption("maxTanimoto"); String fpTag = cmd.getOptionValue("fpTag"); double radius = Double.parseDouble(cmd.getOptionValue("radius")); String inFile = cmd.getOptionValue("in"); String outFile = cmd.getOptionValue("out"); String refFile = cmd.getOptionValue("ref"); SimComparatorFactory<OEMolBase, FPComparator, FPComparator> compFact = new FPComparatorFact(doMaxTanimoto, fpTag); SphereExclusion<FPComparator, FPComparator> alg = new SphereExclusion<FPComparator, FPComparator>(compFact, refFile, outFile, radius, reverseMatch, printSphereMatchCount, printAll); alg.run(inFile); alg.close(); }
From source file:com.genentech.struchk.OEMDLPercieveChecker.java
public static void main(String[] args) throws ParseException, JDOMException, IOException { // create command line Options object Options options = new Options(); Option opt = new Option("i", true, "input file [.ism,.sdf,...]"); opt.setRequired(true); options.addOption(opt);//w w w . j a va 2 s . c o m opt = new Option("o", true, "output file"); opt.setRequired(false); options.addOption(opt); opt = new Option("d", false, "debug: wait for user to press key at startup."); 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(); } if (args.length != 0) { exitWithHelp(options); } String inFile = cmd.getOptionValue("i"); String outFile = cmd.getOptionValue("o"); OEMDLPercieveChecker checker = null; try { checker = new OEMDLPercieveChecker(); oemolostream out = new oemolostream(outFile); oemolistream in = new oemolistream(inFile); OEGraphMol mol = new OEGraphMol(); while (oechem.OEReadMolecule(in, mol)) { if (!checker.checkMol(mol)) oechem.OEWriteMolecule(out, mol); } checker.delete(); in.close(); in.delete(); out.close(); out.delete(); } catch (Exception e) { throw new Error(e); } System.err.println("Done:"); }
From source file:com.aestel.chemistry.openEye.fp.FPDictionarySorter.java
public static void main(String... args) throws IOException { long start = System.currentTimeMillis(); int iCounter = 0; int fpCounter = 0; // create command line Options object Options options = new Options(); Option opt = new Option("i", true, "input file [.ism,.sdf,...]"); opt.setRequired(true); options.addOption(opt);//from www . j a v a2s . c o m opt = new Option("fpType", true, "fingerPrintType: maccs|linear7|linear7*4"); opt.setRequired(true); options.addOption(opt); opt = new Option("sampleFract", true, "fraction of input molecules to use (Default=1)"); 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(); } if (args.length != 0) { exitWithHelp(options); } String type = cmd.getOptionValue("fpType"); boolean updateDictionaryFile = false; boolean hashUnknownFrag = false; Fingerprinter fprinter = Fingerprinter.createFingerprinter(type, updateDictionaryFile, hashUnknownFrag); OEMolBase mol = new OEGraphMol(); String inFile = cmd.getOptionValue("i"); oemolistream ifs = new oemolistream(inFile); double fract = 2D; String tmp = cmd.getOptionValue("sampleFract"); if (tmp != null) fract = Double.parseDouble(tmp); Random rnd = new Random(); LearningStrcutureCodeMapper mapper = (LearningStrcutureCodeMapper) fprinter.getMapper(); int dictSize = mapper.getMaxIdx() + 1; int[] freq = new int[dictSize]; while (oechem.OEReadMolecule(ifs, mol)) { iCounter++; if (rnd.nextDouble() < fract) { fpCounter++; Fingerprint fp = fprinter.getFingerprint(mol); for (int bit : fp.getBits()) freq[bit]++; } if (iCounter % 100 == 0) System.err.print("."); if (iCounter % 4000 == 0) { System.err.printf(" %d %d %dsec\n", iCounter, fpCounter, (System.currentTimeMillis() - start) / 1000); } } System.err.printf("FPDictionarySorter: Read %d structures calculated %d fprints in %d sec\n", iCounter, fpCounter, (System.currentTimeMillis() - start) / 1000); mapper.reSortDictionary(freq); mapper.writeDictionary(); fprinter.close(); }
From source file:io.minimum.minecraft.rbclean.RedisBungeeClean.java
public static void main(String... args) { Options options = new Options(); Option hostOption = new Option("h", "host", true, "Sets the Redis host to use."); hostOption.setRequired(true); options.addOption(hostOption);//w w w. j ava2s.c o m Option portOption = new Option("p", "port", true, "Sets the Redis port to use."); options.addOption(portOption); Option passwordOption = new Option("w", "password", true, "Sets the Redis password to use."); options.addOption(passwordOption); Option dryRunOption = new Option("d", "dry-run", false, "Performs a dry run (no data is modified)."); options.addOption(dryRunOption); CommandLine commandLine; try { commandLine = new DefaultParser().parse(options, args); } catch (ParseException e) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("RedisBungeeClean", options); return; } int port = commandLine.hasOption('p') ? Integer.parseInt(commandLine.getOptionValue('p')) : 6379; try (Jedis jedis = new Jedis(commandLine.getOptionValue('h'), port, 0)) { if (commandLine.hasOption('w')) { jedis.auth(commandLine.getOptionValue('w')); } System.out.println("Fetching UUID cache..."); Map<String, String> uuidCache = jedis.hgetAll("uuid-cache"); Gson gson = new Gson(); // Just in case we need it, compress everything in JSON format. if (!commandLine.hasOption('d')) { SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd-hh-mm-ss"); File file = new File("uuid-cache-previous-" + dateFormat.format(new Date()) + ".json.gz"); try { file.createNewFile(); } catch (IOException e) { System.out.println("Can't write backup of the UUID cache, will NOT proceed."); e.printStackTrace(); return; } System.out.println("Creating backup (as " + file.getName() + ")..."); try (OutputStreamWriter bw = new OutputStreamWriter( new GZIPOutputStream(new FileOutputStream(file)))) { gson.toJson(uuidCache, bw); } catch (IOException e) { System.out.println("Can't write backup of the UUID cache, will NOT proceed."); e.printStackTrace(); return; } } System.out.println("Cleaning out the bird cage (this may take a while...)"); int originalSize = uuidCache.size(); for (Iterator<Map.Entry<String, String>> it = uuidCache.entrySet().iterator(); it.hasNext();) { CachedUUIDEntry entry = gson.fromJson(it.next().getValue(), CachedUUIDEntry.class); if (entry.expired()) { it.remove(); } } int newSize = uuidCache.size(); if (commandLine.hasOption('d')) { System.out.println( (originalSize - newSize) + " records would be expunged if a dry run was not conducted."); } else { System.out.println("Expunging " + (originalSize - newSize) + " records..."); Transaction transaction = jedis.multi(); transaction.del("uuid-cache"); transaction.hmset("uuid-cache", uuidCache); transaction.exec(); System.out.println("Expunging complete."); } } }
From source file:com.browseengine.bobo.index.MakeBobo.java
/** * @param args// ww w.j ava 2 s .c o m */ public static void main(String[] args) throws IOException { // TODO Auto-generated method stub Option help = new Option("help", false, "print this message"); OptionBuilder.withArgName("path"); OptionBuilder.hasArg(); OptionBuilder.withDescription("data source - required"); Option src = OptionBuilder.create("source"); src.setRequired(true); OptionBuilder.withArgName("path"); OptionBuilder.hasArg(); OptionBuilder.withDescription("index to create - required"); Option index = OptionBuilder.create("index"); index.setRequired(true); OptionBuilder.withArgName("file"); OptionBuilder.hasArg(); OptionBuilder.withDescription("field configuration - optional"); Option conf = OptionBuilder.create("conf"); OptionBuilder.withArgName("class"); OptionBuilder.hasArg(); OptionBuilder.withDescription("class name of the data digester - default: xml digester"); Option digesterOpt = OptionBuilder.create("digester"); OptionBuilder.withArgName("name"); OptionBuilder.hasArg(); OptionBuilder.withDescription("character set name - default: UTF-8"); Option charset = OptionBuilder.create("charset"); OptionBuilder.withArgName("maxdocs"); OptionBuilder.hasArg(); OptionBuilder.withDescription("maximum number of documents - default: 100"); Option maxdocs = OptionBuilder.create("maxdocs"); Options options = new Options(); options.addOption(help); options.addOption(conf); options.addOption(index); options.addOption(src); options.addOption(charset); options.addOption(digesterOpt); options.addOption(maxdocs); // create the parser CommandLineParser parser = new BasicParser(); try { // parse the command line arguments CommandLine line = parser.parse(options, args); String output = line.getOptionValue("index"); File data = new File(line.getOptionValue("source")); Class digesterClass; if (line.hasOption("digester")) digesterClass = Class.forName(line.getOptionValue("digester")); else throw new RuntimeException("digester not specified"); Charset chset; if (line.hasOption("charset")) { chset = Charset.forName(line.getOptionValue("charset")); } else { chset = Charset.forName("UTF-8"); } int maxDocs; try { maxDocs = Integer.parseInt(line.getOptionValue("maxdocs")); } catch (Exception e) { maxDocs = 100; } FileDigester digester; try { Constructor constructor = digesterClass.getConstructor(new Class[] { File.class }); digester = (FileDigester) constructor.newInstance(new Object[] { data }); digester.setCharset(chset); digester.setMaxDocs(maxDocs); } catch (Exception e) { throw new RuntimeException("Invalid digester class.", e); } BoboIndexer indexer = new BoboIndexer(digester, FSDirectory.open(new File(output))); indexer.index(); } catch (ParseException exp) { exp.printStackTrace(); usage(options); } catch (ClassNotFoundException e) { System.out.println("Invalid digester class."); usage(options); } }
From source file:eu.delving.x3ml.X3MLCommandLine.java
public static void main(String[] args) { Option xml = new Option("xml", true, "XML input records: -xml input.xml (@ = stdin)"); xml.setRequired(true); Option x3ml = new Option("x3ml", true, "X3ML mapping definition: -x3ml mapping.x3ml (@ = stdin)"); x3ml.setRequired(true);/* w w w. jav a 2 s . c o m*/ Option rdf = new Option("rdf", true, "The RDF output file name: -rdf output.rdf"); Option policy = new Option("policy", true, "The value policy file: -policy policy.xml"); Option rdfFormat = new Option("format", true, "Output format: -format application/n-triples, text/turtle, application/rdf+xml (default)"); Option validate = new Option("validate", false, "Validate X3ML v1.0 using XSD"); Option uuidTestSize = new Option("uuidTestSize", true, "Create a test UUID generator of the given size. Default is UUID from operating system"); options.addOption(rdfFormat).addOption(rdf).addOption(x3ml).addOption(xml).addOption(policy) .addOption(validate).addOption(uuidTestSize); try { CommandLine cli = PARSER.parse(options, args); int uuidTestSizeValue = -1; String uuidTestSizeString = cli.getOptionValue("uuidTestSize"); if (uuidTestSizeString != null) { uuidTestSizeValue = Integer.parseInt(uuidTestSizeString); } go(cli.getOptionValue("xml"), cli.getOptionValue("x3ml"), cli.getOptionValue("policy"), cli.getOptionValue("rdf"), cli.getOptionValue("format"), cli.hasOption("validate"), uuidTestSizeValue); } catch (Exception e) { error(e.getMessage()); } }
From source file:de.htwg_konstanz.in.uce.hp.parallel.integration_test.SourceMock.java
public static void main(String[] args) { CommandLineParser parser = new PosixParser(); // create the Options Options options = new Options(); Option o = new Option("m", "mediatorIP", true, "mediator ip"); o.setRequired(true); options.addOption(o);//from w ww . java 2 s. c o m o = new Option("p", "mediatorPort", true, "mediator port"); o.setRequired(true); options.addOption(o); o = new Option("t", "targetId", true, "target ID"); o.setRequired(true); options.addOption(o); o = new Option("d", "description", true, "scenario description"); o.setRequired(true); options.addOption(o); o = new Option("sin", "numberOfsimultaneousConnections", true, "number of simultaneous " + "connections"); o.setRequired(false); options.addOption(o); o = new Option("si", "simultaneousConnections", false, "simultaneous connections test"); o.setRequired(false); options.addOption(o); o = new Option("su", "successiveConnections", false, "successive connections test"); o.setRequired(false); options.addOption(o); o = new Option("r", "realisticConnections", false, "realistic connections test"); o.setRequired(false); options.addOption(o); CommandLine cmd; try { cmd = parser.parse(options, args); } catch (ParseException e) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("SourceMock", options); return; } String mediatorIP = cmd.getOptionValue("mediatorIP"); String mediatorPort = cmd.getOptionValue("mediatorPort"); String description = cmd.getOptionValue("description"); String targetId = cmd.getOptionValue("targetId"); InetSocketAddress mediatorSocketAddress; try { int port = Integer.parseInt(mediatorPort); mediatorSocketAddress = new InetSocketAddress(mediatorIP, port); } catch (NumberFormatException e) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("SourceMock", options); return; } catch (IllegalArgumentException e) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("SourceMock", options); return; } if (cmd.hasOption("numberOfsimultaneousConnections")) { int simConnections = Integer.parseInt(cmd.getOptionValue("numberOfsimultaneousConnections")); new SourceMock(description, targetId, mediatorSocketAddress, simConnections).runTests( cmd.hasOption("simultaneousConnections"), cmd.hasOption("successiveConnections"), cmd.hasOption("realisticConnections")); } else { new SourceMock(description, targetId, mediatorSocketAddress).runTests( cmd.hasOption("simultaneousConnections"), cmd.hasOption("successiveConnections"), cmd.hasOption("realisticConnections")); } }
From source file:com.genentech.chemistry.tool.SDF2HtmlTab.java
public static void main(String[] args) throws ParseException, JDOMException, IOException { long start = System.currentTimeMillis(); // create command line Options object Options options = new Options(); Option opt = new Option("in", true, "input sd file"); opt.setRequired(true); options.addOption(opt);/* w w w. ja va2 s . c o m*/ 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 inFile = cmd.getOptionValue("in"); args = cmd.getArgs(); if (args.length > 0) { exitWithHelp(options); } oemolistream ifs; Set<String> tagSet = getTagSet(inFile); System.out.println( "<html xmlns:v='urn:schemas-microsoft-com:vml' xmlns:o='urn:schemas-microsoft-com:office:office'>"); System.out.println("<head>"); System.out.println("<BASE href='" + BASEUrl + "'/>"); System.out.println( "<link href='/" + Settings.SERVLET_CONTEXT + "/css/Aestel.css' rel='stylesheet' type='text/css'/>"); System.out.println("<style type='text/css'>"); System.out.println("td.stru { width: " + (IMGWidth + 2) + "px; height: " + (IMGHeigth + 4) + "px; vertical-align: top; }"); System.out.println("table.grid tr.first { border-top: 3px solid black; }"); // for tables in tables System.out.println("table.grid table td { border: 0px; text-align: right;}"); System.out.println("table.grid table td:first-child { text-align: left;}"); System.out.println("th.head { border-left: 1px solid black; border-bottom: 2px solid black;\n" + " empty-cells: show; background-color: #6297ff; color: #000000;\n" + " padding: 0em .3em 0em .3em; vertical-align: middle; }"); System.out.println("</style>"); System.out.println("</head>"); System.out.println("<body>"); System.out.println("<table class='grid'><tr>"); System.out.println("<th class='head'>Structure</th>"); for (String tag : tagSet) System.out.println("<th class='head'>" + tag + "</th>"); System.out.println("</tr>"); OEGraphMol mol = new OEGraphMol(); ifs = new oemolistream(inFile); int iCounter = 0; while (oechem.OEReadMolecule(ifs, mol)) { iCounter++; System.out.println("<tr>"); String smi = OETools.molToCanSmi(mol, true); String img = DepictHelper.DEFAULT.getExcelSmilesImageElement(BASEUrl, 120, 120, ImageType.PNG, smi, null); System.out.print(" <td class='stru'>"); System.out.print(img); System.out.println("</td>"); for (String tag : tagSet) { String val = oechem.OEGetSDData(mol, tag); System.out.print(" <td>"); System.out.print(val); System.out.println("</td>"); } System.out.println("</tr>"); } System.out.println("</table></body></html>"); System.err.printf("SDF2HtmlTab: Exported %d structures in %dsec\n", iCounter, (System.currentTimeMillis() - start) / 1000); }
From source file:cross.io.PropertyFileGenerator.java
/** * * @param args/*from w w w.j a va 2 s . c o m*/ */ public static void main(String[] args) { Options options = new Options(); options.addOption("f", true, "base directory for output of files"); Option provOptions = new Option("p", true, "Comma separated list of provider classes to create Properties for"); provOptions.setRequired(true); provOptions.setValueSeparator(','); options.addOption(provOptions); CommandLineParser parser = new PosixParser(); HelpFormatter hf = new HelpFormatter(); try { File basedir = null; List<String> providers = Collections.emptyList(); CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("f")) { basedir = new File(cmd.getOptionValue("f")); } else { hf.printHelp("java -cp maltcms.jar " + PropertyFileGenerator.class, options); } if (cmd.hasOption("p")) { String[] str = cmd.getOptionValues("p"); providers = Arrays.asList(str); } else { hf.printHelp("java -cp maltcms.jar " + PropertyFileGenerator.class, options); } for (String provider : providers) { createProperties(provider, basedir); } } catch (ParseException ex) { Logger.getLogger(PropertyFileGenerator.class.getName()).log(Level.SEVERE, null, ex); } }