public static JibContainerBuilder toJibContainerBuilder(
      ArtifactProcessor processor,
      CommonCliOptions commonCliOptions,
      CommonContainerConfigCliOptions commonContainerConfigCliOptions,
      ConsoleLogger logger)
      throws IOException, InvalidImageReferenceException {
    String baseImage = commonContainerConfigCliOptions.getFrom().orElse("jetty");
    JibContainerBuilder containerBuilder =
        ContainerBuilders.create(baseImage, Collections.emptySet(), commonCliOptions, logger);
    List<String> programArguments = commonContainerConfigCliOptions.getProgramArguments();
    if (!commonContainerConfigCliOptions.getProgramArguments().isEmpty()) {
      containerBuilder.setProgramArguments(programArguments);
    }
    containerBuilder
        .setEntrypoint(computeEntrypoint(commonContainerConfigCliOptions))
        .setFileEntriesLayers(processor.createLayers())
        .setExposedPorts(commonContainerConfigCliOptions.getExposedPorts())
        .setVolumes(commonContainerConfigCliOptions.getVolumes())
        .setEnvironment(commonContainerConfigCliOptions.getEnvironment())
        .setLabels(commonContainerConfigCliOptions.getLabels());
    commonContainerConfigCliOptions.getUser().ifPresent(containerBuilder::setUser);
    commonContainerConfigCliOptions.getFormat().ifPresent(containerBuilder::setFormat);
    commonContainerConfigCliOptions.getCreationTime().ifPresent(containerBuilder::setCreationTime);

    return containerBuilder;
  }
@Test
  public void testToJibContainerBuilder_optionalParameters()
      throws IOException, InvalidImageReferenceException {
    when(mockCommonContainerConfigCliOptions.getFrom()).thenReturn(Optional.of("base-image"));
    when(mockCommonContainerConfigCliOptions.getExposedPorts())
        .thenReturn(ImmutableSet.of(Port.udp(123)));
    when(mockCommonContainerConfigCliOptions.getVolumes())
        .thenReturn(
            ImmutableSet.of(AbsoluteUnixPath.get("/volume1"), AbsoluteUnixPath.get("/volume2")));
    when(mockCommonContainerConfigCliOptions.getEnvironment())
        .thenReturn(ImmutableMap.of("key1", "value1"));
    when(mockCommonContainerConfigCliOptions.getLabels())
        .thenReturn(ImmutableMap.of("label", "mylabel"));
    when(mockCommonContainerConfigCliOptions.getUser()).thenReturn(Optional.of("customUser"));
    when(mockCommonContainerConfigCliOptions.getFormat()).thenReturn(Optional.of(ImageFormat.OCI));
    when(mockCommonContainerConfigCliOptions.getProgramArguments())
        .thenReturn(ImmutableList.of("arg1"));
    when(mockCommonContainerConfigCliOptions.getEntrypoint())
        .thenReturn(ImmutableList.of("custom", "entrypoint"));
    when(mockCommonContainerConfigCliOptions.getCreationTime())
        .thenReturn(Optional.of(Instant.ofEpochSecond(5)));

    JibContainerBuilder containerBuilder =
        WarFiles.toJibContainerBuilder(
            mockStandardWarExplodedProcessor,
            mockCommonCliOptions,
            mockCommonContainerConfigCliOptions,
            mockLogger);
    ContainerBuildPlan buildPlan = containerBuilder.toContainerBuildPlan();

    assertThat(buildPlan.getBaseImage()).isEqualTo("base-image");
    assertThat(buildPlan.getExposedPorts()).isEqualTo(ImmutableSet.of(Port.udp(123)));
    assertThat(buildPlan.getVolumes())
        .isEqualTo(
            ImmutableSet.of(AbsoluteUnixPath.get("/volume1"), AbsoluteUnixPath.get("/volume2")));
    assertThat(buildPlan.getEnvironment()).isEqualTo(ImmutableMap.of("key1", "value1"));
    assertThat(buildPlan.getLabels()).isEqualTo(ImmutableMap.of("label", "mylabel"));
    assertThat(buildPlan.getUser()).isEqualTo("customUser");
    assertThat(buildPlan.getFormat()).isEqualTo(ImageFormat.OCI);
    assertThat(buildPlan.getCmd()).isEqualTo(ImmutableList.of("arg1"));
    assertThat(buildPlan.getEntrypoint()).isEqualTo(ImmutableList.of("custom", "entrypoint"));
    assertThat(buildPlan.getCreationTime()).isEqualTo(Instant.ofEpochSecond(5));
  }