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

Code before:
   */
  static ImmutableList<String> computeEntrypointForPackagedStandard(Path jarPath)
      throws IOException {
    try (JarFile jarFile = new JarFile(jarPath.toFile())) {
      String mainClass =
          jarFile.getManifest().getMainAttributes().getValue(Attributes.Name.MAIN_CLASS);
      if (mainClass == null) {
        throw new IllegalArgumentException(
            "`Main-Class:` attribute for an application main class not defined in the input JAR's "
                + "manifest (`META-INF/MANIFEST.MF` in the JAR).");
      }
      return ImmutableList.of("java", "-jar", APP_ROOT + "/" + jarPath.getFileName().toString());
    }
  }

  private static List<FileEntriesLayer> getDependenciesLayers(Path jarPath, String mode)
      throws IOException {
    List<FileEntriesLayer> layers = new ArrayList<>();

    // Get dependencies from Class-Path in the jar's manifest and add a layer each for non-snapshot
    // and snapshot dependencies. If Class-Path is not present in the jar's manifest then skip
    // adding the dependencies layers.
    try (JarFile jarFile = new JarFile(jarPath.toFile())) {
      String classPath =
          jarFile.getManifest().getMainAttributes().getValue(Attributes.Name.CLASS_PATH);
      if (classPath != null) {
        Path jarParent = jarPath.getParent() == null ? Paths.get("") : jarPath.getParent();
        Predicate<String> isSnapshot = name -> name.contains("SNAPSHOT");
        List<String> allDependencies = Splitter.onPattern("\\s+").splitToList(classPath.trim());
        List<Path> nonSnapshotDependencies =
            allDependencies
                .stream()
                .filter(isSnapshot.negate())
                .map(Paths::get)
                .collect(Collectors.toList());
        List<Path> snapshotDependencies =
            allDependencies
                .stream()
                .filter(isSnapshot)
                .map(Paths::get)
                .collect(Collectors.toList());
        if (!nonSnapshotDependencies.isEmpty()) {
          FileEntriesLayer.Builder nonSnapshotDependenciesLayerBuilder =
              FileEntriesLayer.builder().setName(DEPENDENCIES);
          nonSnapshotDependencies.forEach(
              path ->
                  addDependency(
                      nonSnapshotDependenciesLayerBuilder,
                      jarParent.resolve(path),
                      mode.equals("packaged")
                          ? APP_ROOT.resolve(path)

Review comment (suggestion):
I think short-circuiting will help readability.
```java
      if (classPath == null) {  // should flip the comparison
        return new ArrayList<>();
      }
      List<FileEntriesLayer> layers = new ArrayList<>();
```

Code after:
   */
  static ImmutableList<String> computeEntrypointForPackagedStandard(Path jarPath)
      throws IOException {
    try (JarFile jarFile = new JarFile(jarPath.toFile())) {
      String mainClass =
          jarFile.getManifest().getMainAttributes().getValue(Attributes.Name.MAIN_CLASS);
      if (mainClass == null) {
        throw new IllegalArgumentException(
            "`Main-Class:` attribute for an application main class not defined in the input JAR's "
                + "manifest (`META-INF/MANIFEST.MF` in the JAR).");
      }
      return ImmutableList.of("java", "-jar", APP_ROOT + "/" + jarPath.getFileName().toString());
    }
  }

  private static List<FileEntriesLayer> getDependenciesLayers(Path jarPath, ProcessingMode mode)
      throws IOException {

    // Get dependencies from Class-Path in the jar's manifest and add a layer each for non-snapshot
    // and snapshot dependencies. If Class-Path is not present in the jar's manifest then skip
    // adding the dependencies layers.
    try (JarFile jarFile = new JarFile(jarPath.toFile())) {
      String classPath =
          jarFile.getManifest().getMainAttributes().getValue(Attributes.Name.CLASS_PATH);
      if (classPath == null) {
        return new ArrayList<>();
      } else {
        List<FileEntriesLayer> layers = new ArrayList<>();
        Path jarParent = jarPath.getParent() == null ? Paths.get("") : jarPath.getParent();
        Predicate<String> isSnapshot = name -> name.contains("SNAPSHOT");
        List<String> allDependencies = Splitter.onPattern("\\s+").splitToList(classPath.trim());
        List<Path> nonSnapshots =
            allDependencies
                .stream()
                .filter(isSnapshot.negate())
                .map(Paths::get)
                .collect(Collectors.toList());
        List<Path> snapshots =
            allDependencies
                .stream()
                .filter(isSnapshot)
                .map(Paths::get)
                .collect(Collectors.toList());
        if (!nonSnapshots.isEmpty()) {
          FileEntriesLayer.Builder nonSnapshotLayer =
              FileEntriesLayer.builder().setName(DEPENDENCIES);
          nonSnapshots.forEach(
              path ->
                  addDependency(
                      nonSnapshotLayer,
                      jarParent.resolve(path),