Home | History | Annotate | Download | only in index
      1  260   trond /*
      2  260   trond  * CDDL HEADER START
      3  260   trond  *
      4  260   trond  * The contents of this file are subject to the terms of the
      5  260   trond  * Common Development and Distribution License (the "License").
      6  260   trond  * You may not use this file except in compliance with the License.
      7  260   trond  *
      8  260   trond  * See LICENSE.txt included in this distribution for the specific
      9  260   trond  * language governing permissions and limitations under the License.
     10  260   trond  *
     11  260   trond  * When distributing Covered Code, include this CDDL HEADER in each
     12  260   trond  * file and include the License file at LICENSE.txt.
     13  260   trond  * If applicable, add the following below this CDDL HEADER, with the
     14  260   trond  * fields enclosed by brackets "[]" replaced with your own identifying
     15  260   trond  * information: Portions Copyright [yyyy] [name of copyright owner]
     16  260   trond  *
     17  260   trond  * CDDL HEADER END
     18  260   trond  */
     19  260   trond 
     20  260   trond /*
     21  260   trond  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
     22  260   trond  * Use is subject to license terms.
     23  260   trond  */
     24  260   trond package org.opensolaris.opengrok.index;
     25  260   trond 
     26  260   trond import java.io.BufferedReader;
     27  260   trond import java.io.IOException;
     28  260   trond import java.io.InputStreamReader;
     29  260   trond import java.io.PrintWriter;
     30  260   trond import java.io.StringWriter;
     31  260   trond import java.text.DateFormat;
     32  260   trond import java.util.ArrayList;
     33  260   trond import java.util.Date;
     34  364   trond import java.util.Iterator;
     35  260   trond import java.util.List;
     36  260   trond 
     37  260   trond public class CommandLineOptions {
     38  260   trond 
     39  465  jorgen     private final static String ON_OFF = "on/off";
     40  465  jorgen 
     41  344  jorgen     static class Option {
     42  465  jorgen 
     43  260   trond         char option;
     44  260   trond         String argument;
     45  260   trond         String description;
     46  260   trond 
     47  260   trond         public Option(char opt, String arg, String descr) {
     48  260   trond             option = opt;
     49  260   trond             argument = arg;
     50  260   trond             description = descr;
     51  260   trond         }
     52  260   trond 
     53  260   trond         public String getUsage() {
     54  260   trond             StringBuilder sb = new StringBuilder();
     55  260   trond             sb.append('-');
     56  260   trond             sb.append(option);
     57  260   trond             if (argument != null) {
     58  260   trond                 sb.append(' ');
     59  260   trond                 sb.append(argument);
     60  260   trond             }
     61  260   trond             sb.append("\n\t");
     62  260   trond             sb.append(description);
     63  260   trond 
     64  260   trond             return sb.toString();
     65  260   trond         }
     66  260   trond     }
     67  456  jorgen     private final List<Option> options;
     68  260   trond 
     69  260   trond     public CommandLineOptions() {
     70  260   trond         options = new ArrayList<Option>();
     71  260   trond         options.add(new Option('q', null, "Run as quietly as possible"));
     72  260   trond         options.add(new Option('v', null, "Print progress information as we go along"));
     73  272   trond         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."));
     74  260   trond         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."));
     75  260   trond         options.add(new Option('R', "/path/to/configuration", "Read configuration from the specified file"));
     76  260   trond         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"));
     77  260   trond         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)"));
     78  260   trond         options.add(new Option('P', null, "Generate a project for each of the top-level directories in source root"));
     79  894   Lubos         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(when no other project set either in cookie or in parameter). You should strip off the source root."));
     80  465  jorgen         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)"));
     81  260   trond         options.add(new Option('n', null, "Do not generate indexes, but process all other command line options"));
     82  260   trond         options.add(new Option('H', null, "Generate history cache for all external repositories"));
     83  260   trond         options.add(new Option('h', "/path/to/repository", "Generate history cache for the specified repos (absolute path from source root)"));
     84  886    Knut         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)"));
     85  886    Knut         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\""));
     86  886    Knut         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\""));
     87  465  jorgen         options.add(new Option('r', ON_OFF, "Turn on/off support for remote SCM systems"));
     88  260   trond         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\""));
     89  465  jorgen         options.add(new Option('l', ON_OFF, "Turn on/off locking of the Lucene database during index generation"));
     90  465  jorgen         options.add(new Option('O', ON_OFF, "Turn on/off the optimization of the index database as part of the indexing step"));
     91  465  jorgen         options.add(new Option('a', ON_OFF, "Allow or disallow leading wildcards in a search"));
     92  260   trond         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."));
     93  260   trond         options.add(new Option('i', "pattern", "Ignore the named files or directories"));
     94  260   trond         options.add(new Option('A', "ext:analyzer", "Files with the named extension should be analyzed with the specified class"));
     95  260   trond         options.add(new Option('m', "number", "The maximum words to index in a file"));
     96  260   trond         options.add(new Option('S', null, "Search for \"external\" source repositories and add them"));
     97  260   trond         options.add(new Option('s', "/path/to/source/root", "The root directory of the source tree"));
     98  260   trond         options.add(new Option('d', "/path/to/data/root", "The directory where OpenGrok stores the generated data"));
     99  261   trond         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"));
    100  260   trond         options.add(new Option('?', null, "Help"));
    101  467   trond         options.add(new Option('V', null, "Print version and quit"));
    102  260   trond     }
    103  260   trond 
    104  260   trond     public String getCommandString() {
    105  260   trond         StringBuilder sb = new StringBuilder();
    106  260   trond         for (Option o : options) {
    107  260   trond             sb.append(o.option);
    108  260   trond             if (o.argument != null) {
    109  260   trond                 sb.append(':');
    110  260   trond             }
    111  260   trond         }
    112  260   trond         return sb.toString();
    113  260   trond     }
    114  260   trond 
    115  260   trond     public String getCommandUsage(char c) {
    116  260   trond         for (Option o : options) {
    117  260   trond             if (o.option == c) {
    118  260   trond                 return o.getUsage();
    119  260   trond             }
    120  260   trond         }
    121  260   trond 
    122  260   trond         return null;
    123  260   trond     }
    124  260   trond 
    125  260   trond     private void spool(BufferedReader reader, PrintWriter out, String tag) throws IOException {
    126  260   trond         String line;
    127  260   trond         while ((line = reader.readLine()) != null) {
    128  260   trond             if (line.equals(tag)) {
    129  260   trond                 return;
    130  260   trond             }
    131  260   trond             out.println(line);
    132  260   trond         }
    133  260   trond     }
    134  260   trond 
    135  260   trond     public String getUsage() {
    136  260   trond         StringWriter wrt = new StringWriter();
    137  260   trond         PrintWriter out = new PrintWriter(wrt);
    138  260   trond 
    139  260   trond         out.println("Usage: opengrok.jar [options]");
    140  260   trond         for (Option o : options) {
    141  260   trond             out.println(o.getUsage());
    142  260   trond         }
    143  260   trond 
    144  260   trond         out.flush();
    145  260   trond         out.close();
    146  260   trond 
    147  260   trond         return wrt.toString();
    148  260   trond     }
    149  260   trond 
    150  260   trond     public String getManPage() throws IOException {
    151  260   trond         StringWriter wrt = new StringWriter();
    152  260   trond         PrintWriter out = new PrintWriter(wrt);
    153  260   trond 
    154  260   trond         BufferedReader reader = new BufferedReader(new InputStreamReader(
    155  345  jorgen                 CommandLineOptions.class.getResourceAsStream("opengrok.xml"), "US-ASCII"));
    156  260   trond 
    157  260   trond         spool(reader, out, "___INSERT_DATE___");
    158  260   trond         out.print("<refmiscinfo class=\"date\">");
    159  260   trond         out.print(DateFormat.getDateInstance(DateFormat.MEDIUM).format(new Date()));
    160  260   trond         out.println("</refmiscinfo>");
    161  260   trond 
    162  260   trond         spool(reader, out, "___INSERT_USAGE___");
    163  260   trond         for (Option o : options) {
    164  260   trond             out.println("<optional><option>");
    165  260   trond             out.print(o.option);
    166  260   trond             if (o.argument != null) {
    167  260   trond                 out.print(" <replaceable>");
    168  260   trond                 out.print(o.argument);
    169  260   trond                 out.print("</replaceable>");
    170  260   trond             }
    171  260   trond             out.println("</option></optional>");
    172  260   trond         }
    173  260   trond 
    174  260   trond         spool(reader, out, "___INSERT_OPTIONS___");
    175  260   trond         for (Option o : options) {
    176  260   trond             out.print("<varlistentry><term><option>");
    177  260   trond             out.print(o.option);
    178  260   trond             out.print("</option></term><listitem><para>");
    179  260   trond             out.print(o.description);
    180  260   trond             out.println("</para></listitem></varlistentry>");
    181  260   trond         }
    182  260   trond 
    183  260   trond         spool(reader, out, "___END_OF_FILE___");
    184  260   trond         out.flush();
    185  260   trond         reader.close();
    186  260   trond 
    187  260   trond         return wrt.toString();
    188  260   trond     }
    189  260   trond 
    190  260   trond     /**
    191  364   trond      * Not intended for normal use, but for the JUnit test suite to validate
    192  364   trond      * that all options contains a description :-)
    193  364   trond      *
    194  364   trond      * @return an iterator to iterate through all of the command line options
    195  364   trond      */
    196  800    Knut     Iterator<Option> getOptionsIterator() {
    197  364   trond         return options.iterator();
    198  364   trond     }
    199  540  jorgen 
    200  540  jorgen    /**
    201  540  jorgen     * Print out a manual page on standard out. Used for building manual page.
    202  540  jorgen     *
    203  540  jorgen     * @param argv argument vector. not used.
    204  540  jorgen     */
    205  540  jorgen    @SuppressWarnings("PMD.SystemPrintln")
    206  540  jorgen    public static void main(String[] argv) {
    207  540  jorgen        CommandLineOptions co = new CommandLineOptions();
    208  540  jorgen        try {
    209  540  jorgen            System.out.println(co.getManPage());
    210  540  jorgen        } catch (IOException exp) {
    211  540  jorgen            exp.printStackTrace(System.err);
    212  540  jorgen            System.exit(1);
    213  540  jorgen        }
    214  540  jorgen    }
    215  260   trond }
    216