in java/src/org/apache/qetest/FileBasedTest.java [506:774]
public boolean initializeFromArray(String[] args, boolean flag)
{
// Read in command line args and setup internal variables
String optPrefix = "-";
int nArgs = args.length;
// We don't require any arguments: but subclasses might
// want to require certain ones
// Must read in properties file first, so cmdline can
// override values from properties file
boolean propsOK = true;
// IF we are being called the first time on this
// array of arguments, go ahead and process unknown ones
// otherwise, don't bother
if (flag)
{
for (int k = 0; k < nArgs; k++)
{
if (args[k].equalsIgnoreCase(optPrefix + OPT_LOAD))
{
if (++k >= nArgs)
{
System.err.println(
"ERROR: must supply properties filename for: "
+ optPrefix + OPT_LOAD);
return false;
}
String loadPropsName = args[k];
try
{
// Load named file into our properties block
FileInputStream fIS = new FileInputStream(loadPropsName);
Properties p = new Properties();
p.load(fIS);
p.put(OPT_LOAD, loadPropsName); // Pass along with properties
propsOK &= initializeFromProperties(p);
}
catch (Exception e)
{
System.err.println(
"ERROR: loading properties file failed: " + loadPropsName);
e.printStackTrace();
return false;
}
break;
}
} // end of for(...)
} // end of if ((flag))
// Now read in the rest of the command line
// @todo cleanup loop to be more table-driven
for (int i = 0; i < nArgs; i++)
{
// Set any String args and place them in testProps
if (args[i].equalsIgnoreCase(optPrefix + OPT_INPUTDIR))
{
if (++i >= nArgs)
{
System.err.println("ERROR: must supply arg for: "
+ optPrefix + OPT_INPUTDIR);
return false;
}
inputDir = args[i];
testProps.put(OPT_INPUTDIR, inputDir);
continue;
}
if (args[i].equalsIgnoreCase(optPrefix + OPT_OUTPUTDIR))
{
if (++i >= nArgs)
{
System.err.println("ERROR: must supply arg for: "
+ optPrefix + OPT_OUTPUTDIR);
return false;
}
outputDir = args[i];
testProps.put(OPT_OUTPUTDIR, outputDir);
continue;
}
if (args[i].equalsIgnoreCase(optPrefix + OPT_GOLDDIR))
{
if (++i >= nArgs)
{
System.err.println("ERROR: must supply arg for: "
+ optPrefix + OPT_GOLDDIR);
return false;
}
goldDir = args[i];
testProps.put(OPT_GOLDDIR, goldDir);
continue;
}
if (args[i].equalsIgnoreCase(optPrefix + OPT_CATEGORY))
{
if (++i >= nArgs)
{
System.err.println("ERROR: must supply arg for: "
+ optPrefix + OPT_CATEGORY);
return false;
}
testProps.put(OPT_CATEGORY, args[i]);
continue;
}
if (args[i].equalsIgnoreCase(optPrefix + OPT_EXCLUDES))
{
if (++i >= nArgs)
{
System.err.println("ERROR: must supply arg for: "
+ optPrefix + OPT_EXCLUDES);
return false;
}
testProps.put(OPT_EXCLUDES, args[i]);
continue;
}
if (args[i].equalsIgnoreCase(optPrefix + Reporter.OPT_LOGGERS))
{
if (++i >= nArgs)
{
System.err.println("ERROR: must supply arg for: "
+ optPrefix + Reporter.OPT_LOGGERS);
return false;
}
testProps.put(Reporter.OPT_LOGGERS, args[i]);
continue;
}
if (args[i].equalsIgnoreCase(optPrefix + Logger.OPT_LOGFILE))
{
if (++i >= nArgs)
{
System.err.println("ERROR: must supply arg for: "
+ optPrefix + Logger.OPT_LOGFILE);
return false;
}
testProps.put(Logger.OPT_LOGFILE, args[i]);
continue;
}
if (args[i].equalsIgnoreCase(optPrefix + OPT_FILECHECKER))
{
if (++i >= nArgs)
{
System.out.println("ERROR: must supply arg for: "
+ optPrefix + OPT_FILECHECKER);
return false;
}
testProps.put(OPT_FILECHECKER, args[i]);
continue;
}
// Boolean values are simple flags to switch from defaults only
if (args[i].equalsIgnoreCase(optPrefix + Reporter.OPT_DEBUG))
{
debug = true;
testProps.put(Reporter.OPT_DEBUG, "true");
continue;
}
if (args[i].equalsIgnoreCase(optPrefix
+ Reporter.OPT_PERFLOGGING))
{
testProps.put(Reporter.OPT_PERFLOGGING, "true");
continue;
}
// Parse out the integer value
// This isn't strictly necessary since the catch-all
// below should take care of it, but better safe than sorry
if (args[i].equalsIgnoreCase(optPrefix
+ Reporter.OPT_LOGGINGLEVEL))
{
if (++i >= nArgs)
{
System.err.println("ERROR: must supply arg for: "
+ optPrefix
+ Reporter.OPT_LOGGINGLEVEL);
return false;
}
try
{
testProps.put(Reporter.OPT_LOGGINGLEVEL, args[i]);
}
catch (NumberFormatException numEx)
{ /* no-op */
}
continue;
}
// IF we are being called the first time on this
// array of arguments, go ahead and process unknown ones
// otherwise, don't bother
if (flag)
{
// Found an arg that we don't know how to process,
// so store it for any subclass' use as a catch-all
// If it starts with - dash, and another non-dash arg follows,
// set as a name=value pair in the property block
if ((args[i].startsWith(optPrefix)) && (i + 1 < nArgs)
&& (!args[i + 1].startsWith(optPrefix)))
{
// Scrub off the "-" prefix before setting the name
testProps.put(args[i].substring(1), args[i + 1]);
i++; // Increment counter to skip next arg
}
// Otherwise, just set as name="" in the property block
else
{
// Scrub off the "-" prefix before setting the name
testProps.put(args[i].substring(1), "");
}
}
} // end of for() loop
// If we got here, we set the array params OK, so simply return
// the value the initializeFromProperties method returned
return propsOK;
}