CommandLineOptions.java revision 886
58N/A/*
58N/A * CDDL HEADER START
58N/A *
58N/A * The contents of this file are subject to the terms of the
58N/A * Common Development and Distribution License (the "License").
58N/A * You may not use this file except in compliance with the License.
58N/A *
58N/A * See LICENSE.txt included in this distribution for the specific
58N/A * language governing permissions and limitations under the License.
58N/A *
58N/A * When distributing Covered Code, include this CDDL HEADER in each
58N/A * file and include the License file at LICENSE.txt.
58N/A * If applicable, add the following below this CDDL HEADER, with the
58N/A * fields enclosed by brackets "[]" replaced with your own identifying
58N/A * information: Portions Copyright [yyyy] [name of copyright owner]
58N/A *
58N/A * CDDL HEADER END
58N/A */
58N/A
58N/A/*
77N/A * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
58N/A * Use is subject to license terms.
58N/A */
58N/Apackage org.opensolaris.opengrok.index;
58N/A
234N/Aimport java.io.BufferedReader;
234N/Aimport java.io.IOException;
234N/Aimport java.io.InputStreamReader;
234N/Aimport java.io.PrintWriter;
639N/Aimport java.io.StringWriter;
639N/Aimport java.text.DateFormat;
234N/Aimport java.util.ArrayList;
234N/Aimport java.util.Date;
234N/Aimport java.util.Iterator;
234N/Aimport java.util.List;
639N/A
639N/Apublic class CommandLineOptions {
58N/A
667N/A private final static String ON_OFF = "on/off";
58N/A
664N/A static class Option {
112N/A
58N/A char option;
58N/A String argument;
77N/A String description;
77N/A
77N/A public Option(char opt, String arg, String descr) {
77N/A option = opt;
58N/A argument = arg;
418N/A description = descr;
58N/A }
773N/A
773N/A public String getUsage() {
58N/A StringBuilder sb = new StringBuilder();
773N/A sb.append('-');
773N/A sb.append(option);
773N/A if (argument != null) {
773N/A sb.append(' ');
58N/A sb.append(argument);
773N/A }
773N/A sb.append("\n\t");
773N/A sb.append(description);
773N/A
58N/A return sb.toString();
58N/A }
58N/A }
664N/A private final List<Option> options;
58N/A
65N/A public CommandLineOptions() {
77N/A options = new ArrayList<Option>();
99N/A options.add(new Option('q', null, "Run as quietly as possible"));
99N/A options.add(new Option('v', null, "Print progress information as we go along"));
125N/A options.add(new Option('e', null, "Economical - consumes less disk space. It does not generate hyper text cross reference files offline, but will do so on demand - which could be sightly slow."));
112N/A options.add(new Option('c', "/path/to/ctags", "Path to Exuberant Ctags from http://ctags.sf.net by default takes the Exuberant Ctags in PATH."));
129N/A options.add(new Option('R', "/path/to/configuration", "Read configuration from the specified file"));
129N/A options.add(new Option('W', "/path/to/configuration", "Write the current configuration to the specified file (so that the web application can use the same configuration"));
129N/A options.add(new Option('U', "host:port", "Send the current configuration to the specified address (This is most likely the web-app configured with ConfigAddress)"));
318N/A options.add(new Option('P', null, "Generate a project for each of the top-level directories in source root"));
318N/A options.add(new Option('p', "/path/to/default/project", "This is the path to the project that should be selected by default in the web application. You should strip off the source root."));
144N/A options.add(new Option('Q', ON_OFF, "Turn on/off quick context scan. By default only the first 32k of a file is scanned, and a '[..all..]' link is inserted if the file is bigger. Activating this may slow the server down (Note: this is setting only affects the web application)"));
173N/A options.add(new Option('n', null, "Do not generate indexes, but process all other command line options"));
253N/A options.add(new Option('H', null, "Generate history cache for all external repositories"));
296N/A options.add(new Option('h', "/path/to/repository", "Generate history cache for the specified repos (absolute path from source root)"));
335N/A options.add(new Option('D', null, "Store history cache in a database (needs the JDBC driver in the classpath, typically derbyclient.jar or derby.jar)"));
480N/A options.add(new Option('j', "class", "Name of the JDBC driver class used by the history cache. Can use one of the shorthands \"client\" (org.apache.derby.jdbc.ClientDriver) or \"embedded\" (org.apache.derby.jdbc.EmbeddedDriver). Default: \"client\""));
816N/A options.add(new Option('u', "url", "URL to the database that contains the history cache. Default: If -j specifies \"embedded\", \"jdbc:derby:$DATA_ROOT/cachedb;create=true\"; otherwise, \"jdbc:derby://localhost/cachedb;create=true\""));
816N/A options.add(new Option('r', ON_OFF, "Turn on/off support for remote SCM systems"));
816N/A options.add(new Option('L', "path", "Path to the subdirectory in the web-application containing the requested stylesheet. The following factory-defaults exist: \"default\", \"offwhite\" and \"polished\""));
816N/A options.add(new Option('l', ON_OFF, "Turn on/off locking of the Lucene database during index generation"));
58N/A options.add(new Option('O', ON_OFF, "Turn on/off the optimization of the index database as part of the indexing step"));
58N/A options.add(new Option('a', ON_OFF, "Allow or disallow leading wildcards in a search"));
816N/A options.add(new Option('w', "webapp-context", "Context of webapp. Default is /source. If you specify a different name, make sure to rename source.war to that name."));
58N/A options.add(new Option('i', "pattern", "Ignore the named files or directories"));
58N/A options.add(new Option('A', "ext:analyzer", "Files with the named extension should be analyzed with the specified class"));
773N/A options.add(new Option('m', "number", "The maximum words to index in a file"));
58N/A options.add(new Option('S', null, "Search for \"external\" source repositories and add them"));
664N/A options.add(new Option('s', "/path/to/source/root", "The root directory of the source tree"));
58N/A options.add(new Option('d', "/path/to/data/root", "The directory where OpenGrok stores the generated data"));
99N/A options.add(new Option('T', "number", "The number of threads to use for index generation. By default the number of threads will be set to the number of available CPUs"));
99N/A options.add(new Option('?', null, "Help"));
99N/A options.add(new Option('V', null, "Print version and quit"));
101N/A }
106N/A
112N/A public String getCommandString() {
129N/A StringBuilder sb = new StringBuilder();
129N/A for (Option o : options) {
129N/A sb.append(o.option);
318N/A if (o.argument != null) {
318N/A sb.append(':');
144N/A }
173N/A }
253N/A return sb.toString();
296N/A }
335N/A
480N/A public String getCommandUsage(char c) {
816N/A for (Option o : options) {
816N/A if (o.option == c) {
58N/A return o.getUsage();
58N/A }
58N/A }
58N/A
58N/A return null;
58N/A }
58N/A
58N/A private void spool(BufferedReader reader, PrintWriter out, String tag) throws IOException {
58N/A String line;
816N/A while ((line = reader.readLine()) != null) {
816N/A if (line.equals(tag)) {
816N/A return;
816N/A }
816N/A out.println(line);
816N/A }
816N/A }
816N/A
816N/A public String getUsage() {
816N/A StringWriter wrt = new StringWriter();
816N/A PrintWriter out = new PrintWriter(wrt);
816N/A
816N/A out.println("Usage: opengrok.jar [options]");
816N/A for (Option o : options) {
816N/A out.println(o.getUsage());
816N/A }
773N/A
773N/A out.flush();
773N/A out.close();
773N/A
773N/A return wrt.toString();
773N/A }
58N/A
58N/A public String getManPage() throws IOException {
58N/A StringWriter wrt = new StringWriter();
773N/A PrintWriter out = new PrintWriter(wrt);
773N/A
773N/A BufferedReader reader = new BufferedReader(new InputStreamReader(
773N/A CommandLineOptions.class.getResourceAsStream("opengrok.xml"), "US-ASCII"));
773N/A
58N/A spool(reader, out, "___INSERT_DATE___");
58N/A out.print("<refmiscinfo class=\"date\">");
58N/A out.print(DateFormat.getDateInstance(DateFormat.MEDIUM).format(new Date()));
773N/A out.println("</refmiscinfo>");
773N/A
773N/A spool(reader, out, "___INSERT_USAGE___");
773N/A for (Option o : options) {
773N/A out.println("<optional><option>");
773N/A out.print(o.option);
773N/A if (o.argument != null) {
773N/A out.print(" <replaceable>");
773N/A out.print(o.argument);
58N/A out.print("</replaceable>");
58N/A }
58N/A out.println("</option></optional>");
773N/A }
773N/A
773N/A spool(reader, out, "___INSERT_OPTIONS___");
773N/A for (Option o : options) {
773N/A out.print("<varlistentry><term><option>");
773N/A out.print(o.option);
773N/A out.print("</option></term><listitem><para>");
58N/A out.print(o.description);
58N/A out.println("</para></listitem></varlistentry>");
58N/A }
773N/A
773N/A spool(reader, out, "___END_OF_FILE___");
773N/A out.flush();
773N/A reader.close();
773N/A
773N/A return wrt.toString();
773N/A }
773N/A
773N/A /**
773N/A * Not intended for normal use, but for the JUnit test suite to validate
773N/A * that all options contains a description :-)
773N/A *
773N/A * @return an iterator to iterate through all of the command line options
773N/A */
773N/A Iterator<Option> getOptionsIterator() {
773N/A return options.iterator();
773N/A }
773N/A
773N/A /**
773N/A * Print out a manual page on standard out. Used for building manual page.
773N/A *
773N/A * @param argv argument vector. not used.
773N/A */
58N/A @SuppressWarnings("PMD.SystemPrintln")
58N/A public static void main(String[] argv) {
58N/A CommandLineOptions co = new CommandLineOptions();
58N/A try {
58N/A System.out.println(co.getManPage());
58N/A } catch (IOException exp) {
58N/A exp.printStackTrace(System.err);
58N/A System.exit(1);
58N/A }
58N/A }
58N/A}
58N/A