public AppVersion createAppVersion()

in runtime/impl/src/main/java/com/google/apphosting/runtime/AppVersionFactory.java [172:270]


  public AppVersion createAppVersion(
      AppInfo appInfo,
      AppEngineWebXml appEngineWebXml,
      ApplicationEnvironment.RuntimeConfiguration configuration)
      throws IOException {
    AppVersionKey appVersionKey = AppVersionKey.fromAppInfo(appInfo);

    File rootDirectory = getRootDirectory(appInfo);
    logger.atFine().log("Loaded appengine-web.xml: %s", appEngineWebXml);
    Map<String, String> sysProps = createSystemProperties(appEngineWebXml, appInfo);
    Map<String, String> envVars = createEnvironmentVariables(appEngineWebXml, appInfo);

    ThreadGroup rootThreadGroup = new ThreadGroup("App Engine: " + appVersionKey);

    FileEncodingSetter.set(sysProps);

    // Pull in Mail API system properties
    String supportExtendedAttachments = System.getProperty(
        "appengine.mail.supportExtendedAttachmentEncodings");
    if (supportExtendedAttachments != null) {
      // b/23225723
      sysProps.put("appengine.mail.supportExtendedAttachmentEncodings",
                   supportExtendedAttachments);
    }

    String forceCloudsqlReadahead = System.getProperty(
        "appengine.jdbc.forceReadaheadOnCloudsqlSocket");
    if (forceCloudsqlReadahead != null) {
      sysProps.put("appengine.jdbc.forceReadaheadOnCloudsqlSocket",
                   forceCloudsqlReadahead);
    }

    String preventInlining = System.getProperty("appengine.mail.filenamePreventsInlining");
    if (preventInlining != null) {
      // b/19910938
      sysProps.put("appengine.mail.filenamePreventsInlining", preventInlining);
    }

    ApplicationEnvironment environment =
        new ApplicationEnvironment(
            appInfo.getAppId(),
            appInfo.getVersionId(),
            sysProps,
            envVars,
            rootDirectory,
            configuration);

    String urlStreamHandlerType = appEngineWebXml.getUrlStreamHandlerType();
    if (urlStreamHandlerType == null && defaultToNativeUrlStreamHandler) {
      urlStreamHandlerType = AppEngineWebXml.URL_HANDLER_NATIVE;
    }
    if (forceUrlfetchUrlStreamHandler) {
      urlStreamHandlerType = AppEngineWebXml.URL_HANDLER_URLFETCH;
    }
    boolean useNative = NetworkServiceDiverter.useNativeUrlStreamHandler(urlStreamHandlerType);
    if (!useNative) {
      URL.setURLStreamHandlerFactory(new StreamHandlerFactory());
    }

    // Pull in URLFetch system properties (b/10429975):
    String deadline = sysProps.get(URLFetchService.DEFAULT_DEADLINE_PROPERTY);
    if (deadline != null) {
      try {
        Double.parseDouble(deadline);
      } catch (NumberFormatException e) {
        logger.atInfo().log(
            "Invalid value for %s property", URLFetchService.DEFAULT_DEADLINE_PROPERTY);
      }
      System.setProperty(URLFetchService.DEFAULT_DEADLINE_PROPERTY, deadline);
    }

    ClassLoader classLoader =
        createClassLoader(environment, rootDirectory, appInfo, appEngineWebXml);
    SessionsConfig sessionsConfig =
        new SessionsConfig(
            appEngineWebXml.getSessionsEnabled(),
            appEngineWebXml.getAsyncSessionPersistence(),
            appEngineWebXml.getAsyncSessionPersistenceQueueName());
    UncaughtExceptionHandler uncaughtExceptionHandler =
        (thread, ex) -> logger.atWarning().withCause(ex).log("Uncaught exception from %s", thread);
    ThreadGroupPool threadGroupPool =
        ThreadGroupPool.builder()
            .setParentThreadGroup(rootThreadGroup)
            .setThreadGroupNamePrefix("Request #")
            .setUncaughtExceptionHandler(uncaughtExceptionHandler)
            .setIgnoreDaemonThreads(ignoreDaemonThreads)
            .build();
    setApplicationDirectory(rootDirectory.getAbsolutePath());
    return AppVersion.builder()
        .setAppVersionKey(appVersionKey)
        .setAppInfo(appInfo)
        .setRootDirectory(rootDirectory)
        .setClassLoader(classLoader)
        .setEnvironment(environment)
        .setSessionsConfig(sessionsConfig)
        .setPublicRoot(appEngineWebXml.getPublicRoot())
        .setThreadGroupPool(threadGroupPool)
        .build();
  }