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

Code before:
            ? createJibContainerBuilder(baseImageSpec.get(), commonCliOptions, logger)
            : Jib.fromScratch();

    buildFile.getCreationTime().ifPresent(containerBuilder::setCreationTime);
    buildFile.getFormat().ifPresent(containerBuilder::setFormat);
    containerBuilder.setEnvironment(buildFile.getEnvironment());
    containerBuilder.setLabels(buildFile.getLabels());
    containerBuilder.setVolumes(buildFile.getVolumes());
    containerBuilder.setExposedPorts(buildFile.getExposedPorts());
    buildFile.getUser().ifPresent(containerBuilder::setUser);
    buildFile.getWorkingDirectory().ifPresent(containerBuilder::setWorkingDirectory);
    buildFile.getEntrypoint().ifPresent(containerBuilder::setEntrypoint);
    buildFile.getCmd().ifPresent(containerBuilder::setProgramArguments);

    if (buildFile.getLayers().isPresent()) {
      containerBuilder.setFileEntriesLayers(
          Layers.toLayers(projectRoot, buildFile.getLayers().get()));
    }
    return containerBuilder;
  }

  private static JibContainerBuilder createJibContainerBuilder(
      BaseImageSpec baseImageSpec, CommonCliOptions commonCliOptions, ConsoleLogger logger)
      throws InvalidImageReferenceException, FileNotFoundException {
    List<Platform> platforms = new ArrayList<>();
    if (!baseImageSpec.getPlatforms().isEmpty()) {
      platforms =
          baseImageSpec
              .getPlatforms()
              .stream()
              .map(
                  platformSpec ->
                      new Platform(platformSpec.getArchitecture(), platformSpec.getOs()))
              .collect(Collectors.toList());
    }
    return ContainerBuilders.create(baseImageSpec.getImage(), platforms, commonCliOptions, logger);
  }
}


Review comment (suggestion):
This `if (...)` probably isn't necessary. For an empty list, stream will return an empty collection. So just `List<Platform> platforms = baseImageSpec.getPlatforms().stream().map().collect()`.

Code after:
            : Jib.fromScratch();

    buildFile.getCreationTime().ifPresent(containerBuilder::setCreationTime);
    buildFile.getFormat().ifPresent(containerBuilder::setFormat);
    containerBuilder.setEnvironment(buildFile.getEnvironment());
    containerBuilder.setLabels(buildFile.getLabels());
    containerBuilder.setVolumes(buildFile.getVolumes());
    containerBuilder.setExposedPorts(buildFile.getExposedPorts());
    buildFile.getUser().ifPresent(containerBuilder::setUser);
    buildFile.getWorkingDirectory().ifPresent(containerBuilder::setWorkingDirectory);
    buildFile.getEntrypoint().ifPresent(containerBuilder::setEntrypoint);
    buildFile.getCmd().ifPresent(containerBuilder::setProgramArguments);

    if (buildFile.getLayers().isPresent()) {
      containerBuilder.setFileEntriesLayers(
          Layers.toLayers(projectRoot, buildFile.getLayers().get()));
    }
    return containerBuilder;
  }

  private static JibContainerBuilder createJibContainerBuilder(
      BaseImageSpec baseImageSpec, CommonCliOptions commonCliOptions, ConsoleLogger logger)
      throws InvalidImageReferenceException, FileNotFoundException {
    LinkedHashSet<Platform> platforms =
        baseImageSpec
            .getPlatforms()
            .stream()
            .map(platformSpec -> new Platform(platformSpec.getArchitecture(), platformSpec.getOs()))
            .collect(Collectors.toCollection(LinkedHashSet::new));
    return ContainerBuilders.create(baseImageSpec.getImage(), platforms, commonCliOptions, logger);
  }
}