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/*
1393N/A * Copyright (c) 2008, 2012, Oracle and/or its affiliates. All rights reserved.
1190N/A *
1185N/A * Portions Copyright 2011 Jens Elkner.
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;
1195N/Aimport org.opensolaris.opengrok.util.IOUtils;
260N/A
260N/Apublic class CommandLineOptions {
260N/A
1238N/A private static final String ON_OFF = "on/off";
1238N/A private static final String NUMBER = "number";
465N/A
344N/A static class Option {
1190N/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>();
1185N/A options.add(new Option('?', null, "Help"));
1185N/A options.add(new Option('A', "ext:analyzer", "Files with the named extension should be analyzed with the specified class"));
1185N/A options.add(new Option('a', ON_OFF, "Allow or disallow leading wildcards in a search"));
1185N/A options.add(new Option('B', "url", "Base URL of the user Information provider. Default: \"http://www.opensolaris.org/viewProfile.jspa?username=\""));
1115N/A options.add(new Option('C', null, "Print per project percentage progress information(I/O extensive, since one read through dir structure is made before indexing, needs -v, otherwise it just goes to the log)"));
1185N/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."));
1185N/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)"));
1185N/A options.add(new Option('d', "/path/to/data/root", "The directory where OpenGrok stores the generated data"));
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."));
1348N/A options.add(new Option('E', null, "Turn off compression of generated hyper text cross reference files. Might be useful, if the underlying filesystem has compression already enabled."));
1185N/A options.add(new Option('H', null, "Generate history cache for all repositories"));
1185N/A options.add(new Option('h', "/path/to/repository", "just generate history cache for the specified repos (absolute path from source root)"));
1185N/A options.add(new Option('I', "pattern", "Only files matching this pattern will be examined (supports wildcards, example: -I *.java -I *.c)"));
1185N/A options.add(new Option('i', "pattern", "Ignore the named files or directories (supports wildcards, example: -i *.so -i *.dll)"));
1185N/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\""));
1185N/A options.add(new Option('k', "/path/to/repository", "Kill the history cache for the given repository and exit. Use '*' to delete the cache for all repositories."));
1185N/A options.add(new Option('K', null, "List all repository pathes and exit."));
1185N/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\""));
1185N/A options.add(new Option('l', ON_OFF, "Turn on/off locking of the Lucene database during index generation"));
1235N/A options.add(new Option('m', NUMBER, "The maximum words to index in a file"));
1185N/A options.add(new Option('N', "/path/to/symlink", "Allow this symlink to be followed. Option may be repeated."));
1185N/A options.add(new Option('n', null, "Do not generate indexes, but process all other command line options"));
1185N/A options.add(new Option('O', ON_OFF, "Turn on/off the optimization of the index database as part of the indexing step"));
1393N/A options.add(new Option('o', "path", "File with extra command line options for ctags"));
260N/A options.add(new Option('P', null, "Generate a project for each of the top-level directories in source root"));
894N/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(when no other project set either in cookie or in parameter). 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)"));
1327N/A options.add(new Option('q', null, "Run as quietly as possible, reset console loggers to suppress messages with a severity < WARMING and file loggers to supress messages with a severity < INFO as well as verbose messages."));
1185N/A options.add(new Option('R', "/path/to/configuration", "Read configuration from the specified file"));
1185N/A options.add(new Option('r', ON_OFF, "Turn on/off support for remote SCM systems"));
1185N/A options.add(new Option('S', null, "Search for \"external\" source repositories and add them"));
1185N/A options.add(new Option('s', "/path/to/source/root", "The root directory of the source tree"));
1235N/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"));
1235N/A options.add(new Option('t', NUMBER, "Default tabsize to use (number of spaces per tab character)"));
1185N/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)"));
886N/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\""));
1185N/A options.add(new Option('V', null, "Print version and quit"));
1327N/A options.add(new Option('v', null, "Enable verbose messages, i.e. reset console and file loggers to suppress messages with a severity < INFO, only."));
1185N/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('w', "webapp-context", "Context of webapp. Default is /source. If you specify a different name, make sure to rename source.war to that name."));
1185N/A options.add(new Option('X', "url:suffix", "URL Suffix for the user Information provider. Default: \"\""));
1235N/A options.add(new Option('z', NUMBER, "depth of scanning for repositories in directory structure relative to source root"));
1330N/A options.add(new Option('Z', null, "allow printing the internal settings in /status.jsp. Per default it is disabled for security reasons."));
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();
1195N/A IOUtils.close(out);
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(
1044N/A getClass().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();
1195N/A IOUtils.close(reader);
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 :-)
1190N/A *
364N/A * @return an iterator to iterate through all of the command line options
364N/A */
800N/A Iterator<Option> getOptionsIterator() {
364N/A return options.iterator();
364N/A }
1190N/A
540N/A /**
540N/A * Print out a manual page on standard out. Used for building manual page.
1190N/A *
540N/A * @param argv argument vector. not used.
540N/A */
540N/A @SuppressWarnings("PMD.SystemPrintln")
540N/A public static void main(String[] argv) {
540N/A CommandLineOptions co = new CommandLineOptions();
540N/A try {
540N/A System.out.println(co.getManPage());
540N/A } catch (IOException exp) {
1185N/A System.err.println(exp.getLocalizedMessage());
540N/A }
540N/A }
260N/A}