Repository: GoogleContainerTools/jib
File: jib-cli/src/main/java/com/google/cloud/tools/jib/cli/jar/JarFiles.java (Java)

Code before:

  /**
   * Generates a {@link JibContainerBuilder} from contents of a jar file.
   *
   * @param processor jar processor
   * @param jarOptions jar cli options
   * @param commonCliOptions common cli options
   * @param commonContainerConfigCliOptions common command line options shared between jar and war
   *     command
   * @param logger console logger
   * @return JibContainerBuilder
   * @throws IOException if I/O error occurs when opening the jar file or if temporary directory
   *     provided doesn't exist
   * @throws InvalidImageReferenceException if the base image reference is invalid
   */
  public static JibContainerBuilder toJibContainerBuilder(
      ArtifactProcessor processor,
      Jar jarOptions,
      CommonCliOptions commonCliOptions,
      CommonContainerConfigCliOptions commonContainerConfigCliOptions,
      ConsoleLogger logger)
      throws IOException, InvalidImageReferenceException {

    // Use AdoptOpenJDK image as the default base image.
    JibContainerBuilder containerBuilder;
    Optional<String> baseImageRef = commonContainerConfigCliOptions.getFrom();
    if (baseImageRef.isPresent()) {
      containerBuilder =
          ContainerBuilders.create(
              baseImageRef.get(), Collections.emptySet(), commonCliOptions, logger);
    } else {
      containerBuilder =
          (processor.getJavaVersion() <= 8)
              ? ContainerBuilders.create(
                  "adoptopenjdk:8-jre", Collections.emptySet(), commonCliOptions, logger)
              : ContainerBuilders.create(
                  "adoptopenjdk:11-jre", Collections.emptySet(), commonCliOptions, logger);
    }

    List<FileEntriesLayer> layers = processor.createLayers();
    List<String> customEntrypoint = commonContainerConfigCliOptions.getEntrypoint();
    List<String> entrypoint =
        customEntrypoint.isEmpty()
            ? processor.computeEntrypoint(jarOptions.getJvmFlags())
            : customEntrypoint;

    containerBuilder
        .setEntrypoint(entrypoint)
        .setFileEntriesLayers(layers)
        .setExposedPorts(commonContainerConfigCliOptions.getExposedPorts())
        .setVolumes(commonContainerConfigCliOptions.getVolumes())

Review comment (suggestion):
```suggestion
    Optional<String> imageReference = commonContainerConfigCliOptions.getFrom();
```

Code after:

  /**
   * Generates a {@link JibContainerBuilder} from contents of a jar file.
   *
   * @param processor jar processor
   * @param jarOptions jar cli options
   * @param commonCliOptions common cli options
   * @param commonContainerConfigCliOptions common command line options shared between jar and war
   *     command
   * @param logger console logger
   * @return JibContainerBuilder
   * @throws IOException if I/O error occurs when opening the jar file or if temporary directory
   *     provided doesn't exist
   * @throws InvalidImageReferenceException if the base image reference is invalid
   */
  public static JibContainerBuilder toJibContainerBuilder(
      ArtifactProcessor processor,
      Jar jarOptions,
      CommonCliOptions commonCliOptions,
      CommonContainerConfigCliOptions commonContainerConfigCliOptions,
      ConsoleLogger logger)
      throws IOException, InvalidImageReferenceException {

    // Use AdoptOpenJDK image as the default base image.
    JibContainerBuilder containerBuilder;
    Optional<String> imageReference = commonContainerConfigCliOptions.getFrom();
    if (imageReference.isPresent()) {
      containerBuilder =
          ContainerBuilders.create(
              imageReference.get(), Collections.emptySet(), commonCliOptions, logger);
    } else {
      containerBuilder =
          (processor.getJavaVersion() <= 8)
              ? ContainerBuilders.create(
                  "adoptopenjdk:8-jre", Collections.emptySet(), commonCliOptions, logger)
              : ContainerBuilders.create(
                  "adoptopenjdk:11-jre", Collections.emptySet(), commonCliOptions, logger);
    }

    List<FileEntriesLayer> layers = processor.createLayers();
    List<String> customEntrypoint = commonContainerConfigCliOptions.getEntrypoint();
    List<String> entrypoint =
        customEntrypoint.isEmpty()
            ? processor.computeEntrypoint(jarOptions.getJvmFlags())
            : customEntrypoint;

    containerBuilder
        .setEntrypoint(entrypoint)
        .setFileEntriesLayers(layers)
        .setExposedPorts(commonContainerConfigCliOptions.getExposedPorts())
        .setVolumes(commonContainerConfigCliOptions.getVolumes())