public void start() {
      WorkerProcessBuilder builder = workerFactory.create();
      builder.applicationClasspath(classPathRegistry.getClassPath("ANT").getAsFiles());
      builder.sharedPackages("org.apache.tools.ant");
      builder.getJavaCommand().systemProperty("test.system.property", "value");
      builder.getJavaCommand().environment("TEST_ENV_VAR", "value");
      builder.worker(action);

      if (mainClass != null) {
        builder.getJavaCommand().setMain(mainClass);
      }

      proc = builder.build();
      try {
        proc.start();
        assertFalse(startFails);
      } catch (ExecException e) {
        assertTrue(startFails);
        return;
      }
      proc.getConnection().addIncoming(TestListenerInterface.class, exceptionListener);
      if (serverAction != null) {
        serverAction.execute(proc.getConnection());
      }
    }
 public void waitForStop() {
   if (startFails) {
     return;
   }
   try {
     proc.waitForStop();
     assertFalse("Expected process to fail", stopFails);
   } catch (ExecException e) {
     assertTrue("Unexpected failure in worker process", stopFails);
   }
 }
  RemoteTestClassProcessor forkProcess() {
    WorkerProcessBuilder builder = workerFactory.create();
    builder.setBaseName("Gradle Test Executor");
    builder.applicationClasspath(classPath);
    builder.setLoadApplicationInSystemClassLoader(true);
    builder.worker(new TestWorker(processorFactory));
    options.copyTo(builder.getJavaCommand());
    buildConfigAction.execute(builder);

    workerProcess = builder.build();
    workerProcess.start();

    ObjectConnection connection = workerProcess.getConnection();
    connection.useParameterSerializer(TestEventSerializer.create());
    connection.addIncoming(TestResultProcessor.class, resultProcessor);
    RemoteTestClassProcessor remoteProcessor =
        connection.addOutgoing(RemoteTestClassProcessor.class);
    connection.connect();
    remoteProcessor.startProcessing();
    return remoteProcessor;
  }
 public void stop() {
   if (remoteProcessor != null) {
     remoteProcessor.stop();
     workerProcess.waitForStop();
   }
 }