private File populateStagingDirectory()

in lib/tools_api/src/main/java/com/google/appengine/tools/admin/Application.java [914:1014]


  private File populateStagingDirectory(
      ApplicationProcessingOptions opts,
      boolean isStaging,
      String runtime)
      throws IOException {
    if (runtime.equals("java7")) {
      throw new AppEngineConfigException("GAE Java7 is not supported anymore.");
    }
    File staticDir = new File(stageDir, "__static__");
    staticDir.mkdir();
    copyOrLink(baseDir, stageDir, staticDir, /* forceResource= */ false, opts, runtime);
    if (externalResourceDir != null) {
      // If there is an external resource directory then we now copy its
      // contents to the staging directory. We copy it after the baseDir
      // so that it wins any name collisions.
      String previousPrefix = appEngineWebXml.getSourcePrefix();
      String newPrefix = buildNormalizedPath(externalResourceDir);
      try {
        appEngineWebXml.setSourcePrefix(newPrefix);
        copyOrLink(
            externalResourceDir, stageDir, staticDir, /* forceResource= */ false, opts, runtime);
      } finally {
        appEngineWebXml.setSourcePrefix(previousPrefix);
      }
    }

    // Now determine our API version, and remove the API jars so we don't
    // upload them, except for env:flex where we keep the jar at the user level.
    apiVersion = findApiVersion(stageDir);

    StagingOptions staging = getStagingOptions(opts);

    if (opts.isCompileJspsSet()) {
      compileJsps(stageDir, opts, runtime);
    }

    if (staging.jarClasses().get() && new File(stageDir, "WEB-INF/classes").isDirectory()) {
      zipWebInfClassesFiles(new File(stageDir, "WEB-INF"));
    }

    int maxJarSize = 32000000;
    // We need to split the jars before processing the quickstart logic, so that that logic takes
    // the split jars.
    if (staging.splitJarFiles().get()) {
      splitJars(
          new File(new File(stageDir, "WEB-INF"), "lib"),
          maxJarSize,
          staging.splitJarFilesExcludes().get());
    }

    // must call after compileJsps because that reloads the web.xml
    boolean vm = appEngineWebXml.getUseVm() || appEngineWebXml.isFlexible();
    if (vm) {
      statusUpdate("Warning: Google App Engine Java compat Flexible product is deprecated.");
      statusUpdate("Warning: See https://cloud.google.com/appengine/docs/flexible/java/upgrading");
    }

    boolean isServlet31OrAbove = servletVersion != null && !"2.5".equals(servletVersion);
    // Do not create quickstart for Java7 standardapps, even is Servlet 3.1 schema is used.
    // This behaviour is compatible with what was there before supporting Java8, we just now print
    // a warning.
    if (!isJava8OrAbove() && !vm && isServlet31OrAbove) {
      statusUpdate(
          "Warning: you are using the Java7 runtime with a Servlet 3.1 or above web.xml file.");
      statusUpdate("The Servlet annotations will be ignored and not processed.");
    } else if (opts.isQuickstart() || isServlet31OrAbove) {
      // Cover Flex compat (deprecated but still there in Java7 or Java8 flavor) and Java8 standard:
      try {
        createQuickstartWebXml(opts);
        webXml =
            new WebXmlReader(stageDir.getAbsolutePath(), "/WEB-INF/min-quickstart-web.xml")
                .readWebXml();
      } catch (SAXException | ParserConfigurationException | TransformerException e) {
        throw new IOException(e);
      }
      if (!webXml.getContextParams().isEmpty()) {
        fallThroughToRuntimeOnContextInitializers();
      }
    }

    // And generate app.yaml string
    appYaml = generateAppYaml(stageDir, runtime, appEngineWebXml);

    // Write prepared {app,backends,index,cron,queue,dos}.yaml files to generation
    // subdirectory within stage directory.
    if (GenerationDirectory.getGenerationDirectory(stageDir).mkdirs()) {
      writePreparedYamlFile(
          "app",
          isStaging ? generateAppYaml(stageDir, runtime, getScrubbedAppEngineWebXml()) : appYaml);
      writePreparedYamlFile("backends", backendsXml == null ? null : backendsXml.toYaml());
      writePreparedYamlFile("index", indexesXml.size() == 0 ? null : indexesXml.toYaml());
      writePreparedYamlFile("cron", cronXml == null ? null : cronXml.toYaml());
      writePreparedYamlFile("queue", queueXml == null ? null : queueXml.toYaml());
      writePreparedYamlFile("dos", dosXml == null ? null : dosXml.toYaml());
      if (isStaging && dispatchXml != null) {
        writePreparedYamlFile("dispatch", dispatchXml.toYaml());
      }
    }

    return stageDir;
  }