List of usage examples for org.apache.commons.cli PosixParser parse
public CommandLine parse(Options options, String[] arguments) throws ParseException
arguments
based on the specifed Options . From source file:org.duracloud.common.cli.Command.java
public void execute(String[] args) { try {/*from www .ja v a 2s .c o m*/ PosixParser parser = new PosixParser(); CommandLine cl = parser.parse(options, args); executeImpl(args, cl); } catch (ParseException ex) { usage(args); } }
From source file:org.icefaces.ace.util.cssurlmapper.Main.java
public static void main(String[] args) { Options options = new Options(); Option helpOpt = OptionBuilder.withDescription("print this message").withLongOpt("help").create('h'); Option rootDirOpt = OptionBuilder.withArgName("directory").hasArg() .withDescription("root directory containing all CSS files to be processed").withLongOpt("root-dir") .create('r'); Option fileOpt = OptionBuilder.withArgName("file").hasArg().withDescription("individual file to process") .withLongOpt("file").create('f'); Option libraryNameOpt = OptionBuilder.withArgName("name").hasArg() .withDescription("name of JSF resource library to include in mapped URLs (required)") .withLongOpt("library-name").create('l'); Option referenceDirOpt = OptionBuilder.withArgName("directory").hasArg() .withDescription("directory to use as starting point when building relative paths to resources") .withLongOpt("reference-dir").create('n'); Option outputDirOpt = OptionBuilder.withArgName("directory").hasArg() .withDescription("directory to where all output files will be written (required)") .withLongOpt("output-dir").create('o'); options.addOption(helpOpt);/* w ww.j a v a 2s .c o m*/ options.addOption(rootDirOpt); options.addOption(fileOpt); options.addOption(libraryNameOpt); options.addOption(referenceDirOpt); options.addOption(outputDirOpt); PosixParser posixParser = new PosixParser(); String libraryNameVal = null; String fileVal = null; String rootDirVal = null; String referenceDirVal = null; String outputDirVal = null; File rootDir = null; File file = null; File referenceDir = null; File outputDir = null; try { CommandLine line = posixParser.parse(options, args); // check for help option first if (line.hasOption('h')) { printHelp(options); Runtime.getRuntime().exit(0); } // make sure library name was specified if (line.hasOption('l')) { libraryNameVal = line.getOptionValue('l'); } else { throw new MissingOptionException("ERROR: library name was not supplied."); } // check for root directory or file if (line.hasOption('f')) { fileVal = line.getOptionValue('f'); } if (line.hasOption('r')) { rootDirVal = line.getOptionValue('r'); } if (fileVal == null && rootDirVal == null) { throw new MissingOptionException("ERROR: either file or root directory must be specified."); } if (rootDirVal != null) { rootDir = new File(rootDirVal); if (!rootDir.exists()) { throw new Exception("ERROR: root directory does not exist."); } else if (!rootDir.isDirectory()) { throw new Exception("ERROR: root directory is not a real directory."); } } else { // file must be non-null then file = new File(fileVal); if (!file.exists()) { throw new Exception("ERROR: input file does not exist."); } else if (!file.isFile()) { throw new Exception("ERROR: input file is not a real file."); } } // check for output directory if (line.hasOption('o')) { outputDirVal = line.getOptionValue('o'); outputDir = new File(outputDirVal); outputDir.mkdirs(); if (!outputDir.exists()) { throw new Exception("ERROR: could not create output directory."); } else if (!outputDir.isDirectory()) { throw new Exception("ERROR: output directory is not a real directory."); } } else { throw new MissingOptionException("ERROR: output directory was not supplied."); } // check for reference directory if (line.hasOption('n')) { referenceDirVal = line.getOptionValue('n'); referenceDir = new File(referenceDirVal); if (!referenceDir.exists()) { throw new Exception("ERROR: reference directory does not exist."); } else if (!referenceDir.isDirectory()) { throw new Exception("ERROR: reference directory is not a real directory."); } String referenceDirPath = referenceDir.getCanonicalPath(); if (rootDir != null) { String rootDirPath = rootDir.getCanonicalPath(); if (!rootDirPath.startsWith(referenceDirPath)) { throw new Exception("ERROR: reference directory must be an ancestor of root directory."); } } else { // file must be non-null then String filePath = file.getCanonicalPath(); if (!filePath.startsWith(referenceDirPath)) { throw new Exception("ERROR: reference directory must be an ancestor of input file."); } } } } catch (ParseException e) { System.out.println(e.getMessage()); System.out.println(); printHelp(options); Runtime.getRuntime().exit(0); } catch (Exception e) { System.out.println(e.getMessage()); Runtime.getRuntime().exit(0); } // all input was validated, so proceed with file processing if (rootDir != null) { if (referenceDir != null) { processDirectory(rootDir, libraryNameVal, referenceDir, outputDir); } else { processDirectory(rootDir, libraryNameVal, rootDir, outputDir); } } else { processFile(file, libraryNameVal, referenceDir, outputDir); } }
From source file:org.jumpmind.symmetric.AbstractCommandLauncher.java
public void execute(String args[]) { PosixParser parser = new PosixParser(); Options options = new Options(); buildOptions(options);//from ww w. j a v a 2s .c o m try { CommandLine line = parser.parse(options, args); if (line.hasOption(HELP) || (line.getArgList().contains(HELP)) || ((args == null || args.length == 0) && line.getOptions().length == 0 && printHelpIfNoOptionsAreProvided())) { printHelp(line, options); System.exit(2); } configureLogging(line); configurePropertiesFile(line); if (line.getOptions() != null) { for (Option option : line.getOptions()) { log.info("Option: name={}, value={}", new Object[] { option.getLongOpt() != null ? option.getLongOpt() : option.getOpt(), ArrayUtils.toString(option.getValues()) }); } } executeWithOptions(line); } catch (ParseException e) { System.err.println(e.getMessage()); printUsage(options); System.exit(4); } catch (Exception e) { System.err.println("-------------------------------------------------------------------------------"); System.err.println("An exception occurred. Please see the following for details:"); System.err.println("-------------------------------------------------------------------------------"); ExceptionUtils.printRootCauseStackTrace(e, System.err); System.err.println("-------------------------------------------------------------------------------"); System.exit(1); } }
From source file:org.meresco.lucene.http.LuceneHttpServer.java
public static void main(String[] args) throws Exception { Options options = new Options(); Option option = new Option("p", "port", true, "Port number"); option.setType(Integer.class); option.setRequired(true);/* w ww . j a va 2s. c om*/ options.addOption(option); option = new Option("d", "stateDir", true, "Directory in which lucene data is located"); option.setType(String.class); option.setRequired(true); options.addOption(option); option = new Option(null, "core", true, "Lucene core"); option.setType(String[].class); option.setRequired(true); options.addOption(option); PosixParser parser = new PosixParser(); CommandLine commandLine = null; try { commandLine = parser.parse(options, args); } catch (MissingOptionException e) { HelpFormatter helpFormatter = new HelpFormatter(); helpFormatter.printHelp("start-lucene-server", options); System.exit(1); } Integer port = new Integer(commandLine.getOptionValue("p")); String storeLocation = commandLine.getOptionValue("d"); String[] cores = commandLine.getOptionValues("core"); if (Charset.defaultCharset() != Charset.forName("UTF-8")) { System.err.println("file.encoding must be UTF-8."); System.exit(1); } TermNumerator termNumerator = new TermNumerator(new File(storeLocation, "keys-termnumerator")); ContextHandlerCollection contexts = new ContextHandlerCollection(); List<Lucene> lucenes = new ArrayList<Lucene>(); for (String core : cores) { Lucene lucene = new Lucene(core, new File(storeLocation, "lucene-" + core)); lucenes.add(lucene); } ExecutorThreadPool pool = new ExecutorThreadPool(50, 200, 60, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(1000)); Server server = new Server(pool); ServerConnector http = new ServerConnector(server, new HttpConnectionFactory()); http.setPort(port); server.addConnector(http); OutOfMemoryShutdown shutdown = new LuceneShutdown(server, lucenes, termNumerator, storeLocation); for (Lucene lucene : lucenes) { String core = lucene.name; ContextHandler context = new ContextHandler("/" + core + "/query"); context.setHandler(new QueryHandler(lucene, shutdown)); contexts.addHandler(context); context = new ContextHandler("/" + core + "/update"); context.setHandler(new UpdateHandler(lucene, termNumerator, shutdown)); contexts.addHandler(context); context = new ContextHandler("/" + core + "/delete"); context.setHandler(new DeleteHandler(lucene, shutdown)); contexts.addHandler(context); context = new ContextHandler("/" + core + "/settings"); context.setHandler(new SettingsHandler(lucene, shutdown)); contexts.addHandler(context); context = new ContextHandler("/" + core + "/prefixSearch"); context.setHandler(new PrefixSearchHandler(lucene, shutdown)); contexts.addHandler(context); context = new ContextHandler("/" + core); context.setHandler(new OtherHandler(lucene, shutdown)); contexts.addHandler(context); } ContextHandler composedQueryHandler = new ContextHandler("/query"); composedQueryHandler.setHandler(new ComposedQueryHandler(new MultiLucene(lucenes), shutdown)); contexts.addHandler(composedQueryHandler); ContextHandler exportKeysHandler = new ContextHandler("/exportkeys"); exportKeysHandler.setHandler(new ExportKeysHandler(new MultiLucene(lucenes), shutdown)); contexts.addHandler(exportKeysHandler); ContextHandler numerateHandler = new ContextHandler("/numerate"); numerateHandler.setHandler(new NumerateHandler(termNumerator, shutdown)); contexts.addHandler(numerateHandler); ContextHandler commitHandler = new ContextHandler("/commit"); commitHandler.setHandler(new CommitHandler(termNumerator, lucenes, shutdown)); contexts.addHandler(commitHandler); registerShutdownHandler(shutdown); server.setHandler(contexts); server.start(); server.join(); }
From source file:org.meresco.lucene.numerate.NumerateHttpServer.java
public static void main(String[] args) throws Exception { Options options = new Options(); Option option = new Option("p", "port", true, "Port number"); option.setType(Integer.class); option.setRequired(true);/* w ww. j a va 2s .co m*/ options.addOption(option); option = new Option("d", "stateDir", true, "Directory in which lucene data is located"); option.setType(String.class); option.setRequired(true); options.addOption(option); PosixParser parser = new PosixParser(); CommandLine commandLine = null; try { commandLine = parser.parse(options, args); } catch (MissingOptionException e) { HelpFormatter helpFormatter = new HelpFormatter(); helpFormatter.printHelp("start-numerate-server", options); System.exit(1); } Integer port = new Integer(commandLine.getOptionValue("p")); String stateDir = commandLine.getOptionValue("d"); if (Charset.defaultCharset() != Charset.forName("UTF-8")) { System.err.println("file.encoding must be UTF-8."); System.exit(1); } UriEnumerate uriEnumerate = new UriEnumerate(new File(stateDir, "keys-termnumerator").getAbsolutePath()); ExecutorThreadPool pool = new ExecutorThreadPool(50, 200, 60, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(1000)); Server server = new Server(pool); ServerConnector http = new ServerConnector(server, new HttpConnectionFactory()); http.setPort(port); server.addConnector(http); registerShutdownHandler(stateDir, uriEnumerate, server); server.setHandler(new NumerateHandler(uriEnumerate)); server.start(); server.join(); }
From source file:org.meresco.lucene.suggestion.SuggestionHttpServer.java
public static void main(String[] args) throws Exception { Options options = new Options(); Option option = new Option("p", "port", true, "Port number"); option.setType(Integer.class); option.setRequired(true);//from ww w.j a va 2 s .c om options.addOption(option); option = new Option("d", "stateDir", true, "Directory in which lucene data is located"); option.setType(String.class); option.setRequired(true); options.addOption(option); PosixParser parser = new PosixParser(); CommandLine commandLine = null; try { commandLine = parser.parse(options, args); } catch (MissingOptionException e) { HelpFormatter helpFormatter = new HelpFormatter(); helpFormatter.printHelp("start-suggestion-server", options); System.exit(1); } Integer port = new Integer(commandLine.getOptionValue("p")); String stateDir = commandLine.getOptionValue("d"); if (Charset.defaultCharset() != Charset.forName("UTF-8")) { System.err.println("file.encoding must be UTF-8."); System.exit(1); } SuggestionIndex suggestionIndex = new SuggestionIndex(stateDir + "/suggestions", stateDir + "/ngram", MIN_SHINGLE_SIZE, MAX_SHINGLE_SIZE, COMMIT_COUNT); ExecutorThreadPool pool = new ExecutorThreadPool(50, 200, 60, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(1000)); Server server = new Server(pool); ServerConnector http = new ServerConnector(server, new HttpConnectionFactory()); http.setPort(port); server.addConnector(http); OutOfMemoryShutdown shutdown = new SuggestionShutdown(server, suggestionIndex); registerShutdownHandler(shutdown); server.setHandler(new SuggestionHandler(suggestionIndex, shutdown)); server.start(); server.join(); }
From source file:org.meresco.triplestore.GraphDBServer.java
public static void main(String[] args) throws Exception { Option option;//www . jav a2s .c o m Options options = new Options(); // Port Number option = new Option("p", "port", true, "Port number"); option.setType(Integer.class); option.setRequired(true); options.addOption(option); // Triplestore name option = new Option("n", "name", true, "Name of the triplestore. Defaults to triplestore"); option.setType(String.class); option.setRequired(false); options.addOption(option); // Triplestore location option = new Option("d", "stateDir", true, "Directory in which triplestore is located"); option.setType(String.class); option.setRequired(true); options.addOption(option); option = new Option(null, "cacheMemory", true, "Cache size; Usually half -Xmx"); option.setType(String.class); option.setRequired(false); options.addOption(option); option = new Option(null, "entityIndexSize", true, "Entity index size. Usually half the number of entities (Uri's, blank nodes, literals). Cannot be changed after indexing."); option.setType(Integer.class); option.setRequired(false); options.addOption(option); option = new Option(null, "queryTimeout", true, "Query timeout in seconds. Defaults to 0 (no limit)"); option.setType(Integer.class); option.setRequired(false); options.addOption(option); option = new Option(null, "maxCommitCount", true, "Max number of commits for updates."); option.setType(Integer.class); option.setRequired(false); options.addOption(option); option = new Option(null, "maxCommitTimeout", true, "Maximum seconds after update for a commit."); option.setType(Integer.class); option.setRequired(false); options.addOption(option); PosixParser parser = new PosixParser(); CommandLine commandLine = null; try { commandLine = parser.parse(options, args); } catch (MissingOptionException e) { HelpFormatter helpFormatter = new HelpFormatter(); helpFormatter.printHelp("start-graphdb", options); System.exit(1); } Integer port = new Integer(commandLine.getOptionValue("p")); String storeLocation = commandLine.getOptionValue("d"); String storeName = commandLine.getOptionValue("n"); if (storeName == null) storeName = "triplestore"; String cacheMemory = commandLine.getOptionValue("cacheMemory"); String entityIndexSize = commandLine.getOptionValue("entityIndexSize"); String queryTimeout = commandLine.getOptionValue("queryTimeout"); if (queryTimeout == null) queryTimeout = "0"; String maxCommitCount = commandLine.getOptionValue("maxCommitCount"); String maxCommitTimeout = commandLine.getOptionValue("maxCommitTimeout"); if (Charset.defaultCharset() != Charset.forName("UTF-8")) { System.err.println("file.encoding must be UTF-8."); System.exit(1); } long startTime = System.currentTimeMillis(); GraphDBTriplestore tripleStore = new GraphDBTriplestore(new File(storeLocation), storeName, cacheMemory, entityIndexSize, queryTimeout); if (maxCommitCount != null) tripleStore.setMaxCommitCount(Integer.parseInt(maxCommitCount)); if (maxCommitTimeout != null) tripleStore.setMaxCommitTimeout(Integer.parseInt(maxCommitTimeout)); ExecutorThreadPool pool = new ExecutorThreadPool(50, 200, 60, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(1000)); Server server = new Server(pool); ContextHandler context = new ContextHandler("/"); context.setHandler(new HttpHandler(tripleStore)); ServerConnector http = new ServerConnector(server, new HttpConnectionFactory()); http.setPort(port); server.addConnector(http); registerShutdownHandler(tripleStore, server); server.setHandler(context); server.start(); server.join(); }
From source file:org.meresco.triplestore.SesameServer.java
public static void main(String[] args) throws Exception { Option option;/*from ww w. j a v a2 s . c o m*/ Options options = new Options(); // Port Number option = new Option("p", "port", true, "Port number"); option.setType(Integer.class); option.setRequired(true); options.addOption(option); // Triplestore name option = new Option("n", "name", true, "Name of the triplestore"); option.setType(String.class); option.setRequired(true); options.addOption(option); // Triplestore location option = new Option("d", "stateDir", true, "Directory in which triplestore is located"); option.setType(String.class); option.setRequired(true); options.addOption(option); PosixParser parser = new PosixParser(); CommandLine commandLine = null; try { commandLine = parser.parse(options, args); } catch (MissingOptionException e) { HelpFormatter helpFormatter = new HelpFormatter(); helpFormatter.printHelp("start-owlim", options); System.exit(1); } Integer port = new Integer(commandLine.getOptionValue("p")); String storeLocation = commandLine.getOptionValue("d"); String storeName = commandLine.getOptionValue("n"); if (Charset.defaultCharset() != Charset.forName("UTF-8")) { System.err.println("file.encoding must be UTF-8."); System.exit(1); } long startTime = System.currentTimeMillis(); Triplestore tripleStore = new SesameTriplestoreImpl(new File(storeLocation), storeName); System.out.println("Starting took " + (System.currentTimeMillis() - startTime) / 1000 + " seconds"); HttpHandler handler = new HttpHandler(tripleStore); HttpServer httpServer = new HttpServer(port, 15); registerShutdownHandler(tripleStore, httpServer); httpServer.setHandler(handler); httpServer.start(); }
From source file:org.meresco.triplestore.VirtuosoServer.java
public static void main(String[] args) throws Exception { Option option;//from w w w. ja va 2s . c om Options options = new Options(); option = new Option("p", "port", true, "Port number"); option.setType(Integer.class); option.setRequired(true); options.addOption(option); option = new Option("d", "stateDir", true, "State directory for backup e.d."); option.setType(String.class); option.setRequired(true); options.addOption(option); option = new Option(null, "hostname", true, "Hostame of the virtuoso instance"); option.setType(String.class); option.setRequired(true); options.addOption(option); option = new Option(null, "odbcPort", true, "Odbc port number of the virtuoso instance"); option.setType(Integer.class); option.setRequired(true); options.addOption(option); option = new Option(null, "username", true, "Username of the virtuoso instance"); option.setType(String.class); option.setRequired(true); options.addOption(option); option = new Option(null, "password", true, "Password of the virtuoso instance"); option.setType(String.class); option.setRequired(true); options.addOption(option); PosixParser parser = new PosixParser(); CommandLine commandLine = null; try { commandLine = parser.parse(options, args); } catch (MissingOptionException e) { HelpFormatter helpFormatter = new HelpFormatter(); helpFormatter.printHelp("start-virtuoso", options); System.exit(1); } Integer port = new Integer(commandLine.getOptionValue("p")); String stateDir = commandLine.getOptionValue("d"); String hostname = commandLine.getOptionValue("hostname"); Integer odbcPort = new Integer(commandLine.getOptionValue("odbcPort")); String username = commandLine.getOptionValue("username"); String password = commandLine.getOptionValue("password"); Boolean disableTransactionLog = commandLine.hasOption("disableTransactionLog"); if (Charset.defaultCharset() != Charset.forName("UTF-8")) { System.err.println("file.encoding must be UTF-8."); System.exit(1); } Triplestore tripleStore = new VirtuosoTriplestore(new File(stateDir), hostname, odbcPort, username, password); ExecutorThreadPool pool = new ExecutorThreadPool(50, 200, 60, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(1000)); Server server = new Server(pool); ContextHandler context = new ContextHandler("/"); context.setHandler(new HttpHandler(tripleStore)); ServerConnector http = new ServerConnector(server, new HttpConnectionFactory()); http.setPort(port); server.addConnector(http); System.out.println("Triplestore started with " + String.valueOf(tripleStore.size()) + " statements"); System.out.flush(); server.setHandler(context); server.start(); server.join(); }
From source file:org.multicore_association.measure.cycle.generate.ParameterParser.java
/** * Check and Parse the command line parameters. * @param args command line parameters/*www . j a v a2 s .c o m*/ * @return Flag for success judgements * @throws ParseException */ public boolean parseParam(String[] args) throws ParseException { boolean ch = true; PosixParser parser = new PosixParser(); org.apache.commons.cli.Options opts = generateOpts(); cl = parser.parse(opts, args); if (cl.hasOption(PRINTHELP_LOPT)) { // printHelp(); return false; } System.out.println(); if (cl.hasOption(ARCH_NAME_LOPT)) { architectureName = cl.getOptionValue(ARCH_NAME_LOPT); System.out.println("Architecture: " + architectureName + ""); } else { System.out.println("Architecture: None specified"); } if (cl.hasOption(INSTSET_NAME_LOPT)) { instructionSetName = cl.getOptionValue(INSTSET_NAME_LOPT); System.out.println("CommonInstructionSet name: " + instructionSetName + ""); } else { System.out.println("CommonInstructionSet name: None specified"); } if (cl.hasOption(SHIM_SCHEMA_LOPT)) { shimSchemaPath = cl.getOptionValue(SHIM_SCHEMA_LOPT); System.out.println("SHIM Schema: " + shimSchemaPath + ""); } else { System.out.println("SHIM Schema: None specified"); } if (cl.hasOption(INPUT_SHIM_LOPT)) { shimDataPath = cl.getOptionValue(INPUT_SHIM_LOPT); System.out.println("Input SHIM: " + shimDataPath + ""); } else { System.out.println("Input SHIM: None specified"); } if (cl.hasOption(SHIM_SCHEMA_LOPT)) { shimSchemaPath = cl.getOptionValue(SHIM_SCHEMA_LOPT); System.out.println("SHIM Schema: " + shimSchemaPath + ""); } else { System.out.println("SHIM Schema: None specified"); } if (cl.hasOption(CONF_DIR_LOPT)) { configDir = cl.getOptionValue(CONF_DIR_LOPT); System.out.println("Configuration file directory: " + configDir + ""); } else { System.out.println("Configuration file directory: None specified"); } if (cl.hasOption(DEST_DIR_LOPT)) { destDir = cl.getOptionValue(DEST_DIR_LOPT); System.out.println("Destination directory: " + destDir + ""); } else { System.out.println("Destination directory: ."); } if (cl.hasOption(FILE_PREFIX_LOPT)) { prefix = cl.getOptionValue(FILE_PREFIX_LOPT); System.out.println("Prefix: " + prefix); } else { System.out.println("Prefix: None specified"); } System.out.println(); return ch; }