Methods Summary |
---|
public static com.vladium.emma.Command | create(java.lang.String name, java.lang.String usageName, java.lang.String[] args)
final Command tool;
// TODO: dynamic load here?
if ("run".equals (name))
tool = new runCommand (usageName, args);
else if ("instr".equals (name))
tool = new instrCommand (usageName, args);
else if ("report".equals (name))
tool = new reportCommand (usageName, args);
else if ("merge".equals (name))
tool = new mergeCommand (usageName, args);
else
throw new IllegalArgumentException ("unknown command: [" + name + "]");
tool.initialize ();
return tool;
|
protected final void | exit(boolean showBuildID, java.lang.String msg, java.lang.Throwable t, int rc)
if (showBuildID)
{
m_out.println (IAppConstants.APP_USAGE_BUILD_ID);
}
if (msg != null)
{
m_out.print (toolNameToCommandName (m_usageToolName) + ": "); m_out.println (msg);
}
if (rc != RC_OK)
{
// error exit:
//if ((showBuildID) || (msg != null)) m_out.println ();
if (m_exit)
{
if (t != null) t.printStackTrace (m_out);
System.exit (rc);
}
else
{
if (t instanceof EMMARuntimeException)
throw (EMMARuntimeException) t;
else if (t != null)
throw msg != null ? new EMMARuntimeException (msg, t) : new EMMARuntimeException ("unexpected failure: ", t);
}
}
else
{
// normal exit: 't' is ignored
if (m_exit)
{
System.exit (0);
}
}
|
protected static java.lang.String[] | getListOptValue(IOptsParser.IOpt opt, java.lang.String delimiters, boolean processAtFiles)
return Strings.mergeAT (opt.getValues (), delimiters, processAtFiles);
|
protected final com.vladium.util.args.IOptsParser | getOptParser(java.lang.ClassLoader loader)
return IOptsParser.Factory.create (usageResName (getToolName ()), loader,
usageMsgPrefix (m_usageToolName), USAGE_OPT_NAMES);
|
protected static boolean | getOptionalBooleanOptValue(IOptsParser.IOpt opt)
if (opt.getValueCount () == 0)
return true;
else
{
final String v = opt.getFirstValue ().toLowerCase ();
return Property.toBoolean (v);
}
|
protected final java.lang.String | getToolName()
// TODO: embed build number etc
final String clsName = getClass ().getName ();
return clsName.substring (0, clsName.length () - 7);
|
protected void | initialize()
m_exit = false;
if (m_out != null) try { m_out.flush (); } catch (Throwable ignore) {}
m_out = new PrintWriter (System.out, true);
|
protected final void | processCmdPropertyOverrides(IOptsParser.IOpts parsedopts)
final IOptsParser.IOpt [] popts = parsedopts.getOpts (EMMAProperties.GENERIC_PROPERTY_OVERRIDE_PREFIX);
if ((popts != null) && (popts.length != 0))
{
final Properties cmdOverrides = new XProperties ();
for (int o = 0; o < popts.length; ++ o)
{
final IOptsParser.IOpt opt = popts [o];
final String on = opt.getName ().substring (opt.getPatternPrefix ().length ());
// TODO: support mergeable prefixed opts?
cmdOverrides.setProperty (on, opt.getFirstValue ());
}
// command line user overrides are have highest precedence:
m_propertyOverrides = Property.combine (cmdOverrides, m_propertyOverrides);
}
|
protected final boolean | processFilePropertyOverrides()
if (m_propertyFile != null)
{
final Properties fileOverrides;
try
{
fileOverrides = Property.getPropertiesFromFile (m_propertyFile);
}
catch (IOException ioe)
{
exit (true, "property override file [" + m_propertyFile.getAbsolutePath () + "] could not be read", ioe, RC_USAGE);
return false;
}
// props file overrides have second highest precendence:
m_propertyOverrides = Property.combine (m_propertyOverrides, fileOverrides);
}
return true;
|
protected final boolean | processOpt(IOptsParser.IOpt opt)
final String on = opt.getCanonicalName ();
if ("exit".equals (on)) // 'exit' should always be first in this else-if chain
{
m_exit = getOptionalBooleanOptValue (opt);
return true;
}
else if ("p".equals (on))
{
m_propertyFile = new File (opt.getFirstValue ());
return true;
}
else if ("verbose".equals (on))
{
setPropertyOverride (AppLoggers.PROPERTY_VERBOSITY_LEVEL, ILogLevels.VERBOSE_STRING);
return true;
}
else if ("quiet".equals (on))
{
setPropertyOverride (AppLoggers.PROPERTY_VERBOSITY_LEVEL, ILogLevels.WARNING_STRING);
return true;
}
else if ("silent".equals (on))
{
setPropertyOverride (AppLoggers.PROPERTY_VERBOSITY_LEVEL, ILogLevels.SEVERE_STRING);
return true;
}
else if ("debug".equals (on))
{
if (opt.getValueCount () == 0)
setPropertyOverride (AppLoggers.PROPERTY_VERBOSITY_LEVEL, ILogLevels.TRACE1_STRING);
else
setPropertyOverride (AppLoggers.PROPERTY_VERBOSITY_LEVEL, opt.getFirstValue ());
return true;
}
else if ("debugcls".equals (on))
{
setPropertyOverride (AppLoggers.PROPERTY_VERBOSITY_FILTER, Strings.toListForm (Strings.merge (opt.getValues (), COMMA_DELIMITERS, true), ',"));
return true;
}
return false;
|
public abstract void | run()
|
private void | setPropertyOverride(java.lang.String key, java.lang.String value)
// package: ...............................................................
// private: ...............................................................
/*
* Lazily instantiates m_propertyOverrides if necessary.
*/
Properties propertyOverrides = m_propertyOverrides;
if (propertyOverrides == null)
{
m_propertyOverrides = propertyOverrides = new XProperties ();
}
propertyOverrides.setProperty (key, value);
|
protected static java.lang.String | toolNameToCommandName(java.lang.String toolName)
final int lastDot = toolName.lastIndexOf ('.");
return lastDot > 0 ? toolName.substring (lastDot + 1) : toolName;
|
protected abstract java.lang.String | usageArgsMsg()
|
protected static java.lang.String | usageMsgPrefix(java.lang.String toolName)
return toolNameToCommandName (toolName).concat (" usage: ");
|
protected static java.lang.String | usageResName(java.lang.String toolName)
return toolName.replace ('.", '/").concat ("_usage.res");
|
protected final void | usageexit(com.vladium.util.args.IOptsParser parser, int level, java.lang.String msg)
if (msg != null)
{
m_out.print (usageMsgPrefix (m_usageToolName));
m_out.println (msg);
}
if (parser != null)
{
m_out.println ();
m_out.print (usageMsgPrefix (m_usageToolName));
m_out.println (toolNameToCommandName (m_usageToolName) + " " + usageArgsMsg () + ",");
m_out.println (" where options include:");
m_out.println ();
parser.usage (m_out, level, STDOUT_WIDTH);
}
m_out.println ();
exit (true, null, null, RC_USAGE);
|