/**
   * Constructs the launch config using the other {@code create*} methods.
   *
   * <p>A launch config will be created using {@link LaunchConfigBuilder#baseDir(java.io.File)},
   * with the path returned by the factory given at construction. The launch config will also
   * default to using a port value of {@code 0} (i.e. an ephemeral port).
   *
   * <p>Register modules and objects using the {@link #bindings(groovy.lang.Closure)} method.
   *
   * <p>Define the handlers using the {@link #handlers(groovy.lang.Closure)} method.
   *
   * <p>Prefer overriding specific {@code create*} methods instead of this one.
   *
   * @return The created launch config.
   */
  @Override
  protected LaunchConfig createLaunchConfig() {
    LaunchConfigBuilder launchConfigBuilder;
    if (this.baseDirFactory != null) {
      Path baseDirPath = baseDirFactory.create();

      launchConfigBuilder = LaunchConfigBuilder.baseDir(baseDirPath).port(0);
    } else {
      launchConfigBuilder = LaunchConfigBuilder.noBaseDir().port(0);
    }

    configureDelegateFirst(launchConfigBuilder, launchConfigClosure);

    final Action<? super BindingsSpec> bindingsAction = createBindingsAction();

    return launchConfigBuilder.build(
        new HandlerFactory() {
          public Handler create(LaunchConfig launchConfig) throws Exception {
            GuiceBackedHandlerFactory handlerFactory = createHandlerFactory(launchConfig);
            Function<? super Module, ? extends Injector> injectorFactory =
                createInjectorFactory(launchConfig);
            Function<? super Injector, ? extends Handler> handlerTransformer =
                createHandlerTransformer(launchConfig);

            return handlerFactory.create(bindingsAction, injectorFactory, handlerTransformer);
          }
        });
  }
 static GroovyEmbeddedApp of(
     @DelegatesTo(value = GroovyRatpackServerSpec.class, strategy = Closure.DELEGATE_FIRST)
         Closure<?> definition)
     throws Exception {
   return from(
       EmbeddedApp.of(
           s -> ClosureUtil.configureDelegateFirst(GroovyRatpackServerSpec.from(s), definition)));
 }
 static GroovyEmbeddedApp fromServer(
     ServerConfig serverConfig,
     @DelegatesTo(value = GroovyRatpackServerSpec.class, strategy = Closure.DELEGATE_FIRST)
         Closure<?> definition) {
   return from(
       EmbeddedApp.fromServer(
           serverConfig,
           s -> ClosureUtil.configureDelegateFirst(GroovyRatpackServerSpec.from(s), definition)));
 }