List of usage examples for org.apache.commons.cli PosixParser PosixParser
PosixParser
From source file:name.wagners.fssp.Main.java
/** * @param args//from w ww . ja v a 2 s. co m * command-line arguments */ public static void main(final String[] args) { // create the command line parser CommandLineParser parser = new PosixParser(); // create the Options Options options = new Options(); options.addOption(OptionBuilder.hasArg().withArgName("gn").withLongOpt("generations") .withDescription("Number of generations [default: 50]").withType(Integer.valueOf(0)).create("g")); options.addOption(OptionBuilder.hasArg().withArgName("mp").withLongOpt("mutation") .withDescription("Mutation propability [default: 0.5]").withType(Double.valueOf(0)).create("m")); options.addOption(OptionBuilder.hasArg().withArgName("ps").withLongOpt("populationsize") .withDescription("Size of population [default: 20]").withType(Integer.valueOf(0)).create("p")); options.addOption(OptionBuilder.hasArg().withArgName("rp").withLongOpt("recombination") .withDescription("Recombination propability [default: 0.8]").withType(Double.valueOf(0)) .create("r")); options.addOption(OptionBuilder.hasArg().withArgName("sp").withLongOpt("selectionpressure") .withDescription("Selection pressure [default: 4]").withType(Integer.valueOf(0)).create("s")); options.addOption(OptionBuilder.withLongOpt("help").withDescription("print this message").create("h")); options.addOption(OptionBuilder.hasArg().withArgName("filename").isRequired().withLongOpt("file") .withDescription("Problem file [default: \"\"]").withType(String.valueOf("")).create("f")); options.addOptionGroup(new OptionGroup() .addOption(OptionBuilder.withLongOpt("verbose").withDescription("be extra verbose").create("v")) .addOption(OptionBuilder.withLongOpt("quiet").withDescription("be extra quiet").create("q"))); options.addOption(OptionBuilder.withLongOpt("version") .withDescription("print the version information and exit").create("V")); try { // parse the command line arguments CommandLine line = parser.parse(options, args); // validate that block-size has been set if (line.hasOption("h")) { // automatically generate the help statement HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("fssp", options); } } catch (MissingOptionException exp) { log.info("An option was missing:" + exp.getMessage(), exp); // automatically generate the help statement HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("fssp", options); } catch (MissingArgumentException exp) { log.info("An argument was missing:" + exp.getMessage(), exp); // automatically generate the help statement HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("fssp", options); } catch (AlreadySelectedException exp) { // automatically generate the help statement HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("fssp", options); } catch (ParseException exp) { log.info("Unexpected exception:" + exp.getMessage(), exp); // automatically generate the help statement HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("fssp", options); System.exit(1); } // Ausgabe der eingestellten Optionen log.info("Configuration"); // log.info(" Datafile: {}", fname); }
From source file:edu.toronto.cs.phenotips.obo2solr.Main.java
public static void main(String[] args) { Options options = generateOptions(); try {//w ww . j av a2s. co m CommandLineParser parser = new PosixParser(); CommandLine cmd = parser.parse(options, args); if (!cmd.hasOption(OBO_DB_LOCATION_OPTION) || cmd.hasOption(HELP_OPTION)) { showUsage(options); System.exit(cmd.hasOption(HELP_OPTION) ? 0 : 1); } ParameterPreparer paramPrep = new ParameterPreparer(); SolrUpdateGenerator generator = new SolrUpdateGenerator(); File input = paramPrep.getInputFileHandler(cmd.getOptionValue(OBO_DB_LOCATION_OPTION)); File output = paramPrep.getOutputFileHandler( cmd.getOptionValue(OUTPUT_XML_LOCATION_OPTION, DEFAULT_OUTPUT_XML_LOCATION)); Map<String, Double> fieldSelection = paramPrep .getFieldSelection(cmd.getOptionValue(INDEX_FILEDS_OPTION, "")); generator.transform(input, output, fieldSelection); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:dk.statsbiblioteket.jpar2.filecompare.FileCompare.java
/** * Main method. /*from ww w . jav a 2s. c o m*/ * @param args */ public static void main(String[] args) { Options options = new Options(); options.addOption("s", "slices", true, "The number of slices to use in the comparison"); CommandLineParser parser = new PosixParser(); try { CommandLine cmd = parser.parse(options, args); args = cmd.getArgs(); if (!cmd.hasOption("s") || args.length != 2) { System.exit(2); } int slices = Integer.parseInt(cmd.getOptionValue("s").trim()); File f1 = new File(args[0]); File f2 = new File(args[1]); if (f1.length() == f2.length()) { int sliceSize = (int) (f1.length() / slices);//rounding here... DataFile df1 = new DataFile(f1, sliceSize); DataFile df2 = new DataFile(f2, sliceSize); List<Integer> defectIndexes = df1.compareWithIndex(df2); for (int index : defectIndexes) { System.out.println("index " + index + ", from " + index * sliceSize + " to " + (index + 1) * sliceSize + " is defect"); } if (defectIndexes.size() == 0) { System.out.println("Files are identical"); } } else { System.out.println("Files differ in length, cannot help you"); } } catch (ParseException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } catch (IOException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } }
From source file:gr.seab.r2rml.beans.Main.java
public static void main(String[] args) { Calendar c0 = Calendar.getInstance(); long t0 = c0.getTimeInMillis(); CommandLineParser cmdParser = new PosixParser(); Options cmdOptions = new Options(); cmdOptions.addOption("p", "properties", true, "define the properties file. Example: r2rml-parser -p r2rml.properties"); cmdOptions.addOption("h", "print help", false, "help"); String propertiesFile = "r2rml.properties"; try {// w w w. j a va 2 s.c om CommandLine line = cmdParser.parse(cmdOptions, args); if (line.hasOption("h")) { HelpFormatter help = new HelpFormatter(); help.printHelp("r2rml-parser\n", cmdOptions); System.exit(0); } if (line.hasOption("p")) { propertiesFile = line.getOptionValue("p"); } } catch (ParseException e1) { //e1.printStackTrace(); log.error("Error parsing command line arguments."); System.exit(1); } try { if (StringUtils.isNotEmpty(propertiesFile)) { properties.load(new FileInputStream(propertiesFile)); log.info("Loaded properties from " + propertiesFile); } } catch (FileNotFoundException e) { //e.printStackTrace(); log.error("Properties file not found (" + propertiesFile + ")."); System.exit(1); } catch (IOException e) { //e.printStackTrace(); log.error("Error reading properties file (" + propertiesFile + ")."); System.exit(1); } ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("app-context.xml"); Database db = (Database) context.getBean("db"); db.setProperties(properties); Parser parser = (Parser) context.getBean("parser"); parser.setProperties(properties); MappingDocument mappingDocument = parser.parse(); mappingDocument.getTimestamps().add(t0); //0 Started mappingDocument.getTimestamps().add(Calendar.getInstance().getTimeInMillis()); //1 Finished parsing. Starting generating result model. Generator generator = (Generator) context.getBean("generator"); generator.setProperties(properties); generator.setResultModel(parser.getResultModel()); //Actually do the output generator.createTriples(mappingDocument); context.close(); Calendar c1 = Calendar.getInstance(); long t1 = c1.getTimeInMillis(); log.info("Finished in " + (t1 - t0) + " milliseconds. Done."); mappingDocument.getTimestamps().add(Calendar.getInstance().getTimeInMillis()); //5 Finished. //log.info("5 Finished."); //output the result for (int i = 0; i < mappingDocument.getTimestamps().size(); i++) { if (i > 0) { long l = (mappingDocument.getTimestamps().get(i).longValue() - mappingDocument.getTimestamps().get(i - 1).longValue()); //System.out.println(l); log.info(String.valueOf(l)); } } log.info("Parse. Generate in memory. Dump to disk/database. Log. - Alltogether in " + String.valueOf(mappingDocument.getTimestamps().get(5).longValue() - mappingDocument.getTimestamps().get(0).longValue()) + " msec."); log.info("Done."); System.out.println("Done."); }
From source file:com.matthatem.ai.search.applications.MSASolver.java
public static void main(String[] args) { Options options = createOptions();// ww w . ja v a 2 s . c o m CommandLineParser parser = new PosixParser(); CommandLine cmd = null; try { cmd = parser.parse(options, args); } catch (ParseException e) { e.printStackTrace(); System.exit(1); } MSA msa = createMSAInstance(cmd); SearchAlgorithm algo = createSearchAlgorithm(cmd, msa); System.gc(); long t = System.currentTimeMillis(); SearchResult<MSAState> result = algo.search(); long td = System.currentTimeMillis(); result.setAlgorithm(algoString); result.setInitialH((int) msa.getHeuristic().getInitH()); result.setStartTime(t); result.setEndTime(td); System.out.println(result); //System.out.println(msa.alignmentToString()); System.out.println(msa.alignmentToMSFString()); }
From source file:com.googlecode.hiberpcml.generator.Tool.java
public static void main(String arg[]) throws Exception { CommandLineParser parser = new PosixParser(); Options options = new Options(); Option destinyOpt = new Option("t", "target", true, "target of the generated classes"); destinyOpt.setArgName("target"); options.addOption(destinyOpt);// w w w .j a v a2 s. com Option packageOpt = new Option("p", "package", true, "Java Package of the generated classes"); packageOpt.setArgName("package"); options.addOption(packageOpt); Option webServiceOpt = new Option("w", "webservice", true, "build webservice classes"); webServiceOpt.setArgs(2); webServiceOpt.setArgName("serviceName service"); options.addOption(webServiceOpt); options.addOption(webServiceOpt); CommandLine cmd = parser.parse(options, arg); if (cmd.getArgs().length == 0) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("generator [options] FILE|DIRECTORY.", options); System.exit(1); } Pcml pcml; ArrayList<File> filesToParse = getFilesToParse(cmd.getArgs()[0]); JCodeModel cm = new JCodeModel(); JPackage _package = cm._package(cmd.getOptionValue("p", "")); Generator generator; WSGenerator wsGenerator = null; File targetFile = new File(cmd.getOptionValue("t", "./target")); targetFile.mkdirs(); if (cmd.hasOption("w")) { wsGenerator = new WSGenerator(_package, cmd.getOptionValues("w")[0], cmd.getOptionValues("w")[1]); } for (File file : filesToParse) { pcml = Util.load(file); if (cmd.hasOption("w")) { wsGenerator.addMethod(pcml); } else { generator = new Generator(); generator.generate(_package, pcml); } } cm.build(targetFile); }
From source file:at.newmedialab.ldpath.backend.linkeddata.LDQuery.java
public static void main(String[] args) { Options options = buildOptions();// www .j av a 2 s . co m CommandLineParser parser = new PosixParser(); try { CommandLine cmd = parser.parse(options, args); Level logLevel = Level.WARN; if (cmd.hasOption("loglevel")) { String logLevelName = cmd.getOptionValue("loglevel"); if ("DEBUG".equals(logLevelName.toUpperCase())) { logLevel = Level.DEBUG; } else if ("INFO".equals(logLevelName.toUpperCase())) { logLevel = Level.INFO; } else if ("WARN".equals(logLevelName.toUpperCase())) { logLevel = Level.WARN; } else if ("ERROR".equals(logLevelName.toUpperCase())) { logLevel = Level.ERROR; } else { log.error("unsupported log level: {}", logLevelName); } } if (logLevel != null) { for (String logname : new String[] { "at", "org", "net", "com" }) { ch.qos.logback.classic.Logger logger = (ch.qos.logback.classic.Logger) LoggerFactory .getLogger(logname); logger.setLevel(logLevel); } } String format = null; if (cmd.hasOption("format")) { format = cmd.getOptionValue("format"); } GenericSesameBackend backend; if (cmd.hasOption("store")) { backend = new LDPersistentBackend(new File(cmd.getOptionValue("store"))); } else { backend = new LDMemoryBackend(); } Resource context = null; if (cmd.hasOption("context")) { context = backend.getRepository().getValueFactory().createURI(cmd.getOptionValue("context")); } if (backend != null && context != null) { LDPath<Value> ldpath = new LDPath<Value>(backend); if (cmd.hasOption("path")) { String path = cmd.getOptionValue("path"); for (Value v : ldpath.pathQuery(context, path, null)) { System.out.println(v.stringValue()); } } else if (cmd.hasOption("program")) { File file = new File(cmd.getOptionValue("program")); Map<String, Collection<?>> result = ldpath.programQuery(context, new FileReader(file)); for (String field : result.keySet()) { StringBuilder line = new StringBuilder(); line.append(field); line.append(" = "); line.append("{"); for (Iterator it = result.get(field).iterator(); it.hasNext();) { line.append(it.next().toString()); if (it.hasNext()) { line.append(", "); } } line.append("}"); System.out.println(line); } } } if (backend instanceof LDPersistentBackend) { ((LDPersistentBackend) backend).shutdown(); } } catch (ParseException e) { System.err.println("invalid arguments"); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("LDQuery", options, true); } catch (LDPathParseException e) { System.err.println("path or program could not be parsed"); e.printStackTrace(); } catch (FileNotFoundException e) { System.err.println("file or program could not be found"); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("LDQuery", options, true); } catch (IOException e) { System.err.println("could not access cache data directory"); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("LDQuery", options, true); } }
From source file:hisqisnoten.HisqisNoten.java
public static void main(String[] args) { options = new Options(); options.addOption("h", "help", false, "this help"); options.addOption("u", "user", true, "username for hisqis"); options.addOption("p", "pass", true, "password for hisqis"); options.addOption("c", "console", false, "console mode instead of gui mode"); CommandLineParser parser = new PosixParser(); try {/*from www .j av a2 s . co m*/ CommandLine cmdline = parser.parse(options, args); if (cmdline.hasOption("help")) { printHelp(); System.exit(0); } if (cmdline.getArgList().size() != 0) { System.err.println("Please use the new commandline options."); System.out.println(); printHelp(); System.exit(1); } HisqisSettings settings = null; HisqisSettings.genConfigPath(); for (File configpath : HisqisSettings.configpath) { if (configpath.exists() && configpath.canRead()) { settings = HisqisSettingsReader.loadDocument(configpath); if (settings != null) { break; } } } if (settings == null) { settings = new HisqisSettings(); } String user = cmdline.getOptionValue("user", null); String pass = cmdline.getOptionValue("pass", null); if (user != null) { settings.username = user; } if (pass != null) { settings.password = pass; } if (cmdline.hasOption("console")) { new HisqisConsole(settings); } else { new HisqisGUI(settings); } } catch (ParseException e) { printHelp(); } }
From source file:boa.BoaMain.java
public static void main(final String[] args) throws IOException { final Options options = new Options(); options.addOption("p", "parse", false, "parse and semantic check a Boa program (don't generate code)"); options.addOption("c", "compile", false, "compile a Boa program"); options.addOption("e", "execute", false, "execute a Boa program locally"); options.addOption("g", "generate", false, "generate a Boa dataset"); try {/*from www.j a v a 2 s . c om*/ if (args.length == 0) { printHelp(options, null); return; } else { final CommandLine cl = new PosixParser().parse(options, new String[] { args[0] }); final String[] tempargs = new String[args.length - 1]; System.arraycopy(args, 1, tempargs, 0, args.length - 1); if (cl.hasOption("c")) { boa.compiler.BoaCompiler.main(tempargs); } else if (cl.hasOption("p")) { boa.compiler.BoaCompiler.parseOnly(tempargs); } else if (cl.hasOption("e")) { boa.evaluator.BoaEvaluator.main(tempargs); } else if (cl.hasOption("g")) { boa.datagen.BoaGenerator.main(tempargs); } } } catch (final org.apache.commons.cli.ParseException e) { printHelp(options, e.getMessage()); } }
From source file:com.mvdb.etl.actions.ScanDBChanges.java
public static void main(String[] args) throws IOException { String customerName = null;/*from ww w .ja v a2s.c o m*/ String snapshotDir = null; 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("snapshotDir")) { snapshotDir = commandLine.getOptionValue("snapshotDir"); } } 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 (snapshotDir == null) { System.err.println("Could not find snapshotDir. Aborting..."); System.exit(1); } ApplicationContext context = Top.getContext(); final ConfigurationDAO configurationDAO = (ConfigurationDAO) context.getBean("configurationDAO"); final GenericDAO genericDAO = (GenericDAO) context.getBean("genericDAO"); File snapshotDirectory = getSnapshotDirectory(configurationDAO, customerName, snapshotDir); //write file schema-orders.dat in snapshotDirectory Metadata metadata = genericDAO.getMetadata("orders", snapshotDirectory); //writes files: header-orders.dat, data-orders.dat in snapshotDirectory genericDAO.scan2("orders", snapshotDirectory); }