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

Code before:
   * @return the jar type.
   * @throws IOException if I/O error occurs when opening the file.
   */
  public static JarType determineJarType(Path jarPath) throws IOException {
    JarFile jarFile = new JarFile(jarPath.toFile());
    if (jarFile.getEntry("BOOT-INF") != null) {
      return JarType.SPRING_BOOT;
    }
    return JarType.STANDARD;
  }

  /**
   * Explode jar and create three layers for classes, resources and dependencies on container.
   *
   * @param jarPath path to jar file.
   * @return list of {@link FileEntriesLayer}.
   * @throws IOException if I/O error occurs when opening the file.
   */
  public static List<FileEntriesLayer> explodeStandardJar(Path jarPath) throws IOException {
    TempDirectoryProvider tempDirectoryProvider = new TempDirectoryProvider();
    Path tempDirectoryPath = tempDirectoryProvider.newDirectory();
    ZipUtil.unzip(jarPath, tempDirectoryPath);

    List<FileEntriesLayer> layers = new ArrayList<>();
    Predicate<Path> isClassFile = path -> path.getFileName().toString().endsWith(".class");
    Predicate<Path> isResourceFile = path -> !path.getFileName().toString().endsWith(".class");

    // Determine class and resource files in the directory containing jar contents and create
    // FileEntriesLayer for each type of layer (class or resource), while maintaining the
    // file's original project structure.
    FileEntriesLayer classesLayer =
        addDirectoryContentsToLayer(
                FileEntriesLayer.builder(),
                tempDirectoryPath,
                isClassFile,
                APP_ROOT.resolve(RelativeUnixPath.get("explodedJar")))
            .setName("Classes")
            .build();
    FileEntriesLayer resourcesLayer =
        addDirectoryContentsToLayer(
                FileEntriesLayer.builder(),
                tempDirectoryPath,
                isResourceFile,
                APP_ROOT.resolve(RelativeUnixPath.get("explodedJar")))
            .setName("Resources")
            .build();

    // Get dependencies from Class-Path in the jar's manifest and create a FileEntriesLayer.Builder
    // with these dependencies as entries.
    List<Path> dependencies = new ArrayList<>();
    JarFile jarFile = new JarFile(jarPath.toFile());

Review comment (suggestion):
Another option is `... isResrouceFile = isClassFile.negate()`, which I think works better in this case.

Code after:
   * @param jarPath path to the jar
   * @return the jar type
   * @throws IOException if I/O error occurs when opening the file
   */
  public static JarType determineJarType(Path jarPath) throws IOException {
    JarFile jarFile = new JarFile(jarPath.toFile());
    if (jarFile.getEntry("BOOT-INF") != null) {
      return JarType.SPRING_BOOT;
    }
    return JarType.STANDARD;
  }

  /**
   * Explodes jar and create three layers for classes, resources and dependencies on container.
   *
   * @param jarPath path to jar file
   * @param tempDirPath path to temporary jib local directory
   * @return list of {@link FileEntriesLayer}
   * @throws IOException if I/O error occurs when opening the jar file or if temporary directory
   *     provided doesn't exist
   */
  public static List<FileEntriesLayer> explodeStandardJar(Path jarPath, Path tempDirPath)
      throws IOException {
    Path localExplodedJarRoot = tempDirPath;
    ZipUtil.unzip(jarPath, localExplodedJarRoot);
    List<FileEntriesLayer> layers = new ArrayList<>();

    // Get dependencies from Class-Path in the jar's manifest and add a layer with these
    // dependencies as entries. If Class-Path is not present in the jar's manifest then skip adding
    // a dependencies layer.
    JarFile jarFile = new JarFile(jarPath.toFile());
    String classPath =
        jarFile.getManifest().getMainAttributes().getValue(Attributes.Name.CLASS_PATH);
    if (classPath != null) {
      List<Path> dependencies =
          Splitter.onPattern("\\s+")
              .splitToList(classPath.trim())
              .stream()
              .map(Paths::get)
              .collect(Collectors.toList());
      FileEntriesLayer.Builder dependenciesLayerBuilder =
          FileEntriesLayer.builder().setName("dependencies");
      dependencies.forEach(
          path ->
              dependenciesLayerBuilder.addEntry(
                  path, APP_ROOT.resolve(RelativeUnixPath.get("dependencies")).resolve(path)));
      layers.add(dependenciesLayerBuilder.build());
    }

    Predicate<Path> isClassFile = path -> path.getFileName().toString().endsWith(".class");
    Predicate<Path> isResourceFile = isClassFile.negate();