*
* @return Commandline holding command to be executed
* @throws CruiseControlException on unquotable attributes
*/
public Commandline buildCommandline() throws CruiseControlException {
Commandline cmdLine = new Commandline();
if (useScript) {
cmdLine.setExecutable(antScript);
} else {
if (isWindows) {
cmdLine.setExecutable("java.exe");
} else {
cmdLine.setExecutable("java");
}
for (Iterator argsIterator = args.iterator(); argsIterator.hasNext(); ) {
String arg = ((AntBuilder.JVMArg) argsIterator.next()).getArg();
// empty args may break the command line
if (arg != null && arg.length() > 0) {
cmdLine.createArgument().setValue(arg);
}
}
cmdLine.createArgument().setValue("-classpath");
cmdLine.createArgument().setValue(getAntLauncherJarLocation(systemClassPath, isWindows));
cmdLine.createArgument().setValue("org.apache.tools.ant.launch.Launcher");
cmdLine.createArgument().setValue("-lib");
cmdLine.createArgument().setValue(systemClassPath);
}
if (useLogger) {
cmdLine.createArgument().setValue("-logger");
cmdLine.createArgument().setValue(getLoggerClassName());
cmdLine.createArgument().setValue("-logfile");
cmdLine.createArgument().setValue(tempFileName);
} else {
cmdLine.createArgument().setValue("-listener");
cmdLine.createArgument().setValue(getLoggerClassName());
cmdLine.createArgument().setValue("-DXmlLogger.file=" + tempFileName);
}
// -debug and -quiet only affect loggers, not listeners: when we use the loggerClassName as
// a listener, they will affect the default logger that writes to the console
if (useDebug) {
cmdLine.createArgument().setValue("-debug");
} else if (useQuiet) {
cmdLine.createArgument().setValue("-quiet");
}
for (Iterator propertiesIter = buildProperties.entrySet().iterator(); propertiesIter.hasNext(); ) {
Map.Entry property = (Map.Entry) propertiesIter.next();
String value = (String) property.getValue();
if (!"".equals(value)) {
cmdLine.createArgument().setValue("-D" + property.getKey() + "=" + value);
}
}
for (Iterator antPropertiesIterator = properties.iterator(); antPropertiesIterator.hasNext(); ) {
Property property = (Property) antPropertiesIterator.next();
cmdLine.createArgument().setValue("-D" + property.getName() + "=" + property.getValue());
}
cmdLine.createArgument().setValue("-buildfile");
cmdLine.createArgument().setValue(buildFile);
StringTokenizer targets = new StringTokenizer(target);
while (targets.hasMoreTokens()) {
cmdLine.createArgument().setValue(targets.nextToken());
}
return cmdLine;
}