*/
@Override
public void execute() throws BuildException {
validateOptions();
CommandlineJava cmd= getJavaCommand();
cmd.setClassname(m_mainClass);
List<String> argv= new ArrayList<String>();
if(null != m_isJUnit) {
if(m_isJUnit.booleanValue()) {
argv.add(TestNGCommandLineArgs.JUNIT_DEF_OPT);
}
}
if(null != m_verbose) {
argv.add(TestNGCommandLineArgs.LOG);
argv.add(m_verbose.toString());
}
if(m_assertEnabled) {
cmd.createVmArgument().setValue("-ea");
}
if(m_useDefaultListeners != null) {
String useDefaultListeners = "false";
if ("yes".equalsIgnoreCase(m_useDefaultListeners)
|| "true".equalsIgnoreCase(m_useDefaultListeners))
{
useDefaultListeners = "true";
}
argv.add(TestNGCommandLineArgs.USE_DEFAULT_LISTENERS);
argv.add(useDefaultListeners);
}
if((null != m_outputDir)) {
if(!m_outputDir.exists()) {
m_outputDir.mkdirs();
}
if(m_outputDir.isDirectory()) {
argv.add(TestNGCommandLineArgs.OUTDIR_COMMAND_OPT);
argv.add(m_outputDir.getAbsolutePath());
}
else {
throw new BuildException("Output directory is not a directory: " + m_outputDir);
}
}
if(null != m_target) {
argv.add(TestNGCommandLineArgs.ANNOTATIONS_COMMAND_OPT);
argv.add(m_target);
}
if((null != m_testjar) && m_testjar.isFile()) {
argv.add(TestNGCommandLineArgs.TESTJAR_COMMAND_OPT);
argv.add(m_testjar.getAbsolutePath());
}
if(null != m_sourceDirPath) {
String srcPath= createPathString(m_sourceDirPath, ";");
argv.add(TestNGCommandLineArgs.SRC_COMMAND_OPT);
argv.add(srcPath);
}
if((null != m_includedGroups) && !"".equals(m_includedGroups)) {
argv.add(TestNGCommandLineArgs.GROUPS_COMMAND_OPT);
argv.add(m_includedGroups);
}
if((null != m_excludedGroups) && !"".equals(m_excludedGroups)) {
argv.add(TestNGCommandLineArgs.EXCLUDED_GROUPS_COMMAND_OPT);
argv.add(m_excludedGroups);
}
if(m_classFilesets.size() > 0) {
argv.add(TestNGCommandLineArgs.TESTCLASS_COMMAND_OPT);
for(String file : fileset(m_classFilesets)) {
argv.add(file);
}
}
if(m_listeners != null && m_listeners.size() > 0) {
argv.add(TestNGCommandLineArgs.LISTENER_COMMAND_OPT);
StringBuffer listeners= new StringBuffer();
for(int i= 0; i < m_listeners.size(); i++) {
listeners.append(m_listeners.get(i));
if(i < m_listeners.size() - 1) listeners.append(';');
}
argv.add(listeners.toString());
}
if(m_objectFactory != null) {
argv.add(TestNGCommandLineArgs.OBJECT_FACTORY_COMMAND_OPT);
argv.add(m_objectFactory);
}
if(m_parallelMode != null) {
argv.add(TestNGCommandLineArgs.PARALLEL_MODE);
argv.add(m_parallelMode);
}
if(m_threadCount != null) {
argv.add(TestNGCommandLineArgs.THREAD_COUNT);
argv.add(m_threadCount);
}
if(!"".equals(m_suiteName)) {
argv.add(TestNGCommandLineArgs.SUITE_NAME_OPT);
argv.add(m_suiteName);
}
if(!"".equals(m_testName)) {
argv.add(TestNGCommandLineArgs.TEST_NAME_OPT);
argv.add(m_testName);
}
if (!reporterConfigs.isEmpty()) {
for (ReporterConfig reporterConfig : reporterConfigs) {
argv.add(TestNGCommandLineArgs.REPORTER);
argv.add(reporterConfig.serialize());
}
}
if(m_xmlFilesets.size() > 0) {
for(String file : fileset(m_xmlFilesets)) {
argv.add(file);
}
}
String fileName= "";
FileWriter fw= null;
BufferedWriter bw= null;
try {
File f= File.createTempFile("testng", "");
fileName= f.getAbsolutePath();
// If the user asked to see the command, preserve the file
if(!m_dump) {
f.deleteOnExit();
}
fw= new FileWriter(f);
bw= new BufferedWriter(fw);
for(String arg : argv) {
bw.write(arg);
bw.newLine();
}
bw.flush();
}
catch(IOException e) {
e.printStackTrace();
}
finally {
try {
if(bw != null) {
bw.close();
}
if(fw != null) {
fw.close();
}
}
catch(IOException e) {
e.printStackTrace();
}
}
printDebugInfo(fileName);
createClasspath().setLocation(findJar());
cmd.createArgument().setValue("@" + fileName);
ExecuteWatchdog watchdog= createWatchdog();
boolean wasKilled= false;
int exitValue= executeAsForked(cmd, watchdog);
if(null != watchdog) {