}
public Element build(Map projectProperties) throws CruiseControlException {
try {
final BuildAgentService agent = pickAgent();
// agent is now marked as claimed
final Element buildResults;
try {
projectProperties.put(PropertiesHelper.DISTRIBUTED_OVERRIDE_TARGET, overrideTarget);
projectProperties.put(PropertiesHelper.DISTRIBUTED_MODULE, module);
projectProperties.put(PropertiesHelper.DISTRIBUTED_AGENT_LOGDIR, getAgentLogDir());
projectProperties.put(PropertiesHelper.DISTRIBUTED_AGENT_OUTPUTDIR, getAgentOutputDir());
LOG.info("Starting remote build on agent: " + agent.getMachineName() + " of module: " + module);
buildResults = agent.doBuild(getChildBuilderElement(), projectProperties);
final String rootDirPath;
try {
// watch out on Windoze, problems if root dir is c: instead of c:/
LOG.debug("rootDir: " + rootDir + "; rootDir.cp: " + rootDir.getCanonicalPath());
rootDirPath = rootDir.getCanonicalPath();
} catch (IOException e) {
String message = "Error getting canonical path for: " + rootDir;
LOG.error(message);
System.err.println(message);
throw new CruiseControlException(message, e);
}
String masterDir;
if (getMasterLogDir() == null || "".equals(getMasterLogDir())) {
masterDir = rootDirPath + File.separator + PropertiesHelper.RESULT_TYPE_LOGS;
} else {
masterDir = getMasterLogDir();
}
getResultsFiles(agent, PropertiesHelper.RESULT_TYPE_LOGS, rootDirPath, masterDir);
if (getMasterOutputDir() == null || "".equals(getMasterOutputDir())) {
masterDir = rootDirPath + File.separator + PropertiesHelper.RESULT_TYPE_OUTPUT;
} else {
masterDir = getMasterOutputDir();
}
getResultsFiles(agent, PropertiesHelper.RESULT_TYPE_OUTPUT, rootDirPath, masterDir);
agent.clearOutputFiles();
} catch (RemoteException e) {
String agentMachine = "unknown";
try {
agentMachine = agent.getMachineName();
} catch (RemoteException e1) {
; // ignored
}
String message = "RemoteException from"
+ "\nagent on: " + agentMachine
+ "\nwhile building module: " + module;
LOG.error(message, e);
System.err.println(message + " - " + e.getMessage());
try {
agent.clearOutputFiles();
} catch (RemoteException re) {
LOG.error("Exception after prior exception while clearing agent output files (to set busy false).",
re);
}
throw new CruiseControlException(message, e);