CommandLineOptions.java revision 345
30N/A/*
30N/A * CDDL HEADER START
30N/A *
30N/A * The contents of this file are subject to the terms of the
30N/A * Common Development and Distribution License (the "License").
30N/A * You may not use this file except in compliance with the License.
30N/A *
30N/A * See LICENSE.txt included in this distribution for the specific
30N/A * language governing permissions and limitations under the License.
30N/A *
30N/A * When distributing Covered Code, include this CDDL HEADER in each
30N/A * file and include the License file at LICENSE.txt.
30N/A * If applicable, add the following below this CDDL HEADER, with the
30N/A * fields enclosed by brackets "[]" replaced with your own identifying
30N/A * information: Portions Copyright [yyyy] [name of copyright owner]
30N/A *
30N/A * CDDL HEADER END
30N/A */
30N/A
30N/A/*
1054N/A * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
30N/A * Use is subject to license terms.
30N/A */
30N/Apackage org.opensolaris.opengrok.index;
58N/A
58N/Aimport java.io.BufferedReader;
58N/Aimport java.io.IOException;
30N/Aimport java.io.InputStreamReader;
1016N/Aimport java.io.PrintWriter;
30N/Aimport java.io.StringWriter;
58N/Aimport java.text.DateFormat;
58N/Aimport java.util.ArrayList;
58N/Aimport java.util.Date;
58N/Aimport java.util.List;
58N/A
667N/Apublic class CommandLineOptions {
58N/A
1016N/A static class Option {
320N/A
320N/A char option;
490N/A String argument;
664N/A String description;
664N/A
1026N/A public Option(char opt, String arg, String descr) {
112N/A option = opt;
570N/A argument = arg;
30N/A description = descr;
30N/A }
30N/A
58N/A public String getUsage() {
30N/A StringBuilder sb = new StringBuilder();
418N/A sb.append('-');
58N/A sb.append(option);
456N/A if (argument != null) {
30N/A sb.append(' ');
320N/A sb.append(argument);
320N/A }
30N/A sb.append("\n\t");
30N/A sb.append(description);
77N/A
77N/A return sb.toString();
77N/A }
77N/A }
30N/A private List<Option> options;
30N/A
30N/A public CommandLineOptions() {
30N/A options = new ArrayList<Option>();
30N/A options.add(new Option('q', null, "Run as quietly as possible"));
77N/A options.add(new Option('v', null, "Print progress information as we go along"));
77N/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."));
30N/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."));
30N/A options.add(new Option('R', "/path/to/configuration", "Read configuration from the specified file"));
58N/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"));
145N/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)"));
145N/A options.add(new Option('P', null, "Generate a project for each of the top-level directories in source root"));
145N/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."));
145N/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)"));
145N/A options.add(new Option('n', null, "Do not generate indexes, but process all other command line options"));
58N/A options.add(new Option('H', null, "Generate history cache for all external repositories"));
77N/A options.add(new Option('h', "/path/to/repository", "Generate history cache for the specified repos (absolute path from source root)"));
490N/A options.add(new Option('r', "on/off", "Turn on/off support for remote SCM systems"));
490N/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\""));
490N/A options.add(new Option('l', "on/off", "Turn on/off locking of the Lucene database during index generation"));
490N/A options.add(new Option('O', "on/off", "Turn on/off the optimization of the index database as part of the indexing step"));
490N/A options.add(new Option('a', "on/off", "Allow or disallow leading wildcards in a search"));
490N/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."));
490N/A options.add(new Option('i', "pattern", "Ignore the named files or directories"));
490N/A options.add(new Option('A', "ext:analyzer", "Files with the named extension should be analyzed with the specified class"));
490N/A options.add(new Option('m', "number", "The maximum words to index in a file"));
490N/A options.add(new Option('S', null, "Search for \"external\" source repositories and add them"));
490N/A options.add(new Option('s', "/path/to/source/root", "The root directory of the source tree"));
490N/A options.add(new Option('d', "/path/to/data/root", "The directory where OpenGrok stores the generated data"));
490N/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"));
993N/A options.add(new Option('?', null, "Help"));
993N/A }
993N/A
993N/A public String getCommandString() {
993N/A StringBuilder sb = new StringBuilder();
993N/A for (Option o : options) {
993N/A sb.append(o.option);
993N/A if (o.argument != null) {
77N/A sb.append(':');
77N/A }
77N/A }
77N/A return sb.toString();
58N/A }
145N/A
58N/A public String getCommandUsage(char c) {
58N/A for (Option o : options) {
77N/A if (o.option == c) {
77N/A return o.getUsage();
77N/A }
77N/A }
30N/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;
58N/A while ((line = reader.readLine()) != null) {
58N/A if (line.equals(tag)) {
30N/A return;
58N/A }
77N/A out.println(line);
77N/A }
77N/A }
77N/A
77N/A public String getUsage() {
492N/A StringWriter wrt = new StringWriter();
504N/A PrintWriter out = new PrintWriter(wrt);
504N/A
1054N/A out.println("Usage: opengrok.jar [options]");
492N/A for (Option o : options) {
490N/A out.println(o.getUsage());
77N/A }
77N/A
77N/A out.flush();
77N/A out.close();
77N/A
77N/A return wrt.toString();
77N/A }
145N/A
77N/A public String getManPage() throws IOException {
77N/A StringWriter wrt = new StringWriter();
77N/A PrintWriter out = new PrintWriter(wrt);
77N/A
77N/A BufferedReader reader = new BufferedReader(new InputStreamReader(
77N/A CommandLineOptions.class.getResourceAsStream("opengrok.xml"), "US-ASCII"));
30N/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()));
58N/A out.println("</refmiscinfo>");
58N/A
58N/A spool(reader, out, "___INSERT_USAGE___");
58N/A for (Option o : options) {
58N/A out.println("<optional><option>");
58N/A out.print(o.option);
77N/A if (o.argument != null) {
77N/A out.print(" <replaceable>");
77N/A out.print(o.argument);
77N/A out.print("</replaceable>");
58N/A }
490N/A out.println("</option></optional>");
58N/A }
1016N/A
1016N/A spool(reader, out, "___INSERT_OPTIONS___");
1016N/A for (Option o : options) {
1016N/A out.print("<varlistentry><term><option>");
1016N/A out.print(o.option);
1016N/A out.print("</option></term><listitem><para>");
1016N/A out.print(o.description);
1016N/A out.println("</para></listitem></varlistentry>");
1016N/A }
1016N/A
1016N/A spool(reader, out, "___END_OF_FILE___");
1016N/A out.flush();
1066N/A reader.close();
1066N/A
1066N/A return wrt.toString();
1066N/A }
1066N/A
1066N/A /**
1066N/A * Print out a manual page on standard out
1066N/A *
1066N/A * @param argv argument vector. not used.
1016N/A */
1016N/A public static void main(String[] argv) {
1066N/A CommandLineOptions co = new CommandLineOptions();
1016N/A try {
58N/A System.out.println(co.getManPage());
77N/A } catch (IOException exp) {
77N/A exp.printStackTrace();
77N/A System.exit(1);
77N/A }
58N/A System.exit(0);
58N/A }
456N/A}
58N/A