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

Code before:
import com.google.cloud.tools.jib.plugins.common.logging.ConsoleLogger;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.concurrent.Callable;
import picocli.CommandLine;

@CommandLine.Command(
    name = "build",
    showAtFileInUsageHelp = true,
    description = "Build a container")
public class Build implements Callable<Integer> {
  @CommandLine.ParentCommand
  @SuppressWarnings("NullAway.Init") // initialized by picocli
  protected JibCli globalOptions;

  @Override
  public Integer call() {
    globalOptions.validate();

    try {
      ConsoleLogger logger =
          CliLogger.newLogger(globalOptions.getVerbosity(), globalOptions.getConsoleOutput());

      Path buildFile = globalOptions.getBuildFile();
      if (!Files.isReadable(buildFile)) {
        logger.log(Level.ERROR, "Cannot open Build File YAML: " + buildFile);
        return 1;
      }
      if (!Files.isRegularFile(buildFile)) {
        logger.log(Level.ERROR, "Build File YAML path is a not a file: " + buildFile);
        return 1;
      }

      Containerizer containerizer = Containerizers.from(globalOptions, logger);

      JibContainerBuilder containerBuilder =
          BuildFiles.toJibContainerBuilder(
              globalOptions.getContextRoot(), buildFile, globalOptions, logger);

      containerBuilder.containerize(containerizer);
    } catch (Exception ex) {
      if (globalOptions.isStacktrace()) {
        ex.printStackTrace();
      }
      System.err.println(ex.getClass().getName() + ": " + ex.getMessage());
      return 1;
    }
    return 0;
  }
}


Review comment (suggestion):
Maybe we can make the error message a bit more specific - "The Build File YAML either does not exist or cannot be opened for reading" since `isReadable` checks for both.

Code after:
import com.google.cloud.tools.jib.plugins.common.logging.ConsoleLogger;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.concurrent.Callable;
import picocli.CommandLine;

@CommandLine.Command(
    name = "build",
    showAtFileInUsageHelp = true,
    description = "Build a container")
public class Build implements Callable<Integer> {
  @CommandLine.ParentCommand
  @SuppressWarnings("NullAway.Init") // initialized by picocli
  protected JibCli globalOptions;

  @Override
  public Integer call() {
    globalOptions.validate();

    try {
      ConsoleLogger logger =
          CliLogger.newLogger(globalOptions.getVerbosity(), globalOptions.getConsoleOutput());

      Path buildFile = globalOptions.getBuildFile();
      if (!Files.isReadable(buildFile)) {
        logger.log(
            Level.ERROR,
            "The Build File YAML either does not exist or cannot be opened for reading: "
                + buildFile);
        return 1;
      }
      if (!Files.isRegularFile(buildFile)) {
        logger.log(Level.ERROR, "Build File YAML path is a not a file: " + buildFile);
        return 1;
      }

      Containerizer containerizer = Containerizers.from(globalOptions, logger);

      JibContainerBuilder containerBuilder =
          BuildFiles.toJibContainerBuilder(
              globalOptions.getContextRoot(), buildFile, globalOptions, logger);

      containerBuilder.containerize(containerizer);
    } catch (Exception ex) {
      if (globalOptions.isStacktrace()) {
        ex.printStackTrace();
      }
      System.err.println(ex.getClass().getName() + ": " + ex.getMessage());
      return 1;
    }
    return 0;