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