public Process createForkedProcess(final int workerId, final ParallelJUnitTaskConfig config, final int serverPort)
{
final List<String> jvmCommand = config.getCommand(RemoteTestRunner.class, workerId, serverPort);
final DelegatingProcessBuilder processBuilder = processBuilderFactory.createProcessBuilder(jvmCommand);
final File workingDirectory = config.getDirectory(workerId);
if (workingDirectory != null)
{
if (!workingDirectory.mkdirs() && !workingDirectory.isDirectory())
{
throw new BuildException("Failed to create worker directory: " + workingDirectory.getPath());
}
processBuilder.directory(workingDirectory);
}
final Map<String, String> environment = processBuilder.environment();
if (config.isNewEnvironment())
{
environment.clear();
}
environment.putAll(config.getEnvironment());
try
{
return processBuilder.start();
}
catch (final IOException e)
{
throw new BuildException("Error starting forked process.", e);
}