/**
   * Instantiates a controller through the "TYPE" attribute and {@link JenkinsControllerFactory}.
   */
  @Provides
  @TestScope
  public JenkinsController createController(
      Injector injector, ExtensionList<JenkinsControllerFactory> factories) throws IOException {
    String type = System.getenv("type"); // this is lower case for backward compatibility
    if (type == null) type = System.getenv("TYPE");
    if (type == null) {
      if (JenkinsControllerPoolProcess.SOCKET.exists() && !JenkinsControllerPoolProcess.MAIN)
        return new PooledJenkinsController(injector);
      else type = "winstone";
    }

    for (JenkinsControllerFactory f : factories) {
      if (f.getId().equalsIgnoreCase(type)) {
        final JenkinsController c = f.create();
        c.postConstruct(injector);
        return c;
      }
    }

    throw new AssertionError("Invalid controller type: " + type);
  }
 @Provides
 @TestScope
 public Jenkins createJenkins(Injector injector, JenkinsController controller) {
   if (!controller.isRunning()) return null;
   return new Jenkins(injector, controller);
 }