001 /**
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License. You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017 package org.apache.geronimo.cli.daemon;
018
019 import java.io.OutputStream;
020
021 import org.apache.commons.cli.Option;
022 import org.apache.commons.cli.OptionBuilder;
023 import org.apache.commons.cli.OptionGroup;
024 import org.apache.geronimo.cli.BaseCLParser;
025 import org.apache.geronimo.cli.PrintHelper;
026
027
028 /**
029 * @version $Rev: 476049 $ $Date: 2006-11-17 15:35:17 +1100 (Fri, 17 Nov 2006) $
030 */
031 public class DaemonCLParser extends BaseCLParser {
032 private final static String ARGUMENT_NO_PROGRESS_SHORTFORM = "q";
033 private final static String ARGUMENT_NO_PROGRESS = "quiet";
034
035 private final static String ARGUMENT_LONG_PROGRESS_SHORTFORM = "l";
036 private final static String ARGUMENT_LONG_PROGRESS = "long";
037
038 private final static String ARGUMENT_MODULE_OVERRIDE_SHORTFORM = "o";
039 private final static String ARGUMENT_MODULE_OVERRIDE = "override";
040
041 public DaemonCLParser(OutputStream out) {
042 super(out);
043 addProgressOptions();
044 addOverride();
045 }
046
047 public boolean isNoProgress() {
048 return commandLine.hasOption(ARGUMENT_NO_PROGRESS_SHORTFORM);
049 }
050
051 public boolean isLongProgress() {
052 return commandLine.hasOption(ARGUMENT_LONG_PROGRESS_SHORTFORM);
053 }
054
055 public String[] getOverride() {
056 return commandLine.getOptionValues(ARGUMENT_MODULE_OVERRIDE_SHORTFORM);
057 }
058
059 public void displayHelp() {
060 PrintHelper printHelper = new PrintHelper(out);
061 printHelper.printHelp("java -jar bin/server.jar $options",
062 "\nThe following options are available:",
063 options,
064 "\nIn addition you may specify a replacement for var/config/config.xml by setting the property "
065 + "-Dorg.apache.geronimo.config.file=var/config/<my-config.xml>. "
066 + "This is resolved relative to the geronimo base directory.\n",
067 true);
068 }
069
070 protected void addOverride() {
071 OptionBuilder optionBuilder = OptionBuilder.hasArgs().withArgName("moduleId ...");
072 optionBuilder = optionBuilder.withLongOpt(ARGUMENT_MODULE_OVERRIDE);
073 optionBuilder = optionBuilder.withDescription("USE WITH CAUTION! Overrides the modules in "
074 + "var/config/config.xml such that only the modules listed on "
075 + "the command line will be started. Note that many J2EE "
076 + "features depend on certain modules being started, so you "
077 + "should be very careful what you omit. Any arguments after "
078 + "this are assumed to be module names.");
079 Option option = optionBuilder.create(ARGUMENT_MODULE_OVERRIDE_SHORTFORM);
080 options.addOption(option);
081 }
082
083 protected void addProgressOptions() {
084 OptionGroup optionGroup = new OptionGroup();
085
086 Option option = new Option(ARGUMENT_NO_PROGRESS_SHORTFORM,
087 ARGUMENT_NO_PROGRESS,
088 false,
089 "Suppress the normal startup progress bar. This is typically "
090 + "used when redirecting console output to a file, or starting "
091 + "the server from an IDE or other tool.");
092 optionGroup.addOption(option);
093
094 option = new Option(ARGUMENT_LONG_PROGRESS_SHORTFORM,
095 ARGUMENT_LONG_PROGRESS,
096 false,
097 "Write startup progress to the console in a format that is "
098 + "suitable for redirecting console output to a file, or starting "
099 + "the server from an IDE or other tool (doesn't use linefeeds to "
100 + "update the progress information that is used by default if you " + "don't specify "
101 + ARGUMENT_NO_PROGRESS + " or " + ARGUMENT_LONG_PROGRESS + ").");
102 optionGroup.addOption(option);
103
104 options.addOptionGroup(optionGroup);
105 }
106
107 }