Skip to content

Commit

Permalink
Fixing up the command line help print (both the main process and the …
Browse files Browse the repository at this point in the history
…launcher may print its own help).

Unification of launcher/launch - launch is used.
The default configuration file is named cruisecontrol.xml and refers to the launcher configuration file.
  • Loading branch information
t-dan committed Nov 8, 2018
1 parent b02ecf5 commit f62c484
Show file tree
Hide file tree
Showing 9 changed files with 190 additions and 120 deletions.
3 changes: 3 additions & 0 deletions binaryrelease/config.xml → binaryrelease/cruisecontrol.xml
Expand Up @@ -29,4 +29,7 @@
</publishers>

</project>

<!-- Use this file to launch the cruisecontrol -->
<launch>launch.xml</launch>
</cruisecontrol>
9 changes: 8 additions & 1 deletion binaryrelease/launch.xml
@@ -1,4 +1,8 @@
<?xml version="1.0"?>
<!--
This is the default file requested by cruisecontol-launch.jar (the launcher of the CruiseControl continuous integration
builder).
-->
<launch>

<!-- Set absolute path to directory where cruisecontrol is installed. Does not have to be set if lib/cruisecontrol-launcher.jar
Expand All @@ -10,8 +14,11 @@
<proj>/a/dir/with/projects</proj>
-->

<!-- cruisecontrol configuration. If not set as absolute path, is searched under <proj> and $HOME directories -->
<!-- cruisecontrol configuration. If not set as absolute path, is searched under <proj> and $HOME directories
The option does not have to be set when the <launch>launch.xml</launch> was configured in the main configuration file
passed to the cruisecontrol-launcher.jar
<configfile>config.xml</configfile>
-->

<!-- The URL to log4j config. Does not have to be set if log4j.properties file is under <dist> directory
<log4jconfig>file:///home/dtihelka/temp/cruisecontrol-bin-master/log4j.properties</log4jconfig>
Expand Down
Expand Up @@ -157,7 +157,7 @@ public CruiseControlConfig(final Element ccElement, final ResolverHolder resolve

private void parse(final Element ccElement) throws CruiseControlException {
// Ignore the <launch>...</launch> section, see LaunchConfiguration
ccElement.removeChild("launcher");
ccElement.removeChild("launch");
// parse properties and plugins first, so their order in the config file
// doesn't matter
for (final Object o : ccElement.getChildren("property")) {
Expand Down Expand Up @@ -490,10 +490,10 @@ private void handleProject(final Element projectElement) throws CruiseControlExc

if (isCustomPropertiesPlugin(element.getName())) {
ProjectXMLHelper.registerCustomProperty(nonFullyResolvedProjectProperties,
(Element) element.clone(), resolvers, FAIL_UPON_MISSING_PROPERTY,
element.clone(), resolvers, FAIL_UPON_MISSING_PROPERTY,
PluginRegistry.createRegistry(rootPlugins));
} else {
ProjectXMLHelper.registerProperty(nonFullyResolvedProjectProperties, (Element) element.clone(),
ProjectXMLHelper.registerProperty(nonFullyResolvedProjectProperties, element.clone(),
resolvers, FAIL_UPON_MISSING_PROPERTY);
}
}
Expand Down
108 changes: 53 additions & 55 deletions main/src/net/sourceforge/cruisecontrol/CruiseControlSettings.java
Expand Up @@ -77,56 +77,27 @@ public class CruiseControlSettings implements Config {

/** Array of default values for all the option keys */
private static final Option[] DEFAULT_OPTIONS = {
new Option(KEY_CONFIG_FILE, new File("config.xml"), File.class,
"configuration file; default config.xml"),
new Option(KEY_DIST_DIR, null, File.class,
"The root directory under which the CriseControl was installed. Required to be set."),
new Option(KEY_PROJ_DIR, null, File.class,
"The root directory where CruiseControl projects are located. Required to be set."),
new Option(KEY_PRINT_HELP1, Boolean.FALSE, Boolean.class,
"Prints this help message"),
new Option(KEY_PRINT_HELP2, Boolean.FALSE, Boolean.class,
"Prints this help message"),
new Option(KEY_DEBUG, Boolean.FALSE, Boolean.class,
"Set logging level to DEBUG"),
new Option(KEY_RMI_PORT, new Integer(1099), Integer.class,
"RMI port of the Controller; default 1099"),
new Option(KEY_PORT, new Integer(8000), Integer.class,
"Deprecated. Use -" + KEY_JMX_PORT + " instead"),
new Option(KEY_JMX_PORT, new Integer(8000), Integer.class,
"Port of the JMX HttpAdapter; default 8000"),
new Option(KEY_WEB_PORT, new Integer(8080), Integer.class,
"Port for the Reporting website; default 8080, removing this propery will make "
+ "cruisecontrol start without Jetty"),
new Option(KEY_JETTY_XML, new File("etc/jetty.xml"), File.class,
"Jetty configuration xml. Defaults to jetty.xml"),
new Option(KEY_WEBAPP_PATH, new File("/webapps/cruisecontrol"),
File.class,
""),
new Option(KEY_DASHBOARD, new File("/webapps/dashboard"), File.class,
""),
new Option(KEY_DASHBOARD_URL, "http://localhost:8080/dashboard",
URL.class, // TODO: URL!!!
"the url for dashboard (used for posting build information),"
+ "default is http://localhost:8080/dashboard\","),
new Option(KEY_XLS_PATH, new File("."), File.class,
"location of jmx xsl files; default files in package,"
+ "CruiseControlSettings.KEY_JMX_AGENT_UTIL"
+ "[true/false] load JMX Build Agent utility; default is true."),
new Option(KEY_POST_INTERVAL, new Integer(5), Integer.class,
"how frequently build information will be posted to dashboard,,"
+ "default is 5 (in seconds)."),
new Option(KEY_POST_ENABLED, Boolean.TRUE, Boolean.class,
"TODO"),
new Option(KEY_PASSWORD, null, String.class,
"password for HttpAdapter; default no login required"),
new Option(KEY_USER, null, String.class,
"username for HttpAdapter; default no login required"),
new Option(KEY_CC_NAME, "", String.class,
"A logical name which will be displayed in the "
+ "reporting Application's status page."),
new Option(KEY_JMX_AGENT_UTIL, "", String.class,
"TODO"),
new Option(KEY_CONFIG_FILE, new File("cruisecontrol.xml"), File.class),
new Option(KEY_DIST_DIR, null, File.class),
new Option(KEY_PROJ_DIR, null, File.class),
new Option(KEY_PRINT_HELP1, Boolean.FALSE, Boolean.class),
new Option(KEY_PRINT_HELP2, Boolean.FALSE, Boolean.class),
new Option(KEY_DEBUG, Boolean.FALSE, Boolean.class),
new Option(KEY_RMI_PORT, new Integer(1099), Integer.class),
new Option(KEY_PORT, new Integer(8000), Integer.class),
new Option(KEY_JMX_PORT, new Integer(8000), Integer.class),
new Option(KEY_WEB_PORT, new Integer(8080), Integer.class),
new Option(KEY_JETTY_XML, new File("etc/jetty.xml"), File.class),
new Option(KEY_WEBAPP_PATH, new File("webapps/cruisecontrol"), File.class),
new Option(KEY_DASHBOARD, new File("webapps/dashboard"), File.class),
new Option(KEY_DASHBOARD_URL, "http://localhost:8080/dashboard", URL.class),
new Option(KEY_XLS_PATH, new File("."), File.class),
new Option(KEY_POST_INTERVAL, new Integer(5), Integer.class),
new Option(KEY_POST_ENABLED, Boolean.TRUE, Boolean.class),
new Option(KEY_PASSWORD, null, String.class),
new Option(KEY_USER, null, String.class),
new Option(KEY_CC_NAME, "", String.class),
new Option(KEY_JMX_AGENT_UTIL, null, Boolean.class),
};

/** The holder of options */
Expand Down Expand Up @@ -353,6 +324,37 @@ public URL getOptionUrl(String key) throws CruiseControlException {
throw new CruiseControlException("Option '" + key + "' = '" + opt.val + "' does not represent URL!");
}

/**
* Gets the base help message for the given option key. The message consists of the option key, type
* and its default value formated as a single line string
* @param key the name of the option.
* @return the help message
*/
public static String getBaseHelp(String key) {
// Find under the known options
for (final Option o : DEFAULT_OPTIONS) {
if (o.key.equals(key)) {
Object d = o.val;
// Default according to the type
if (d != null) {
if (d instanceof String) {
d = "\"" + d + "\"";
}
if (d instanceof File) {
d = "\"" + ((File) d).getAbsolutePath() + "\"";
}
if (d instanceof Boolean) {
d = null; // no default value, it is either set or not
}
}
// Get the formatted help
return "-" + o.key + "[" + o.type.getSimpleName() + "]" + (d != null ? ", default=" + d : "");
}
}
// Not found
return "";
}

/**
* Constructor. It is hidden since the class can only be used as singleton, but protected to be
* overridable for test purposes
Expand Down Expand Up @@ -413,10 +415,8 @@ private static final class Option {
final Object val;
/** The class the option type belongs to */
final Class< ? > type;
/* The help message */
final String help;

Option(final String key, Object val, final Class< ? > type, final String help) {
Option(final String key, Object val, final Class< ? > type) {
// Special hack for URL type
if (type == URL.class && val instanceof String) {
try {
Expand All @@ -433,7 +433,6 @@ private static final class Option {
this.key = key;
this.val = val;
this.type = type;
this.help = help;
}

Option(final Option opt, final Object val) {
Expand All @@ -445,7 +444,6 @@ private static final class Option {
this.key = opt.key;
this.val = val;
this.type = opt.type;
this.help = opt.help;
}
}
}
85 changes: 41 additions & 44 deletions main/src/net/sourceforge/cruisecontrol/Main.java
Expand Up @@ -69,7 +69,6 @@ public final class Main implements CruiseControlMain {



@Override
public Config confFactory(Object owner) {
try {
return CruiseControlSettings.getInstance(owner);
Expand All @@ -84,7 +83,6 @@ public Config confFactory(Object owner) {
*
* @return true indicates normal return/exit.
*/
@Override
public boolean start() {
CruiseControlSettings config;

Expand Down Expand Up @@ -216,57 +214,56 @@ static void checkDeprecatedArguments() throws CruiseControlException {
*/
static final String SYSPROP_CCMAIN_SKIP_USAGE = "cc.main.skip.usage";


@Override
public Iterable<String> confHelp() {
return null;
}

public static void printUsage() {
public void printUsage() {
if (Boolean.getBoolean(SYSPROP_CCMAIN_SKIP_USAGE)) {
return;
}

// TODO: finish !!!

System.out.println("");
System.out.println("Usage:");
System.out.println("");
System.out.println("Starts a continuous integration loop");
System.out.println("");
System.out.println("cruisecontrol [options]");
System.out.println("");
System.out.println("Build loop options are:");
System.out.println("");
System.out.println(" -configfile file configuration file; default config.xml");
System.out.println(" -" + CruiseControlSettings.KEY_DEBUG + " set logging level to DEBUG");
//System.out.println(" -" + CruiseControlSettings.KEY_LOG4J_CONFIG + " url URL to a log4j "
// + "config (example: ""\"file:/c:/mylog4j.xml\")");
System.out.println(" -" + CruiseControlSettings.KEY_PRINT_HELP1 + " or -"
+ CruiseControlSettings.KEY_PRINT_HELP2 + " print this usage message");
System.out.println(CruiseControlSettings.getBaseHelp(CruiseControlSettings.KEY_CONFIG_FILE));
System.out.println(" ... the main cruisecontrol configuration file. It is the XML file with ");
System.out.println(" <cruisecontrol> root element.");
System.out.println(CruiseControlSettings.getBaseHelp(CruiseControlSettings.KEY_DEBUG));
System.out.println(" ... set logging level to DEBUG.");
System.out.println(CruiseControlSettings.getBaseHelp(CruiseControlSettings.KEY_PRINT_HELP1));
System.out.println(CruiseControlSettings.getBaseHelp(CruiseControlSettings.KEY_PRINT_HELP2));
System.out.println(" ... print this usage message.");
System.out.println("");
System.out.println("Options when using JMX");
System.out.println(" Note: JMX server only started if -jmxport and/or -rmiport specified");
System.out.println(" -jmxport [number] port of the JMX HttpAdapter; default 8000");
System.out.println(" -rmiport [number] RMI port of the Controller; default 1099");
System.out.println(" -user username username for HttpAdapter; default no login required");
System.out.println(" -password pwd password for HttpAdapter; default no login required");
System.out.println(" -xslpath directory location of jmx xsl files; default files in package");
System.out.println(" -" + CruiseControlSettings.KEY_JMX_AGENT_UTIL
+ " [true/false] load JMX Build Agent utility; default is true");
System.out.println(" Note: JMX server is only started if -jmxport and/or -rmiport specified.");
System.out.println(CruiseControlSettings.getBaseHelp(CruiseControlSettings.KEY_JMX_PORT));
System.out.println(" ... port of the JMX HttpAdapter.");
System.out.println(CruiseControlSettings.getBaseHelp(CruiseControlSettings.KEY_RMI_PORT));
System.out.println(" ... RMI port of the Controller.");
System.out.println(CruiseControlSettings.getBaseHelp(CruiseControlSettings.KEY_USER));
System.out.println(" ... username for HttpAdapter; when not set, no login is required.");
System.out.println(CruiseControlSettings.getBaseHelp(CruiseControlSettings.KEY_PASSWORD));
System.out.println(" ... password for HttpAdapter; when not set, no login is required.");
System.out.println(CruiseControlSettings.getBaseHelp(CruiseControlSettings.KEY_XLS_PATH));
System.out.println(" ... location of jmx xsl files.");
System.out.println(CruiseControlSettings.getBaseHelp(CruiseControlSettings.KEY_JMX_AGENT_UTIL));
System.out.println(" ... load JMX Build Agent utility.");
System.out.println("");
System.out.println("Options when using embedded Jetty");
System.out.println(" -webport [number] port for the Reporting website; default 8080, removing");
System.out.println(" this propery will make cruisecontrol start without Jetty");
System.out.println(" -jettyxml file Jetty configuration xml. Defaults to jetty.xml");
System.out.println(" -postenabled enabled switch of posting current build information to dashboard");
System.out.println(" default is true");
System.out.println(" -dashboardurl url the url for dashboard (used for posting build information)");
System.out.println(" default is http://localhost:8080/dashboard");
System.out.println(" -postinterval interval how frequently build information will be posted to dashboard");
System.out.println(" default is 5 (in seconds).");
System.out.println(" -ccname name A logical name which will be displayed in the");
System.out.println(" Reporting Application's status page.");
System.out.println(CruiseControlSettings.getBaseHelp(CruiseControlSettings.KEY_WEB_PORT));
System.out.println(" ... port for the Reporting website; removing this propery will make ");
System.out.println(" cruisecontrol start without Jetty.");
System.out.println(CruiseControlSettings.getBaseHelp(CruiseControlSettings.KEY_JETTY_XML));
System.out.println(" ... Jetty configuration xml.");
System.out.println(CruiseControlSettings.getBaseHelp(CruiseControlSettings.KEY_POST_ENABLED));
System.out.println(" ... switch of posting current build information to dashboard.");
System.out.println(CruiseControlSettings.getBaseHelp(CruiseControlSettings.KEY_POST_INTERVAL));
System.out.println(" ... interval how frequently build information will be posted to dashboard,");
System.out.println(" value in seconds.");
System.out.println(CruiseControlSettings.getBaseHelp(CruiseControlSettings.KEY_DASHBOARD_URL));
System.out.println(" ... the url for dashboard (used for posting build information).");
System.out.println(CruiseControlSettings.getBaseHelp(CruiseControlSettings.KEY_CC_NAME));
System.out.println(" ... A logical name which will be displayed in the Reporting Application's");
System.out.println(" status page.");

System.out.println("");
}

Expand Down Expand Up @@ -459,12 +456,12 @@ static String parseXslPath() throws CruiseControlException {

static CruiseControlControllerAgent.LOAD_JMX_AGENTUTIL parseEnableJMXAgentUtility() throws CruiseControlException {
final CruiseControlSettings config = CruiseControlSettings.getInstance();
final String argval = config.getOptionStr(CruiseControlSettings.KEY_JMX_AGENT_UTIL);
if (argval.isEmpty()) {
final Boolean argval = (Boolean) config.getOptionType(CruiseControlSettings.KEY_JMX_AGENT_UTIL, Boolean.class);
if (argval == null) {
/** default, if no command line arg present. Not an error if load fails. */
return CruiseControlControllerAgent.LOAD_JMX_AGENTUTIL.LOAD_IF_AVAILABLE;
}
if (Boolean.parseBoolean(argval)) {
if (argval.booleanValue()) {
/** -agentutil true. Considered an error if load fails. */
return CruiseControlControllerAgent.LOAD_JMX_AGENTUTIL.FORCE_LOAD;
}
Expand Down
Expand Up @@ -66,13 +66,6 @@ public interface CruiseControlMain {
* @return new instance
*/
public Config confFactory(Object owner);
/**
* Gets the iterator through help messages explaining CruiseControl configuration options. Each string
* represents option (it is allowed the string be formatted).
*
* @return the iterator with help to print
*/
public Iterable<String> confHelp();
/**
* Start CruiseControl
* @return
Expand Down

0 comments on commit f62c484

Please sign in to comment.