ILaunch launch, final IJavaProject jproject, final int port, final String runMode)
throws CoreException {
String[] classPath = getClasspath(configuration);
String progArgs = getProgramArguments(configuration);
VMRunnerConfiguration vmConfig =
new VMRunnerConfiguration(getMainTypeName(configuration), classPath);
// insert the program arguments
Vector<String> argv = new Vector<String>(10);
ExecutionArguments execArgs = new ExecutionArguments("", progArgs); //$NON-NLS-1$
String[] pa = execArgs.getProgramArgumentsArray();
for (String element : pa) {
argv.add(element);
}
// Use -serPort (serialized protocol) or -port (string protocol) based on
// a system property
if (LaunchUtil.useStringProtocol(configuration)) {
p("Using the string protocol");
argv.add(CommandLineArgs.PORT);
} else {
p("Using the serialized protocol");
argv.add(RemoteArgs.PORT);
}
argv.add(Integer.toString(port));
IProject project = jproject.getProject();
// if (!isJDK15(javaVersion)) {
// List<File> sourceDirs = JDTUtil.getSourceDirFileList(jproject);
// if (null != sourceDirs) {
// argv.add(TestNGCommandLineArgs.SRC_COMMAND_OPT);
// argv.add(Utils.toSinglePath(sourceDirs, ";")); //$NON-NLS-1$
// }
// }
PreferenceStoreUtil storage = TestNGPlugin.getPluginPreferenceStore();
argv.add(CommandLineArgs.OUTPUT_DIRECTORY);
argv.add(storage.getOutputAbsolutePath(jproject).toOSString());
// String reporters = storage.getReporters(project.getName(), false);
// if (null != reporters && !"".equals(reporters)) {
// argv.add(TestNGCommandLineArgs.LISTENER_COMMAND_OPT);
// argv.add(reporters.replace(' ', ';'));
// }
String preDefinedListeners = configuration.getAttribute(TestNGLaunchConfigurationConstants.PRE_DEFINED_LISTENERS,"");
if (!preDefinedListeners.trim().equals("")){
if (!argv.contains(CommandLineArgs.LISTENER)) {
argv.add(CommandLineArgs.LISTENER);
argv.add(preDefinedListeners);
} else {
String listeners = argv.get(argv.size() - 1);
listeners += (";" + preDefinedListeners);
argv.set(argv.size() - 1, listeners);
}
}
List<ITestNGListener> contributors = ListenerContributorUtil.findReporterContributors();
contributors.addAll(ListenerContributorUtil.findTestContributors());
StringBuffer reportersContributors = new StringBuffer();
boolean isFirst = true;
for (ITestNGListener contributor : contributors) {
if (isFirst) {
reportersContributors.append(contributor.getClass().getName());
} else {
reportersContributors.append(";" + contributor.getClass().getName());
}
isFirst = false;
}
if (!reportersContributors.toString().trim().equals("")) {
if (!argv.contains(CommandLineArgs.LISTENER)) {
argv.add(CommandLineArgs.LISTENER);
argv.add(reportersContributors.toString().trim());
} else {
String listeners = argv.get(argv.size() - 1);
listeners += (";" + reportersContributors.toString().trim());
argv.set(argv.size() - 1, listeners);
}
}
boolean disabledReporters = storage.hasDisabledListeners(project.getName(), false);
if (disabledReporters) {
argv.add(CommandLineArgs.USE_DEFAULT_LISTENERS);
argv.add("false");
}
List<LaunchSuite> launchSuiteList =
ConfigurationHelper.getLaunchSuites(jproject, configuration);
List<String> suiteList = new ArrayList<String>();
List<String> tempSuites = new ArrayList<String>();
// Regular mode: generate a new random suite path
File suiteDir = TestNGPlugin.isDebug() ? new File(RemoteTestNG.DEBUG_SUITE_DIRECTORY)
: TestNGPlugin.getPluginPreferenceStore().getTemporaryDirectory();
for (LaunchSuite launchSuite : launchSuiteList) {
File suiteFile = launchSuite.save(suiteDir);
suiteList.add(suiteFile.getAbsolutePath());
if (launchSuite.isTemporary()) {
suiteFile.deleteOnExit();
tempSuites.add(suiteFile.getAbsolutePath());
}
}
if (null != suiteList) {
for (String suite : suiteList) {
argv.add(suite);
}
launch.setAttribute(TestNGLaunchConfigurationConstants.TEMP_SUITE_LIST,
StringUtils.listToString(tempSuites));
}
vmConfig.setProgramArguments(argv.toArray(new String[argv.size()]));
return vmConfig;
}