@Override
public void execute() throws BuildException
{
FDSocketServer xmlSocket = null;
TestASMessageHandler handler = new TestASMessageHandler();
if (port < 1)
{
port = DEFAULT_PORT;
}
if (null == server || "".equals(server))
{
server = DEFAULT_SERVER;
}
if (swfURL == null || "".equals(swfURL))
{
throw new BuildException("swf URL not provided.");
}
log("opening socket: " + server + ":" + port + "...");
try
{
xmlSocket = FDSocketServer.getInstance(server,port);
xmlSocket.setSocketTimeout(timeout);
xmlSocket.setMessageHandler(handler);
new Thread(xmlSocket).start();
//xmlSocket.run();
} catch (Exception e)
{
e.printStackTrace();
throw new BuildException("Error starting TestAS server: " + e.getMessage(), e);
}
log("opening browser...");
try
{
Random generator = new Random();
int tick = generator.nextInt();
String param = "";
if(swfURL.indexOf("?") < 0)
{
param = "?tick=" + tick;
}
else
{
param = "&tick=" + tick;
}
String launchURL = swfURL + param;
BrowserLauncher.openURL(launchURL);
} catch (Exception e)
{
xmlSocket.shutdown();
throw new BuildException("Error opening browser", e);
}
log("running tests... (please wait)");
while (xmlSocket.isRunning())
{
try
{
Thread.sleep(10);
} catch (InterruptedException e)
{
throw new BuildException(e);
}
}
Throwable t = handler.getError();
if (t != null)
{
if(t instanceof SocketTimeoutException)
{
log("Socket timed out waiting for test results",Project.MSG_ERR);
throw new BuildException("Socket timed out waiting for test results");
}
else
{
xmlSocket.shutdown();
t.printStackTrace();
throw new BuildException(t);
}
}
//everything's good, publish the reports
IReporter reporter = new AntReporter(getProject(), haltOnFail,
haltOnError, failureProperty, errorProperty);
for (ReportWriterElement tag : writerTags)
{
try
{
reporter.addReportWriter(tag.newWriterInstance());
} catch (Exception e)
{
xmlSocket.shutdown();
throw new BuildException("Error creating report writer "
+ tag.getClassname(), e, getLocation());
}
}
if (showOutput)
{
reporter.addReportWriter(new AntLogWriter(this));
log("===============================================");
log("| Unit Test Results |");
log("| format: runs/fails/errors SuiteName |");
log("===============================================");
}
try
{
reporter.publishReport(handler.getJSONData());
}
catch (JSONException je)
{
xmlSocket.shutdown();
System.out.println("Error parsing JSON Data:");
System.out.println(je.getMessage());
System.out.println("------------------------------- BEGIN JSON DATA --------------------------------");
System.out.println(handler.getJSONData());
System.out.println("-------------------------------- END JSON DATA ---------------------------------");
je.printStackTrace();
throw new BuildException("Error parsing JSON Data:",je,getLocation());
}
catch (Exception e)