@VisibleForTesting
  static void addJvmArgFilesLayer(
      RawConfiguration rawConfiguration,
      ProjectProperties projectProperties,
      JibContainerBuilder jibContainerBuilder,
      String classpath,
      String mainClass)
      throws IOException, InvalidAppRootException {
    Path projectCache = projectProperties.getDefaultCacheDirectory();
    Path classpathFile = projectCache.resolve(JIB_CLASSPATH_FILE);
    Path mainClassFile = projectCache.resolve(JIB_MAIN_CLASS_FILE);

    // It's perfectly fine to always generate a new temp file or rewrite an existing file. However,
    // fixing the source file path and preserving the file timestamp prevents polluting the Jib
    // layer cache space by not creating new cache selectors every time. (Note, however, creating
    // new selectors does not affect correctness at all.)
    writeFileConservatively(classpathFile, classpath);
    writeFileConservatively(mainClassFile, mainClass);

    AbsoluteUnixPath appRoot = getAppRootChecked(rawConfiguration, projectProperties);
    jibContainerBuilder.addFileEntriesLayer(
        FileEntriesLayer.builder()
            .setName(LayerType.JVM_ARG_FILES.getName())
            .addEntry(classpathFile, appRoot.resolve(JIB_CLASSPATH_FILE))
            .addEntry(mainClassFile, appRoot.resolve(JIB_MAIN_CLASS_FILE))
            .build());
  }
@Test
  public void testAddJvmArgFilesLayer() throws IOException, InvalidAppRootException {
    String classpath = "/extra:/app/classes:/app/libs/dep.jar";
    String mainClass = "com.example.Main";
    PluginConfigurationProcessor.addJvmArgFilesLayer(
        rawConfiguration, projectProperties, jibContainerBuilder, classpath, mainClass);

    Path classpathFile = appCacheDirectory.resolve("jib-classpath-file");
    Path mainClassFile = appCacheDirectory.resolve("jib-main-class-file");
    String classpathRead = new String(Files.readAllBytes(classpathFile), StandardCharsets.UTF_8);
    String mainClassRead = new String(Files.readAllBytes(mainClassFile), StandardCharsets.UTF_8);
    assertThat(classpathRead).isEqualTo(classpath);
    assertThat(mainClassRead).isEqualTo(mainClass);

    List<FileEntry> layerEntries =
        getLayerEntries(jibContainerBuilder.toContainerBuildPlan(), "jvm arg files");
    assertThat(layerEntries)
        .comparingElementsUsing(SOURCE_FILE_OF)
        .containsExactly(
            appCacheDirectory.resolve("jib-classpath-file"),
            appCacheDirectory.resolve("jib-main-class-file"));
    assertThat(layerEntries)
        .comparingElementsUsing(EXTRACTION_PATH_OF)
        .containsExactly("/app/jib-classpath-file", "/app/jib-main-class-file");
  }